@@ -2426,8 +2426,6 @@ static VarDecl *synthesizeLocalWrappedValueVar(VarDecl *var) {
2426
2426
VarDecl *localVar = new (ctx) VarDecl (/* IsStatic=*/ false ,
2427
2427
VarDecl::Introducer::Var,
2428
2428
var->getLoc (), name, dc);
2429
- if (!var->hasImplicitPropertyWrapper ())
2430
- localVar->setInterfaceType (var->getInterfaceType ());
2431
2429
localVar->setImplicit ();
2432
2430
localVar->getAttrs () = var->getAttrs ();
2433
2431
localVar->overwriteAccess (var->getFormalAccess ());
@@ -2456,8 +2454,7 @@ static VarDecl *synthesizeLocalWrappedValueVar(VarDecl *var) {
2456
2454
// / Synthesize a computed property `$foo` for a property with an attached
2457
2455
// / wrapper that has a `projectedValue` property.
2458
2456
static VarDecl *synthesizePropertyWrapperProjectionVar (
2459
- ASTContext &ctx, VarDecl *var, Type wrapperType,
2460
- VarDecl *wrapperVar) {
2457
+ ASTContext &ctx, VarDecl *var, VarDecl *wrapperVar) {
2461
2458
// If the original property has a @_projectedValueProperty attribute, use
2462
2459
// that to find the storage wrapper property.
2463
2460
if (auto attr = var->getAttrs ().getAttribute <ProjectedValuePropertyAttr>()){
@@ -2496,33 +2493,16 @@ static VarDecl *synthesizePropertyWrapperProjectionVar(
2496
2493
}
2497
2494
Identifier name = ctx.getIdentifier (nameBuf);
2498
2495
2499
- // Determine the type of the property.
2500
- Type propertyType;
2501
- if (wrapperType)
2502
- propertyType = computeProjectedValueType (var, wrapperType);
2503
-
2504
2496
// Form the property.
2505
2497
auto dc = var->getDeclContext ();
2506
2498
VarDecl *property = new (ctx) VarDecl (/* IsStatic=*/ var->isStatic (),
2507
2499
VarDecl::Introducer::Var,
2508
2500
var->getLoc (),
2509
2501
name, dc);
2510
- if (propertyType)
2511
- property->setInterfaceType (propertyType);
2512
2502
property->setImplicit ();
2513
2503
property->setOriginalWrappedProperty (var);
2514
2504
addMemberToContextIfNeeded (property, dc, var);
2515
2505
2516
- // Create the pattern binding declaration for the property.
2517
- Pattern *pbdPattern = NamedPattern::createImplicit (ctx, property);
2518
- pbdPattern->setType (propertyType);
2519
- pbdPattern = TypedPattern::createImplicit (ctx, pbdPattern, propertyType);
2520
- auto pbd = PatternBindingDecl::createImplicit (
2521
- ctx, property->getCorrectStaticSpelling (), pbdPattern,
2522
- /* init*/ nullptr , dc, SourceLoc ());
2523
- addMemberToContextIfNeeded (pbd, dc, var);
2524
- pbd->setStatic (var->isStatic ());
2525
-
2526
2506
// Determine the access level for the property.
2527
2507
property->overwriteAccess (var->getFormalAccess ());
2528
2508
@@ -2759,38 +2739,15 @@ PropertyWrapperAuxiliaryVariablesRequest::evaluate(Evaluator &evaluator,
2759
2739
VarDecl *projectionVar = nullptr ;
2760
2740
VarDecl *wrappedValueVar = nullptr ;
2761
2741
2742
+ // Create the backing storage property.
2762
2743
if (auto *param = dyn_cast<ParamDecl>(var)) {
2763
2744
backingVar = ParamDecl::cloneWithoutType (ctx, param);
2764
2745
backingVar->setName (name);
2765
- Type wrapperType;
2766
-
2767
- // If this is a function parameter, compute the backing
2768
- // type now. For closure parameters, let the constraint
2769
- // system infer the backing type.
2770
- if (!var->getInterfaceType ()->hasError ()) {
2771
- wrapperType = var->getPropertyWrapperBackingPropertyType ();
2772
- if (!wrapperType || wrapperType->hasError ())
2773
- return PropertyWrapperAuxiliaryVariables ();
2774
-
2775
- backingVar->setInterfaceType (wrapperType);
2776
- }
2777
- }
2778
-
2779
- auto wrapperType = var->getPropertyWrapperBackingPropertyType ();
2780
-
2781
- // Create the backing storage property and note it in the cache.
2782
- if (!backingVar) {
2783
- if (!wrapperType || wrapperType->hasError ())
2784
- return PropertyWrapperAuxiliaryVariables ();
2785
-
2786
- Type storageInterfaceType = wrapperType;
2787
- Type storageType = dc->mapTypeIntoContext (storageInterfaceType);
2788
-
2746
+ } else {
2789
2747
backingVar = new (ctx) VarDecl (/* IsStatic=*/ var->isStatic (),
2790
2748
VarDecl::Introducer::Var,
2791
2749
var->getLoc (),
2792
2750
name, dc);
2793
- backingVar->setInterfaceType (storageInterfaceType);
2794
2751
backingVar->setImplicit ();
2795
2752
backingVar->setOriginalWrappedProperty (var);
2796
2753
@@ -2799,21 +2756,11 @@ PropertyWrapperAuxiliaryVariablesRequest::evaluate(Evaluator &evaluator,
2799
2756
backingVar->overwriteSetterAccess (AccessLevel::Private);
2800
2757
2801
2758
addMemberToContextIfNeeded (backingVar, dc, var);
2802
-
2803
- // Create the pattern binding declaration for the backing property.
2804
- Pattern *pbdPattern = NamedPattern::createImplicit (ctx, backingVar);
2805
- pbdPattern->setType (storageType);
2806
- pbdPattern = TypedPattern::createImplicit (ctx, pbdPattern, storageType);
2807
- PatternBindingDecl *pbd = PatternBindingDecl::createImplicit (
2808
- ctx, var->getCorrectStaticSpelling (), pbdPattern, /* init*/ nullptr ,
2809
- dc, SourceLoc ());
2810
- addMemberToContextIfNeeded (pbd, dc, var);
2811
- pbd->setStatic (var->isStatic ());
2812
2759
}
2813
2760
2814
2761
if (wrapperInfo.projectedValueVar || var->getName ().hasDollarPrefix ()) {
2815
2762
projectionVar = synthesizePropertyWrapperProjectionVar (
2816
- ctx, var, wrapperType, wrapperInfo.projectedValueVar );
2763
+ ctx, var, wrapperInfo.projectedValueVar );
2817
2764
}
2818
2765
2819
2766
if ((wrappedValueVar = synthesizeLocalWrappedValueVar (var))) {
@@ -2844,18 +2791,28 @@ PropertyWrapperInitializerInfoRequest::evaluate(Evaluator &evaluator,
2844
2791
if (!wrapperType || wrapperType->hasError ())
2845
2792
return PropertyWrapperInitializerInfo ();
2846
2793
2847
- Type storageInterfaceType = wrapperType;
2848
- Type storageType = dc->mapTypeIntoContext (storageInterfaceType);
2849
-
2794
+ Type storageType = dc->mapTypeIntoContext (wrapperType);
2850
2795
Expr *initializer = nullptr ;
2851
2796
PropertyWrapperValuePlaceholderExpr *wrappedValue = nullptr ;
2852
2797
2798
+ auto createPBD = [&](VarDecl *singleVar) -> PatternBindingDecl * {
2799
+ Pattern *pattern = NamedPattern::createImplicit (ctx, singleVar);
2800
+ pattern->setType (singleVar->getType ());
2801
+ pattern = TypedPattern::createImplicit (ctx, pattern, singleVar->getType ());
2802
+ PatternBindingDecl *pbd = PatternBindingDecl::createImplicit (
2803
+ ctx, var->getCorrectStaticSpelling (), pattern, /* init*/ nullptr ,
2804
+ dc, SourceLoc ());
2805
+ addMemberToContextIfNeeded (pbd, dc, var);
2806
+ pbd->setStatic (var->isStatic ());
2807
+ return pbd;
2808
+ };
2809
+
2853
2810
// Take the initializer from the original property.
2854
2811
if (!isa<ParamDecl>(var)) {
2855
2812
auto parentPBD = var->getParentPatternBinding ();
2856
2813
unsigned patternNumber = parentPBD->getPatternEntryIndexForVarDecl (var);
2857
2814
auto *backingVar = var->getPropertyWrapperBackingProperty ();
2858
- auto *pbd = backingVar-> getParentPatternBinding ( );
2815
+ auto *pbd = createPBD (backingVar );
2859
2816
2860
2817
// Force the default initializer to come into existence, if there is one,
2861
2818
// and the wrapper doesn't provide its own.
@@ -2897,21 +2854,25 @@ PropertyWrapperInitializerInfoRequest::evaluate(Evaluator &evaluator,
2897
2854
// If there is a projection property (projectedValue) in the wrapper,
2898
2855
// synthesize a computed property for '$foo'.
2899
2856
Expr *projectedValueInit = nullptr ;
2900
- if (wrapperInfo.projectedValueVar && wrapperInfo.hasProjectedValueInit &&
2901
- isa<ParamDecl>(var)) {
2902
- // Projected-value initialization is currently only supported for parameters.
2903
- auto *param = dyn_cast<ParamDecl>(var);
2904
- auto projectionType = computeProjectedValueType (var, storageType);
2905
- auto *placeholder = PropertyWrapperValuePlaceholderExpr::create (
2906
- ctx, var->getSourceRange (), projectionType, /* projectedValue=*/ nullptr );
2907
- projectedValueInit = buildPropertyWrapperInitCall (
2908
- var, storageType, placeholder, PropertyWrapperInitKind::ProjectedValue);
2909
- TypeChecker::typeCheckExpression (projectedValueInit, dc);
2910
-
2911
- // Check initializer effects.
2912
- auto *initContext = new (ctx) PropertyWrapperInitializer (
2913
- dc, param, PropertyWrapperInitializer::Kind::ProjectedValue);
2914
- TypeChecker::checkInitializerEffects (initContext, projectedValueInit);
2857
+ if (auto *projection = var->getPropertyWrapperProjectionVar ()) {
2858
+ createPBD (projection);
2859
+
2860
+ auto wrapperInfo = var->getAttachedPropertyWrapperTypeInfo (0 );
2861
+ if (wrapperInfo.hasProjectedValueInit && isa<ParamDecl>(var)) {
2862
+ // Projected-value initialization is currently only supported for parameters.
2863
+ auto *param = dyn_cast<ParamDecl>(var);
2864
+ auto *placeholder = PropertyWrapperValuePlaceholderExpr::create (
2865
+ ctx, var->getSourceRange (), projection->getType (), /* projectedValue=*/ nullptr );
2866
+ projectedValueInit = buildPropertyWrapperInitCall (
2867
+ var, storageType, placeholder, PropertyWrapperInitKind::ProjectedValue);
2868
+ TypeChecker::typeCheckExpression (projectedValueInit, dc);
2869
+
2870
+ // Check initializer effects.
2871
+ auto *initContext = new (ctx) PropertyWrapperInitializer (
2872
+ dc, param, PropertyWrapperInitializer::Kind::ProjectedValue);
2873
+ checkInitializerActorIsolation (initContext, projectedValueInit);
2874
+ TypeChecker::checkInitializerEffects (initContext, projectedValueInit);
2875
+ }
2915
2876
}
2916
2877
2917
2878
// Form the initialization of the backing property from a value of the
@@ -2920,7 +2881,8 @@ PropertyWrapperInitializerInfoRequest::evaluate(Evaluator &evaluator,
2920
2881
if (wrappedValue) {
2921
2882
wrappedValueInit = initializer;
2922
2883
} else if (!initializer &&
2923
- var->allAttachedPropertyWrappersHaveWrappedValueInit ()) {
2884
+ var->allAttachedPropertyWrappersHaveWrappedValueInit () &&
2885
+ !var->getName ().hasDollarPrefix ()) {
2924
2886
wrappedValueInit = PropertyWrapperValuePlaceholderExpr::create (
2925
2887
ctx, var->getSourceRange (), var->getType (), /* wrappedValue=*/ nullptr );
2926
2888
0 commit comments