Skip to content

Commit c3a1c7f

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 6446e64 commit c3a1c7f

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
@@ -144,8 +144,14 @@ SILGenFunction::emitGlobalFunctionRef(SILLocation loc, SILDeclRef constant,
144144
}
145145

146146
auto f = SGM.getFunction(constant, NotForDefinition);
147-
assert(f->getLoweredFunctionTypeInContext(B.getTypeExpansionContext()) ==
148-
constantInfo.SILFnType);
147+
#ifndef NDEBUG
148+
auto constantFnTypeInContext =
149+
SGM.Types.getLoweredType(constantInfo.SILFnType,
150+
B.getTypeExpansionContext())
151+
.castTo<SILFunctionType>();
152+
assert(f->getLoweredFunctionTypeInContext(B.getTypeExpansionContext())
153+
== constantFnTypeInContext);
154+
#endif
149155
if (callPreviousDynamicReplaceableImpl)
150156
return B.createPreviousDynamicFunctionRef(loc, f);
151157
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)