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

[do not merge]: replace typeMap->constants with IR-based constants #526

Closed
wants to merge 2 commits into from

Conversation

cc10512
Copy link
Contributor

@cc10512 cc10512 commented Apr 26, 2017

This PR attempts to replace the typeMap->isCompileTimeConstant/setCompileTimeConstant with that functionality handled by IR nodes.

Note that less than half of all tests pass with this change. Most fail with the dreaded:

terminating with uncaught exception of type Util::CompilerBug: COMPILER BUG: ../frontends/p4/typeChecking/typeChecker.cpp:118
<P4Program>(19779): typechecker mutated node <P4Program>(17743)

@mbudiu-vmw: I need help in figuring out which of the IR nodes in typeChecker is missing the right information. I traced all the changes and they seem to capture all the places where constants were set. For one of the test cases (testdata/p4_16_samples/inline-stack-bmv2.p4), I tracked this down to invoking the apply method on the aux instance in the sequence below. Commenting out the aux.apply line allows the program to go through.

control X {
  Aux();
  apply {
     aux.apply(hdr);
  }
}

Calin Cascaval added 2 commits April 25, 2017 22:09
Defines a member in the IRCompileTimeValue class to
determine whether the node is a compile time constant.
…ants

This commit eliminates the use of the typeMap->constants to keep track
of compile time constants, and relies on the IR nodes to know whether
they are constants themselves. There are a couple of instances
(Members and PathExpressions) where the compile time constantness is
defined by the type declaration. In this case we add a method just to
those nodes to give them the ability to be set as constants.
@cc10512 cc10512 requested a review from mihaibudiu April 26, 2017 05:22
Copy link
Contributor

@mihaibudiu mihaibudiu left a comment

Choose a reason for hiding this comment

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

The information about whether something is a compile-time constant is only used during type-checking. So I think that storing it in the IR is overkill. You just need to compute a set<IR::Node> for all nodes that are compile-time constants. This information is used to reject programs that are malformed and is no longer used afterwards. This probably can be factored into an Inspector pass.

BTW: this is the whole point of the visitor pattern: you (almost never) need to change the IR.

@cc10512
Copy link
Contributor Author

cc10512 commented Apr 27, 2017

Actually it should be used in constantFolding, no?
Also seems to be used in sideEffects, and I would expect to use it in the backend as well.

@mihaibudiu
Copy link
Contributor

No, constant folding maps nodes to actual values.
This pass only implements section 16.1 from the Spec, "compile-time known values". It only checks to see whether all arguments for directionless parameters can be evaluated statically. It is logically part of type-checking.

SideEffects does not need this, it just updates the information so it remains correct.
None of the public back-ends uses this information.

@sethfowler
Copy link
Contributor

Leaving aside the issue of whether we should do this, this came up again today and I thought it might be worth recording here that "isLeftValue()" is something else we could store directly on the nodes instead of in a table if we so chose.

@ChrisDodd
Copy link
Contributor

ChrisDodd commented Jun 21, 2017 via email

@mihaibudiu
Copy link
Contributor

@cc10512 : are you still interested to refactor this piece of code?
We can file an issue about it and close this PR.

@mihaibudiu
Copy link
Contributor

Since this is 3 years old I will close it.

@mihaibudiu mihaibudiu closed this Apr 9, 2020
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.

4 participants