Skip to content

Commit

Permalink
AST: Rename AnyFunctionType::Param::getType() to getOldType()
Browse files Browse the repository at this point in the history
  • Loading branch information
slavapestov committed Sep 26, 2018
1 parent 4975f3a commit 3b60ae1
Show file tree
Hide file tree
Showing 29 changed files with 100 additions and 94 deletions.
12 changes: 6 additions & 6 deletions include/swift/AST/TypeMatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,14 +217,14 @@ class TypeMatcher {
if (firstElt.getLabel() != secondElt.getLabel() ||
firstElt.isVariadic() != secondElt.isVariadic() ||
firstElt.isInOut() != secondElt.isInOut())
return mismatch(firstElt.getType().getPointer(),
secondElt.getType(),
sugaredFirstFunc->getParams()[i].getType());
return mismatch(firstElt.getOldType().getPointer(),
secondElt.getOldType(),
sugaredFirstFunc->getParams()[i].getOldType());

// Recurse on parameter components.
if (!this->visit(firstElt.getType()->getCanonicalType(),
secondElt.getType(),
sugaredFirstFunc->getParams()[i].getType()))
if (!this->visit(firstElt.getOldType()->getCanonicalType(),
secondElt.getOldType(),
sugaredFirstFunc->getParams()[i].getOldType()))
return false;
}

Expand Down
18 changes: 13 additions & 5 deletions include/swift/AST/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -2647,13 +2647,21 @@ class AnyFunctionType : public TypeBase {
ParameterTypeFlags Flags = {};

public:
/// FIXME(Remove InOutType): This is mostly for copying between param
/// types and should go away.
Type getType() const;
/// FIXME: Remove this. Return the formal type of the parameter in the
/// function type, including the InOutType if there is one.
///
/// For example, 'inout Int' => 'inout Int', 'Int...' => 'Int'.
Type getOldType() const;

/// Return the formal type of the parameter.
///
/// For example, 'inout Int' => 'Int', 'Int...' => 'Int'.
Type getPlainType() const { return Ty; }

/// The type of the parameter. Adjusts for varargs, but not inout.
/// The type of the parameter when referenced inside the function body
/// as an rvalue.
///
/// For example, 'inout Int' => 'Int', 'Int...' => '[Int]'.
Type getParameterType(bool forCanonical = false,
ASTContext *ctx = nullptr) const;

Expand Down Expand Up @@ -2699,7 +2707,7 @@ class AnyFunctionType : public TypeBase {
public:
static CanParam getFromParam(const Param &param) { return CanParam(param); }

CanType getType() const { return CanType(Param::getType()); }
CanType getOldType() const { return CanType(Param::getOldType()); }
CanType getPlainType() const { return CanType(Param::getPlainType()); }
CanType getParameterType() const {
return CanType(Param::getParameterType(/*forCanonical*/ true));
Expand Down
13 changes: 5 additions & 8 deletions lib/AST/ASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1029,8 +1029,8 @@ FuncDecl *ASTContext::getEqualIntDecl() const {
intType, [=](FunctionType *type) {
// Check for the signature: (Int, Int) -> Bool
if (type->getParams().size() != 2) return false;
if (!type->getParams()[0].getType()->isEqual(intType) ||
!type->getParams()[1].getType()->isEqual(intType)) return false;
if (!type->getParams()[0].getOldType()->isEqual(intType) ||
!type->getParams()[1].getOldType()->isEqual(intType)) return false;
return type->getResult()->isEqual(boolType);
});
getImpl().EqualIntDecl = decl;
Expand All @@ -1046,7 +1046,7 @@ FuncDecl *ASTContext::getGetBoolDecl(LazyResolver *resolver) const {
resolver, [=](FunctionType *type) {
// Look for the signature (Builtin.Int1) -> Bool
if (type->getParams().size() != 1) return false;
if (!isBuiltinInt1Type(type->getParams()[0].getType())) return false;
if (!isBuiltinInt1Type(type->getParams()[0].getOldType())) return false;
return type->getResult()->isEqual(boolType);
});
getImpl().GetBoolDecl = decl;
Expand Down Expand Up @@ -1238,7 +1238,7 @@ FuncDecl *ASTContext::getIsOSVersionAtLeastDecl(LazyResolver *resolver) const {
return nullptr;

if (llvm::any_of(intrinsicsParams, [](const AnyFunctionType::Param &p) {
return !isBuiltinWordType(p.getType());
return !isBuiltinWordType(p.getOldType());
})) {
return nullptr;
}
Expand Down Expand Up @@ -3155,11 +3155,8 @@ Type TupleTypeElt::getType() const {
return ElementType;
}

Type AnyFunctionType::Param::getType() const {
Type AnyFunctionType::Param::getOldType() const {
if (Flags.isInOut()) return InOutType::get(Ty);
// FIXME: Callers are inconsistenly setting this flag and retrieving this
// type with and without the Array Slice type.
// if (Flags.isVariadic()) return ArraySliceType::get(Ty);
return Ty;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/AST/ASTDumper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3404,7 +3404,7 @@ namespace {
if (param.hasLabel())
printField("name", param.getLabel().str());
dumpParameterFlags(param.getParameterFlags());
printRec(param.getType());
printRec(param.getOldType());
OS << ")";
}
Indent -= 2;
Expand Down
4 changes: 2 additions & 2 deletions lib/AST/Decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3772,7 +3772,7 @@ findProtocolSelfReferences(const ProtocolDecl *proto, Type type,
if (auto funcTy = type->getAs<AnyFunctionType>()) {
auto inputKind = SelfReferenceKind::None();
for (auto &elt : funcTy->getParams()) {
inputKind |= findProtocolSelfReferences(proto, elt.getType(),
inputKind |= findProtocolSelfReferences(proto, elt.getOldType(),
skipAssocTypes);
}
auto resultKind = findProtocolSelfReferences(proto, funcTy->getResult(),
Expand Down Expand Up @@ -3882,7 +3882,7 @@ ProtocolDecl::findProtocolSelfReferences(const ValueDecl *value,
if (!allowCovariantParameters) {
auto inputKind = SelfReferenceKind::None();
for (auto &elt : type->castTo<AnyFunctionType>()->getParams()) {
inputKind |= ::findProtocolSelfReferences(this, elt.getType(),
inputKind |= ::findProtocolSelfReferences(this, elt.getOldType(),
skipAssocTypes);
}

Expand Down
8 changes: 4 additions & 4 deletions lib/AST/Type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1538,8 +1538,8 @@ bool TypeBase::isBindableTo(Type b) {
return false;

for (unsigned i : indices(func->getParams())) {
if (!visit(func->getParams()[i].getType(),
substFunc.getParams()[i].getType()))
if (!visit(func->getParams()[i].getOldType(),
substFunc.getParams()[i].getOldType()))
return false;
}

Expand Down Expand Up @@ -1916,7 +1916,7 @@ getForeignRepresentable(Type type, ForeignLanguage language,
for (const auto &param : functionType->getParams()) {
if (param.isVariadic())
return failure();
if (recurse(param.getType()))
if (recurse(param.getOldType()))
return failure();
}

Expand Down Expand Up @@ -2277,7 +2277,7 @@ static bool matches(CanType t1, CanType t2, TypeMatchOptions matchMode,

// Inputs are contravariant.
for (auto i : indices(fn2.getParams())) {
if (!matches(fn2Params[i].getType(), fn1Params[i].getType(),
if (!matches(fn2Params[i].getOldType(), fn1Params[i].getOldType(),
matchMode, ParameterPosition::ParameterTupleElement,
OptionalUnwrapping::None)) {
return false;
Expand Down
2 changes: 1 addition & 1 deletion lib/AST/TypeWalker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class Traversal : public TypeVisitor<Traversal, bool>

bool visitAnyFunctionType(AnyFunctionType *ty) {
for (const auto &param : ty->getParams()) {
if (doIt(param.getType()))
if (doIt(param.getOldType()))
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/ClangImporter/ImportDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1648,7 +1648,7 @@ static std::pair<Type, ParamDecl *> decomposeSubscriptSetter(FuncDecl *setter) {
->castTo<AnyFunctionType>()
->getResult()
->castTo<AnyFunctionType>()
->getParams().front().getType();
->getParams().front().getOldType();
ParamDecl *keyDecl = PL->get(1);

return {elementType, keyDecl};
Expand Down
6 changes: 3 additions & 3 deletions lib/IDE/CodeCompletion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1567,7 +1567,7 @@ static bool hasTrivialTrailingClosure(const FuncDecl *FD,
if (defaultMap.size() - defaultMap.count() == 1) {
auto param = funcType->getParams().back();
if (!param.isAutoClosure()) {
if (auto Fn = param.getType()->getAs<AnyFunctionType>()) {
if (auto Fn = param.getOldType()->getAs<AnyFunctionType>()) {
return Fn->getParams().empty() && Fn->getResult()->isVoid();
}
}
Expand Down Expand Up @@ -3885,8 +3885,8 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
if (seenNames.insert(Param.getLabel()).second)
ExpectedNames.push_back(Param.getLabel().str());
} else {
if (seenTypes.insert(Param.getType().getPointer()).second)
ExpectedTypes.push_back(Param.getType());
if (seenTypes.insert(Param.getOldType().getPointer()).second)
ExpectedTypes.push_back(Param.getOldType());
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions lib/IDE/TypeReconstruction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -935,7 +935,7 @@ static void VisitNodeConstructor(
// inits are typed as (Foo.Type) -> (args...) -> Foo, but don't
// assert that in case we're dealing with broken code.
if (identifier_func->getParams().size() == 1 &&
identifier_func->getParams()[0].getType()->is<AnyMetatypeType>() &&
identifier_func->getParams()[0].getOldType()->is<AnyMetatypeType>() &&
identifier_func->getResult()->is<AnyFunctionType>()) {
identifier_func =
identifier_func->getResult()->getAs<AnyFunctionType>();
Expand Down Expand Up @@ -1227,7 +1227,8 @@ static bool CompareFunctionTypes(const AnyFunctionType *f,
auto label1 = getLabel(fLabels, param1, i);
auto label2 = getLabel(gLabels, param2, i);

if (label1.equals(label2) && param1.getType()->isEqual(param2.getType()))
if (label1.equals(label2) &&
param1.getOldType()->isEqual(param2.getOldType()))
continue;

in_matches = false;
Expand Down
2 changes: 1 addition & 1 deletion lib/IRGen/GenProto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3046,7 +3046,7 @@ void NecessaryBindings::addTypeMetadata(CanType type) {
}
if (auto fn = dyn_cast<FunctionType>(type)) {
for (const auto &elt : fn.getParams())
addTypeMetadata(elt.getType());
addTypeMetadata(elt.getOldType());
addTypeMetadata(fn.getResult());
return;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/PrintAsObjC/PrintAsObjC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1909,7 +1909,7 @@ class ObjCPrinter : private DeclVisitor<ObjCPrinter>,
if (!FT->getParams().empty()) {
interleave(FT->getParams(),
[this](const AnyFunctionType::Param &param) {
print(param.getType(), OTK_None, param.getLabel(),
print(param.getOldType(), OTK_None, param.getLabel(),
IsFunctionParam);
},
[this] { os << ", "; });
Expand Down Expand Up @@ -2061,7 +2061,7 @@ class ReferencedTypeFinder : public TypeVisitor<ReferencedTypeFinder> {

void visitAnyFunctionType(AnyFunctionType *fnTy) {
for (auto &param : fnTy->getParams())
visit(param.getType());
visit(param.getOldType());
visit(fnTy->getResult());
}

Expand Down
2 changes: 1 addition & 1 deletion lib/SILGen/SILGenBridging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ static SmallVector<CanType, 8>
expandTupleTypes(AnyFunctionType::CanParamArrayRef params) {
SmallVector<CanType, 8> results;
for (auto param : params)
expandTupleTypes(param.getType(), results);
expandTupleTypes(param.getOldType(), results);
return results;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/SILGen/SILGenConstructor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ static SILValue emitConstructorMetatypeArg(SILGenFunction &SGF,
auto ctorFnType = ctor->getInterfaceType()->castTo<AnyFunctionType>();
assert(ctorFnType->getParams().size() == 1 &&
"more than one self parameter?");
Type metatype = ctorFnType->getParams()[0].getType();
Type metatype = ctorFnType->getParams()[0].getOldType();
auto *DC = ctor->getInnermostDeclContext();
auto &AC = SGF.getASTContext();
auto VD =
Expand Down
2 changes: 1 addition & 1 deletion lib/SILOptimizer/Utils/Generics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ static std::pair<unsigned, unsigned> getTypeDepthAndWidth(Type t) {
for (auto &Param : Params) {
unsigned TypeWidth;
unsigned TypeDepth;
std::tie(TypeDepth, TypeWidth) = getTypeDepthAndWidth(Param.getType());
std::tie(TypeDepth, TypeWidth) = getTypeDepthAndWidth(Param.getOldType());
if (TypeDepth > MaxTypeDepth)
MaxTypeDepth = TypeDepth;
Width += TypeWidth;
Expand Down
16 changes: 8 additions & 8 deletions lib/Sema/CSApply.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ namespace {
if (wantsRValueInstanceType)
return base.getPlainType()->getMetatypeInstanceType();

return base.getType();
return base.getOldType();
}

public:
Expand Down Expand Up @@ -1441,7 +1441,7 @@ namespace {
// Dig the key path expression out of the arguments.
auto indexKP = cast<TupleExpr>(index)->getElement(0);
auto keyPathExprTy = cs.getType(indexKP);
auto keyPathTy = applicationTy->getParams().front().getType();
auto keyPathTy = applicationTy->getParams().front().getOldType();

Type valueTy;
Type baseTy;
Expand Down Expand Up @@ -5584,7 +5584,7 @@ Expr *ExprRewriter::coerceCallArguments(
return nullptr;

// Record this parameter.
auto paramBaseType = param.getType();
auto paramBaseType = param.getOldType();
assert(sliceType.isNull() && "Multiple variadic parameters?");
sliceType = tc.getArraySliceType(arg->getLoc(), paramBaseType);
toSugarFields.push_back(
Expand Down Expand Up @@ -5632,8 +5632,8 @@ Expr *ExprRewriter::coerceCallArguments(
toSugarFields.push_back(TupleTypeElt(
param.isVariadic()
? tc.getArraySliceType(arg->getLoc(),
param.getType())
: param.getType(),
param.getOldType())
: param.getOldType(),
param.getLabel(),
param.getParameterFlags()));

Expand All @@ -5657,7 +5657,7 @@ Expr *ExprRewriter::coerceCallArguments(
sources.push_back(argIdx);

// If the types exactly match, this is easy.
auto paramType = param.getType();
auto paramType = param.getOldType();
if (argType->isEqual(paramType)) {
toSugarFields.push_back(
TupleTypeElt(param.getPlainType(), getArgLabel(argIdx),
Expand Down Expand Up @@ -6298,7 +6298,7 @@ Expr *ExprRewriter::coerceToType(Expr *expr, Type toType,

// This handles situations like argument: (()), parameter: ().
if (params1.size() == 1 && params2.empty()) {
auto tupleTy = params1.front().getType()->getAs<TupleType>();
auto tupleTy = params1.front().getOldType()->getAs<TupleType>();
if (tupleTy && tupleTy->getNumElements() == 0)
break;
}
Expand Down Expand Up @@ -7127,7 +7127,7 @@ Expr *ExprRewriter::finishApply(ApplyExpr *apply, Type openedType,

auto escapable = new (tc.Context)
OpaqueValueExpr(apply->getFn()->getLoc(), Type());
cs.setType(escapable, escapableParams[0].getType());
cs.setType(escapable, escapableParams[0].getOldType());

auto getType = [&](const Expr *E) -> Type {
return cs.getType(E);
Expand Down
Loading

0 comments on commit 3b60ae1

Please sign in to comment.