@@ -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,38 +2441,20 @@ static CanAnyFunctionType getStoredPropertyInitializerInterfaceType(
2447
2441
// / (property-type) -> backing-type.
2448
2442
static CanAnyFunctionType getPropertyWrapperBackingInitializerInterfaceType (
2449
2443
TypeConverter &TC,
2450
- VarDecl *VD) {
2451
- CanType resultType =
2452
- VD->getPropertyWrapperBackingPropertyType ()->getCanonicalType ();
2453
-
2454
- auto *DC = VD->getInnermostDeclContext ();
2455
- CanType inputType =
2456
- VD->getPropertyWrapperInitValueInterfaceType ()->getCanonicalType ();
2457
-
2458
- auto sig = DC->getGenericSignatureOfContext ();
2459
-
2460
- AnyFunctionType::Param param (
2461
- inputType, Identifier (),
2462
- ParameterTypeFlags ().withValueOwnership (ValueOwnership::Owned));
2463
- // FIXME: Verify ExtInfo state is correct, not working by accident.
2464
- CanAnyFunctionType::ExtInfo info;
2465
- return CanAnyFunctionType::get (getCanonicalSignatureOrNull (sig), {param},
2466
- resultType, info);
2467
- }
2468
-
2469
- static CanAnyFunctionType getPropertyWrapperInitFromProjectedValueInterfaceType (TypeConverter &TC,
2470
- VarDecl *VD) {
2444
+ SILDeclRef c) {
2445
+ auto *VD = cast<VarDecl>(c.getDecl ());
2471
2446
CanType resultType =
2472
2447
VD->getPropertyWrapperBackingPropertyType ()->getCanonicalType ();
2473
2448
2474
- Type interfaceType = VD->getPropertyWrapperProjectionVar ()->getInterfaceType ();
2475
- if (interfaceType->hasArchetype ())
2476
- interfaceType = interfaceType->mapTypeOutOfContext ();
2477
-
2478
- CanType inputType = interfaceType->getCanonicalType ();
2449
+ CanType inputType;
2450
+ if (c.kind == SILDeclRef::Kind::PropertyWrapperBackingInitializer) {
2451
+ inputType = VD->getPropertyWrapperInitValueInterfaceType ()->getCanonicalType ();
2452
+ } else {
2453
+ Type interfaceType = VD->getPropertyWrapperProjectionVar ()->getInterfaceType ();
2454
+ inputType = interfaceType->getCanonicalType ();
2455
+ }
2479
2456
2480
- auto *DC = VD->getInnermostDeclContext ();
2481
- auto sig = DC->getGenericSignatureOfContext ();
2457
+ GenericSignature sig = TC.getConstantGenericSignature (c);
2482
2458
2483
2459
AnyFunctionType::Param param (
2484
2460
inputType, Identifier (),
@@ -2639,15 +2615,12 @@ CanAnyFunctionType TypeConverter::makeConstantInterfaceType(SILDeclRef c) {
2639
2615
return getGlobalAccessorType (var->getInterfaceType ()->getCanonicalType ());
2640
2616
}
2641
2617
case SILDeclRef::Kind::DefaultArgGenerator:
2642
- return getDefaultArgGeneratorInterfaceType (c);
2618
+ return getDefaultArgGeneratorInterfaceType (* this , c);
2643
2619
case SILDeclRef::Kind::StoredPropertyInitializer:
2644
2620
return getStoredPropertyInitializerInterfaceType (cast<VarDecl>(vd));
2645
2621
case SILDeclRef::Kind::PropertyWrapperBackingInitializer:
2646
- return getPropertyWrapperBackingInitializerInterfaceType (*this ,
2647
- cast<VarDecl>(vd));
2648
2622
case SILDeclRef::Kind::PropertyWrapperInitFromProjectedValue:
2649
- return getPropertyWrapperInitFromProjectedValueInterfaceType (*this ,
2650
- cast<VarDecl>(vd));
2623
+ return getPropertyWrapperBackingInitializerInterfaceType (*this , c);
2651
2624
case SILDeclRef::Kind::IVarInitializer:
2652
2625
return getIVarInitDestroyerInterfaceType (cast<ClassDecl>(vd),
2653
2626
c.isForeign , false );
@@ -2683,11 +2656,27 @@ TypeConverter::getConstantGenericSignature(SILDeclRef c) {
2683
2656
return getEffectiveGenericSignature (
2684
2657
vd->getInnermostDeclContext (), captureInfo);
2685
2658
}
2659
+ case SILDeclRef::Kind::PropertyWrapperBackingInitializer:
2660
+ case SILDeclRef::Kind::PropertyWrapperInitFromProjectedValue: {
2661
+ // FIXME: It might be better to compute lowered local captures of
2662
+ // the property wrapper generator directly and collapse this into the
2663
+ // above case. For now, take the generic signature of the enclosing
2664
+ // context.
2665
+ auto *dc = vd->getDeclContext ();
2666
+ if (dc->isLocalContext ()) {
2667
+ SILDeclRef enclosingDecl;
2668
+ if (auto *closure = dyn_cast<AbstractClosureExpr>(dc)) {
2669
+ enclosingDecl = SILDeclRef (closure);
2670
+ } else {
2671
+ enclosingDecl = SILDeclRef (cast<AbstractFunctionDecl>(dc));
2672
+ }
2673
+ return getConstantGenericSignature (enclosingDecl);
2674
+ }
2675
+ return dc->getGenericSignatureOfContext ();
2676
+ }
2686
2677
case SILDeclRef::Kind::EnumElement:
2687
2678
case SILDeclRef::Kind::GlobalAccessor:
2688
2679
case SILDeclRef::Kind::StoredPropertyInitializer:
2689
- case SILDeclRef::Kind::PropertyWrapperBackingInitializer:
2690
- case SILDeclRef::Kind::PropertyWrapperInitFromProjectedValue:
2691
2680
return vd->getDeclContext ()->getGenericSignatureOfContext ();
2692
2681
}
2693
2682
0 commit comments