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] Remove complete from the model, make it part of the evaluation step instead. #4015

Merged
merged 3 commits into from
Jun 9, 2023

Conversation

fruffy-bfn
Copy link
Contributor

@fruffy-bfn fruffy-bfn commented May 25, 2023

The complete step, which assigns default variables to symbolic variables that are not present in the Z3 model, is redundant. It requires us to keep track of symbolic variables in the execution state, which cost additional memory. Instead, we can just lazily complete a variable at the moment we evaluate it. We simply add a parameter to the evaluate function.

With these changes we can both simplify the model and the execution state. For example, since we do not need to track variable creation any more we will not need the call ExecutionState::createSymbolicVariable and can directly call ToolsVariables::getSymbolicVariable. This means we do not always need an execution state to create a new symbolic variable.

@vlstill With this change, use ToolsVariables::getSymbolicVariable instead of nextState.createSymbolicVariable. Now there will not be an error anymore if one uses the wrong call to create a symbolic variable.

@fruffy fruffy added the p4tools Topics related to the P4Tools back end label May 26, 2023
@fruffy-bfn fruffy-bfn marked this pull request as ready for review June 5, 2023 13:54
@fruffy fruffy changed the title Remove complete from the model, make it part of the evaluation step instead. [P4Testgen] Remove complete from the model, make it part of the evaluation step instead. Jun 5, 2023
uint16_t numAllocatedPacketVariables = 0;

/// Helper function to create a new, unique symbolic packet variable.
/// Keeps track of the allocated packet variables by incrementing @ref
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: No ref in this context.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's a doxygen ref to the member value in the execution state. But I think we have not been writing doxygen comments right 😅 .

const IR::Expression *programPacket) {
// First propagate taint and simplify the packet.
const auto *taintedPacket = programPacket->apply(TaintPropagator(varMap));
// Then create the mask based on the remaining expressions.
const auto *mask = taintedPacket->apply(MaskBuilder());
// Produce the evaluated literal. The hex expression should only have 0 or f.
return completedModel->evaluate(mask);
return evaluatedModel->evaluate(mask, false);
Copy link
Contributor

Choose a reason for hiding this comment

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

There are only few places where this is false, so can't we make it a default argument as true?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have been thinking about this and I would rather make this explicit to force users to think about whether they want to autocomplete values or not.

Copy link
Contributor

@pkotikal pkotikal left a comment

Choose a reason for hiding this comment

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

Looks good!

@fruffy fruffy merged commit ca2e383 into p4lang:main Jun 9, 2023
@fruffy-bfn fruffy-bfn deleted the fruffy/remove_complete branch June 19, 2023 19:47
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.

3 participants