Skip to content

Commit 5a93255

Browse files
committed
[ConstraintSystem] Introduce new LValueObject constraint
1 parent 00eee36 commit 5a93255

File tree

5 files changed

+41
-0
lines changed

5 files changed

+41
-0
lines changed

include/swift/Sema/Constraint.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,8 @@ enum class ConstraintKind : char {
221221
/// The first type is a tuple containing a single unlabeled element that is a
222222
/// pack expansion. The second type is its pattern type.
223223
MaterializePackExpansion,
224+
/// The first type is a l-value type whose object type is the second type.
225+
LValueObject,
224226
};
225227

226228
/// Classification of the different kinds of constraints.
@@ -691,6 +693,7 @@ class Constraint final : public llvm::ilist_node<Constraint>,
691693
case ConstraintKind::PackElementOf:
692694
case ConstraintKind::SameShape:
693695
case ConstraintKind::MaterializePackExpansion:
696+
case ConstraintKind::LValueObject:
694697
return ConstraintClassification::Relational;
695698

696699
case ConstraintKind::ValueMember:

include/swift/Sema/ConstraintSystem.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5239,6 +5239,12 @@ class ConstraintSystem {
52395239
TypeMatchOptions flags,
52405240
ConstraintLocatorBuilder locator);
52415241

5242+
/// Extract the object type of the l-value type (type1) and bind it to
5243+
/// to type2.
5244+
SolutionKind simplifyLValueObjectConstraint(Type type1, Type type2,
5245+
TypeMatchOptions flags,
5246+
ConstraintLocatorBuilder locator);
5247+
52425248
public: // FIXME: Public for use by static functions.
52435249
/// Simplify a conversion constraint with a fix applied to it.
52445250
SolutionKind simplifyFixConstraint(ConstraintFix *fix, Type type1, Type type2,

lib/Sema/CSBindings.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1797,6 +1797,11 @@ void PotentialBindings::infer(Constraint *constraint) {
17971797
// Constraints from which we can't do anything.
17981798
break;
17991799

1800+
case ConstraintKind::LValueObject: {
1801+
DelayedBy.push_back(constraint);
1802+
break;
1803+
}
1804+
18001805
// For now let's avoid inferring protocol requirements from
18011806
// this constraint, but in the future we could do that to
18021807
// to filter bindings.

lib/Sema/CSSimplify.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2313,6 +2313,7 @@ ConstraintSystem::matchTupleTypes(TupleType *tuple1, TupleType *tuple2,
23132313
case ConstraintKind::ExplicitGenericArguments:
23142314
case ConstraintKind::SameShape:
23152315
case ConstraintKind::MaterializePackExpansion:
2316+
case ConstraintKind::LValueObject:
23162317
llvm_unreachable("Bad constraint kind in matchTupleTypes()");
23172318
}
23182319

@@ -2673,6 +2674,7 @@ static bool matchFunctionRepresentations(FunctionType::ExtInfo einfo1,
26732674
case ConstraintKind::ExplicitGenericArguments:
26742675
case ConstraintKind::SameShape:
26752676
case ConstraintKind::MaterializePackExpansion:
2677+
case ConstraintKind::LValueObject:
26762678
return true;
26772679
}
26782680

@@ -3318,6 +3320,7 @@ ConstraintSystem::matchFunctionTypes(FunctionType *func1, FunctionType *func2,
33183320
case ConstraintKind::ExplicitGenericArguments:
33193321
case ConstraintKind::SameShape:
33203322
case ConstraintKind::MaterializePackExpansion:
3323+
case ConstraintKind::LValueObject:
33213324
llvm_unreachable("Not a relational constraint");
33223325
}
33233326

@@ -7179,6 +7182,7 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
71797182
case ConstraintKind::ExplicitGenericArguments:
71807183
case ConstraintKind::SameShape:
71817184
case ConstraintKind::MaterializePackExpansion:
7185+
case ConstraintKind::LValueObject:
71827186
llvm_unreachable("Not a relational constraint");
71837187
}
71847188
}
@@ -14147,6 +14151,13 @@ ConstraintSystem::simplifyExplicitGenericArgumentsConstraint(
1414714151
return SolutionKind::Solved;
1414814152
}
1414914153

14154+
ConstraintSystem::SolutionKind
14155+
ConstraintSystem::simplifyLValueObjectConstraint(
14156+
Type type1, Type type2, TypeMatchOptions flags,
14157+
ConstraintLocatorBuilder locator) {
14158+
return SolutionKind::Error;
14159+
}
14160+
1415014161
static llvm::PointerIntPair<Type, 3, unsigned>
1415114162
getBaseTypeForPointer(TypeBase *type) {
1415214163
unsigned unwrapCount = 0;
@@ -15614,6 +15625,9 @@ ConstraintSystem::addConstraintImpl(ConstraintKind kind, Type first,
1561415625
return simplifyMaterializePackExpansionConstraint(first, second, subflags,
1561515626
locator);
1561615627

15628+
case ConstraintKind::LValueObject:
15629+
return simplifyLValueObjectConstraint(first, second, subflags, locator);
15630+
1561715631
case ConstraintKind::ValueMember:
1561815632
case ConstraintKind::UnresolvedValueMember:
1561915633
case ConstraintKind::ValueWitness:
@@ -16209,6 +16223,11 @@ ConstraintSystem::simplifyConstraint(const Constraint &constraint) {
1620916223
return simplifyMaterializePackExpansionConstraint(
1621016224
constraint.getFirstType(), constraint.getSecondType(),
1621116225
/*flags*/ std::nullopt, constraint.getLocator());
16226+
16227+
case ConstraintKind::LValueObject:
16228+
return simplifyLValueObjectConstraint(
16229+
constraint.getFirstType(), constraint.getSecondType(),
16230+
/*flags*/ std::nullopt, constraint.getLocator());
1621216231
}
1621316232

1621416233
llvm_unreachable("Unhandled ConstraintKind in switch.");

lib/Sema/Constraint.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ Constraint::Constraint(ConstraintKind Kind, Type First, Type Second,
8585
case ConstraintKind::ExplicitGenericArguments:
8686
case ConstraintKind::SameShape:
8787
case ConstraintKind::MaterializePackExpansion:
88+
case ConstraintKind::LValueObject:
8889
assert(!First.isNull());
8990
assert(!Second.isNull());
9091
break;
@@ -176,6 +177,7 @@ Constraint::Constraint(ConstraintKind Kind, Type First, Type Second, Type Third,
176177
case ConstraintKind::ExplicitGenericArguments:
177178
case ConstraintKind::SameShape:
178179
case ConstraintKind::MaterializePackExpansion:
180+
case ConstraintKind::LValueObject:
179181
llvm_unreachable("Wrong constructor");
180182

181183
case ConstraintKind::KeyPath:
@@ -326,6 +328,7 @@ Constraint *Constraint::clone(ConstraintSystem &cs) const {
326328
case ConstraintKind::ExplicitGenericArguments:
327329
case ConstraintKind::SameShape:
328330
case ConstraintKind::MaterializePackExpansion:
331+
case ConstraintKind::LValueObject:
329332
return create(cs, getKind(), getFirstType(), getSecondType(), getLocator());
330333

331334
case ConstraintKind::ApplicableFunction:
@@ -590,6 +593,10 @@ void Constraint::print(llvm::raw_ostream &Out, SourceManager *sm,
590593
Out << " materialize pack expansion ";
591594
break;
592595

596+
case ConstraintKind::LValueObject:
597+
Out << " l-value object type ";
598+
break;
599+
593600
case ConstraintKind::Disjunction:
594601
llvm_unreachable("disjunction handled above");
595602
case ConstraintKind::Conjunction:
@@ -760,6 +767,7 @@ gatherReferencedTypeVars(Constraint *constraint,
760767
case ConstraintKind::ExplicitGenericArguments:
761768
case ConstraintKind::SameShape:
762769
case ConstraintKind::MaterializePackExpansion:
770+
case ConstraintKind::LValueObject:
763771
constraint->getFirstType()->getTypeVariables(typeVars);
764772
constraint->getSecondType()->getTypeVariables(typeVars);
765773
break;

0 commit comments

Comments
 (0)