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

Variable capture: synchronize with aliases in nested scopes #14035

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

asgerf
Copy link
Contributor

@asgerf asgerf commented Aug 23, 2023

When a variable refers to a closure, we emulate what would happen if that closure had been inlined at that point.

var x
fun one() {
  use x;
}
fun two() {
  one() // if 'one' was to be inlined here, then 'two' would also capture 'x'
}

@asgerf asgerf marked this pull request as ready for review August 24, 2023 11:00
@asgerf asgerf requested a review from a team as a code owner August 24, 2023 11:00
@asgerf asgerf changed the title Variable capture: synchronize with aliases in nested scoped Variable capture: synchronize with aliases in nested scopes Aug 24, 2023
@@ -562,7 +583,7 @@ module Flow<InputSig Input> implements OutputSig<Input> {

/**
* Holds if `access` is a reference to `ce` evaluated in the `i`th node of `bb`.
* The reference is restricted to be in the same callable as `ce` as a
* The reference is restricted to be nested within the same callable as `ce` as a
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this update, I'd like this predicate renamed from localClosureAccess to localOrNestedClosureAccess. Or something like this - the "local" prefix certainly is no longer true.

result = bb.getEnclosingCallable() and
// The reference to `ce` is allowed to occur in a more deeply nested context
closureExprGetEnclosingCallable(ce) = callableGetEnclosingCallable*(result)
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we merge closureExprGetAReferencingCallable and closureExprGetCallable into one predicate, please? I.e. add the following here:

Suggested change
)
)
or
result = closureExprGetEnclosingCallable(ce)

@@ -391,16 +391,6 @@ module Flow<InputSig Input> implements OutputSig<Input> {
msg = "ClosureExpr has no body" and not ce.hasBody(_)
}

query predicate closureAliasMustBeLocal(ClosureExpr ce, Expr access, string msg) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps, instead of deleting this check, could we update it to check that all aliases are either local or in a nested scope? Since that's what we now rely on.

Copy link
Contributor

@aschackmull aschackmull left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

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

Successfully merging this pull request may close these issues.

None yet

2 participants