Skip to content

Commit 705da29

Browse files
committed
AST: ParameterList::getInterfaceType() now takes an ASTContext instead of a DeclContext
We no longer have to mapTypeOutOfContext() here, so the dc isn't needed.
1 parent 7eb09a1 commit 705da29

File tree

7 files changed

+29
-48
lines changed

7 files changed

+29
-48
lines changed

include/swift/AST/ParameterList.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -135,21 +135,21 @@ class alignas(ParamDecl *) ParameterList final :
135135
/// the ParamDecls, so they can be reparented into a new DeclContext.
136136
ParameterList *clone(const ASTContext &C,
137137
OptionSet<CloneFlags> options = None) const;
138-
139-
/// Return a TupleType or ParenType for this parameter list. This returns a
140-
/// null type if one of the ParamDecls does not have a type set for it yet.
138+
139+
/// Return a TupleType or ParenType for this parameter list, written in terms
140+
/// of contextual archetypes.
141141
Type getType(const ASTContext &C) const;
142-
143-
/// Return a TupleType or ParenType for this parameter list written in terms
142+
143+
/// Return a TupleType or ParenType for this parameter list, written in terms
144144
/// of interface types.
145-
Type getInterfaceType(DeclContext *DC) const;
145+
Type getInterfaceType(const ASTContext &C) const;
146146

147147
/// Return the full function type for a set of curried parameter lists that
148148
/// returns the specified result type written in terms of interface types.
149149
static Type getFullInterfaceType(Type resultType, ArrayRef<ParameterList*> PL,
150-
DeclContext *DC);
151-
152-
150+
const ASTContext &C);
151+
152+
153153
/// Return the full source range of this parameter.
154154
SourceRange getSourceRange() const;
155155
SourceLoc getStartLoc() const { return getSourceRange().Start; }

lib/AST/Parameter.cpp

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -109,17 +109,15 @@ ParameterList *ParameterList::clone(const ASTContext &C,
109109
return create(C, params);
110110
}
111111

112-
/// Return a TupleType or ParenType for this parameter list. This returns a
113-
/// null type if one of the ParamDecls does not have a type set for it yet.
112+
/// Return a TupleType or ParenType for this parameter list, written in terms
113+
/// of contextual archetypes.
114114
Type ParameterList::getType(const ASTContext &C) const {
115115
if (size() == 0)
116116
return TupleType::getEmpty(C);
117117

118118
SmallVector<TupleTypeElt, 8> argumentInfo;
119119

120120
for (auto P : *this) {
121-
if (!P->hasType()) return Type();
122-
123121
argumentInfo.emplace_back(
124122
P->getType(), P->getArgumentName(),
125123
ParameterTypeFlags::fromParameterType(P->getType(), P->isVariadic()));
@@ -128,11 +126,9 @@ Type ParameterList::getType(const ASTContext &C) const {
128126
return TupleType::get(argumentInfo, C);
129127
}
130128

131-
/// Hack to deal with the fact that Sema/CodeSynthesis.cpp creates ParamDecls
132-
/// containing contextual types.
133-
Type ParameterList::getInterfaceType(DeclContext *DC) const {
134-
auto &C = DC->getASTContext();
135-
129+
/// Return a TupleType or ParenType for this parameter list, written in terms
130+
/// of interface types.
131+
Type ParameterList::getInterfaceType(const ASTContext &C) const {
136132
if (size() == 0)
137133
return TupleType::getEmpty(C);
138134

@@ -157,10 +153,10 @@ Type ParameterList::getInterfaceType(DeclContext *DC) const {
157153
///
158154
Type ParameterList::getFullInterfaceType(Type resultType,
159155
ArrayRef<ParameterList*> PLL,
160-
DeclContext *DC) {
156+
const ASTContext &C) {
161157
auto result = resultType;
162158
for (auto PL : reversed(PLL)) {
163-
auto paramType = PL->getInterfaceType(DC);
159+
auto paramType = PL->getInterfaceType(C);
164160
result = FunctionType::get(paramType, result);
165161
}
166162
return result;

lib/ClangImporter/ImportDecl.cpp

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ static FuncDecl *makeEnumRawValueGetter(ClangImporter::Implementation &Impl,
440440
getterDecl->setImplicit();
441441

442442
auto type = ParameterList::getFullInterfaceType(enumDecl->getRawType(),
443-
params, enumDecl);
443+
params, C);
444444

445445
getterDecl->setInterfaceType(type);
446446

@@ -502,8 +502,7 @@ static FuncDecl *makeNewtypeBridgedRawValueGetter(
502502
TypeLoc::withoutLoc(computedType), structDecl);
503503
getterDecl->setImplicit();
504504

505-
auto type = ParameterList::getFullInterfaceType(computedType, params,
506-
structDecl);
505+
auto type = ParameterList::getFullInterfaceType(computedType, params, C);
507506

508507
getterDecl->setInterfaceType(type);
509508

@@ -552,8 +551,7 @@ static FuncDecl *makeFieldGetterDecl(ClangImporter::Implementation &Impl,
552551
TypeLoc::withoutLoc(getterType), importedDecl, clangNode);
553552
getterDecl->setAccessibility(Accessibility::Public);
554553

555-
auto type = ParameterList::getFullInterfaceType(getterType, params,
556-
importedDecl);
554+
auto type = ParameterList::getFullInterfaceType(getterType, params, C);
557555
getterDecl->setInterfaceType(type);
558556

559557

@@ -588,8 +586,7 @@ static FuncDecl *makeFieldSetterDecl(ClangImporter::Implementation &Impl,
588586
/*GenericParams=*/nullptr, params,
589587
TypeLoc::withoutLoc(voidTy), importedDecl, clangNode);
590588

591-
auto type = ParameterList::getFullInterfaceType(voidTy, params,
592-
importedDecl);
589+
auto type = ParameterList::getFullInterfaceType(voidTy, params, C);
593590
setterDecl->setInterfaceType(type);
594591

595592
setterDecl->setAccessibility(Accessibility::Public);
@@ -1262,7 +1259,7 @@ static FuncDecl *buildSubscriptGetterDecl(ClangImporter::Implementation &Impl,
12621259

12631260
// Form the type of the getter.
12641261
auto getterType =
1265-
ParameterList::getFullInterfaceType(elementTy, getterArgs, dc);
1262+
ParameterList::getFullInterfaceType(elementTy, getterArgs, C);
12661263

12671264
auto interfaceType =
12681265
getGenericMethodType(dc, getterType->castTo<AnyFunctionType>());
@@ -1322,7 +1319,7 @@ static FuncDecl *buildSubscriptSetterDecl(ClangImporter::Implementation &Impl,
13221319

13231320
// Form the type of the setter.
13241321
Type setterType = ParameterList::getFullInterfaceType(TupleType::getEmpty(C),
1325-
setterArgs, dc);
1322+
setterArgs, C);
13261323

13271324
auto interfaceType =
13281325
getGenericMethodType(dc, setterType->castTo<AnyFunctionType>());
@@ -1486,8 +1483,7 @@ static bool addErrorDomain(NominalTypeDecl *swiftDecl,
14861483
ParameterList::createWithoutLoc(
14871484
ParamDecl::createSelf(SourceLoc(), swiftDecl, isStatic)),
14881485
ParameterList::createEmpty(C)};
1489-
auto toStringTy = ParameterList::getFullInterfaceType(stringTy, params,
1490-
swiftDecl);
1486+
auto toStringTy = ParameterList::getFullInterfaceType(stringTy, params, C);
14911487

14921488
FuncDecl *getterDecl =
14931489
FuncDecl::create(C, /*StaticLoc=*/SourceLoc(), StaticSpellingKind::None,
@@ -4815,7 +4811,7 @@ Decl *SwiftDeclConverter::importGlobalAsMethod(const clang::FunctionDecl *decl,
48154811
auto swiftResultTy = Impl.importFunctionReturnType(
48164812
dc, decl, decl->getReturnType(), allowNSUIntegerAsInt);
48174813
auto fnType =
4818-
ParameterList::getFullInterfaceType(swiftResultTy, bodyParams, dc);
4814+
ParameterList::getFullInterfaceType(swiftResultTy, bodyParams, C);
48194815

48204816
auto loc = Impl.importSourceLoc(decl->getLocation());
48214817
auto nameLoc = Impl.importSourceLoc(decl->getLocation());
@@ -7048,7 +7044,7 @@ ClangImporter::Implementation::createConstant(Identifier name, DeclContext *dc,
70487044
getterArgs.push_back(ParameterList::createEmpty(C));
70497045

70507046
// Form the type of the getter.
7051-
auto getterType = ParameterList::getFullInterfaceType(type, getterArgs, dc);
7047+
auto getterType = ParameterList::getFullInterfaceType(type, getterArgs, C);
70527048

70537049
// Create the getter function declaration.
70547050
auto func =

lib/ClangImporter/ImportType.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2117,7 +2117,7 @@ Type ClangImporter::Implementation::importMethodType(
21172117

21182118
// Form the function type.
21192119
return FunctionType::get(
2120-
(*bodyParams)->getInterfaceType(const_cast<DeclContext*>(dc)),
2120+
(*bodyParams)->getInterfaceType(SwiftContext),
21212121
swiftResultTy, extInfo);
21222122
}
21232123

lib/Sema/TypeCheckDecl.cpp

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3742,7 +3742,7 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
37423742
if (SD->hasInterfaceType())
37433743
return;
37443744

3745-
auto indicesIfaceTy = SD->getIndices()->getInterfaceType(dc);
3745+
auto indicesIfaceTy = SD->getIndices()->getInterfaceType(TC.Context);
37463746

37473747
auto elementTy = SD->getElementTypeLoc().getType();
37483748
auto elementIfaceTy = dc->mapTypeOutOfContext(elementTy);
@@ -4337,17 +4337,6 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
43374337
return true;
43384338
}
43394339

4340-
auto paramLists = FD->getParameterLists();
4341-
4342-
for (unsigned i = 0, e = paramLists.size(); i != e; ++i) {
4343-
Type argTy = paramLists[e - i - 1]->getType(TC.Context);
4344-
if (!argTy) {
4345-
FD->setInterfaceType(ErrorType::get(TC.Context));
4346-
FD->setInvalid();
4347-
return true;
4348-
}
4349-
}
4350-
43514340
return false;
43524341
}
43534342

lib/Sema/TypeCheckGeneric.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,7 @@ void TypeChecker::configureInterfaceType(AbstractFunctionDecl *func,
672672
initArgTy = func->computeInterfaceSelfType(/*isInitializingCtor=*/true);
673673
}
674674
} else {
675-
argTy = paramLists[e - i - 1]->getInterfaceType(func->getDeclContext());
675+
argTy = paramLists[e - i - 1]->getInterfaceType(Context);
676676

677677
if (initFuncTy)
678678
initArgTy = argTy;

lib/Sema/TypeCheckREPL.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ void REPLChecker::generatePrintOfExpression(StringRef NameStr, Expr *E) {
245245
TypeLoc(), discriminator, newTopLevel);
246246

247247
CE->setType(ParameterList::getFullInterfaceType(
248-
TupleType::getEmpty(Context), params, newTopLevel));
248+
TupleType::getEmpty(Context), params, Context));
249249

250250
// Convert the pattern to a string we can print.
251251
llvm::SmallString<16> PrefixString;

0 commit comments

Comments
 (0)