Skip to content

Commit 5957a92

Browse files
committed
Reapply Simplify resolveLocatorToDecl to return a ConcreteDeclRef instead of
having it return a ResolvedLocator, allowing us to remove ResolvedLocator The previous commit accidentally dropped the hunk in CSApply.cpp. NFC.
1 parent f4e26ea commit 5957a92

File tree

3 files changed

+25
-84
lines changed

3 files changed

+25
-84
lines changed

lib/Sema/CSApply.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3393,7 +3393,7 @@ findDefaultArgsOwner(ConstraintSystem &cs, const Solution &solution,
33933393

33943394
return decl;
33953395
})) {
3396-
return resolved.getDecl();
3396+
return resolved;
33973397
}
33983398

33993399
return nullptr;

lib/Sema/CSDiag.cpp

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ static ParameterList *getParameterList(ValueDecl *decl) {
303303
return nullptr;
304304
}
305305

306-
ResolvedLocator constraints::resolveLocatorToDecl(
306+
ConcreteDeclRef constraints::resolveLocatorToDecl(
307307
ConstraintSystem &cs,
308308
ConstraintLocator *locator,
309309
std::function<Optional<SelectedOverload>(ConstraintLocator *)> findOvlChoice,
@@ -312,7 +312,7 @@ ResolvedLocator constraints::resolveLocatorToDecl(
312312
{
313313
assert(locator && "Null locator");
314314
if (!locator->getAnchor())
315-
return ResolvedLocator();
315+
return ConcreteDeclRef();
316316

317317
ConcreteDeclRef declRef;
318318
auto anchor = locator->getAnchor();
@@ -391,7 +391,7 @@ ResolvedLocator constraints::resolveLocatorToDecl(
391391

392392
// If we didn't find the declaration, we're out of luck.
393393
if (!declRef)
394-
return ResolvedLocator();
394+
return ConcreteDeclRef();
395395

396396
// Use the declaration and the path to produce a more specific result.
397397
// FIXME: This is an egregious hack. We'd be far better off
@@ -416,10 +416,8 @@ ResolvedLocator constraints::resolveLocatorToDecl(
416416
if (!parameterList) break;
417417

418418
unsigned index = path[0].getValue2();
419-
if (index < parameterList->size()) {
420-
auto param = parameterList->get(index);
421-
return ResolvedLocator(ResolvedLocator::ForVar, param);
422-
}
419+
if (index < parameterList->size())
420+
return parameterList->get(index);
423421
break;
424422
}
425423

@@ -431,14 +429,13 @@ ResolvedLocator constraints::resolveLocatorToDecl(
431429
}
432430

433431
// Otherwise, do the best we can with the declaration we found.
434-
if (isa<FuncDecl>(declRef.getDecl()))
435-
return ResolvedLocator(ResolvedLocator::ForFunction, declRef);
436-
if (isa<ConstructorDecl>(declRef.getDecl()))
437-
return ResolvedLocator(ResolvedLocator::ForConstructor, declRef);
438-
439432
// FIXME: Deal with the other interesting cases here, e.g.,
440433
// subscript declarations.
441-
return ResolvedLocator();
434+
if (isa<FuncDecl>(declRef.getDecl()) ||
435+
isa<ConstructorDecl>(declRef.getDecl()))
436+
return declRef;
437+
438+
return ConcreteDeclRef();
442439
}
443440

444441
/// Emit a note referring to the target of a diagnostic, e.g., the function
@@ -463,32 +460,29 @@ static void noteTargetOfDiagnostic(ConstraintSystem &cs,
463460
if (!resolved)
464461
return;
465462

466-
switch (resolved.getKind()) {
467-
case ResolvedLocatorKind::Unresolved:
468-
// Can't emit any diagnostic here.
469-
return;
470-
471-
case ResolvedLocatorKind::Function: {
472-
auto name = resolved.getDecl().getDecl()->getName();
473-
cs.getTypeChecker().diagnose(resolved.getDecl().getDecl(),
463+
auto decl = resolved.getDecl();
464+
if (isa<FuncDecl>(decl)) {
465+
auto name = decl->getName();
466+
cs.getTypeChecker().diagnose(decl,
474467
name.isOperator()? diag::note_call_to_operator
475468
: diag::note_call_to_func,
476-
resolved.getDecl().getDecl()->getName());
469+
name);
477470
return;
478471
}
479472

480-
case ResolvedLocatorKind::Constructor:
473+
if (isa<ConstructorDecl>(decl)) {
481474
// FIXME: Specialize for implicitly-generated constructors.
482-
cs.getTypeChecker().diagnose(resolved.getDecl().getDecl(),
483-
diag::note_call_to_initializer);
475+
cs.getTypeChecker().diagnose(decl, diag::note_call_to_initializer);
484476
return;
477+
}
485478

486-
case ResolvedLocatorKind::Parameter:
487-
cs.getTypeChecker().diagnose(resolved.getDecl().getDecl(),
488-
diag::note_init_parameter,
489-
resolved.getDecl().getDecl()->getName());
479+
if (isa<ParamDecl>(decl)) {
480+
cs.getTypeChecker().diagnose(decl, diag::note_init_parameter,
481+
decl->getName());
490482
return;
491483
}
484+
485+
// FIXME: Other decl types too.
492486
}
493487

494488
/// \brief Determine the number of distinct overload choices in the

lib/Sema/ConstraintSystem.h

Lines changed: 1 addition & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -2232,59 +2232,6 @@ void simplifyLocator(Expr *&anchor,
22322232
SmallVectorImpl<LocatorPathElt> &targetPath,
22332233
SourceRange &range);
22342234

2235-
/// Describes the kind of entity to which a locator was resolved.
2236-
enum class ResolvedLocatorKind : uint8_t {
2237-
/// The locator could not be resolved.
2238-
Unresolved,
2239-
/// The locator refers to a function.
2240-
Function,
2241-
/// The locator refers to a constructor.
2242-
Constructor,
2243-
/// The locator refers to a parameter of a function.
2244-
Parameter
2245-
};
2246-
2247-
/// The entity to which a locator resolved.
2248-
class ResolvedLocator {
2249-
ResolvedLocatorKind kind;
2250-
ConcreteDeclRef decl;
2251-
2252-
public:
2253-
ResolvedLocator() : kind(ResolvedLocatorKind::Unresolved) { }
2254-
2255-
enum ForFunction_t { ForFunction };
2256-
enum ForConstructor_t { ForConstructor };
2257-
enum ForVar_t { ForVar };
2258-
2259-
ResolvedLocator(ForFunction_t, ConcreteDeclRef decl)
2260-
: kind(ResolvedLocatorKind::Function), decl(decl)
2261-
{
2262-
assert(isa<FuncDecl>(decl.getDecl()));
2263-
}
2264-
2265-
ResolvedLocator(ForConstructor_t, ConcreteDeclRef decl)
2266-
: kind(ResolvedLocatorKind::Constructor), decl(decl)
2267-
{
2268-
assert(isa<ConstructorDecl>(decl.getDecl()));
2269-
}
2270-
2271-
ResolvedLocator(ForVar_t, ConcreteDeclRef decl)
2272-
: kind(ResolvedLocatorKind::Parameter), decl(decl)
2273-
{
2274-
assert(isa<VarDecl>(decl.getDecl()));
2275-
}
2276-
2277-
/// Determine the kind of entity to which the locator resolved.
2278-
ResolvedLocatorKind getKind() const { return kind; }
2279-
2280-
/// Retrieve the declaration to which the locator resolved.
2281-
ConcreteDeclRef getDecl() const { return decl; }
2282-
2283-
explicit operator bool() const {
2284-
return getKind() != ResolvedLocatorKind::Unresolved;
2285-
}
2286-
};
2287-
22882235
/// Resolve a locator to the specific declaration it references, if possible.
22892236
///
22902237
/// \param cs The constraint system in which the locator will be resolved.
@@ -2298,7 +2245,7 @@ class ResolvedLocator {
22982245
/// \returns the entity to which the locator resolved.
22992246
///
23002247
/// FIXME: It would be more natural to express the result as a locator.
2301-
ResolvedLocator resolveLocatorToDecl(
2248+
ConcreteDeclRef resolveLocatorToDecl(
23022249
ConstraintSystem &cs,
23032250
ConstraintLocator *locator,
23042251
std::function<Optional<SelectedOverload>(ConstraintLocator *)>

0 commit comments

Comments
 (0)