Skip to content

Commit d0f1efb

Browse files
committed
[SILGenExpr] Lower initializers.
1 parent 2e4113b commit d0f1efb

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

lib/SILGen/SILGenExpr.cpp

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3243,7 +3243,8 @@ static PreparedArguments loadIndexValuesForKeyPathComponent(
32433243
SILGenFunction &SGF, SILLocation loc, ValueDecl *storage,
32443244
ArrayRef<IndexTypePair> indexes, SILValue pointer) {
32453245
// If not a subscript or method, do nothing.
3246-
if (!(isa<SubscriptDecl>(storage) || isa<FuncDecl>(storage)))
3246+
if (!(isa<SubscriptDecl>(storage) || isa<FuncDecl>(storage) ||
3247+
isa<ConstructorDecl>(storage)))
32473248
return PreparedArguments();
32483249

32493250
SmallVector<AnyFunctionType::Param, 8> indexParams;
@@ -4277,7 +4278,7 @@ static void lowerKeyPathMemberIndexTypes(
42774278
}
42784279
needsGenericContext |= methodSubstTy->hasArchetype();
42794280
processIndicesOrParameters(method->getParameters(), &sig);
4280-
}
4281+
}
42814282
}
42824283

42834284
static void lowerKeyPathMemberIndexPatterns(
@@ -4350,8 +4351,16 @@ KeyPathPatternComponent SILGenModule::emitKeyPathComponentForDecl(
43504351
argPatterns, argEquals, argHash);
43514352
}
43524353

4353-
auto representative = SILDeclRef(storage, SILDeclRef::Kind::Func,
4354-
/*isForeign*/ storage->isImportAsMember());
4354+
SILDeclRef::Kind kind;
4355+
if (isa<FuncDecl>(storage)) {
4356+
kind = SILDeclRef::Kind::Func;
4357+
} else if (isa<ConstructorDecl>(storage)) {
4358+
kind = SILDeclRef::Kind::Allocator;
4359+
} else {
4360+
llvm_unreachable("Unsupported decl kind");
4361+
}
4362+
SILDeclRef representative(storage, kind,
4363+
/*isForeign*/ storage->isImportAsMember());
43554364
auto id = getFunction(representative, NotForDefinition);
43564365

43574366
SILFunction *func = nullptr;
@@ -4646,8 +4655,9 @@ RValue RValueEmitter::visitKeyPathExpr(KeyPathExpr *E, SGFContext C) {
46464655
/*for descriptor*/ false, /*is applied func*/ isApplied));
46474656
baseTy = loweredComponents.back().getComponentType();
46484657
if ((kind == KeyPathExpr::Component::Kind::Member &&
4649-
!dyn_cast<FuncDecl>(decl)) ||
4650-
(dyn_cast<FuncDecl>(decl) && !isApplied))
4658+
!dyn_cast<FuncDecl>(decl) && !dyn_cast<ConstructorDecl>(decl)) ||
4659+
((dyn_cast<FuncDecl>(decl) || dyn_cast<ConstructorDecl>(decl)) &&
4660+
!isApplied))
46514661
break;
46524662

46534663
auto loweredArgs = SGF.emitKeyPathOperands(

0 commit comments

Comments
 (0)