Skip to content

Commit 074480e

Browse files
committed
[CS] Set property wrapper auxiliary var types in constraint generation
Rather than computing these each time we need to solve an element that has a reference to them, let's just set them up-front when we generate constraints for the corresponding variable.
1 parent 0f28563 commit 074480e

File tree

1 file changed

+23
-30
lines changed

1 file changed

+23
-30
lines changed

lib/Sema/CSSyntacticElement.cpp

Lines changed: 23 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -141,36 +141,6 @@ class TypeVariableRefFinder : public ASTWalker {
141141
if (!var)
142142
return Action::Continue(expr);
143143

144-
if (auto *wrappedVar = var->getOriginalWrappedProperty()) {
145-
// If there is no type it means that the body of the
146-
// closure hasn't been resolved yet, so we can
147-
// just skip it and wait for \c applyPropertyWrapperToParameter
148-
// to assign types.
149-
if (wrappedVar->hasImplicitPropertyWrapper())
150-
return Action::Continue(expr);
151-
152-
auto outermostWrapperAttr =
153-
wrappedVar->getOutermostAttachedPropertyWrapper();
154-
155-
// If the attribute doesn't have a type it could only mean
156-
// that the declaration was incorrect.
157-
if (!CS.hasType(outermostWrapperAttr->getTypeExpr()))
158-
return Action::Continue(expr);
159-
160-
auto wrapperType =
161-
CS.simplifyType(CS.getType(outermostWrapperAttr->getTypeExpr()));
162-
163-
if (var->getName().hasDollarPrefix()) {
164-
// $<name> is the projected value var
165-
CS.setType(var, computeProjectedValueType(wrappedVar, wrapperType));
166-
} else {
167-
// _<name> is the wrapper var
168-
CS.setType(var, wrapperType);
169-
}
170-
171-
return Action::Continue(expr);
172-
}
173-
174144
// If there is no type recorded yet, let's check whether
175145
// it is a placeholder variable implicitly generated by the
176146
// compiler.
@@ -817,6 +787,26 @@ class SyntacticElementConstraintGenerator
817787
patternType);
818788
}
819789

790+
void setPropertyWrapperAuxiliaryTypes(const SyntacticElementTarget &target) {
791+
if (!target.isForInitialization())
792+
return;
793+
794+
auto *wrappedVar = target.getInitializationWrappedVar();
795+
if (!wrappedVar)
796+
return;
797+
798+
auto *outermostAttr = wrappedVar->getOutermostAttachedPropertyWrapper();
799+
auto *wrapperTypeExpr = outermostAttr->getTypeExpr();
800+
801+
auto wrapperTy = cs.simplifyType(cs.getType(wrapperTypeExpr));
802+
if (auto *projectedVal = wrappedVar->getPropertyWrapperProjectionVar()) {
803+
auto projectedTy = computeProjectedValueType(wrappedVar, wrapperTy);
804+
cs.setType(projectedVal, projectedTy);
805+
}
806+
if (auto *backing = wrappedVar->getPropertyWrapperBackingProperty())
807+
cs.setType(backing, wrapperTy);
808+
}
809+
820810
void visitPatternBindingElement(PatternBindingDecl *patternBinding) {
821811
assert(locator->isLastElement<LocatorPathElt::PatternBindingElement>());
822812

@@ -847,6 +837,9 @@ class SyntacticElementConstraintGenerator
847837
hadError = true;
848838
return;
849839
}
840+
841+
// Set the types of any auxiliary property wrapper vars.
842+
setPropertyWrapperAuxiliaryTypes(*target);
850843
}
851844

852845
void visitDecl(Decl *decl) {

0 commit comments

Comments
 (0)