@@ -2383,6 +2383,7 @@ static CanType removeNoEscape(CanType resultType) {
2383
2383
2384
2384
// / Get the type of a default argument generator, () -> T.
2385
2385
static CanAnyFunctionType getDefaultArgGeneratorInterfaceType (
2386
+ TypeConverter &TC,
2386
2387
SILDeclRef c) {
2387
2388
auto *vd = c.getDecl ();
2388
2389
auto resultTy = getParameterAt (vd,
@@ -2400,14 +2401,7 @@ static CanAnyFunctionType getDefaultArgGeneratorInterfaceType(
2400
2401
canResultTy = removeNoEscape (canResultTy);
2401
2402
2402
2403
// Get the generic signature from the surrounding context.
2403
- auto sig = vd->getInnermostDeclContext ()->getGenericSignatureOfContext ();
2404
- if (auto *afd = dyn_cast<AbstractFunctionDecl>(vd)) {
2405
- auto *param = getParameterAt (afd, c.defaultArgIndex );
2406
- if (param->hasDefaultExpr ()) {
2407
- auto captureInfo = param->getDefaultArgumentCaptureInfo ();
2408
- sig = getEffectiveGenericSignature (afd, captureInfo);
2409
- }
2410
- }
2404
+ auto sig = TC.getConstantGenericSignature (c);
2411
2405
2412
2406
// FIXME: Verify ExtInfo state is correct, not working by accident.
2413
2407
CanAnyFunctionType::ExtInfo info;
@@ -2447,24 +2441,20 @@ static CanAnyFunctionType getStoredPropertyInitializerInterfaceType(
2447
2441
// / (property-type) -> backing-type.
2448
2442
static CanAnyFunctionType getPropertyWrapperBackingInitializerInterfaceType (
2449
2443
TypeConverter &TC,
2450
- VarDecl *VD,
2451
- bool fromWrappedValue) {
2444
+ SILDeclRef c) {
2445
+ auto *VD = cast<VarDecl>(c. getDecl ());
2452
2446
CanType resultType =
2453
2447
VD->getPropertyWrapperBackingPropertyType ()->getCanonicalType ();
2454
2448
2455
- auto *DC = VD->getInnermostDeclContext ();
2456
2449
CanType inputType;
2457
- if (fromWrappedValue ) {
2450
+ if (c. kind == SILDeclRef::Kind::PropertyWrapperBackingInitializer ) {
2458
2451
inputType = VD->getPropertyWrapperInitValueInterfaceType ()->getCanonicalType ();
2459
2452
} else {
2460
2453
Type interfaceType = VD->getPropertyWrapperProjectionVar ()->getInterfaceType ();
2461
2454
inputType = interfaceType->getCanonicalType ();
2462
2455
}
2463
2456
2464
- GenericSignature sig;
2465
- auto *closure = dyn_cast<AbstractClosureExpr>(DC);
2466
- if (!closure || closure->getCaptureInfo ().hasGenericParamCaptures ())
2467
- sig = DC->getGenericSignatureOfContext ();
2457
+ GenericSignature sig = TC.getConstantGenericSignature (c);
2468
2458
2469
2459
AnyFunctionType::Param param (
2470
2460
inputType, Identifier (),
@@ -2664,13 +2654,12 @@ CanAnyFunctionType TypeConverter::makeConstantInterfaceType(SILDeclRef c) {
2664
2654
return getGlobalAccessorType (var->getInterfaceType ()->getCanonicalType ());
2665
2655
}
2666
2656
case SILDeclRef::Kind::DefaultArgGenerator:
2667
- return getDefaultArgGeneratorInterfaceType (c);
2657
+ return getDefaultArgGeneratorInterfaceType (* this , c);
2668
2658
case SILDeclRef::Kind::StoredPropertyInitializer:
2669
2659
return getStoredPropertyInitializerInterfaceType (cast<VarDecl>(vd));
2670
2660
case SILDeclRef::Kind::PropertyWrapperBackingInitializer:
2671
2661
case SILDeclRef::Kind::PropertyWrapperInitFromProjectedValue:
2672
- return getPropertyWrapperBackingInitializerInterfaceType (
2673
- *this , cast<VarDecl>(vd), c.kind == SILDeclRef::Kind::PropertyWrapperBackingInitializer);
2662
+ return getPropertyWrapperBackingInitializerInterfaceType (*this , c);
2674
2663
case SILDeclRef::Kind::IVarInitializer:
2675
2664
return getIVarInitDestroyerInterfaceType (cast<ClassDecl>(vd),
2676
2665
c.isForeign , false );
@@ -2708,11 +2697,27 @@ TypeConverter::getConstantGenericSignature(SILDeclRef c) {
2708
2697
return getEffectiveGenericSignature (
2709
2698
vd->getInnermostDeclContext (), captureInfo);
2710
2699
}
2700
+ case SILDeclRef::Kind::PropertyWrapperBackingInitializer:
2701
+ case SILDeclRef::Kind::PropertyWrapperInitFromProjectedValue: {
2702
+ // FIXME: It might be better to compute lowered local captures of
2703
+ // the property wrapper generator directly and collapse this into the
2704
+ // above case. For now, take the generic signature of the enclosing
2705
+ // context.
2706
+ auto *dc = vd->getDeclContext ();
2707
+ if (dc->isLocalContext ()) {
2708
+ SILDeclRef enclosingDecl;
2709
+ if (auto *closure = dyn_cast<AbstractClosureExpr>(dc)) {
2710
+ enclosingDecl = SILDeclRef (closure);
2711
+ } else {
2712
+ enclosingDecl = SILDeclRef (cast<AbstractFunctionDecl>(dc));
2713
+ }
2714
+ return getConstantGenericSignature (enclosingDecl);
2715
+ }
2716
+ return dc->getGenericSignatureOfContext ();
2717
+ }
2711
2718
case SILDeclRef::Kind::EnumElement:
2712
2719
case SILDeclRef::Kind::GlobalAccessor:
2713
2720
case SILDeclRef::Kind::StoredPropertyInitializer:
2714
- case SILDeclRef::Kind::PropertyWrapperBackingInitializer:
2715
- case SILDeclRef::Kind::PropertyWrapperInitFromProjectedValue:
2716
2721
return vd->getDeclContext ()->getGenericSignatureOfContext ();
2717
2722
case SILDeclRef::Kind::EntryPoint:
2718
2723
llvm_unreachable (" Doesn't have generic signature" );
0 commit comments