Skip to content

Commit 6860238

Browse files
Merge pull request #65552 from adrian-prantl/108736443
Remove a stateful workaround for Property Wrappers.
2 parents e1ff376 + dcd881e commit 6860238

File tree

3 files changed

+31
-14
lines changed

3 files changed

+31
-14
lines changed

lib/SIL/Verifier/SILVerifier.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6311,6 +6311,15 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
63116311
// inherit the sourrounding scope in IRGenSIL.
63126312
if (SI.getLoc().getKind() == SILLocation::MandatoryInlinedKind)
63136313
continue;
6314+
// FIXME: There are situations where the execution legitimately goes
6315+
// backwards, such as
6316+
//
6317+
// while case let w: String? = Optional.some("b") {}
6318+
//
6319+
// where the RHS of the assignment gets run first and then the
6320+
// result is copied into the LHS.
6321+
if (!llvm::isa<BeginBorrowInst>(&SI) || !llvm::isa<CopyValueInst>(&SI))
6322+
continue;
63146323

63156324
// If we haven't seen this debug scope yet, update the
63166325
// map and go on.

lib/SILGen/SILGenFunction.cpp

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -370,20 +370,9 @@ SILGenFunction::getOrCreateScope(const ast_scope::ASTScopeImpl *ASTScope,
370370
// Decide whether to pick a parent scope instead.
371371
if (ASTScope->ignoreInDebugInfo()) {
372372
LLVM_DEBUG(llvm::dbgs() << "ignored\n");
373-
// FIXME: it would be more deterministic to use
374-
// getOrCreateScope(ASTScope->getParent().getPtrOrNull());
375-
// here. Unfortunately property wrappers rearrange AST
376-
// nodes without marking them as implicit, e.g.:
377-
//
378-
// @Wrapper(a) var v = b
379-
// ->
380-
// let _tmp = Constructor(a, b); var v = _tmp
381-
//
382-
// Since the arguments to Constructor aren't marked as implicit,
383-
// argument b is in the scope of v, but the call to Constructor
384-
// isn't, which correctly triggers the scope hole verifier.
385-
auto *CurScope = B.getCurrentDebugScope();
386-
return CurScope->InlinedCallSite != InlinedAt ? FnScope : CurScope;
373+
auto *ParentScope = getOrCreateScope(ASTScope->getParent().getPtrOrNull(),
374+
FnScope, InlinedAt);
375+
return ParentScope->InlinedCallSite != InlinedAt ? FnScope : ParentScope;
387376
}
388377

389378
// Collapse BraceStmtScopes whose parent is a .*BodyScope.

test/DebugInfo/guard-let-scope3.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// RUN: %target-swift-frontend -g -emit-sil %s -parse-as-library -module-name a | %FileCheck %s
2+
public class C {}
3+
public enum MyError : Error {
4+
init() { self.init() }
5+
}
6+
public class S {
7+
private var c = [Int : C?]()
8+
public func f(_ i: Int) throws -> C {
9+
guard let x = c[i], let x else {
10+
// CHECK: sil_scope [[X1:[0-9]+]] { loc "{{.*}}":[[@LINE-1]]:5
11+
// CHECK: sil_scope [[X2:[0-9]+]] { loc "{{.*}}":[[@LINE-2]]:29
12+
// CHECK: debug_value {{.*}} : $Optional<C>, let, name "x", {{.*}}, scope [[X1]]
13+
// CHECK: debug_value %29 : $C, let, name "x", {{.*}}, scope [[X2]]
14+
// CHECK-NEXT: scope [[X2]]
15+
throw MyError()
16+
}
17+
return x
18+
}
19+
}

0 commit comments

Comments
 (0)