Skip to content

Commit ae6cea7

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 9c04037 commit ae6cea7

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
@@ -4047,9 +4047,15 @@ void SILBoxType::Profile(llvm::FoldingSetNodeID &id, SILLayout *Layout,
40474047
Substitutions.profile(id);
40484048
}
40494049

4050-
static RecursiveTypeProperties getRecursivePropertiesOfMap(
4051-
SubstitutionMap subMap) {
4050+
static RecursiveTypeProperties getBoxRecursiveProperties(
4051+
SILLayout *Layout, SubstitutionMap subMap) {
40524052
RecursiveTypeProperties props;
4053+
for (auto &field : Layout->getFields()) {
4054+
auto fieldProps = field.getLoweredType()->getRecursiveProperties();
4055+
fieldProps.removeHasTypeParameter();
4056+
fieldProps.removeHasDependentMember();
4057+
props |= fieldProps;
4058+
}
40534059
for (auto replacementType : subMap.getReplacementTypes()) {
40544060
if (replacementType) props |= replacementType->getRecursiveProperties();
40554061
}
@@ -4058,7 +4064,8 @@ static RecursiveTypeProperties getRecursivePropertiesOfMap(
40584064

40594065
SILBoxType::SILBoxType(ASTContext &C,
40604066
SILLayout *Layout, SubstitutionMap Substitutions)
4061-
: TypeBase(TypeKind::SILBox, &C, getRecursivePropertiesOfMap(Substitutions)),
4067+
: TypeBase(TypeKind::SILBox, &C,
4068+
getBoxRecursiveProperties(Layout, Substitutions)),
40624069
Layout(Layout), Substitutions(Substitutions) {
40634070
assert(Substitutions.isCanonical());
40644071
}

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)