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

Scope logic in base Visitor class #17

Closed
pjattke opened this issue Apr 28, 2020 · 1 comment
Closed

Scope logic in base Visitor class #17

pjattke opened this issue Apr 28, 2020 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@pjattke
Copy link
Contributor

pjattke commented Apr 28, 2020

The base Visitor implements the scope logic that defines when a new scope is opened or an existing one is closed. The scopes build a hierarchy, i.e., scopes are linked with each other while a scope refers to an outer scope and one or multiple nested scopes. This hierarchy is determined while visiting the statements, hence it is important that the classes call the base Visitor's visit method.

The initial design did not take into account that moving nodes may require updating the scope hierarchy. This is important as searching for a variable's value may otherwise fail if a variable declared in an outer scope cannot be found.

Also, sometimes nodes are visited out of order, for example, during partial loop unrolling in the CompileTimeExpressionSimplifier. This was not considered either. As an example, look into the doPartialLoopUnrolling method that moves the For loop's initializer into a Block but visits the initializer directly by skipping the block statement. This causes a wrongly assigned variable scope (but does not lead to break partial unrolling).

@pjattke pjattke added the bug Something isn't working label Apr 28, 2020
@AlexanderViand AlexanderViand self-assigned this Nov 10, 2020
@AlexanderViand AlexanderViand added check required Unconfirmed issues or suspicions requiring investigation and removed check required Unconfirmed issues or suspicions requiring investigation labels Nov 10, 2020
@AlexanderViand
Copy link
Collaborator

This has been resolved in v2.0, where there are now functions ScopedVisitor::enterScope, ScopedVisitor::visitChildren and ScopedVisitor::exitScope that can be used by Visitors derived from the basic visitor to manually decide when to enter/not enter a scope. This doesn't eliminate the possibility of these kinds of issues occurring, but it does provide the tool to prevent and/or fix them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants