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

Report offending node in the type-checker immutability check #4238

Merged
merged 3 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions frontends/p4/typeChecking/typeChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,21 @@ Visitor::profile_t TypeInference::init_apply(const IR::Node *node) {
}

void TypeInference::end_apply(const IR::Node *node) {
if (readOnly && !(*node == *initialNode)) {
BUG("At this point in the compilation typechecking "
"should not infer new types anymore, but it did.");
}
BUG_CHECK(!readOnly || node == initialNode,
"At this point in the compilation typechecking should not infer new types anymore, "
"but it did.");
typeMap->updateMap(node);
if (node->is<IR::P4Program>()) LOG3("Typemap: " << std::endl << typeMap);
Transform::end_apply(node);
}

const IR::Node *TypeInference::apply_visitor(const IR::Node *orig, const char *name) {
const auto *transformed = Transform::apply_visitor(orig, name);
BUG_CHECK(!readOnly || orig == transformed,
"At this point in the compilation typechecking should not infer new types anymore, "
"but it did: node %1% changed to %2%",
orig, transformed);
return transformed;
}

TypeInference *TypeInference::clone() const {
Expand Down
1 change: 1 addition & 0 deletions frontends/p4/typeChecking/typeChecker.h
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ class TypeInference : public Transform {

Visitor::profile_t init_apply(const IR::Node *node) override;
void end_apply(const IR::Node *Node) override;
const IR::Node *apply_visitor(const IR::Node *, const char *name = 0) override;

TypeInference *clone() const override;
// Apply recursively the typechecker to the newly created node
Expand Down
Loading