Skip to content

Commit e901bd0

Browse files
committed
Continue whittling away at complexity in resolveLocatorToDecl.
This time remove the hacky/fixme code to drill into parameter lists which is dead.
1 parent 729a1c8 commit e901bd0

File tree

1 file changed

+22
-75
lines changed

1 file changed

+22
-75
lines changed

lib/Sema/CSDiag.cpp

Lines changed: 22 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -289,20 +289,6 @@ static Expr *simplifyLocatorToAnchor(ConstraintSystem &cs,
289289
return locator->getAnchor();
290290
}
291291

292-
/// Retrieve the argument pattern for the given declaration.
293-
///
294-
static ParameterList *getParameterList(ValueDecl *decl) {
295-
if (auto func = dyn_cast<FuncDecl>(decl))
296-
return func->getParameterList(0);
297-
if (auto constructor = dyn_cast<ConstructorDecl>(decl))
298-
return constructor->getParameterList(1);
299-
if (auto subscript = dyn_cast<SubscriptDecl>(decl))
300-
return subscript->getIndices();
301-
302-
// FIXME: Variables of function type?
303-
return nullptr;
304-
}
305-
306292
ConcreteDeclRef constraints::resolveLocatorToDecl(
307293
ConstraintSystem &cs,
308294
ConstraintLocator *locator,
@@ -314,7 +300,6 @@ ConcreteDeclRef constraints::resolveLocatorToDecl(
314300
if (!locator->getAnchor())
315301
return ConcreteDeclRef();
316302

317-
ConcreteDeclRef declRef;
318303
auto anchor = locator->getAnchor();
319304
// Unwrap any specializations, constructor calls, implicit conversions, and
320305
// '.'s.
@@ -355,79 +340,41 @@ ConcreteDeclRef constraints::resolveLocatorToDecl(
355340
break;
356341
} while (true);
357342

358-
auto getConcreteDeclRefFromOverload
359-
= [&](const SelectedOverload &selected) -> ConcreteDeclRef {
360-
return getConcreteDeclRef(selected.choice.getDecl(),
361-
selected.openedType);
362-
};
343+
// Simple case: direct reference to a declaration.
344+
if (auto dre = dyn_cast<DeclRefExpr>(anchor))
345+
return dre->getDeclRef();
346+
347+
// Simple case: direct reference to a declaration.
348+
if (auto mre = dyn_cast<MemberRefExpr>(anchor))
349+
return mre->getMember();
363350

364-
if (auto dre = dyn_cast<DeclRefExpr>(anchor)) {
365-
// Simple case: direct reference to a declaration.
366-
declRef = dre->getDeclRef();
367-
} else if (auto mre = dyn_cast<MemberRefExpr>(anchor)) {
368-
// Simple case: direct reference to a declaration.
369-
declRef = mre->getMember();
370-
} else if (isa<OverloadedDeclRefExpr>(anchor) ||
371-
isa<OverloadedMemberRefExpr>(anchor) ||
372-
isa<UnresolvedDeclRefExpr>(anchor)) {
351+
if (auto ctorRef = dyn_cast<OtherConstructorDeclRefExpr>(anchor))
352+
return ctorRef->getDeclRef();
353+
354+
if (isa<OverloadedDeclRefExpr>(anchor) ||
355+
isa<OverloadedMemberRefExpr>(anchor) ||
356+
isa<UnresolvedDeclRefExpr>(anchor)) {
373357
// Overloaded and unresolved cases: find the resolved overload.
374358
auto anchorLocator = cs.getConstraintLocator(anchor);
375359
if (auto selected = findOvlChoice(anchorLocator)) {
376360
if (selected->choice.isDecl())
377-
declRef = getConcreteDeclRefFromOverload(*selected);
361+
return getConcreteDeclRef(selected->choice.getDecl(),
362+
selected->openedType);
378363
}
379-
} else if (isa<UnresolvedMemberExpr>(anchor)) {
364+
}
365+
366+
if (isa<UnresolvedMemberExpr>(anchor)) {
380367
// Unresolved member: find the resolved overload.
381-
auto anchorLocator = cs.getConstraintLocator(
382-
anchor,
368+
auto anchorLocator = cs.getConstraintLocator(anchor,
383369
ConstraintLocator::UnresolvedMember);
384370
if (auto selected = findOvlChoice(anchorLocator)) {
385371
if (selected->choice.isDecl())
386-
declRef = getConcreteDeclRefFromOverload(*selected);
372+
return getConcreteDeclRef(selected->choice.getDecl(),
373+
selected->openedType);
387374
}
388-
} else if (auto ctorRef = dyn_cast<OtherConstructorDeclRefExpr>(anchor)) {
389-
declRef = ctorRef->getDeclRef();
390375
}
391376

392-
// If we didn't find the declaration, we're out of luck.
393-
if (!declRef)
394-
return ConcreteDeclRef();
395-
396-
// Use the declaration and the path to produce a more specific result.
397-
// FIXME: This is an egregious hack. We'd be far better off
398-
// FIXME: Perform deeper path resolution?
399-
auto path = locator->getPath();
400-
ParameterList *parameterList = nullptr;
401-
bool impliesFullPattern = false;
402-
while (!path.empty()) {
403-
switch (path[0].getKind()) {
404-
case ConstraintLocator::ApplyArgument:
405-
// If we're calling into something that has parameters, dig into the
406-
// actual parameter pattern.
407-
parameterList = getParameterList(declRef.getDecl());
408-
if (!parameterList)
409-
break;
410-
411-
impliesFullPattern = true;
412-
path = path.slice(1);
413-
continue;
414-
415-
case ConstraintLocator::ApplyArgToParam: {
416-
if (!parameterList) break;
417-
418-
unsigned index = path[0].getValue2();
419-
if (index < parameterList->size())
420-
return parameterList->get(index);
421-
break;
422-
}
423-
424-
default:
425-
break;
426-
}
427-
428-
break;
429-
}
430-
return declRef;
377+
return ConcreteDeclRef();
431378
}
432379

433380
/// Emit a note referring to the target of a diagnostic, e.g., the function

0 commit comments

Comments
 (0)