@@ -2426,8 +2426,6 @@ static VarDecl *synthesizeLocalWrappedValueVar(VarDecl *var) {
24262426 VarDecl *localVar = new (ctx) VarDecl (/* IsStatic=*/ false ,
24272427 VarDecl::Introducer::Var,
24282428 var->getLoc (), name, dc);
2429- if (!var->hasImplicitPropertyWrapper ())
2430- localVar->setInterfaceType (var->getInterfaceType ());
24312429 localVar->setImplicit ();
24322430 localVar->getAttrs () = var->getAttrs ();
24332431 localVar->overwriteAccess (var->getFormalAccess ());
@@ -2456,8 +2454,7 @@ static VarDecl *synthesizeLocalWrappedValueVar(VarDecl *var) {
24562454// / Synthesize a computed property `$foo` for a property with an attached
24572455// / wrapper that has a `projectedValue` property.
24582456static VarDecl *synthesizePropertyWrapperProjectionVar (
2459- ASTContext &ctx, VarDecl *var, Type wrapperType,
2460- VarDecl *wrapperVar) {
2457+ ASTContext &ctx, VarDecl *var, VarDecl *wrapperVar) {
24612458 // If the original property has a @_projectedValueProperty attribute, use
24622459 // that to find the storage wrapper property.
24632460 if (auto attr = var->getAttrs ().getAttribute <ProjectedValuePropertyAttr>()){
@@ -2496,33 +2493,16 @@ static VarDecl *synthesizePropertyWrapperProjectionVar(
24962493 }
24972494 Identifier name = ctx.getIdentifier (nameBuf);
24982495
2499- // Determine the type of the property.
2500- Type propertyType;
2501- if (wrapperType)
2502- propertyType = computeProjectedValueType (var, wrapperType);
2503-
25042496 // Form the property.
25052497 auto dc = var->getDeclContext ();
25062498 VarDecl *property = new (ctx) VarDecl (/* IsStatic=*/ var->isStatic (),
25072499 VarDecl::Introducer::Var,
25082500 var->getLoc (),
25092501 name, dc);
2510- if (propertyType)
2511- property->setInterfaceType (propertyType);
25122502 property->setImplicit ();
25132503 property->setOriginalWrappedProperty (var);
25142504 addMemberToContextIfNeeded (property, dc, var);
25152505
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-
25262506 // Determine the access level for the property.
25272507 property->overwriteAccess (var->getFormalAccess ());
25282508
@@ -2759,38 +2739,15 @@ PropertyWrapperAuxiliaryVariablesRequest::evaluate(Evaluator &evaluator,
27592739 VarDecl *projectionVar = nullptr ;
27602740 VarDecl *wrappedValueVar = nullptr ;
27612741
2742+ // Create the backing storage property.
27622743 if (auto *param = dyn_cast<ParamDecl>(var)) {
27632744 backingVar = ParamDecl::cloneWithoutType (ctx, param);
27642745 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 {
27892747 backingVar = new (ctx) VarDecl (/* IsStatic=*/ var->isStatic (),
27902748 VarDecl::Introducer::Var,
27912749 var->getLoc (),
27922750 name, dc);
2793- backingVar->setInterfaceType (storageInterfaceType);
27942751 backingVar->setImplicit ();
27952752 backingVar->setOriginalWrappedProperty (var);
27962753
@@ -2799,21 +2756,11 @@ PropertyWrapperAuxiliaryVariablesRequest::evaluate(Evaluator &evaluator,
27992756 backingVar->overwriteSetterAccess (AccessLevel::Private);
28002757
28012758 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 ());
28122759 }
28132760
28142761 if (wrapperInfo.projectedValueVar || var->getName ().hasDollarPrefix ()) {
28152762 projectionVar = synthesizePropertyWrapperProjectionVar (
2816- ctx, var, wrapperType, wrapperInfo.projectedValueVar );
2763+ ctx, var, wrapperInfo.projectedValueVar );
28172764 }
28182765
28192766 if ((wrappedValueVar = synthesizeLocalWrappedValueVar (var))) {
@@ -2844,18 +2791,28 @@ PropertyWrapperInitializerInfoRequest::evaluate(Evaluator &evaluator,
28442791 if (!wrapperType || wrapperType->hasError ())
28452792 return PropertyWrapperInitializerInfo ();
28462793
2847- Type storageInterfaceType = wrapperType;
2848- Type storageType = dc->mapTypeIntoContext (storageInterfaceType);
2849-
2794+ Type storageType = dc->mapTypeIntoContext (wrapperType);
28502795 Expr *initializer = nullptr ;
28512796 PropertyWrapperValuePlaceholderExpr *wrappedValue = nullptr ;
28522797
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+
28532810 // Take the initializer from the original property.
28542811 if (!isa<ParamDecl>(var)) {
28552812 auto parentPBD = var->getParentPatternBinding ();
28562813 unsigned patternNumber = parentPBD->getPatternEntryIndexForVarDecl (var);
28572814 auto *backingVar = var->getPropertyWrapperBackingProperty ();
2858- auto *pbd = backingVar-> getParentPatternBinding ( );
2815+ auto *pbd = createPBD (backingVar );
28592816
28602817 // Force the default initializer to come into existence, if there is one,
28612818 // and the wrapper doesn't provide its own.
@@ -2897,21 +2854,25 @@ PropertyWrapperInitializerInfoRequest::evaluate(Evaluator &evaluator,
28972854 // If there is a projection property (projectedValue) in the wrapper,
28982855 // synthesize a computed property for '$foo'.
28992856 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+ }
29152876 }
29162877
29172878 // Form the initialization of the backing property from a value of the
@@ -2920,7 +2881,8 @@ PropertyWrapperInitializerInfoRequest::evaluate(Evaluator &evaluator,
29202881 if (wrappedValue) {
29212882 wrappedValueInit = initializer;
29222883 } else if (!initializer &&
2923- var->allAttachedPropertyWrappersHaveWrappedValueInit ()) {
2884+ var->allAttachedPropertyWrappersHaveWrappedValueInit () &&
2885+ !var->getName ().hasDollarPrefix ()) {
29242886 wrappedValueInit = PropertyWrapperValuePlaceholderExpr::create (
29252887 ctx, var->getSourceRange (), var->getType (), /* wrappedValue=*/ nullptr );
29262888
0 commit comments