Skip to content

Commit f0bec29

Browse files
committed
RequirementMachine: Pull ConcreteTypeMatcher out of unifyConcreteTypes()
I'm going to use this to unify superclass types as well.
1 parent 9eb87df commit f0bec29

File tree

1 file changed

+48
-45
lines changed

1 file changed

+48
-45
lines changed

lib/AST/RequirementMachine/PropertyMap.cpp

Lines changed: 48 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -334,55 +334,21 @@ remapConcreteSubstitutionSchema(CanType concreteType,
334334
}));
335335
}
336336

337-
/// When a type parameter has two concrete types, we have to unify the
338-
/// type constructor arguments.
339-
///
340-
/// For example, suppose that we have two concrete same-type requirements:
341-
///
342-
/// T == Foo<X.Y, Z, String>
343-
/// T == Foo<Int, A.B, W>
344-
///
345-
/// These lower to the following two rules:
346-
///
347-
/// T.[concrete: Foo<τ_0_0, τ_0_1, String> with {X.Y, Z}]
348-
/// T.[concrete: Foo<Int, τ_0_0, τ_0_1> with {A.B, W}]
349-
///
350-
/// The two concrete type symbols will be added to the property bag of 'T',
351-
/// and we will eventually end up in this method, where we will generate three
352-
/// induced rules:
353-
///
354-
/// X.Y.[concrete: Int] => X.Y
355-
/// A.B => Z
356-
/// W.[concrete: String] => W
357-
///
358-
/// Returns the left hand side on success (it could also return the right hand
359-
/// side; since we unified the type constructor arguments, it doesn't matter).
360-
///
361-
/// Returns true if a conflict was detected.
362-
static bool unifyConcreteTypes(
363-
Symbol lhs, Symbol rhs, RewriteContext &ctx,
364-
SmallVectorImpl<std::pair<MutableTerm, MutableTerm>> &inducedRules,
365-
bool debug) {
366-
auto lhsType = lhs.getConcreteType();
367-
auto rhsType = rhs.getConcreteType();
368-
369-
if (debug) {
370-
llvm::dbgs() << "% Unifying " << lhs << " with " << rhs << "\n";
371-
}
372-
373-
class Matcher : public TypeMatcher<Matcher> {
337+
namespace {
338+
class ConcreteTypeMatcher : public TypeMatcher<ConcreteTypeMatcher> {
374339
ArrayRef<Term> lhsSubstitutions;
375340
ArrayRef<Term> rhsSubstitutions;
376341
RewriteContext &ctx;
377342
SmallVectorImpl<std::pair<MutableTerm, MutableTerm>> &inducedRules;
378343
bool debug;
379344

380345
public:
381-
Matcher(ArrayRef<Term> lhsSubstitutions,
382-
ArrayRef<Term> rhsSubstitutions,
383-
RewriteContext &ctx,
384-
SmallVectorImpl<std::pair<MutableTerm, MutableTerm>> &inducedRules,
385-
bool debug)
346+
ConcreteTypeMatcher(ArrayRef<Term> lhsSubstitutions,
347+
ArrayRef<Term> rhsSubstitutions,
348+
RewriteContext &ctx,
349+
SmallVectorImpl<std::pair<MutableTerm,
350+
MutableTerm>> &inducedRules,
351+
bool debug)
386352
: lhsSubstitutions(lhsSubstitutions),
387353
rhsSubstitutions(rhsSubstitutions),
388354
ctx(ctx), inducedRules(inducedRules), debug(debug) {}
@@ -459,10 +425,47 @@ static bool unifyConcreteTypes(
459425
return false;
460426
}
461427
};
428+
}
429+
430+
/// When a type parameter has two concrete types, we have to unify the
431+
/// type constructor arguments.
432+
///
433+
/// For example, suppose that we have two concrete same-type requirements:
434+
///
435+
/// T == Foo<X.Y, Z, String>
436+
/// T == Foo<Int, A.B, W>
437+
///
438+
/// These lower to the following two rules:
439+
///
440+
/// T.[concrete: Foo<τ_0_0, τ_0_1, String> with {X.Y, Z}]
441+
/// T.[concrete: Foo<Int, τ_0_0, τ_0_1> with {A.B, W}]
442+
///
443+
/// The two concrete type symbols will be added to the property bag of 'T',
444+
/// and we will eventually end up in this method, where we will generate three
445+
/// induced rules:
446+
///
447+
/// X.Y.[concrete: Int] => X.Y
448+
/// A.B => Z
449+
/// W.[concrete: String] => W
450+
///
451+
/// Returns the left hand side on success (it could also return the right hand
452+
/// side; since we unified the type constructor arguments, it doesn't matter).
453+
///
454+
/// Returns true if a conflict was detected.
455+
static bool unifyConcreteTypes(
456+
Symbol lhs, Symbol rhs, RewriteContext &ctx,
457+
SmallVectorImpl<std::pair<MutableTerm, MutableTerm>> &inducedRules,
458+
bool debug) {
459+
auto lhsType = lhs.getConcreteType();
460+
auto rhsType = rhs.getConcreteType();
461+
462+
if (debug) {
463+
llvm::dbgs() << "% Unifying " << lhs << " with " << rhs << "\n";
464+
}
462465

463-
Matcher matcher(lhs.getSubstitutions(),
464-
rhs.getSubstitutions(),
465-
ctx, inducedRules, debug);
466+
ConcreteTypeMatcher matcher(lhs.getSubstitutions(),
467+
rhs.getSubstitutions(),
468+
ctx, inducedRules, debug);
466469
if (!matcher.match(lhsType, rhsType)) {
467470
// FIXME: Diagnose the conflict
468471
if (debug) {

0 commit comments

Comments
 (0)