-
Notifications
You must be signed in to change notification settings - Fork 444
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
Conversation
b3c2597
to
a9b29d0
Compare
17f4942
to
c7b4538
Compare
uint16_t numAllocatedPacketVariables = 0; | ||
|
||
/// Helper function to create a new, unique symbolic packet variable. | ||
/// Keeps track of the allocated packet variables by incrementing @ref |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
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 callToolsVariables::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 ofnextState.createSymbolicVariable
. Now there will not be an error anymore if one uses the wrong call to create a symbolic variable.