Fixed bug with dynamic variables escaping static scopes getting diffe… #60
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
…rent names
BuildIt has had a bug with assimilating equivalent variables for a long time. The bug was very rare but shows up when using coroutines with BuildIt. New sample54 demonstrates the bug.
would originally produce -
This happens when the same variable is created with different static tags on separate runs (due to static variable being set inside a branch). This creates a problem when the static var state converges. Since all static variables and static locations are the same, BuildIt happily merges execution from this point onwards. But only one of the two copies of the variable is used which either produces code that doesn't compile or misses updates to variables.
A somewhat simple fix is to identify variables based only on their static location and not the entire tag. This change combined with existing variable hoisting makes sure that the variable is declared upfront and set separately on the two branches. This makes sure that the changes are recorded properly. This simple fix however causes unnecessary merging and hoisting of variables that do not escape the static scope.
As a work around, we now identify variables that escape the scope. This is done by matching the static state at use and decl. Variables that escape static scope get a special metadata. Var Namer then looks for this metadata and any variable with this metadata is identified purely on the basis on static location and not the entire static tag. Thus variables are only merged and hoisted when absolutely necessary.
Finally, this creates a problem with
dyn_arr<T>
since they are supposed to escape the scope of their declarations. Rememberdyn_arr<T>
are heap allocated and the constructor is called with a static_var loop. To get around this elements indyn_arr<T>
get another metadata that allows them to escape static scope. These variables are identified on the basis on their entire static tag.With the changes the sample above now produces -
TODO: Investigate if
dyn_arr<T>
could have forking issues and fix if necessary.