Skip to content

Commit 5f26fa8

Browse files
committed
AST: A class-constrained OpenedArchetypeType should have a layout constraint
This is now the case for archetypes instantiated from a generic signature; let's establish this invariant for opened types as well.
1 parent 60a5780 commit 5f26fa8

File tree

3 files changed

+6
-51
lines changed

3 files changed

+6
-51
lines changed

lib/AST/ASTContext.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3835,6 +3835,11 @@ CanOpenedArchetypeType OpenedArchetypeType::get(Type existential,
38353835
protos.push_back(proto->getDecl());
38363836

38373837
auto layoutConstraint = layout.getLayoutConstraint();
3838+
if (!layoutConstraint && layout.requiresClass()) {
3839+
layoutConstraint = LayoutConstraint::getLayoutConstraint(
3840+
LayoutConstraintKind::Class);
3841+
}
3842+
38383843
auto layoutSuperclass = layout.getSuperclass();
38393844

38403845
auto arena = AllocationArena::Permanent;

lib/AST/Type.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4952,8 +4952,7 @@ ReferenceCounting TypeBase::getReferenceCounting() {
49524952
auto archetype = cast<ArchetypeType>(type);
49534953
auto layout = archetype->getLayoutConstraint();
49544954
(void)layout;
4955-
assert(archetype->requiresClass() ||
4956-
(layout && layout->isRefCounted()));
4955+
assert(layout && layout->isRefCounted());
49574956
if (auto supertype = archetype->getSuperclass())
49584957
return supertype->getReferenceCounting();
49594958
return ReferenceCounting::Unknown;

test/SILOptimizer/inline_generics.sil

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -47,55 +47,6 @@ bb0(%0 : $*T, %1 : $*T):
4747
return %9 : $()
4848
} // end sil function 'testInliningOfGenerics'
4949

50-
sil hidden @P_combine : $@convention(method) <Self where Self : P><T> (@in T, @guaranteed Self) -> @owned @callee_owned (@in T) -> Bool {
51-
bb0(%0 : $*T, %1 : $Self):
52-
// function_ref P.(combine<A> (first : A1) -> (A1) -> Bool).(closure #1)
53-
%4 = function_ref @_TFFE50generic_inlining_partial_apply_opened_existentialsPS_1P7combineurFT5firstqd___Fqd__SbU_Fqd__Sb : $@convention(thin) <τ_0_0 where τ_0_0 : P><τ_1_0> (@in τ_1_0) -> Bool
54-
%5 = partial_apply %4<Self, T>() : $@convention(thin) <τ_0_0 where τ_0_0 : P><τ_1_0> (@in τ_1_0) -> Bool
55-
destroy_addr %0 : $*T
56-
return %5 : $@callee_owned (@in T) -> Bool
57-
} // end sil function 'P_combine'
58-
59-
// P.(combine<A> (first : A1) -> (A1) -> Bool).(closure #1)
60-
sil shared @_TFFE50generic_inlining_partial_apply_opened_existentialsPS_1P7combineurFT5firstqd___Fqd__SbU_Fqd__Sb : $@convention(thin) <Self where Self : P><T> (@in T) -> Bool {
61-
bb0(%0 : $*T):
62-
%2 = integer_literal $Builtin.Int1, -1
63-
%3 = struct $Bool (%2 : $Builtin.Int1)
64-
destroy_addr %0 : $*T
65-
return %3 : $Bool
66-
} // end sil function '_TFFE50generic_inlining_partial_apply_opened_existentialsPS_1P7combineurFT5firstqd___Fqd__SbU_Fqd__Sb'
67-
68-
69-
// Check that P_combine is not inlined into the generic function, because
70-
// doing so would result in a partial_apply instruction, with an opened existential
71-
// in the substitution list. And this cannot be handled by the IRGen yet.
72-
// CHECK-LABEL: sil @dont_inline_callee_with_opened_existential_in_partial_apply_substitution_list
73-
// CHECK: [[FUN_REF:%[0-9]+]] = function_ref @P_combine
74-
// CHECK: apply [[FUN_REF]]
75-
// CHECK: end sil function 'dont_inline_callee_with_opened_existential_in_partial_apply_substitution_list'
76-
sil @dont_inline_callee_with_opened_existential_in_partial_apply_substitution_list : $@convention(thin) <T where T : P> (@owned P) -> @owned @callee_owned (@owned T) -> Bool {
77-
bb0(%0 : $P):
78-
%2 = open_existential_ref %0 : $P to $@opened("41B148C8-F49C-11E6-BE69-A45E60E99281") P
79-
// function_ref P.combine<A> (first : A1) -> (A1) -> Bool
80-
%3 = function_ref @P_combine : $@convention(method) <τ_0_0 where τ_0_0 : P><τ_1_0> (@in τ_1_0, @guaranteed τ_0_0) -> @owned @callee_owned (@in τ_1_0) -> Bool
81-
%4 = open_existential_ref %0 : $P to $@opened("41B14A4E-F49C-11E6-BE69-A45E60E99281") P
82-
%5 = witness_method $@opened("41B14A4E-F49C-11E6-BE69-A45E60E99281") P, #P.getSelf : <Self where Self : P> (Self) -> () -> Self, %4 : $@opened("41B14A4E-F49C-11E6-BE69-A45E60E99281") P : $@convention(witness_method: P) <τ_0_0 where τ_0_0 : P> (@guaranteed τ_0_0) -> @owned τ_0_0
83-
%6 = apply %5<@opened("41B14A4E-F49C-11E6-BE69-A45E60E99281") P>(%4) : $@convention(witness_method: P) <τ_0_0 where τ_0_0 : P> (@guaranteed τ_0_0) -> @owned τ_0_0
84-
%7 = init_existential_ref %6 : $@opened("41B14A4E-F49C-11E6-BE69-A45E60E99281") P : $@opened("41B14A4E-F49C-11E6-BE69-A45E60E99281") P, $P
85-
%8 = alloc_stack $P
86-
store %7 to %8 : $*P
87-
%10 = apply %3<@opened("41B148C8-F49C-11E6-BE69-A45E60E99281") P, P>(%8, %2) : $@convention(method) <τ_0_0 where τ_0_0 : P><τ_1_0> (@in τ_1_0, @guaranteed τ_0_0) -> @owned @callee_owned (@in τ_1_0) -> Bool
88-
// function_ref thunk
89-
%11 = function_ref @thunk1 : $@convention(thin) (@owned P, @owned @callee_owned (@in P) -> Bool) -> Bool
90-
%12 = partial_apply %11(%10) : $@convention(thin) (@owned P, @owned @callee_owned (@in P) -> Bool) -> Bool
91-
// function_ref thunk
92-
%13 = function_ref @thunk2 : $@convention(thin) <τ_0_0 where τ_0_0 : P> (@owned τ_0_0, @owned @callee_owned (@owned P) -> Bool) -> Bool
93-
%14 = partial_apply %13<T>(%12) : $@convention(thin) <τ_0_0 where τ_0_0 : P> (@owned τ_0_0, @owned @callee_owned (@owned P) -> Bool) -> Bool
94-
dealloc_stack %8 : $*P
95-
strong_release %0 : $P
96-
return %14 : $@callee_owned (@owned T) -> Bool
97-
} // end sil function 'dont_inline_callee_with_opened_existential_in_partial_apply_substitution_list'
98-
9950
// thunk
10051
sil shared [transparent] [reabstraction_thunk] @thunk1 : $@convention(thin) (@owned P, @owned @callee_owned (@in P) -> Bool) -> Bool {
10152
bb0(%0 : $P, %1 : $@callee_owned (@in P) -> Bool):

0 commit comments

Comments
 (0)