Skip to content

Re-implement DebuggerContextChange using a new mechanism #33795

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

Merged
merged 7 commits into from
Sep 3, 2020

Conversation

slavapestov
Copy link
Contributor

Expression evaluation in lldb wraps the entire user-written expression
in a new function body, which puts any new declarations written by the
user in local context.

There is a mechanism where declarations can get moved to the top level,
if they're only valid at the top level (imports, extensions etc), or
if the name of the declaration begins with '$'. This mechanism used to
actually add the declaration to the SourceFile's TopLevelDecls list,
which would break ASTScope invariants about source ranges being
monotonically increasing and non-overlapping.

Instead, we use the new 'hoisted' flag to mark the declarations as
hoisted, which leaves them syntactically in their original location
in the AST, but treats them as top level in SILGen and IRGen.

Part of rdar://problem/53971116.

Expression evaluation in lldb wraps the entire user-written expression
in a new function body, which puts any new declarations written by the
user in local context.

There is a mechanism where declarations can get moved to the top level,
if they're only valid at the top level (imports, extensions etc), or
if the name of the declaration begins with '$'. This mechanism used to
actually add the declaration to the SourceFile's TopLevelDecls list,
which would break ASTScope invariants about source ranges being
monotonically increasing and non-overlapping.

Instead, we use the new 'hoisted' flag to mark the declarations as
hoisted, which leaves them syntactically in their original location
in the AST, but treats them as top level in SILGen and IRGen.

Part of <rdar://problem/53971116>.
@slavapestov
Copy link
Contributor Author

@swift-ci Please smoke test

Copy link
Contributor

@davidungar davidungar left a comment

Choose a reason for hiding this comment

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

This is great stuff! I'd like to see the invariant about the hoisting bit and the hoisted list factored out and also reified with an assertion.

Comment on lines +306 to +309
/// Whether this declaration is syntactically scoped inside of
/// a local context, but should behave like a top-level
/// declaration for name lookup purposes. This is used by
/// lldb.
Copy link
Contributor

Choose a reason for hiding this comment

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

Excellent!

Comment on lines +108 to +110
D->setHoisted();
SF->addHoistedDecl(D);
getDebuggerClient()->didGlobalize(D);
Copy link
Contributor

Choose a reason for hiding this comment

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

There is an invariant here, I'm guessing that these three always go together. If so, how about factoring this out, and lines 118-121 into a separate function? I'm guessing you've also added assertions for the invariant.

Comment on lines +224 to +228
for (auto *D : SF->getTopLevelDecls())
visitTopLevelDecl(D);

for (auto *D : SF->getHoistedDecls())
visitTopLevelDecl(D);
Copy link
Contributor

Choose a reason for hiding this comment

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

This might be the place for the consistency-checking assertion.

@slavapestov
Copy link
Contributor Author

I discussed the suggested improvements with @davidungar offline. We both agree they’re good but I’m going to apply them to a follow-up PR since I have more cleanups in this area and I don’t want to run PR tests again.

@slavapestov slavapestov merged commit 782863c into swiftlang:master Sep 3, 2020
@davidungar
Copy link
Contributor

Works for me! Thanks, @Slava -- this is great stuff!

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

Successfully merging this pull request may close these issues.

3 participants