Skip to content

Commit 9729868

Browse files
Merge pull request #25659 from aschwaighofer/ReplaceOpaqueTypesWithUnderlyingTypes_primary_file_mode-5.1
[5.1] ReplaceOpaqueTypesWithUnderlyingTypes: In primary-file mode the…
2 parents 5b6f987 + ff3f0e5 commit 9729868

File tree

3 files changed

+37
-5
lines changed

3 files changed

+37
-5
lines changed

lib/AST/Type.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2563,10 +2563,10 @@ operator()(SubstitutableType *maybeOpaqueType) const {
25632563
}
25642564

25652565
auto subs = opaqueRoot->getDecl()->getUnderlyingTypeSubstitutions();
2566-
// TODO: Check the resilience expansion, and handle opaque types with
2567-
// unknown underlying types. For now, all opaque types are always
2568-
// fragile.
2569-
assert(subs.hasValue() && "resilient opaque types not yet supported");
2566+
// If the body of the opaque decl providing decl has not been type checked we
2567+
// don't have a underlying subsitution.
2568+
if (!subs.hasValue())
2569+
return maybeOpaqueType;
25702570

25712571
// Apply the underlying type substitutions to the interface type of the
25722572
// archetype in question. This will map the inner generic signature of the
@@ -2614,7 +2614,10 @@ operator()(CanType maybeOpaqueType, Type replacementType,
26142614
}
26152615

26162616
auto subs = opaqueRoot->getDecl()->getUnderlyingTypeSubstitutions();
2617-
assert(subs.hasValue());
2617+
// If the body of the opaque decl providing decl has not been type checked we
2618+
// don't have a underlying subsitution.
2619+
if (!subs.hasValue())
2620+
return abstractRef;
26182621

26192622
// Apply the underlying type substitutions to the interface type of the
26202623
// archetype in question. This will map the inner generic signature of the
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
@inline(never)
2+
func bar2(_ x: Int) -> some P {
3+
return x
4+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend -O -Xllvm -enable-opaque-archetype-specializer -disable-availability-checking -primary-file %s %S/Inputs/specialize_opaque_type_archetypes_multifile_A.swift -emit-sil | %FileCheck %s
3+
4+
protocol P {}
5+
6+
extension Int : P {}
7+
8+
struct Pair {
9+
var x: Int64 = 0
10+
var y: Int64 = 0
11+
}
12+
13+
extension Pair : P {}
14+
15+
@inline(never)
16+
func bar(_ x: Int) -> some P {
17+
return x
18+
}
19+
20+
// CHECK-LABEL: sil @$s43specialize_opaque_type_archetypes_multifile4testyyF : $@convention(thin) () -> () {
21+
// CHECK: function_ref @$s43specialize_opaque_type_archetypes_multifile4bar2yQrSiF : $@convention(thin) (Int) -> @out @_opaqueReturnTypeOf("$s43specialize_opaque_type_archetypes_multifile4bar2yQrSiF", 0)
22+
public func test() {
23+
print(bar(5))
24+
print(bar2(5))
25+
}

0 commit comments

Comments
 (0)