Skip to content

Commit e083490

Browse files
committed
SIL: Fix opaque type erasure after clearing [serialized] flags
After serialization, we no longer need to enforce the resilience boundary between inlinable and non-inlinable functions, so we make a pass over the SIL to clear [serialized] flags and substitute any opaque return types. The logic for AST types was wrong; we can't just lower the type and get the AST type out. Instead, do the same thing that TypeSubstCloner does. Fixes rdar://problem/115355709.
1 parent 3dcb1d8 commit e083490

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

lib/SILOptimizer/UtilityPasses/SerializeSILPass.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@ class MapOpaqueArchetypes : public SILCloner<MapOpaqueArchetypes> {
5757
.getTypeExpansionContext()
5858
.shouldLookThroughOpaqueTypeArchetypes())
5959
return ty;
60-
// Remap types containing opaque result types in the current context.
61-
return getBuilder()
62-
.getTypeLowering(SILType::getPrimitiveObjectType(ty))
63-
.getLoweredType()
64-
.getASTType();
60+
61+
return substOpaqueTypesWithUnderlyingTypes(
62+
ty,
63+
TypeExpansionContext(getBuilder().getFunction()),
64+
/*allowLoweredTypes=*/false);
6565
}
6666

6767
ProtocolConformanceRef remapConformance(Type ty,
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend -emit-module %s
3+
4+
// We substitute away opaque archetypes after serialization;
5+
// make sure this correctly handles unlowered types like
6+
// AST functions and packs.
7+
8+
public func horse<T>(_: T) {}
9+
10+
@_transparent public func packCallee<each T>(_ t: repeat each T) {
11+
repeat horse(each t)
12+
}
13+
14+
@inlinable public func packCaller() {
15+
packCallee(opaque())
16+
}
17+
18+
public func opaque() -> some Any { return 3 }

0 commit comments

Comments
 (0)