-
Notifications
You must be signed in to change notification settings - Fork 30
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
FS-25 Try 2 #13
FS-25 Try 2 #13
Conversation
…strumentationContext; Add set of all known names from all source units to NameGenerator, and capability to avoid collisions
…ility contract (in generateUtilsContract). Convert the __scribble_check_state_invariants, __scribble_out_of_contract and __scribble_ReentrancyUtils constants into nameGenerator accesses.
…ctionInstrumenter.insertEnterMarker, FunctionInstrumetner.insertExitMarker to use TranspilingContext; Convert naming of temp bindings struct fields to use TranspilingContext to avoid collisions;
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. Just a smaller suggestion.
@@ -0,0 +1,39 @@ | |||
export class NameGenerator { | |||
private counters: { [base: string]: number }; |
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.
We can use the object here, ofcourse. But would be cool to have a Map<string, number>
instead. It may have some builerplate code, but on large amount of keys it would be more efficient.
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
This PR is based on work done by @norhh here #11. The previous PR did a lot of good work to uncover all of the places we need to fix to handle shadowing. However, the fixes in that PR were complicated by the fact that a lot of the code they touched was not well written (by me) and over-complicated. This got in the way of fixing.
In this PR we attempt to first fix the problems in the code, and then to add code to handle the various cases of name collisions/shadowing. In detail:
Convert the
InstrumentationContext
interface into its own utility class. TheInstrumentationContext
class is responsible for keeping toghether all state shared between the instrumentation of all invariantsRename
UIDGenerator
to the betterNameGenerator
and move it inside ofInstrumentationContext
(it used to be a global var)Add the
existingNames
field toNameGenerator
to allow it to avoid all names that existed in the original ASTConvert several constants from global constant strings into fields of
InstrumentationContext
. Furthermore the values of these fields were obtained by calling intoNameGenerator
. This guarantees that they wont overlap with existing names, and all future instrumentation names wont conflict with them. This includes:SCRIBBLE_VAR
->InstrumentationContext.structVar
REENTRANCY_UTILS_CONTRACT
->InstrumentationContext.utilsContractName
CHECK_STATE_INVS_FUN
->InstrumentationContext.checkStateInvsFuncName
OUT_OF_CONTRACT
->InstrumentationContext.outOfContractFlagName
Introduced the
InstrumentationContext.internalInvariantCheckers
map and corresponding functiongetInternalInvariantCheckerName(ContractDefinition)
to generate names for the internal contract-invariant checker helper function without collisions.Changed the code in
interpose(..)
to useNameGenerator
when renaming the original functions to avoid collisionsAdded the
TranspilingContext
class. It contains the state that is need to compile JUST the annotations for one function/contract. This includes a reference toInstrumentationContext
, as well as the typing and semantic information for the group of annotations for the given function/contract.Changed
flattenExpr
andgenerateExpressions
to take aTranspilingContext
instead of the jumble of arguments they had beforeChanged the flattening and AST generation code to use
TranspilingContext
when computing field names for let-bindings, internal let-vars, internal old-vars as well as some other internals such as the scratch field (what used to beMSTORE_SCRATCH_FIELD
) and theCHECK_INVS_AT_END
flag.Added tests (see
test/samples/increment_inherited_collision.sol
).