-
Notifications
You must be signed in to change notification settings - Fork 10.5k
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
Re-implement DebuggerContextChange using a new mechanism #33795
Conversation
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>.
@swift-ci Please smoke test |
There was a problem hiding this 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.
/// 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent!
D->setHoisted(); | ||
SF->addHoistedDecl(D); | ||
getDebuggerClient()->didGlobalize(D); |
There was a problem hiding this comment.
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.
for (auto *D : SF->getTopLevelDecls()) | ||
visitTopLevelDecl(D); | ||
|
||
for (auto *D : SF->getHoistedDecls()) | ||
visitTopLevelDecl(D); |
There was a problem hiding this comment.
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.
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. |
Works for me! Thanks, @Slava -- this is great stuff! |
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.