Skip to content

Commit 6318ebc

Browse files
authored
Merge pull request #26164 from pschuh/s-13
Delete TypeChecker::callWitness.
2 parents 5969aca + 2d97c34 commit 6318ebc

File tree

2 files changed

+0
-177
lines changed

2 files changed

+0
-177
lines changed

lib/Sema/CSApply.cpp

Lines changed: 0 additions & 154 deletions
Original file line numberDiff line numberDiff line change
@@ -7600,157 +7600,3 @@ Expr *Solution::coerceToType(Expr *expr, Type toType,
76007600
rewriter.finalize(result);
76017601
return result;
76027602
}
7603-
7604-
// Determine whether this is a variadic witness.
7605-
static bool isVariadicWitness(AbstractFunctionDecl *afd) {
7606-
for (auto param : *afd->getParameters())
7607-
if (param->isVariadic())
7608-
return true;
7609-
7610-
return false;
7611-
}
7612-
7613-
static bool argumentNamesMatch(Type argTy, ArrayRef<Identifier> names) {
7614-
auto tupleType = argTy->getAs<TupleType>();
7615-
if (!tupleType)
7616-
return names.size() == 1 && names[0].empty();
7617-
7618-
if (tupleType->getNumElements() != names.size())
7619-
return false;
7620-
7621-
for (unsigned i = 0, n = tupleType->getNumElements(); i != n; ++i) {
7622-
if (tupleType->getElement(i).getName() != names[i])
7623-
return false;
7624-
}
7625-
7626-
return true;
7627-
}
7628-
7629-
Expr *TypeChecker::callWitness(Expr *base, DeclContext *dc,
7630-
ProtocolDecl *protocol,
7631-
ProtocolConformanceRef conformance,
7632-
DeclName name,
7633-
ArrayRef<Expr *> arguments,
7634-
Diag<> brokenProtocolDiag) {
7635-
// Construct an empty constraint system and solution.
7636-
ConstraintSystem cs(*this, dc, ConstraintSystemOptions());
7637-
7638-
for (auto *arg : arguments)
7639-
cs.cacheType(arg);
7640-
7641-
// Find the witness we need to use.
7642-
auto type = base->getType();
7643-
assert(!type->hasTypeVariable() &&
7644-
"Building call to witness with unresolved base type!");
7645-
7646-
if (auto metaType = type->getAs<AnyMetatypeType>())
7647-
type = metaType->getInstanceType();
7648-
7649-
// Find the member used to satisfy the named requirement.
7650-
auto witness = conformance.getWitnessByName(type, name);
7651-
if (!witness || !isa<AbstractFunctionDecl>(witness.getDecl()))
7652-
return nullptr;
7653-
7654-
auto *witnessFn = cast<AbstractFunctionDecl>(witness.getDecl());
7655-
7656-
// Form a syntactic expression that describes the reference to the
7657-
// witness.
7658-
// FIXME: Egregious hack.
7659-
auto unresolvedDot = new (Context) UnresolvedDotExpr(
7660-
base, SourceLoc(),
7661-
witness.getDecl()->getFullName(),
7662-
DeclNameLoc(base->getEndLoc()),
7663-
/*Implicit=*/true);
7664-
unresolvedDot->setFunctionRefKind(FunctionRefKind::SingleApply);
7665-
auto dotLocator = cs.getConstraintLocator(unresolvedDot);
7666-
7667-
// Form a reference to the witness itself.
7668-
Type openedFullType, openedType;
7669-
std::tie(openedFullType, openedType)
7670-
= cs.getTypeOfMemberReference(base->getType(), witness.getDecl(), dc,
7671-
/*isDynamicResult=*/false,
7672-
FunctionRefKind::DoubleApply,
7673-
dotLocator);
7674-
7675-
auto getType = [&](const Expr *E) -> Type {
7676-
return cs.getType(E);
7677-
};
7678-
7679-
// Form the call argument.
7680-
// FIXME: Standardize all callers to always provide all argument names,
7681-
// rather than hack around this.
7682-
CallExpr *call;
7683-
auto argLabels = witness.getDecl()->getFullName().getArgumentNames();
7684-
if (arguments.size() == 1 &&
7685-
(isVariadicWitness(witnessFn) ||
7686-
argumentNamesMatch(cs.getType(arguments[0]), argLabels))) {
7687-
call = CallExpr::create(Context, unresolvedDot, arguments[0], {}, {},
7688-
/*hasTrailingClosure=*/false,
7689-
/*implicit=*/true, Type(), getType);
7690-
} else {
7691-
// The tuple should have the source range enclosing its arguments unless
7692-
// they are invalid or there are no arguments.
7693-
SourceLoc TupleStartLoc = base->getStartLoc();
7694-
SourceLoc TupleEndLoc = base->getEndLoc();
7695-
if (!arguments.empty()) {
7696-
SourceLoc AltStartLoc = arguments.front()->getStartLoc();
7697-
SourceLoc AltEndLoc = arguments.back()->getEndLoc();
7698-
if (AltStartLoc.isValid() && AltEndLoc.isValid()) {
7699-
TupleStartLoc = AltStartLoc;
7700-
TupleEndLoc = AltEndLoc;
7701-
}
7702-
}
7703-
7704-
call = CallExpr::create(Context, unresolvedDot, TupleStartLoc, arguments,
7705-
argLabels, {}, TupleEndLoc,
7706-
/*trailingClosure=*/nullptr,
7707-
/*implicit=*/true, getType);
7708-
}
7709-
7710-
cs.cacheSubExprTypes(call);
7711-
7712-
// Extract the arguments.
7713-
SmallVector<AnyFunctionType::Param, 8> args;
7714-
AnyFunctionType::decomposeInput(cs.getType(call->getArg()), args);
7715-
7716-
// Add the conversion from the argument to the function parameter type.
7717-
auto openedFuncType = openedType->castTo<FunctionType>();
7718-
::matchCallArguments(
7719-
cs, args, openedFuncType->getParams(),
7720-
ConstraintKind::ArgumentConversion,
7721-
cs.getConstraintLocator(call, ConstraintLocator::ApplyArgument));
7722-
7723-
// Solve the system.
7724-
SmallVector<Solution, 1> solutions;
7725-
7726-
cs.cacheExprTypes(call);
7727-
7728-
// If the system failed to produce a solution, post any available diagnostics.
7729-
if (cs.solve(call, solutions) || solutions.size() != 1) {
7730-
cs.salvage(solutions, base);
7731-
return nullptr;
7732-
}
7733-
7734-
Solution &solution = solutions.front();
7735-
ExprRewriter rewriter(cs, solution,
7736-
/*suppressDiagnostics=*/false);
7737-
7738-
auto choice =
7739-
OverloadChoice(openedFullType, witnessFn, FunctionRefKind::SingleApply);
7740-
auto memberRef = rewriter.buildMemberRef(
7741-
base, openedFullType, base->getStartLoc(), choice,
7742-
DeclNameLoc(base->getEndLoc()), openedType, dotLocator, dotLocator,
7743-
/*Implicit=*/true, FunctionRefKind::SingleApply,
7744-
AccessSemantics::Ordinary,
7745-
/*isDynamic=*/false);
7746-
call->setFn(memberRef);
7747-
7748-
// Call the witness.
7749-
Expr *result = rewriter.finishApply(call, openedType,
7750-
cs.getConstraintLocator(call));
7751-
if (!result)
7752-
return nullptr;
7753-
7754-
rewriter.finalize(result);
7755-
return result;
7756-
}

lib/Sema/TypeChecker.h

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1528,29 +1528,6 @@ class TypeChecker final : public LazyResolver {
15281528
/// array literals exist.
15291529
bool requireArrayLiteralIntrinsics(SourceLoc loc);
15301530

1531-
/// Build a call to the witness with the given name and arguments.
1532-
///
1533-
/// \param base The base expression, whose witness will be invoked.
1534-
///
1535-
/// \param protocol The protocol to call through.
1536-
///
1537-
/// \param conformance The conformance of the base type to the given
1538-
/// protocol.
1539-
///
1540-
/// \param name The name of the method to call.
1541-
///
1542-
/// \param arguments The arguments to the witness.
1543-
///
1544-
/// \param brokenProtocolDiag Diagnostic to emit if the protocol is broken.
1545-
///
1546-
/// \returns a fully type-checked call, or null if the protocol was broken.
1547-
Expr *callWitness(Expr *base, DeclContext *dc,
1548-
ProtocolDecl *protocol,
1549-
ProtocolConformanceRef conformance,
1550-
DeclName name,
1551-
ArrayRef<Expr *> arguments,
1552-
Diag<> brokenProtocolDiag);
1553-
15541531
/// Determine whether the given type contains the given protocol.
15551532
///
15561533
/// \param DC The context in which to check conformance. This affects, for

0 commit comments

Comments
 (0)