Skip to content

Commit 2920b4f

Browse files
committed
AST: Remove DeclContext::mapTypeOutOfContext()
1 parent cce30cc commit 2920b4f

19 files changed

+27
-38
lines changed

include/swift/AST/DeclContext.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -323,9 +323,6 @@ class alignas(1 << DeclContextAlignInBits) DeclContext {
323323
/// Map an interface type to a contextual type within this context.
324324
Type mapTypeIntoContext(Type type) const;
325325

326-
/// Map a type within this context to an interface type.
327-
Type mapTypeOutOfContext(Type type) const;
328-
329326
/// Returns this or the first local parent context, or nullptr if it is not
330327
/// contained in one.
331328
DeclContext *getLocalContext();

lib/AST/ASTMangler.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1780,7 +1780,7 @@ void ASTMangler::appendClosureComponents(Type Ty, unsigned discriminator,
17801780
if (!Ty)
17811781
Ty = ErrorType::get(localContext->getASTContext());
17821782

1783-
Ty = parentContext->mapTypeOutOfContext(Ty);
1783+
Ty = Ty->mapTypeOutOfContext();
17841784
appendType(Ty->getCanonicalType());
17851785
appendOperator(isImplicit ? "fu" : "fU", Index(discriminator));
17861786
}
@@ -1978,9 +1978,7 @@ void ASTMangler::appendProtocolConformance(const ProtocolConformance *conformanc
19781978
appendProtocolName(conformance->getProtocol());
19791979
appendIdentifier(behaviorStorage->getBaseName().getIdentifier().str());
19801980
} else {
1981-
auto conformanceDC = conformance->getDeclContext();
1982-
auto conformingType =
1983-
conformanceDC->mapTypeOutOfContext(conformance->getType());
1981+
auto conformingType = conformance->getType()->mapTypeOutOfContext();
19841982
appendType(conformingType->getCanonicalType());
19851983
appendProtocolName(conformance->getProtocol());
19861984
appendModule(conformance->getDeclContext()->getParentModule());

lib/AST/ASTPrinter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ class PrintAST : public ASTVisitor<PrintAST> {
487487
if (T->hasArchetype()) {
488488
// Get the interface type, since TypeLocs still have
489489
// contextual types in them.
490-
T = Current->getInnermostDeclContext()->mapTypeOutOfContext(T);
490+
T = T->mapTypeOutOfContext();
491491
}
492492

493493
auto *M = Current->getDeclContext()->getParentModule();

lib/AST/Decl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2503,7 +2503,7 @@ void TypeAliasDecl::setUnderlyingType(Type underlying) {
25032503
// lldb creates global typealiases containing archetypes
25042504
// sometimes...
25052505
if (underlying->hasArchetype() && isGenericContext())
2506-
underlying = mapTypeOutOfContext(underlying);
2506+
underlying = underlying->mapTypeOutOfContext();
25072507
UnderlyingTy.setType(underlying);
25082508

25092509
// FIXME -- if we already have an interface type, we're changing the
@@ -5185,7 +5185,7 @@ bool EnumElementDecl::computeType() {
51855185

51865186
// The type of the enum element is either (T) -> T or (T) -> ArgType -> T.
51875187
if (auto inputTy = getArgumentTypeLoc().getType()) {
5188-
resultTy = FunctionType::get(ED->mapTypeOutOfContext(inputTy), resultTy);
5188+
resultTy = FunctionType::get(inputTy->mapTypeOutOfContext(), resultTy);
51895189
}
51905190

51915191
if (auto *genericSig = ED->getGenericSignatureOfContext())

lib/AST/DeclContext.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -305,10 +305,6 @@ Type DeclContext::mapTypeIntoContext(Type type) const {
305305
getGenericEnvironmentOfContext(), type);
306306
}
307307

308-
Type DeclContext::mapTypeOutOfContext(Type type) const {
309-
return type->mapTypeOutOfContext();
310-
}
311-
312308
DeclContext *DeclContext::getLocalContext() {
313309
if (isLocalContext())
314310
return this;

lib/ClangImporter/ImportType.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2114,7 +2114,7 @@ Type ClangImporter::Implementation::importMethodType(
21142114
bodyName,
21152115
swiftParamTy,
21162116
ImportedHeaderUnit);
2117-
paramInfo->setInterfaceType(dc->mapTypeOutOfContext(swiftParamTy));
2117+
paramInfo->setInterfaceType(swiftParamTy->mapTypeOutOfContext());
21182118

21192119
// Determine whether we have a default argument.
21202120
if (kind == SpecialMethodKind::Regular ||
@@ -2178,7 +2178,7 @@ Type ClangImporter::Implementation::importMethodType(
21782178

21792179
// Form the function type.
21802180
return FunctionType::get((*bodyParams)->getInterfaceType(SwiftContext),
2181-
dc->mapTypeOutOfContext(swiftResultTy), extInfo);
2181+
swiftResultTy->mapTypeOutOfContext(), extInfo);
21822182
}
21832183

21842184
Type ClangImporter::Implementation::importAccessorMethodType(
@@ -2218,7 +2218,7 @@ Type ClangImporter::Implementation::importAccessorMethodType(
22182218
Type resultTy;
22192219
if (isGetter) {
22202220
*params = ParameterList::createEmpty(SwiftContext);
2221-
resultTy = dc->mapTypeOutOfContext(propertyTy);
2221+
resultTy = propertyTy->mapTypeOutOfContext();
22222222
} else {
22232223
const clang::ParmVarDecl *param = clangDecl->parameters().front();
22242224
ImportedName fullBodyName = importFullName(param, CurrentVersion);
@@ -2233,7 +2233,7 @@ Type ClangImporter::Implementation::importAccessorMethodType(
22332233
argLabel, nameLoc, bodyName,
22342234
propertyTy,
22352235
/*dummy DC*/ImportedHeaderUnit);
2236-
paramInfo->setInterfaceType(dc->mapTypeOutOfContext(propertyTy));
2236+
paramInfo->setInterfaceType(propertyTy->mapTypeOutOfContext());
22372237

22382238
*params = ParameterList::create(SwiftContext, paramInfo);
22392239
resultTy = SwiftContext.getVoidDecl()->getDeclaredInterfaceType();

lib/IRGen/GenReflection.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -880,8 +880,7 @@ emitAssociatedTypeMetadataRecord(const ProtocolConformance *Conformance) {
880880
Type Replacement,
881881
const TypeDecl *TD) -> bool {
882882

883-
auto Subst = Conformance->getDeclContext()->mapTypeOutOfContext(
884-
Replacement);
883+
auto Subst = Replacement->mapTypeOutOfContext();
885884

886885
AssociatedTypes.push_back({
887886
AssocTy->getNameStr(),

lib/SIL/TypeLowering.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1751,7 +1751,7 @@ static CanAnyFunctionType getStoredPropertyInitializerInterfaceType(
17511751
VarDecl *VD) {
17521752
auto *DC = VD->getDeclContext();
17531753
CanType resultTy =
1754-
DC->mapTypeOutOfContext(VD->getParentPattern()->getType())
1754+
VD->getParentPattern()->getType()->mapTypeOutOfContext()
17551755
->getCanonicalType();
17561756
auto sig = TC.getEffectiveGenericSignature(DC);
17571757

@@ -1871,7 +1871,7 @@ CanAnyFunctionType TypeConverter::makeConstantInterfaceType(SILDeclRef c) {
18711871
// FIXME: Closures could have an interface type computed by Sema.
18721872
auto funcTy = cast<AnyFunctionType>(ACE->getType()->getCanonicalType());
18731873
funcTy = cast<AnyFunctionType>(
1874-
ACE->mapTypeOutOfContext(funcTy)
1874+
funcTy->mapTypeOutOfContext()
18751875
->getCanonicalType());
18761876
return getFunctionInterfaceTypeWithCaptures(funcTy, ACE);
18771877
}

lib/SILGen/SILGenConstructor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -892,7 +892,7 @@ static SILValue getBehaviorSetterFn(SILGenFunction &SGF, VarDecl *behaviorVar) {
892892
static Type getInitializationTypeInContext(
893893
DeclContext *fromDC, DeclContext *toDC,
894894
Pattern *pattern) {
895-
auto interfaceType = fromDC->mapTypeOutOfContext(pattern->getType());
895+
auto interfaceType = pattern->getType()->mapTypeOutOfContext();
896896
auto resultType = toDC->mapTypeIntoContext(interfaceType);
897897

898898
return resultType;

lib/SILGen/SILGenFunction.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ void SILGenFunction::emitFunction(FuncDecl *fd) {
406406
void SILGenFunction::emitClosure(AbstractClosureExpr *ace) {
407407
MagicFunctionName = SILGenModule::getMagicFunctionName(ace);
408408

409-
auto resultIfaceTy = ace->mapTypeOutOfContext(ace->getResultType());
409+
auto resultIfaceTy = ace->getResultType()->mapTypeOutOfContext();
410410
emitProlog(ace, ace->getParameters(), resultIfaceTy,
411411
ace->isBodyThrowing());
412412
prepareEpilog(ace->getResultType(), ace->isBodyThrowing(),
@@ -618,7 +618,7 @@ void SILGenFunction::emitGeneratorFunction(SILDeclRef function, Expr *value) {
618618
Loc.markAutoGenerated();
619619

620620
auto *dc = function.getDecl()->getInnermostDeclContext();
621-
auto interfaceType = dc->mapTypeOutOfContext(value->getType());
621+
auto interfaceType = value->getType()->mapTypeOutOfContext();
622622
emitProlog({}, interfaceType, dc, false);
623623
prepareEpilog(value->getType(), false, CleanupLocation::get(Loc));
624624
emitReturnExpr(Loc, value);

0 commit comments

Comments
 (0)