Skip to content

Commit ef02b47

Browse files
committed
xxx
1 parent aba30e7 commit ef02b47

16 files changed

+67
-99
lines changed

include/swift/AST/ArgumentList.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -522,13 +522,6 @@ class alignas(Argument) ArgumentList final
522522
ASTContext &ctx,
523523
llvm::function_ref<Type(Expr *)> getType = __Expr_getType) const;
524524

525-
/// Avoid adding new usages of this. Creates a TupleType or ParenType
526-
/// representing the types in the argument list. A ParenType will be returned
527-
/// for a single argument, otherwise a TupleType.
528-
Type composeTupleOrParenType(
529-
ASTContext &ctx,
530-
llvm::function_ref<Type(Expr *)> getType = __Expr_getType) const;
531-
532525
/// Whether the argument list matches a given parameter list. This will return
533526
/// \c false if the arity doesn't match, or any of the canonical types or
534527
/// labels don't match. Note that this expects types to be present for the

include/swift/AST/DiagnosticsSema.def

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -254,10 +254,6 @@ ERROR(cannot_pass_rvalue_inout,none,
254254
ERROR(cannot_provide_default_value_inout,none,
255255
"cannot provide default value to inout parameter %0", (Identifier))
256256

257-
ERROR(cannot_call_with_params, none,
258-
"cannot invoke %select{|initializer for type }2'%0' with an argument list"
259-
" of type '%1'", (StringRef, StringRef, bool))
260-
261257
ERROR(cannot_call_non_function_value,none,
262258
"cannot call value of non-function type %0", (Type))
263259

include/swift/AST/Types.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2026,6 +2026,11 @@ class ParameterTypeFlags {
20262026
uint8_t toRaw() const { return value.toRaw(); }
20272027
};
20282028

2029+
/// A type that indicates how parameter flags should be handled in an operation
2030+
/// that requires the conversion into a type that doesn't support them, such as
2031+
/// tuples. They must either be dropped, or be enforced to not be present.
2032+
enum class ParameterFlagHandling { Drop, AssertEmpty };
2033+
20292034
class YieldTypeFlags {
20302035
enum YieldFlags : uint8_t {
20312036
None = 0,
@@ -3023,10 +3028,9 @@ class AnyFunctionType : public TypeBase {
30233028
public:
30243029
/// Take an array of parameters and turn it into a tuple or paren type.
30253030
///
3026-
/// \param wantParamFlags Whether to preserve the parameter flags from the
3027-
/// given set of parameters.
3031+
/// \param paramFlagHandling How to handle the parameter flags.
30283032
static Type composeTuple(ASTContext &ctx, ArrayRef<Param> params,
3029-
bool wantParamFlags = true);
3033+
ParameterFlagHandling paramFlagHandling);
30303034

30313035
/// Given two arrays of parameters determine if they are equal in their
30323036
/// canonicalized form. Internal labels and type sugar is *not* taken into

lib/APIDigester/ModuleAnalyzerNodes.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1518,8 +1518,8 @@ SwiftDeclCollector::constructTypeNode(Type T, TypeInitInfo Info) {
15181518
// Still, return type first
15191519
Root->addChild(constructTypeNode(Fun->getResult()));
15201520

1521-
auto Input = AnyFunctionType::composeTuple(Fun->getASTContext(),
1522-
Fun->getParams());
1521+
auto Input = AnyFunctionType::composeTuple(
1522+
Fun->getASTContext(), Fun->getParams(), ParameterFlagHandling::Drop);
15231523
Root->addChild(constructTypeNode(Input));
15241524
return Root;
15251525
}

lib/AST/ASTContext.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3456,12 +3456,17 @@ Type AnyFunctionType::Param::getParameterType(bool forCanonical,
34563456
}
34573457

34583458
Type AnyFunctionType::composeTuple(ASTContext &ctx, ArrayRef<Param> params,
3459-
bool wantParamFlags) {
3459+
ParameterFlagHandling paramFlagHandling) {
34603460
SmallVector<TupleTypeElt, 4> elements;
34613461
for (const auto &param : params) {
3462-
auto flags = wantParamFlags ? param.getParameterFlags()
3463-
: ParameterTypeFlags();
3464-
elements.emplace_back(param.getParameterType(), param.getLabel(), flags);
3462+
switch (paramFlagHandling) {
3463+
case ParameterFlagHandling::Drop:
3464+
break;
3465+
case ParameterFlagHandling::AssertEmpty:
3466+
assert(param.getParameterFlags().isNone());
3467+
break;
3468+
}
3469+
elements.emplace_back(param.getParameterType(), param.getLabel());
34653470
}
34663471
return TupleType::get(elements, ctx);
34673472
}

lib/AST/ArgumentList.cpp

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -255,32 +255,6 @@ Expr *ArgumentList::packIntoImplicitTupleOrParen(
255255
return tuple;
256256
}
257257

258-
Type ArgumentList::composeTupleOrParenType(
259-
ASTContext &ctx, llvm::function_ref<Type(Expr *)> getType) const {
260-
if (auto *unary = getUnlabeledUnaryExpr()) {
261-
auto ty = getType(unary);
262-
assert(ty);
263-
ParameterTypeFlags flags;
264-
if (get(0).isInOut()) {
265-
ty = ty->getInOutObjectType();
266-
flags = flags.withInOut(true);
267-
}
268-
return ParenType::get(ctx, ty, flags);
269-
}
270-
SmallVector<TupleTypeElt, 4> elts;
271-
for (auto arg : *this) {
272-
auto ty = getType(arg.getExpr());
273-
assert(ty);
274-
ParameterTypeFlags flags;
275-
if (arg.isInOut()) {
276-
ty = ty->getInOutObjectType();
277-
flags = flags.withInOut(true);
278-
}
279-
elts.emplace_back(ty, arg.getLabel(), flags);
280-
}
281-
return TupleType::get(elts, ctx);
282-
}
283-
284258
bool ArgumentList::matches(ArrayRef<AnyFunctionType::Param> params,
285259
llvm::function_ref<Type(Expr *)> getType) const {
286260
if (size() != params.size())

lib/SILGen/SILGenApply.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4023,7 +4023,8 @@ RValue CallEmission::applyEnumElementConstructor(SGFContext C) {
40234023
std::move(*callSite).forward());
40244024

40254025
auto payloadTy = AnyFunctionType::composeTuple(SGF.getASTContext(),
4026-
resultFnType->getParams());
4026+
resultFnType->getParams(),
4027+
ParameterFlagHandling::Drop);
40274028
auto arg = RValue(SGF, argVals, payloadTy->getCanonicalType());
40284029
payload = ArgumentSource(uncurriedLoc, std::move(arg));
40294030
formalResultType = cast<FunctionType>(formalResultType).getResult();

lib/SILGen/SILGenExpr.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2662,9 +2662,8 @@ loadIndexValuesForKeyPathComponent(SILGenFunction &SGF, SILLocation loc,
26622662
return indexValues;
26632663
}
26642664

2665-
auto indexLoweredTy =
2666-
SGF.getLoweredType(
2667-
AnyFunctionType::composeTuple(SGF.getASTContext(), indexParams));
2665+
auto indexLoweredTy = SGF.getLoweredType(AnyFunctionType::composeTuple(
2666+
SGF.getASTContext(), indexParams, ParameterFlagHandling::AssertEmpty));
26682667

26692668
auto addr = SGF.B.createPointerToAddress(loc, pointer,
26702669
indexLoweredTy.getAddressType(),

lib/Sema/CSDiagnostics.cpp

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6596,20 +6596,6 @@ bool ExtraneousCallFailure::diagnoseAsError() {
65966596
}
65976597
}
65986598

6599-
if (auto *UDE = getAsExpr<UnresolvedDotExpr>(anchor)) {
6600-
auto *baseExpr = UDE->getBase();
6601-
auto *call = castToExpr<CallExpr>(getRawAnchor());
6602-
6603-
if (getType(baseExpr)->isAnyObject()) {
6604-
auto argsTy = call->getArgs()->composeTupleOrParenType(
6605-
getASTContext(), [&](Expr *E) { return getType(E); });
6606-
emitDiagnostic(diag::cannot_call_with_params,
6607-
UDE->getName().getBaseName().userFacingName(),
6608-
argsTy.getString(), isa<TypeExpr>(baseExpr));
6609-
return true;
6610-
}
6611-
}
6612-
66136599
auto diagnostic =
66146600
emitDiagnostic(diag::cannot_call_non_function_value, getType(anchor));
66156601
removeParensFixIt(diagnostic);

lib/Sema/CSRanking.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -794,9 +794,9 @@ getConstructorParamsAsTuples(ASTContext &ctx, Type boundTy1, Type boundTy2) {
794794
return None;
795795
}
796796
auto tuple1 = AnyFunctionType::composeTuple(ctx, initParams1,
797-
/*wantParamFlags*/ false);
797+
ParameterFlagHandling::Drop);
798798
auto tuple2 = AnyFunctionType::composeTuple(ctx, initParams2,
799-
/*wantParamFlags*/ false);
799+
ParameterFlagHandling::Drop);
800800
return std::make_pair(tuple1, tuple2);
801801
}
802802

lib/Sema/CSSimplify.cpp

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,8 @@ bool constraints::doesMemberRefApplyCurriedSelf(Type baseTy,
125125
}
126126

127127
static bool areConservativelyCompatibleArgumentLabels(
128-
OverloadChoice choice, SmallVectorImpl<FunctionType::Param> &args,
128+
ConstraintSystem &cs, OverloadChoice choice,
129+
SmallVectorImpl<FunctionType::Param> &args,
129130
MatchCallArgumentListener &listener,
130131
Optional<unsigned> unlabeledTrailingClosureArgIndex) {
131132
ValueDecl *decl = nullptr;
@@ -145,9 +146,6 @@ static bool areConservativelyCompatibleArgumentLabels(
145146
return true;
146147
}
147148

148-
if (!decl->hasParameterList())
149-
return true;
150-
151149
// This is a member lookup, which generally means that the call arguments
152150
// (if we have any) will apply to the second level of parameters, with
153151
// the member lookup applying the curried self at the first level. But there
@@ -156,10 +154,22 @@ static bool areConservativelyCompatibleArgumentLabels(
156154
decl->hasCurriedSelf() &&
157155
doesMemberRefApplyCurriedSelf(choice.getBaseType(), decl);
158156

159-
auto *fnType = decl->getInterfaceType()->castTo<AnyFunctionType>();
160-
if (hasAppliedSelf) {
161-
fnType = fnType->getResult()->getAs<AnyFunctionType>();
162-
assert(fnType && "Parameter list curry level does not match type");
157+
AnyFunctionType *fnType = nullptr;
158+
if (decl->hasParameterList()) {
159+
fnType = decl->getInterfaceType()->castTo<AnyFunctionType>();
160+
if (hasAppliedSelf) {
161+
fnType = fnType->getResult()->getAs<AnyFunctionType>();
162+
assert(fnType && "Parameter list curry level does not match type");
163+
}
164+
} else if (auto *VD = dyn_cast<VarDecl>(decl)) {
165+
auto varTy = VD->getValueInterfaceType()->lookThroughAllOptionalTypes();
166+
fnType = varTy->getAs<AnyFunctionType>();
167+
if (!fnType) {
168+
return varTy->isTypeParameter() || varTy->isCallableNominalType(cs.DC) ||
169+
varTy->hasDynamicCallableAttribute();
170+
}
171+
} else {
172+
return true;
163173
}
164174

165175
auto params = fnType->getParams();
@@ -2002,9 +2012,10 @@ static bool fixMissingArguments(ConstraintSystem &cs, ASTNode anchor,
20022012
// If the argument was a single "tuple", let's bind newly
20032013
// synthesized arguments to it.
20042014
if (argumentTuple) {
2005-
cs.addConstraint(ConstraintKind::Bind, *argumentTuple,
2006-
FunctionType::composeTuple(ctx, args),
2007-
cs.getConstraintLocator(anchor));
2015+
cs.addConstraint(
2016+
ConstraintKind::Bind, *argumentTuple,
2017+
FunctionType::composeTuple(ctx, args, ParameterFlagHandling::Drop),
2018+
cs.getConstraintLocator(anchor));
20082019
}
20092020

20102021
return false;
@@ -2238,7 +2249,7 @@ ConstraintSystem::matchFunctionTypes(FunctionType *func1, FunctionType *func2,
22382249
// canImplodeParams makes sure we're not dealing with vargs, inout, etc,
22392250
// we may still have e.g ownership flags left over, which we can drop.
22402251
auto input = AnyFunctionType::composeTuple(getASTContext(), params,
2241-
/*wantParamFlags*/ false);
2252+
ParameterFlagHandling::Drop);
22422253
params.clear();
22432254
// If fixes are disabled let's do an easy thing and implode
22442255
// tuple directly into parameters list.
@@ -6160,8 +6171,9 @@ ConstraintSystem::simplifyConstructionConstraint(
61606171
}
61616172

61626173
// Tuple construction is simply tuple conversion.
6163-
Type argType = AnyFunctionType::composeTuple(getASTContext(),
6164-
fnType->getParams());
6174+
Type argType =
6175+
AnyFunctionType::composeTuple(getASTContext(), fnType->getParams(),
6176+
ParameterFlagHandling::AssertEmpty);
61656177
Type resultType = fnType->getResult();
61666178

61676179
ConstraintLocatorBuilder builder(locator);
@@ -9986,7 +9998,7 @@ bool ConstraintSystem::simplifyAppliedOverloadsImpl(
99869998

99879999
auto labelsMatch = [&](MatchCallArgumentListener &listener) {
998810000
if (areConservativelyCompatibleArgumentLabels(
9989-
choice, argsWithLabels, listener,
10001+
*this, choice, argsWithLabels, listener,
999010002
argList->getFirstTrailingClosureIndex()))
999110003
return true;
999210004

lib/Sema/ConstraintSystem.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3824,19 +3824,16 @@ static bool diagnoseAmbiguity(
38243824
type->lookThroughAllOptionalTypes()->getAs<AnyFunctionType>();
38253825
assert(fn);
38263826

3827-
if (fn->getNumParams() == 1) {
3828-
auto *argList =
3829-
solution.getArgumentList(solution.Fixes.front()->getLocator());
3830-
assert(argList);
3827+
auto *argList =
3828+
solution.getArgumentList(solution.Fixes.front()->getLocator());
3829+
assert(argList);
38313830

3831+
if (fn->getNumParams() == 1 && argList->isUnary()) {
38323832
const auto &param = fn->getParams()[0];
3833-
auto argType = argList->composeTupleOrParenType(
3834-
cs.getASTContext(),
3835-
[&](Expr *E) { return solution.getResolvedType(E); });
3836-
3833+
auto argTy = solution.getResolvedType(argList->getUnaryExpr());
38373834
DE.diagnose(noteLoc, diag::candidate_has_invalid_argument_at_position,
38383835
solution.simplifyType(param.getPlainType()),
3839-
/*position=*/1, param.isInOut(), argType);
3836+
/*position=*/1, param.isInOut(), argTy);
38403837
} else {
38413838
DE.diagnose(noteLoc, diag::candidate_partial_match,
38423839
fn->getParamListAsString(fn->getParams()));

lib/Sema/TypeCheckDeclOverride.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,8 @@ static bool noteFixableMismatchedTypes(ValueDecl *decl, const ValueDecl *base) {
482482
auto *fnType = baseTy->getAs<AnyFunctionType>();
483483
baseTy = fnType->getResult();
484484
Type argTy = FunctionType::composeTuple(
485-
ctx, baseTy->getAs<AnyFunctionType>()->getParams());
485+
ctx, baseTy->getAs<AnyFunctionType>()->getParams(),
486+
ParameterFlagHandling::Drop);
486487
auto diagKind = diag::override_type_mismatch_with_fixits_init;
487488
unsigned numArgs = baseInit->getParameters()->size();
488489
return computeFixitsForOverridenDeclaration(

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2161,10 +2161,10 @@ static void addAssocTypeDeductionString(llvm::SmallString<128> &str,
21612161
static Type getTypeForDisplay(ModuleDecl *module, ValueDecl *decl) {
21622162
// For a constructor, we only care about the parameter types.
21632163
if (auto ctor = dyn_cast<ConstructorDecl>(decl)) {
2164-
return AnyFunctionType::composeTuple(module->getASTContext(),
2165-
ctor->getMethodInterfaceType()
2166-
->castTo<FunctionType>()
2167-
->getParams());
2164+
return AnyFunctionType::composeTuple(
2165+
module->getASTContext(),
2166+
ctor->getMethodInterfaceType()->castTo<FunctionType>()->getParams(),
2167+
ParameterFlagHandling::Drop);
21682168
}
21692169

21702170
Type type = decl->getInterfaceType();

test/ClangImporter/objc_parse.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ class IncompleteProtocolAdopter : Incomplete, IncompleteOptional { // expected-e
506506

507507
func testNullarySelectorPieces(_ obj: AnyObject) {
508508
obj.foo(1, bar: 2, 3) // no-warning
509-
obj.foo(1, 2, bar: 3) // expected-error{{cannot invoke 'foo' with an argument list of type '(Int, Int, bar: Int)'}}
509+
obj.foo(1, 2, bar: 3) // expected-error{{argument 'bar' must precede unnamed argument #2}}
510510
}
511511

512512
func testFactoryMethodAvailability() {

test/Constraints/diagnostics.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1302,9 +1302,9 @@ func f11(_ n: Int) {}
13021302
func f11<T : P2>(_ n: T, _ f: @escaping (T) -> T) {} // expected-note {{where 'T' = 'Int'}}
13031303
f11(3, f4) // expected-error {{global function 'f11' requires that 'Int' conform to 'P2'}}
13041304

1305-
let f12: (Int) -> Void = { _ in } // expected-note {{candidate '(Int) -> Void' requires 1 argument, but 2 were provided}}
1306-
func f12<T : P2>(_ n: T, _ f: @escaping (T) -> T) {} // expected-note {{candidate requires that 'Int' conform to 'P2' (requirement specified as 'T' : 'P2')}}
1307-
f12(3, f4)// expected-error {{no exact matches in call to global function 'f12'}}
1305+
let f12: (Int) -> Void = { _ in }
1306+
func f12<T : P2>(_ n: T, _ f: @escaping (T) -> T) {} // expected-note {{where 'T' = 'Int'}}
1307+
f12(3, f4)// expected-error {{global function 'f12' requires that 'Int' conform to 'P2'}}
13081308

13091309
// SR-12242
13101310
struct SR_12242_R<Value> {}

0 commit comments

Comments
 (0)