Skip to content

Commit 8c4a0dc

Browse files
committed
[ConstraintSystem] Simplify handling of implicit conversions in getArgumentInfo
1 parent f9eb71d commit 8c4a0dc

File tree

1 file changed

+17
-25
lines changed

1 file changed

+17
-25
lines changed

lib/Sema/ConstraintSystem.cpp

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,16 @@ ConstraintLocator *ConstraintSystem::getCalleeLocator(
449449
llvm::function_ref<Type(Type)> simplifyType,
450450
llvm::function_ref<Optional<SelectedOverload>(ConstraintLocator *)>
451451
getOverloadFor) {
452+
if (auto conversion =
453+
locator->findLast<LocatorPathElt::ImplicitConversion>()) {
454+
if (conversion->is(ConversionRestrictionKind::DoubleToCGFloat) ||
455+
conversion->is(ConversionRestrictionKind::CGFloatToDouble)) {
456+
return getConstraintLocator(
457+
ASTNode(), {*conversion, ConstraintLocator::ApplyFunction,
458+
ConstraintLocator::ConstructorMember});
459+
}
460+
}
461+
452462
auto anchor = locator->getAnchor();
453463
assert(bool(anchor) && "Expected an anchor!");
454464

@@ -4304,7 +4314,10 @@ ASTNode constraints::simplifyLocatorToAnchor(ConstraintLocator *locator) {
43044314
}
43054315

43064316
Expr *constraints::getArgumentExpr(ASTNode node, unsigned index) {
4307-
auto *expr = castToExpr(node);
4317+
auto *expr = getAsExpr(node);
4318+
if (!expr)
4319+
return nullptr;
4320+
43084321
Expr *argExpr = nullptr;
43094322
if (auto *AE = dyn_cast<ApplyExpr>(expr))
43104323
argExpr = AE->getArg();
@@ -4443,7 +4456,9 @@ void ConstraintSystem::generateConstraints(
44434456
ConstraintLocator *
44444457
ConstraintSystem::getArgumentInfoLocator(ConstraintLocator *locator) {
44454458
auto anchor = locator->getAnchor();
4446-
if (!anchor)
4459+
4460+
// An empty locator which code completion uses for member references.
4461+
if (anchor.isNull() && locator->getPath().empty())
44474462
return nullptr;
44484463

44494464
// Applies and unresolved member exprs can have callee locators that are
@@ -4477,29 +4492,6 @@ ConstraintSystem::getArgumentInfo(ConstraintLocator *locator) {
44774492
if (!locator)
44784493
return None;
44794494

4480-
// Implicit conversions to/from CGFloat type are modeled without
4481-
// any changes to the AST, so we have to accomodate for that here
4482-
// by faking presence of appopriate AST location.
4483-
if (locator->isLastElement<LocatorPathElt::ApplyArgument>() ||
4484-
locator->isLastElement<LocatorPathElt::ApplyFunction>()) {
4485-
auto path = locator->getPath().drop_back();
4486-
if (!path.empty() && path.back().is<LocatorPathElt::ImplicitConversion>()) {
4487-
auto conversion = path.back()
4488-
.castTo<LocatorPathElt::ImplicitConversion>()
4489-
.getConversionKind();
4490-
4491-
if (conversion == ConversionRestrictionKind::DoubleToCGFloat ||
4492-
conversion == ConversionRestrictionKind::CGFloatToDouble) {
4493-
// TODO: This is not very efficient, long term we should just
4494-
// save a single `ArgumentInfo` and use it for all of
4495-
// the locations where conversion is needed.
4496-
ArrayRef<Identifier> labels{Identifier()};
4497-
return ArgumentInfo{.Labels = allocateCopy(labels),
4498-
.UnlabeledTrailingClosureIndex = None};
4499-
}
4500-
}
4501-
}
4502-
45034495
if (auto *infoLocator = getArgumentInfoLocator(locator)) {
45044496
auto known = ArgumentInfos.find(infoLocator);
45054497
if (known != ArgumentInfos.end())

0 commit comments

Comments
 (0)