Add warning for stray standalone is statements#431
Add warning for stray standalone is statements#431lwaern-intel wants to merge 3 commits intointel:mainfrom
Conversation
py/dml/messages.py
Outdated
| or | ||
| ``` | ||
| field f @ [31:0]; | ||
| is read_only; |
There was a problem hiding this comment.
as you could probably guess it's this second part that first led me down the lexpos rabbit hole. though when I realized it was also why all error messages have been screwed up since forever, it kinda got personal
|
DML Verification : 6: ❌ failure |
|
DML Verification : 7: ❌ failure |
f9566ba to
16131c6
Compare
|
PR Verification: ❌ failure |
|
PR Verification: ✅ success |
|
Dealing with lexical details from the parser has a somewhat unhygienic smell about it; perhaps a different approach might be to do an isolated check on lexer level, essentially the equivalent of
|
16131c6 to
abb7346
Compare
abb7346 to
1250a27
Compare
|
PR Verification: ✅ success |
|
PR Verification: ✅ success |
3659e2f to
67dc202
Compare
The Working on the In addition I'll note this is not completely without precedence, as |
There was a problem hiding this comment.
Pull request overview
This PR improves source-location accuracy in the DML parser (especially around empty productions) and adds a new warning to catch likely-mistaken standalone is statements that appear to be intended to modify the immediately preceding object declaration.
Changes:
- Track the latest lexed token during parsing and fix up
lexposfor empty productions to improve reported line/column locations. - Add warning
WSTRAYISplus parser-side detection to flag suspicious standaloneisstatements. - Add regression tests (DML error test + Python unit test) and document the behavior in release notes.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| test/1.4/errors/T_WSTRAYIS.dml | Adds an errors/warnings test case covering the new WSTRAYIS warning. |
| RELEASENOTES.md | Documents the lexpos fix impact and the new stray-is warning. |
| py/dml/toplevel.py | Passes a custom tokenfunc into PLY parsing to enable latest-token tracking. |
| py/dml/messages.py | Introduces the WSTRAYIS warning definition and message text. |
| py/dml/logging.py | Adds colno to Site and adjusts FileInfo state serialization and column calculation. |
| py/dml/dmlparse.py | Implements empty-production lexpos fixups and adds the stray-is detection pass. |
| py/dml/dmlparse_test.py | Adds unit tests to enforce empty-production fixups and validate site/column behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
67dc202 to
b59c88b
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
b59c88b to
085765a
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
181d853 to
e8c9923
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 7 out of 7 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
PR Verification: ✅ success |
e8c9923 to
b9e5e66
Compare
|
PR Verification: ✅ success |
b9e5e66 to
1e2148d
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Previous iteration went with the stance of "as long as multiple declarations are on the same line, assume SOMETHING is messed up, no matter what the declarations are." This is not necessarily a wrong stance to take, trouble is that in those cases emitting `WSTRAYIS` runs a risk of hurting rather than helping; see the updated tests.
1e2148d to
d420403
Compare
| for (i, stmt) in enumerate(body): | ||
| if stmt.kind == 'object': | ||
| (_, obj_type, _, _, obj_body) = stmt.args | ||
| rough_end_site = (obj_body and obj_body[-1].site) or stmt.site |
There was a problem hiding this comment.
the if expression is the idiomatic construct you are looking for
There was a problem hiding this comment.
but i like abusing boolean operators!
bah, fine
There was a problem hiding this comment.
In truth, this was an artifact from my early development of this PR; i I had a reason to do it this way rather than if expressions, because this way I also catch if obj_body[-1].site is None. Since then, however, I realized that isn't possible in the cases stray_is_check is meant to be used.
| if stmt.kind == 'object': | ||
| (_, obj_type, _, _, obj_body) = stmt.args | ||
| rough_end_site = (obj_body and obj_body[-1].site) or stmt.site | ||
| j = i+1 |
There was a problem hiding this comment.
I would say each call to stray_is_check in the parser deserves one case here. I think this is the main cost of doing it in the parser instead of the lexer, and looks like it's a small cost. This convinces me that your approach is better than a lexer based, whose impl would probably get messier.
I think there is an intrinsic value in these test cases: it concretizes the things we warn for, and lets us contemplate if you can conceive use cases where a stray is can make sense.
One interesting example I can think of is:
connect x { interface y; is z; }
where I would say it is highly unlikely that is z is intended for the interface, assuming the code compiles (because the only templates that are applicable to both connect and interface are the generic ones like init and hard_reset, and these are seldom applicable on interface objects). So this is a way to trigger a WSTRAYIS that not really is helpful. (this is not intended as an argument against your PR, it is just an interesting corner to contemplate).
Still, you can argue that connect x is z { interface y; } is a more idiomatic way to phrase the same, so the warning is not really wrong. With that in mind, a different way to approach the original problem could be to stricten the style rule further, and enforce (by warning) that standalone is statements within a block should appear before subobject declarations. Which would be way more controversial warning, so it is clearly outside the scope of this PR.
I was thinknig of analyzing the token stream directly. We do that sometimes in |
Depends on #430; only the latter two commits shown in this PR are relevant for review.