Skip to content

Commit 1bbea4a

Browse files
committed
AST: Clean up AnyFunctionType::Param API a bit
1 parent 47f046e commit 1bbea4a

File tree

3 files changed

+25
-35
lines changed

3 files changed

+25
-35
lines changed

include/swift/AST/Types.h

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ namespace swift {
5454
class GenericParamList;
5555
class GenericSignature;
5656
class Identifier;
57+
class InOutType;
5758
enum class ReferenceCounting : uint8_t;
5859
enum class ResilienceExpansion : unsigned;
5960
class SILModule;
@@ -2627,9 +2628,13 @@ class AnyFunctionType : public TypeBase {
26272628

26282629
class Param {
26292630
public:
2630-
explicit Param(const TupleTypeElt &tte);
2631-
explicit Param(Type t, Identifier l, ParameterTypeFlags f);
2632-
2631+
explicit Param(Type t,
2632+
Identifier l = Identifier(),
2633+
ParameterTypeFlags f = ParameterTypeFlags())
2634+
: Ty(t), Label(l), Flags(f) {
2635+
assert(!t || !t->is<InOutType>() && "set flags instead");
2636+
}
2637+
26332638
private:
26342639
/// The type of the parameter. For a variadic parameter, this is the
26352640
/// element type.
@@ -2642,14 +2647,10 @@ class AnyFunctionType : public TypeBase {
26422647
ParameterTypeFlags Flags = {};
26432648

26442649
public:
2645-
Type getType() const;
2646-
CanType getCanType() const {
2647-
assert(getType()->isCanonical());
2648-
return CanType(getType());
2649-
}
2650-
26512650
/// FIXME(Remove InOutType): This is mostly for copying between param
26522651
/// types and should go away.
2652+
Type getType() const;
2653+
26532654
Type getPlainType() const { return Ty; }
26542655

26552656
bool hasLabel() const { return !Label.empty(); }
@@ -2694,6 +2695,7 @@ class AnyFunctionType : public TypeBase {
26942695
static CanParam getFromParam(const Param &param) { return CanParam(param); }
26952696

26962697
CanType getType() const { return CanType(Param::getType()); }
2698+
CanType getPlainType() const { return CanType(Param::getPlainType()); }
26972699
};
26982700

26992701
using CanParamArrayRef =

lib/AST/ASTContext.cpp

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3035,20 +3035,6 @@ Type TupleTypeElt::getType() const {
30353035
return ElementType;
30363036
}
30373037

3038-
AnyFunctionType::Param::Param(const TupleTypeElt &tte)
3039-
: Ty(tte.isVararg() ? tte.getVarargBaseTy() : tte.getRawType()),
3040-
Label(tte.getName()), Flags(tte.getParameterFlags()) {
3041-
assert(getType()->is<InOutType>() == Flags.isInOut());
3042-
}
3043-
3044-
AnyFunctionType::Param::Param(Type t, Identifier l, ParameterTypeFlags f)
3045-
: Ty(t), Label(l), Flags(f) {
3046-
if (f.isInOut())
3047-
assert(!t->is<InOutType>() && "caller did not pass a base type");
3048-
if (!t.isNull() && t->is<InOutType>())
3049-
assert(f.isInOut() && "caller did not set flags correctly");
3050-
}
3051-
30523038
Type AnyFunctionType::Param::getType() const {
30533039
if (Flags.isInOut()) return InOutType::get(Ty);
30543040
// FIXME: Callers are inconsistenly setting this flag and retrieving this
@@ -3556,25 +3542,27 @@ void AnyFunctionType::decomposeInput(
35563542
case TypeKind::Tuple: {
35573543
auto tupleTy = cast<TupleType>(type.getPointer());
35583544
for (auto &elt : tupleTy->getElements()) {
3559-
result.push_back(AnyFunctionType::Param(elt));
3545+
result.emplace_back((elt.isVararg()
3546+
? elt.getVarargBaseTy()
3547+
: elt.getRawType()),
3548+
elt.getName(),
3549+
elt.getParameterFlags());
35603550
}
35613551
return;
35623552
}
35633553

35643554
case TypeKind::Paren: {
35653555
auto pty = cast<ParenType>(type.getPointer());
3566-
result.push_back(AnyFunctionType::Param(pty->getUnderlyingType()->getInOutObjectType(),
3567-
Identifier(),
3568-
pty->getParameterFlags()));
3556+
result.emplace_back(pty->getUnderlyingType()->getInOutObjectType(),
3557+
Identifier(),
3558+
pty->getParameterFlags());
35693559
return;
35703560
}
35713561

35723562
default:
3573-
// assert(type->is<InOutType>() && "Found naked inout type");
3574-
result.push_back(
3575-
AnyFunctionType::Param(type->getInOutObjectType(), Identifier(),
3576-
ParameterTypeFlags::fromParameterType(
3577-
type, false, ValueOwnership::Default)));
3563+
result.emplace_back(type->getInOutObjectType(), Identifier(),
3564+
ParameterTypeFlags::fromParameterType(
3565+
type, false, ValueOwnership::Default));
35783566
return;
35793567
}
35803568
}
@@ -3592,8 +3580,8 @@ Type AnyFunctionType::composeInput(ASTContext &ctx, ArrayRef<Param> params,
35923580
else
35933581
eltType = ArraySliceType::get(eltType);
35943582
}
3595-
elements.push_back(TupleTypeElt(eltType, param.getLabel(),
3596-
param.getParameterFlags()));
3583+
elements.emplace_back(eltType, param.getLabel(),
3584+
param.getParameterFlags());
35973585
}
35983586
return TupleType::get(elements, ctx);
35993587
}

lib/Sema/CalleeCandidateInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,7 @@ void CalleeCandidateInfo::filterContextualMemberList(Expr *argExpr) {
819819
if (isa<InOutExpr>(argExpr))
820820
argType = LValueType::get(argType);
821821

822-
return filterListArgs(AnyFunctionType::Param({argType, Identifier(), {}}));
822+
return filterListArgs(AnyFunctionType::Param(argType));
823823
}
824824

825825
// If we have a tuple expression, form a tuple type.

0 commit comments

Comments
 (0)