Skip to content

Remove a stateful workaround for Property Wrappers. #65552

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 1 commit into from
May 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lib/SIL/Verifier/SILVerifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6283,6 +6283,15 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
// inherit the sourrounding scope in IRGenSIL.
if (SI.getLoc().getKind() == SILLocation::MandatoryInlinedKind)
continue;
// FIXME: There are situations where the execution legitimately goes
// backwards, such as
//
// while case let w: String? = Optional.some("b") {}
//
// where the RHS of the assignment gets run first and then the
// result is copied into the LHS.
if (!llvm::isa<BeginBorrowInst>(&SI) || !llvm::isa<CopyValueInst>(&SI))
continue;

// If we haven't seen this debug scope yet, update the
// map and go on.
Expand Down
17 changes: 3 additions & 14 deletions lib/SILGen/SILGenFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,20 +370,9 @@ SILGenFunction::getOrCreateScope(const ast_scope::ASTScopeImpl *ASTScope,
// Decide whether to pick a parent scope instead.
if (ASTScope->ignoreInDebugInfo()) {
LLVM_DEBUG(llvm::dbgs() << "ignored\n");
// FIXME: it would be more deterministic to use
// getOrCreateScope(ASTScope->getParent().getPtrOrNull());
// here. Unfortunately property wrappers rearrange AST
// nodes without marking them as implicit, e.g.:
//
// @Wrapper(a) var v = b
// ->
// let _tmp = Constructor(a, b); var v = _tmp
//
// Since the arguments to Constructor aren't marked as implicit,
// argument b is in the scope of v, but the call to Constructor
// isn't, which correctly triggers the scope hole verifier.
auto *CurScope = B.getCurrentDebugScope();
return CurScope->InlinedCallSite != InlinedAt ? FnScope : CurScope;
auto *ParentScope = getOrCreateScope(ASTScope->getParent().getPtrOrNull(),
FnScope, InlinedAt);
return ParentScope->InlinedCallSite != InlinedAt ? FnScope : ParentScope;
}

// Collapse BraceStmtScopes whose parent is a .*BodyScope.
Expand Down
19 changes: 19 additions & 0 deletions test/DebugInfo/guard-let-scope3.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// RUN: %target-swift-frontend -g -emit-sil %s -parse-as-library -module-name a | %FileCheck %s
public class C {}
public enum MyError : Error {
init() { self.init() }
}
public class S {
private var c = [Int : C?]()
public func f(_ i: Int) throws -> C {
guard let x = c[i], let x else {
// CHECK: sil_scope [[X1:[0-9]+]] { loc "{{.*}}":[[@LINE-1]]:5
// CHECK: sil_scope [[X2:[0-9]+]] { loc "{{.*}}":[[@LINE-2]]:29
// CHECK: debug_value {{.*}} : $Optional<C>, let, name "x", {{.*}}, scope [[X1]]
// CHECK: debug_value %29 : $C, let, name "x", {{.*}}, scope [[X2]]
// CHECK-NEXT: scope [[X2]]
throw MyError()
}
return x
}
}