Skip to content

SILGen: Introduce a new debug scope for GuardStmts [5.4] #35333

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

Conversation

slavapestov
Copy link
Contributor

A GuardStmt can shadow bindings from outer scopes, so make sure
we actually create a new debug scope here.

Note that we push the scope, but pop it when the next innermost
debug scope ends. To keep track of this I added a new bit of state
to the debug scope stack, indicating that this scope originated
from a GuardStmt.

Ideally, debug info would rely on ASTScope which is the canonical
source of truth for this information. For now, this is a spot fix.

I filed rdar://problem/72954242 to track implementing the longer
term solution.

Fixes rdar://problem/72900354.

@slavapestov slavapestov requested a review from a team as a code owner January 9, 2021 04:10
@slavapestov
Copy link
Contributor Author

@adrian-prantl Please take a look.

@slavapestov slavapestov changed the title SILGen: Introduce a new debug scope for GuardStmts SILGen: Introduce a new debug scope for GuardStmts [5.4] Jan 9, 2021
@swift-ci
Copy link
Contributor

swift-ci commented Jan 9, 2021

Build failed
Swift Test Linux Platform
Git Sha - e3ffe5f540c88db8589613c233e82f1ba0d2ee7f

@swift-ci
Copy link
Contributor

swift-ci commented Jan 9, 2021

Build failed
Swift Test OS X Platform
Git Sha - e3ffe5f540c88db8589613c233e82f1ba0d2ee7f

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - e3ffe5f540c88db8589613c233e82f1ba0d2ee7f

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - e3ffe5f540c88db8589613c233e82f1ba0d2ee7f

Copy link
Contributor

@adrian-prantl adrian-prantl left a comment

Choose a reason for hiding this comment

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

Thanks! Few nitpicks inside but otherwise this looks great.

///
/// The boolean tracks whether this is a 'guard' scope, which should be
/// popped automatically when we leave the innermost BraceStmt scope.
std::vector<std::pair<bool, const SILDebugScope *>> DebugScopeStack;
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe use an llvm::PointerIntPair<const SILDebugScope *, 1>?

@@ -590,23 +593,29 @@ class LLVM_LIBRARY_VISIBILITY SILGenFunction
StringRef getMagicFunctionString();

/// Enter the debug scope for \p Loc, creating it if necessary.
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps add something like:

/// \arg isGuardScope marks a scope introduced by a guard let statement. Guard let may used to unwrap an optional and bind it to the same name (as in guard let x = x!). All guard let scopes are popped when their parent lexical scope is popped from DebugScopeStack.

@adrian-prantl
Copy link
Contributor

Looks like @DougGregor needs to sign off for this PR to be mergeable.

@adrian-prantl
Copy link
Contributor

Looks like you are running into the non-contiguous scope SIL verifier.

@adrian-prantl
Copy link
Contributor

Unfortunately its output on the bot is useless since -Xllvm -sil-print-debuginfo is missing 🙄

@adrian-prantl
Copy link
Contributor

If you can post the SIL output (with scopes!) we can see why that is. It should be fairly obvious.

@slavapestov
Copy link
Contributor Author

Thanks for the review, all the suggested changes sound reasonable. I'll nominate the PR once I apply your changes and fix the swiftpm issue.

@slavapestov slavapestov force-pushed the debug-scope-guard-stmt-5.4 branch 2 times, most recently from 069e01a to cbe3ea7 Compare January 12, 2021 00:00
A GuardStmt can shadow bindings from outer scopes, so make sure
we actually create a new debug scope here.

Note that we push the scope, but pop it when the next innermost
debug scope ends. To keep track of this I added a new bit of state
to the debug scope stack, indicating that this scope originated
from a GuardStmt.

Ideally, debug info would rely on ASTScope which is the canonical
source of truth for this information. For now, this is a spot fix.

I filed <rdar://problem/72954242> to track implementing the longer
term solution.

Fixes <rdar://problem/72900354>.
@slavapestov slavapestov force-pushed the debug-scope-guard-stmt-5.4 branch from cbe3ea7 to e9d557a Compare January 12, 2021 03:59
@slavapestov
Copy link
Contributor Author

@swift-ci Please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - e9d557a

@slavapestov
Copy link
Contributor Author

@swift-ci Please test macOS

@slavapestov slavapestov merged commit cffcd9a into swiftlang:release/5.4 Jan 12, 2021
@AnthonyLatsis AnthonyLatsis added swift 5.4 🍒 release cherry pick Flag: Release branch cherry picks labels Jan 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🍒 release cherry pick Flag: Release branch cherry picks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants