File tree Expand file tree Collapse file tree 3 files changed +45
-9
lines changed Expand file tree Collapse file tree 3 files changed +45
-9
lines changed Original file line number Diff line number Diff line change @@ -65,6 +65,13 @@ Type QueryTypeSubstitutionMap::operator()(SubstitutableType *type) const {
65
65
66
66
Type
67
67
QueryTypeSubstitutionMapOrIdentity::operator ()(SubstitutableType *type) const {
68
+ // FIXME: Type::subst should not be pass in non-root archetypes.
69
+ // Consider only root archetypes.
70
+ if (auto *archetype = dyn_cast<ArchetypeType>(type)) {
71
+ if (!archetype->isRoot ())
72
+ return Type ();
73
+ }
74
+
68
75
auto key = type->getCanonicalType ()->castTo <SubstitutableType>();
69
76
auto known = substitutions.find (key);
70
77
if (known != substitutions.end () && known->second )
Original file line number Diff line number Diff line change @@ -2582,18 +2582,16 @@ CanSILFunctionType swift::buildSILFunctionThunkType(
2582
2582
}
2583
2583
2584
2584
auto substTypeHelper = [&](SubstitutableType *type) -> Type {
2585
+ // FIXME: Type::subst should not pass in non-root archetypes.
2586
+ // Consider only root archetypes.
2587
+ if (auto *archetype = dyn_cast<ArchetypeType>(type)) {
2588
+ if (!archetype->isRoot ())
2589
+ return Type ();
2590
+ }
2591
+
2585
2592
if (CanType (type) == openedExistential)
2586
2593
return newArchetype;
2587
2594
2588
- // If a nested archetype is rooted on our opened existential, fail:
2589
- // Type::subst attempts to substitute the parent of a nested archetype
2590
- // only if it fails to find a replacement for the nested one.
2591
- if (auto *opened = dyn_cast<OpenedArchetypeType>(type)) {
2592
- if (openedExistential->isEqual (opened->getRoot ())) {
2593
- return nullptr ;
2594
- }
2595
- }
2596
-
2597
2595
return Type (type).subst (contextSubs);
2598
2596
};
2599
2597
auto substConformanceHelper =
Original file line number Diff line number Diff line change
1
+ // RUN: %target-swift-frontend -emit-sil -O -primary-file %s | %FileCheck %s
2
+
3
+ // FIXME: Ideally, this should be a sil-opt test, but TypeRepr cannot model
4
+ // types like '(@opened("...") P).Assoc' as of now.
5
+
6
+ protocol P {
7
+ associatedtype Assoc : P
8
+
9
+ func f( ) -> Self . Assoc
10
+ }
11
+
12
+ // CHECK-LABEL: sil hidden [always_inline] @$s35mandatory_inlining_open_existential6callee1pAA1P_pAaD_p_tF
13
+ // CHECK: [[OPENED:%[0-9]+]] = open_existential_addr immutable_access {{%[0-9]+}} : $*P to $*[[OPENED_TY:@opened\("[-A-F0-9]+"\) P]]
14
+ // CHECK: [[WITNESS:%[0-9]+]] = witness_method $[[OPENED_TY]], #P.f : <Self where Self : P> (Self) -> () -> Self.Assoc
15
+ // CHECK: [[RESULT:%[0-9]+]] = init_existential_addr {{%[0-9]+}} : $*P, $([[OPENED_TY]]).Assoc
16
+ // CHECK: apply [[WITNESS]]<[[OPENED_TY]]>([[RESULT]], [[OPENED]])
17
+ // CHECK: }
18
+ @inline ( __always)
19
+ func callee( p: any P ) -> any P {
20
+ return p. f ( )
21
+ }
22
+
23
+ // CHECK-LABEL: sil hidden @$s35mandatory_inlining_open_existential6caller1pAA1P_pAaD_p_tF
24
+ // CHECK: [[OPENED:%[0-9]+]] = open_existential_addr immutable_access {{%[0-9]+}} : $*P to $*[[OPENED_TY:@opened\("[-A-F0-9]+"\) P]]
25
+ // CHECK: [[WITNESS:%[0-9]+]] = witness_method $[[OPENED_TY]], #P.f : <Self where Self : P> (Self) -> () -> Self.Assoc
26
+ // CHECK: [[RESULT:%[0-9]+]] = init_existential_addr {{%[0-9]+}} : $*P, $([[OPENED_TY]]).Assoc
27
+ // CHECK: apply [[WITNESS]]<[[OPENED_TY]]>([[RESULT]], [[OPENED]])
28
+ // CHECK: }
29
+ func caller( p: any P ) -> any P {
30
+ return callee ( p: p)
31
+ }
You can’t perform that action at this time.
0 commit comments