From f1c4e1448596e53fbc26cd600f89bdc5866849f6 Mon Sep 17 00:00:00 2001 From: Doug Gregor Date: Wed, 12 Oct 2016 09:41:44 -0700 Subject: [PATCH 1/2] [Type checker] Eliminate generation of useless constraints NFC. There's no point in adding the constraints known on an associated type to the constraint system, because they're implied by the protocol constraint itself. --- lib/Sema/ConstraintSystem.cpp | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/lib/Sema/ConstraintSystem.cpp b/lib/Sema/ConstraintSystem.cpp index f4af19b6f924b..bdf711307c1b9 100644 --- a/lib/Sema/ConstraintSystem.cpp +++ b/lib/Sema/ConstraintSystem.cpp @@ -468,25 +468,6 @@ namespace { FunctionRefKind::Compound, locator)); - if (!archetype) { - // If the nested type is not an archetype (because it was constrained - // to a concrete type by a requirement), return the fresh type - // variable now, and let binding occur during overload resolution. - return memberTypeVar; - } - - // FIXME: Would be better to walk the requirements of the protocol - // of which the associated type is a member. - if (auto superclass = member->getSuperclass()) { - CS.addConstraint(ConstraintKind::Subtype, memberTypeVar, - superclass, locator); - } - - for (auto proto : member->getConformingProtocols()) { - CS.addConstraint(ConstraintKind::ConformsTo, memberTypeVar, - proto->getDeclaredType(), locator); - } - return memberTypeVar; }); } From 735ef839e2aa8d78d521de762285cea84f371671 Mon Sep 17 00:00:00 2001 From: Doug Gregor Date: Thu, 13 Oct 2016 10:16:20 -0700 Subject: [PATCH 2/2] [Code completion] Suppress vacuous infix operator completions. With the previous type-checker change, we end up with some vacuous infix operator completions, where the right-hand side and result type are *both* type variables. Suppress these; they aren't useful to the developer. --- lib/IDE/CodeCompletion.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/IDE/CodeCompletion.cpp b/lib/IDE/CodeCompletion.cpp index ce807b3ac0f6f..8e98882d1de03 100644 --- a/lib/IDE/CodeCompletion.cpp +++ b/lib/IDE/CodeCompletion.cpp @@ -3313,6 +3313,12 @@ class CompletionLookup final : public swift::VisibleDeclConsumer { } } + // If the right-hand side and result type are both type parameters, we're + // not providing a useful completion. + if (expr->getType()->isTypeParameter() && + CCE.getType()->isTypeParameter()) + return; + addInfixOperatorCompletion(op, expr->getType(), CCE.getType()); } }