Skip to content

Commit 138c117

Browse files
committed
[CSGen] Declare generateWrappedPropertyTypeConstraints as a method
on ConstraintSystem.
1 parent 5bb4ad0 commit 138c117

File tree

2 files changed

+30
-25
lines changed

2 files changed

+30
-25
lines changed

include/swift/Sema/ConstraintSystem.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4329,6 +4329,19 @@ class ConstraintSystem {
43294329
llvm::function_ref<ConstraintFix *(unsigned, const OverloadChoice &)>
43304330
getFix = [](unsigned, const OverloadChoice &) { return nullptr; });
43314331

4332+
/// Generate constraints for the given property that has an
4333+
/// attached property wrapper.
4334+
///
4335+
/// \param wrappedVar The property that has a property wrapper.
4336+
/// \param initializerType The type of the initializer for the
4337+
/// backing storage variable.
4338+
/// \param propertyType The type of the wrapped property.
4339+
///
4340+
/// \returns true if there is an error.
4341+
bool generateWrappedPropertyTypeConstraints(VarDecl *wrappedVar,
4342+
Type initializerType,
4343+
Type propertyType);
4344+
43324345
/// Propagate constraints in an effort to enforce local
43334346
/// consistency to reduce the time to solve the system.
43344347
///

lib/Sema/CSGen.cpp

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3602,16 +3602,8 @@ static Expr *generateConstraintsFor(ConstraintSystem &cs, Expr *expr,
36023602
return result;
36033603
}
36043604

3605-
/// Generate constraints to produce the wrapped value type given the property
3606-
/// that has an attached property wrapper.
3607-
///
3608-
/// \param initializerType The type of the adjusted initializer, which
3609-
/// initializes the underlying storage variable.
3610-
/// \param wrappedVar The property that has a property wrapper.
3611-
/// \returns the type of the property.
3612-
static bool generateWrappedPropertyTypeConstraints(
3613-
ConstraintSystem &cs, Type initializerType, VarDecl *wrappedVar,
3614-
Type propertyType) {
3605+
bool ConstraintSystem::generateWrappedPropertyTypeConstraints(
3606+
VarDecl *wrappedVar, Type initializerType, Type propertyType) {
36153607
auto dc = wrappedVar->getInnermostDeclContext();
36163608

36173609
Type wrappedValueType;
@@ -3630,33 +3622,33 @@ static bool generateWrappedPropertyTypeConstraints(
36303622

36313623
if (!wrappedValueType) {
36323624
// Equate the outermost wrapper type to the initializer type.
3633-
auto *locator = cs.getConstraintLocator(typeExpr);
3625+
auto *locator = getConstraintLocator(typeExpr);
36343626
wrapperType =
3635-
cs.replaceInferableTypesWithTypeVars(rawWrapperType, locator);
3627+
replaceInferableTypesWithTypeVars(rawWrapperType, locator);
36363628
if (initializerType)
3637-
cs.addConstraint(ConstraintKind::Equal, wrapperType, initializerType, locator);
3629+
addConstraint(ConstraintKind::Equal, wrapperType, initializerType, locator);
36383630
} else {
36393631
// The former wrappedValue type must be equal to the current wrapper type
3640-
auto *locator = cs.getConstraintLocator(
3632+
auto *locator = getConstraintLocator(
36413633
typeExpr, LocatorPathElt::WrappedValue(wrapperType));
36423634
wrapperType =
3643-
cs.replaceInferableTypesWithTypeVars(rawWrapperType, locator);
3644-
cs.addConstraint(ConstraintKind::Equal, wrapperType, wrappedValueType, locator);
3635+
replaceInferableTypesWithTypeVars(rawWrapperType, locator);
3636+
addConstraint(ConstraintKind::Equal, wrapperType, wrappedValueType, locator);
36453637
}
36463638

3647-
cs.setType(typeExpr, wrapperType);
3639+
setType(typeExpr, wrapperType);
36483640

36493641
wrappedValueType = wrapperType->getTypeOfMember(
36503642
dc->getParentModule(), wrapperInfo.valueVar);
36513643
}
36523644

36533645
// The property type must be equal to the wrapped value type
3654-
cs.addConstraint(
3646+
addConstraint(
36553647
ConstraintKind::Equal, propertyType, wrappedValueType,
3656-
cs.getConstraintLocator(
3648+
getConstraintLocator(
36573649
wrappedVar, LocatorPathElt::ContextualType(CTP_WrappedProperty)));
3658-
cs.setContextualType(wrappedVar, TypeLoc::withoutLoc(wrappedValueType),
3659-
CTP_WrappedProperty);
3650+
setContextualType(wrappedVar, TypeLoc::withoutLoc(wrappedValueType),
3651+
CTP_WrappedProperty);
36603652
return false;
36613653
}
36623654

@@ -3675,8 +3667,8 @@ static bool generateInitPatternConstraints(
36753667
return true;
36763668

36773669
if (auto wrappedVar = target.getInitializationWrappedVar())
3678-
return generateWrappedPropertyTypeConstraints(
3679-
cs, cs.getType(target.getAsExpr()), wrappedVar, patternType);
3670+
return cs.generateWrappedPropertyTypeConstraints(
3671+
wrappedVar, cs.getType(target.getAsExpr()), patternType);
36803672

36813673
if (!patternType->is<OpaqueTypeArchetypeType>()) {
36823674
// Add a conversion constraint between the types.
@@ -3968,7 +3960,7 @@ bool ConstraintSystem::generateConstraints(
39683960
return true;
39693961

39703962
return generateWrappedPropertyTypeConstraints(
3971-
*this, /*initializerType=*/Type(), wrappedVar, propertyType);
3963+
wrappedVar, /*initializerType=*/Type(), propertyType);
39723964
} else {
39733965
auto pattern = target.getAsUninitializedVar();
39743966
auto locator = getConstraintLocator(
@@ -4158,7 +4150,7 @@ ConstraintSystem::applyPropertyWrapperToParameter(
41584150

41594151
initKind = PropertyWrapperInitKind::ProjectedValue;
41604152
} else {
4161-
generateWrappedPropertyTypeConstraints(*this, wrapperType, param, paramType);
4153+
generateWrappedPropertyTypeConstraints(param, wrapperType, paramType);
41624154
initKind = PropertyWrapperInitKind::WrappedValue;
41634155
}
41644156

0 commit comments

Comments
 (0)