Skip to content

Commit

Permalink
SILGen: Relax assertion that incorrectly tripped on lowered opaque ca…
Browse files Browse the repository at this point in the history
…pture 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.
  • Loading branch information
jckarter committed Sep 14, 2020
1 parent c3f801b commit 023066c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/SILGen/SILGenThunk.cpp
Expand Up @@ -124,8 +124,14 @@ SILGenFunction::emitGlobalFunctionRef(SILLocation loc, SILDeclRef constant,
}

auto f = SGM.getFunction(constant, NotForDefinition);
assert(f->getLoweredFunctionTypeInContext(B.getTypeExpansionContext()) ==
constantInfo.SILFnType);
#ifndef NDEBUG
auto constantFnTypeInContext =
SGM.Types.getLoweredType(constantInfo.SILFnType,
B.getTypeExpansionContext())
.castTo<SILFunctionType>();
assert(f->getLoweredFunctionTypeInContext(B.getTypeExpansionContext())
== constantFnTypeInContext);
#endif
if (callPreviousDynamicReplaceableImpl)
return B.createPreviousDynamicFunctionRef(loc, f);
else
Expand Down
12 changes: 12 additions & 0 deletions test/SILGen/serialized-capture-opaque-type-subst.swift
@@ -0,0 +1,12 @@
// RUN: %target-swift-frontend -disable-availability-checking -emit-silgen -verify %s

public func foo() -> some Any { return 1 }

public struct XY<X, Y> { public init(x: X, y: Y) { fatalError() } }

@inlinable
public func bar() -> () -> Any {
let xy = XY(x: 1, y: foo())

return { xy }
}

0 comments on commit 023066c

Please sign in to comment.