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

[P4Testgen] Run typechecking after front and mid end. #4834

Merged
merged 1 commit into from
Oct 31, 2024

Conversation

fruffy
Copy link
Collaborator

@fruffy fruffy commented Jul 26, 2024

Ensure that the program is still well-typed at this step. In some scenarios it can happen that a front or mid end pass leaves typing information incomplete or inaccurate which requires a rerun of type checking. There is no invariant enforcing well-typedness of the program.

@fruffy fruffy added the p4tools Topics related to the P4Tools back end label Jul 26, 2024
@fruffy fruffy requested review from vlstill and removed request for vlstill July 26, 2024 01:21
@fruffy fruffy marked this pull request as draft July 26, 2024 02:23
@fruffy fruffy force-pushed the fruffy/testgen_typechecking branch 2 times, most recently from f496c1d to 4f16467 Compare August 15, 2024 09:34
@fruffy fruffy force-pushed the fruffy/testgen_typechecking branch from 4f16467 to 2066243 Compare October 24, 2024 20:24
@fruffy fruffy marked this pull request as ready for review October 24, 2024 20:25
@fruffy fruffy requested a review from vlstill October 24, 2024 20:25
Copy link
Contributor

@vlstill vlstill left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no invariant enforcing well-typedness of the program.

yep. I was thinking we should have a way to turn something like that for debug build. The hardest part is probably where it should run, as in some cases there can be a set of passes that between them don't have well-typed P4 and it becomes well-typed only at the end.

Comment on lines 69 to 71
/// Add passes that break type checking. These passes may involve IR modifications the front
/// end type checker does not recognize.
virtual void addNonTypeCheckingPasses();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the problem here? It seems very suspicious to have IR that does not type check. If this is because of custom IR nodes, it might be better to use a derived type check that supports them. Or at least (for now?) comment more on the reasons why this does not type check.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the passes contained in this list perform transformations that are useful for the interpreter but TypeChecking can fail on.

The two most problematic ones is the HSIndexSimplifier which converts array indices to members and ConvertVarbits which creates a new varbit type that is not recognized.

CastBooleanTableKeys converts boolean table keys to bit<1>, which type checking also might not support (I have not checked).

All these passes could be handled in the interpreter but it might be a fair bit of work.

@fruffy fruffy force-pushed the fruffy/testgen_typechecking branch from 2066243 to 80bcd03 Compare October 29, 2024 00:02
@fruffy fruffy requested a review from vlstill October 30, 2024 17:03
@fruffy fruffy added this pull request to the merge queue Oct 31, 2024
Merged via the queue into main with commit 8ab8b7d Oct 31, 2024
19 checks passed
@fruffy fruffy deleted the fruffy/testgen_typechecking branch October 31, 2024 13:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p4tools Topics related to the P4Tools back end
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants