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

Data space scoping #22

Open
Aaron3154518 opened this issue Jul 27, 2021 · 4 comments
Open

Data space scoping #22

Aaron3154518 opened this issue Jul 27, 2021 · 4 comments

Comments

@Aaron3154518
Copy link
Collaborator

Not sure if this is an issue or not:

Different scopes can have two distinct variables (data spaces) with the same name. However all data spaces in the Computation class are given the same scope. This creates two distinct data spaces which are treated as one due to having the same name. We need to produce two differently named data spaces.
We can implement this using a static integer counter. Every time we hit a redeclared variable in a new scope, rename it and every use of it within that current scope to var__v{counter}.

Example:

int foo = 0;
if (condition) { int foo = 1; } // different scope is not recognized in Computation
print (foo); // Should be 0, not 1.

Would become:

int foo = 0;
if (condition) { int foo__v1 = 1; } // different scope is not recognized, but variable is renamed so it's all good
print(foo);
@riftEmber
Copy link
Member

Per meeting with Dr. O today, declaring a variable inside a nested scope should be disallowed. Upon encountering it spf-ie should error and exit.

@riftEmber riftEmber changed the title Data space scoping Data space scoping (don't allow decls in nested scopes) Sep 22, 2021
@riftEmber
Copy link
Member

How does this work for nested computations, which will very often have a decl inside a scope

@riftEmber riftEmber changed the title Data space scoping (don't allow decls in nested scopes) Data space scoping Nov 18, 2021
@riftEmber
Copy link
Member

riftEmber commented Nov 18, 2021

Per today's meeting, spf-ie will fail upon encountering a declaraction with a name that matches an existing data space. This applies whether the declaration shadows an existing one, or if they are in different non-nested scopes.
Because of this solution, declarations inside scopes besides the top-level are ok.
Due to renaming this issue will never come up for nested computations.

@riftEmber
Copy link
Member

Implemented in b8e0810

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants