Skip to content

Commit 023066c

Browse files
committed
SILGen: Relax assertion that incorrectly tripped on lowered opaque capture types.
When lowering the SILConstantInfo for a closure implementation type with captures, we are more conservative about substituting opaque types in the capture, since the underlying types may only be available in the local context. This means the SILConstantInfo type may not in fact be exactly what you get from `SILFunction::getFunctionTypeInContext` referencing the implementation function from its originating context, since those opaque types will be substituted in the local context. Fixes SR-13480 | rdar://problem/68159831.
1 parent c3f801b commit 023066c

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

lib/SILGen/SILGenThunk.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,14 @@ SILGenFunction::emitGlobalFunctionRef(SILLocation loc, SILDeclRef constant,
124124
}
125125

126126
auto f = SGM.getFunction(constant, NotForDefinition);
127-
assert(f->getLoweredFunctionTypeInContext(B.getTypeExpansionContext()) ==
128-
constantInfo.SILFnType);
127+
#ifndef NDEBUG
128+
auto constantFnTypeInContext =
129+
SGM.Types.getLoweredType(constantInfo.SILFnType,
130+
B.getTypeExpansionContext())
131+
.castTo<SILFunctionType>();
132+
assert(f->getLoweredFunctionTypeInContext(B.getTypeExpansionContext())
133+
== constantFnTypeInContext);
134+
#endif
129135
if (callPreviousDynamicReplaceableImpl)
130136
return B.createPreviousDynamicFunctionRef(loc, f);
131137
else
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// RUN: %target-swift-frontend -disable-availability-checking -emit-silgen -verify %s
2+
3+
public func foo() -> some Any { return 1 }
4+
5+
public struct XY<X, Y> { public init(x: X, y: Y) { fatalError() } }
6+
7+
@inlinable
8+
public func bar() -> () -> Any {
9+
let xy = XY(x: 1, y: foo())
10+
11+
return { xy }
12+
}

0 commit comments

Comments
 (0)