Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Signal: use reset.value if that field exists. #294

Closed
wants to merge 1 commit into from
Closed

Signal: use reset.value if that field exists. #294

wants to merge 1 commit into from

Conversation

Fatsie
Copy link
Contributor

@Fatsie Fatsie commented Jan 5, 2020

This will allow a Const or an Enum to be passed as reset value when calling Signal().

This will allow a Const or an Enum to be passed as reset value.
@codecov
Copy link

codecov bot commented Jan 5, 2020

Codecov Report

Merging #294 into master will decrease coverage by 0.02%.
The diff coverage is 0%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master    #294      +/-   ##
=========================================
- Coverage   82.13%   82.1%   -0.03%     
=========================================
  Files          34      34              
  Lines        5647    5649       +2     
  Branches     1160    1161       +1     
=========================================
  Hits         4638    4638              
- Misses        864     865       +1     
- Partials      145     146       +1
Impacted Files Coverage Δ
nmigen/hdl/ast.py 86.99% <0%> (-0.2%) ⬇️
nmigen/tracer.py 94.59% <0%> (ø) ⬆️
nmigen/hdl/ir.py 94.43% <0%> (ø) ⬆️
nmigen/back/pysim.py 92.32% <0%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 476ce15...4640f87. Read the comment docs.

@whitequark
Copy link
Contributor

I think this is not the right approach. There are several issues:

  1. Sure, Python uses duck typing, but it doesn't mean you can use arbitrary properties of objects without considering what interface they implement. That there are both Const.value and Enum.value is a complete coincidence: they were never intended to implement the same interface. This is in contrast with something like a "file-like object", where there's a reasonably well-defined interface anyone can comply with.
  2. I'm not actually sure if handling Const as a reset value is the right thing to do. Right now it is clear what values are valid as reset values: literals. If we allow ASTs there, then it raises a question of whether we should allow constant expressions or even arbitrary expressions. Should Const(123, 8)[:4] be allowed as a reset value? Should other_comb_sig + 10 be?

That said, allowing integral Enum values is obviously the right choice here. Feel free to send another PR implementing that or opening an issue and I'll implement it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants