Skip to content

Commit ef6b828

Browse files
committed
AST: Fix calculation of recursive properties for SILBoxType
We need to propagate some bits from the field types, at least the 'has dynamic self' bit, for some SIL verifier assertions to not fire.
1 parent 4469ae9 commit ef6b828

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

lib/AST/Type.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4056,9 +4056,15 @@ void SILBoxType::Profile(llvm::FoldingSetNodeID &id, SILLayout *Layout,
40564056
Substitutions.profile(id);
40574057
}
40584058

4059-
static RecursiveTypeProperties getRecursivePropertiesOfMap(
4060-
SubstitutionMap subMap) {
4059+
static RecursiveTypeProperties getBoxRecursiveProperties(
4060+
SILLayout *Layout, SubstitutionMap subMap) {
40614061
RecursiveTypeProperties props;
4062+
for (auto &field : Layout->getFields()) {
4063+
auto fieldProps = field.getLoweredType()->getRecursiveProperties();
4064+
fieldProps.removeHasTypeParameter();
4065+
fieldProps.removeHasDependentMember();
4066+
props |= fieldProps;
4067+
}
40624068
for (auto replacementType : subMap.getReplacementTypes()) {
40634069
if (replacementType) props |= replacementType->getRecursiveProperties();
40644070
}
@@ -4067,7 +4073,8 @@ static RecursiveTypeProperties getRecursivePropertiesOfMap(
40674073

40684074
SILBoxType::SILBoxType(ASTContext &C,
40694075
SILLayout *Layout, SubstitutionMap Substitutions)
4070-
: TypeBase(TypeKind::SILBox, &C, getRecursivePropertiesOfMap(Substitutions)),
4076+
: TypeBase(TypeKind::SILBox, &C,
4077+
getBoxRecursiveProperties(Layout, Substitutions)),
40714078
Layout(Layout), Substitutions(Substitutions) {
40724079
assert(Substitutions.isCanonical());
40734080
}

test/SILGen/dynamic_self.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,21 @@ class Z {
224224
return self.init()
225225
}
226226

227+
static func testStaticMethodMutableDynamicSelfCaptures() -> Self {
228+
let fn0 = { _ = self; _ = { _ = self } }
229+
fn0()
230+
231+
var x = self
232+
let fn1 = { _ = x }
233+
fn1()
234+
235+
var xx = (self, self)
236+
let fn2 = { _ = xx }
237+
fn2()
238+
239+
return self.init()
240+
}
241+
227242
// Make sure the actual self value has the same lowered type as the
228243
// substituted result of a generic function call
229244
func testDynamicSelfSubstitution(_ b: Bool) -> Self {

0 commit comments

Comments
 (0)