Add lowering support for static_assert#326
Open
devalgupta404 wants to merge 2 commits intop4lang:mainfrom
Open
Add lowering support for static_assert#326devalgupta404 wants to merge 2 commits intop4lang:mainfrom
devalgupta404 wants to merge 2 commits intop4lang:mainfrom
Conversation
asl
requested changes
Mar 9, 2026
|
|
||
| // Ensure the condition is a compile-time constant | ||
| Attribute constAttr; | ||
| if (!matchPattern(args[0], m_Constant(&constAttr))) |
Collaborator
There was a problem hiding this comment.
This should be done differently. Per spec:
these functions require compile-time known values as arguments, thus they can be used to enforce compile-time invariants
So, the condition could really be resolved later and error out here is a premature.
We'd need to low:
- Lower the generic extern call into a (new) op with clear semantics
- Provide evaluation step (we can just constfold out things with positive assertions, but errors must be done in a separate pass to keep context)
Signed-off-by: devalgupta404 <devalgupta4@gmail.com>
Signed-off-by: devalgupta404 <devalgupta4@gmail.com>
a263dec to
ae3988e
Compare
Contributor
Author
|
Hi @asl, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
issue #183
Add lowering support for static_assert in the P4HIRToCoreLib conversion.
First I evaluates the assertion condition at compile time. If the condition is a constant boolean true, the call is replaced with p4hir.const #true. If the condition evaluates to false, a diagnostic (static assertion failed) is emitted during lowering.
Covers Four Test cases
I am using '--split-input-file' to run each cases in an independent module otherwise repeated definations of 'static_assert' will cause duplicate symbol errors.