Skip to content

Commit fb0f372

Browse files
committed
AST: Move mapType{In,OutOf}Context() out of ArchetypeBuilder and clean up headers
- The DeclContext versions of these methods have equivalents on the DeclContext class; use them instead. - The GenericEnvironment versions of these methods are now static methods on the GenericEnvironment class. Note that these are not made redundant by the instance methods on GenericEnvironment, since the static methods can also be called with a null GenericEnvironment, in which case they just assert that the type is fully concrete. - Remove some unnecessary #includes of ArchetypeBuilder.h and GenericEnvironment.h. Now changes to these files result in a lot less recompilation.
1 parent ad45e0b commit fb0f372

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+287
-349
lines changed

include/swift/AST/ASTContext.h

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#define SWIFT_AST_ASTCONTEXT_H
1919

2020
#include "llvm/Support/DataTypes.h"
21-
#include "swift/AST/ArchetypeBuilder.h"
2221
#include "swift/AST/ClangModuleLoader.h"
2322
#include "swift/AST/Identifier.h"
2423
#include "swift/AST/ProtocolConformance.h"
@@ -69,6 +68,7 @@ namespace swift {
6968
class TypeVariableType;
7069
class TupleType;
7170
class FunctionType;
71+
class ArchetypeBuilder;
7272
class ArchetypeType;
7373
class Identifier;
7474
class InheritedNameSet;
@@ -825,25 +825,7 @@ class ASTContext {
825825
DeclContext *gpContext,
826826
ArrayRef<Substitution> Subs) const;
827827

828-
/// Retrieve the archetype builder and potential archetype
829-
/// corresponding to the given archetype type.
830-
///
831-
/// This facility is only used by the archetype builder when forming
832-
/// archetypes.a
833-
std::pair<ArchetypeBuilder *, ArchetypeBuilder::PotentialArchetype *>
834-
getLazyArchetype(const ArchetypeType *archetype);
835-
836-
/// Register information for a lazily-constructed archetype.
837-
void registerLazyArchetype(
838-
const ArchetypeType *archetype,
839-
ArchetypeBuilder &builder,
840-
ArchetypeBuilder::PotentialArchetype *potentialArchetype);
841-
842-
/// Unregister information about the given lazily-constructed archetype.
843-
void unregisterLazyArchetype(const ArchetypeType *archetype);
844-
845828
friend ArchetypeType;
846-
friend ArchetypeBuilder::PotentialArchetype;
847829

848830
/// Provide context-level uniquing for SIL lowered type layouts and boxes.
849831
friend SILLayout;

include/swift/AST/AnyFunctionRef.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#define SWIFT_AST_ANY_FUNCTION_REF_H
1515

1616
#include "swift/Basic/LLVM.h"
17-
#include "swift/AST/ArchetypeBuilder.h"
1817
#include "swift/AST/Decl.h"
1918
#include "swift/AST/Expr.h"
2019
#include "swift/AST/Types.h"
@@ -83,8 +82,7 @@ class AnyFunctionRef {
8382
Type getBodyResultType() const {
8483
if (auto *AFD = TheFunction.dyn_cast<AbstractFunctionDecl *>()) {
8584
if (auto *FD = dyn_cast<FuncDecl>(AFD))
86-
return ArchetypeBuilder::mapTypeIntoContext(
87-
FD, FD->getResultInterfaceType());
85+
return FD->mapTypeIntoContext(FD->getResultInterfaceType());
8886
return TupleType::getEmpty(AFD->getASTContext());
8987
}
9088
return TheFunction.get<AbstractClosureExpr *>()->getResultType();

include/swift/AST/ArchetypeBuilder.h

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -303,21 +303,6 @@ class ArchetypeBuilder {
303303
/// For any type that cannot refer to an archetype, this routine returns null.
304304
PotentialArchetype *resolveArchetype(Type type);
305305

306-
/// Map an interface type to a contextual type.
307-
static Type mapTypeIntoContext(const DeclContext *dc, Type type);
308-
309-
/// Map an interface type to a contextual type.
310-
static Type mapTypeIntoContext(ModuleDecl *M,
311-
GenericEnvironment *genericEnv,
312-
Type type);
313-
314-
/// Map a contextual type to an interface type.
315-
static Type mapTypeOutOfContext(const DeclContext *dc, Type type);
316-
317-
/// Map a contextual type to an interface type.
318-
static Type mapTypeOutOfContext(GenericEnvironment *genericEnv,
319-
Type type);
320-
321306
/// \brief Dump all of the requirements, both specified and inferred.
322307
LLVM_ATTRIBUTE_DEPRECATED(
323308
void dump(),

include/swift/AST/Decl.h

Lines changed: 9 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#include "swift/AST/ClangNode.h"
2323
#include "swift/AST/ConcreteDeclRef.h"
2424
#include "swift/AST/DefaultArgumentKind.h"
25-
#include "swift/AST/GenericEnvironment.h"
2625
#include "swift/AST/GenericSignature.h"
2726
#include "swift/AST/GenericParamKey.h"
2827
#include "swift/AST/LazyResolver.h"
@@ -37,7 +36,6 @@
3736
namespace swift {
3837
enum class AccessSemantics : unsigned char;
3938
class ApplyExpr;
40-
class ArchetypeBuilder;
4139
class GenericEnvironment;
4240
class ArchetypeType;
4341
class ASTContext;
@@ -1495,44 +1493,18 @@ class ExtensionDecl final : public Decl, public DeclContext,
14951493
}
14961494

14971495
/// Retrieve the generic signature for this type.
1498-
GenericSignature *getGenericSignature() const {
1499-
if (auto genericEnv = GenericSigOrEnv.dyn_cast<GenericEnvironment *>())
1500-
return genericEnv->getGenericSignature();
1501-
1502-
if (auto genericSig = GenericSigOrEnv.dyn_cast<GenericSignature *>())
1503-
return genericSig;
1504-
1505-
return nullptr;
1506-
}
1496+
GenericSignature *getGenericSignature() const;
15071497

15081498
/// Retrieve the generic context for this type.
1509-
GenericEnvironment *getGenericEnvironment() const {
1510-
// Fast case: we already have a generic environment.
1511-
if (auto genericEnv = GenericSigOrEnv.dyn_cast<GenericEnvironment *>())
1512-
return genericEnv;
1513-
1514-
// If we only have a generic signature, build the generic environment.
1515-
if (GenericSigOrEnv.dyn_cast<GenericSignature *>())
1516-
return getLazyGenericEnvironmentSlow();
1517-
1518-
return nullptr;
1519-
}
1499+
GenericEnvironment *getGenericEnvironment() const;
15201500

15211501
/// Set a lazy generic environment.
15221502
void setLazyGenericEnvironment(LazyMemberLoader *lazyLoader,
15231503
GenericSignature *genericSig,
15241504
uint64_t genericEnvData);
15251505

15261506
/// Set the generic context of this extension.
1527-
void setGenericEnvironment(GenericEnvironment *genericEnv) {
1528-
assert((GenericSigOrEnv.isNull() ||
1529-
getGenericSignature()->getCanonicalSignature() ==
1530-
genericEnv->getGenericSignature()->getCanonicalSignature()) &&
1531-
"set a generic environment with a different generic signature");
1532-
this->GenericSigOrEnv = genericEnv;
1533-
if (genericEnv)
1534-
genericEnv->setOwningDeclContext(this);
1535-
}
1507+
void setGenericEnvironment(GenericEnvironment *genericEnv);
15361508

15371509
/// Retrieve the type being extended.
15381510
Type getExtendedType() const { return ExtendedType.getType(); }
@@ -2322,28 +2294,10 @@ class GenericTypeDecl : public TypeDecl, public DeclContext {
23222294
}
23232295

23242296
/// Retrieve the generic signature for this type.
2325-
GenericSignature *getGenericSignature() const {
2326-
if (auto genericEnv = GenericSigOrEnv.dyn_cast<GenericEnvironment *>())
2327-
return genericEnv->getGenericSignature();
2328-
2329-
if (auto genericSig = GenericSigOrEnv.dyn_cast<GenericSignature *>())
2330-
return genericSig;
2331-
2332-
return nullptr;
2333-
}
2297+
GenericSignature *getGenericSignature() const;
23342298

23352299
/// Retrieve the generic context for this type.
2336-
GenericEnvironment *getGenericEnvironment() const {
2337-
// Fast case: we already have a generic environment.
2338-
if (auto genericEnv = GenericSigOrEnv.dyn_cast<GenericEnvironment *>())
2339-
return genericEnv;
2340-
2341-
// If we only have a generic signature, build the generic environment.
2342-
if (GenericSigOrEnv.dyn_cast<GenericSignature *>())
2343-
return getLazyGenericEnvironmentSlow();
2344-
2345-
return nullptr;
2346-
}
2300+
GenericEnvironment *getGenericEnvironment() const;
23472301

23482302
void setIsValidatingGenericSignature(bool validating=true) {
23492303
ValidatingGenericSignature = validating;
@@ -2359,16 +2313,7 @@ class GenericTypeDecl : public TypeDecl, public DeclContext {
23592313
uint64_t genericEnvData);
23602314

23612315
/// Set the generic context of this function.
2362-
void setGenericEnvironment(GenericEnvironment *genericEnv) {
2363-
assert((GenericSigOrEnv.isNull() ||
2364-
getGenericSignature()->getCanonicalSignature() ==
2365-
genericEnv->getGenericSignature()->getCanonicalSignature()) &&
2366-
"set a generic environment with a different generic signature");
2367-
this->GenericSigOrEnv = genericEnv;
2368-
2369-
if (genericEnv)
2370-
genericEnv->setOwningDeclContext(this);
2371-
}
2316+
void setGenericEnvironment(GenericEnvironment *genericEnv);
23722317

23732318
// Resolve ambiguity due to multiple base classes.
23742319
using TypeDecl::getASTContext;
@@ -4642,45 +4587,18 @@ class AbstractFunctionDecl : public ValueDecl, public DeclContext {
46424587
bool isTransparent() const;
46434588

46444589
/// Retrieve the generic signature for this function.
4645-
GenericSignature *getGenericSignature() const {
4646-
if (auto genericEnv = GenericSigOrEnv.dyn_cast<GenericEnvironment *>())
4647-
return genericEnv->getGenericSignature();
4648-
4649-
if (auto genericSig = GenericSigOrEnv.dyn_cast<GenericSignature *>())
4650-
return genericSig;
4651-
4652-
return nullptr;
4653-
}
4590+
GenericSignature *getGenericSignature() const;
46544591

46554592
/// Retrieve the generic context for this function.
4656-
GenericEnvironment *getGenericEnvironment() const {
4657-
// Fast case: we already have a generic environment.
4658-
if (auto genericEnv = GenericSigOrEnv.dyn_cast<GenericEnvironment *>())
4659-
return genericEnv;
4660-
4661-
// If we only have a generic signature, build the generic environment.
4662-
if (GenericSigOrEnv.dyn_cast<GenericSignature *>())
4663-
return getLazyGenericEnvironmentSlow();
4664-
4665-
return nullptr;
4666-
}
4593+
GenericEnvironment *getGenericEnvironment() const;
46674594

46684595
/// Set a lazy generic environment.
46694596
void setLazyGenericEnvironment(LazyMemberLoader *lazyLoader,
46704597
GenericSignature *genericSig,
46714598
uint64_t genericEnvData);
46724599

46734600
/// Set the generic context of this function.
4674-
void setGenericEnvironment(GenericEnvironment *genericEnv) {
4675-
assert((GenericSigOrEnv.isNull() ||
4676-
getGenericSignature()->getCanonicalSignature() ==
4677-
genericEnv->getGenericSignature()->getCanonicalSignature()) &&
4678-
"set a generic environment with a different generic signature");
4679-
this->GenericSigOrEnv = genericEnv;
4680-
4681-
if (genericEnv)
4682-
genericEnv->setOwningDeclContext(this);
4683-
}
4601+
void setGenericEnvironment(GenericEnvironment *genericEnv);
46844602

46854603
// Expose our import as member status
46864604
bool isImportAsMember() const { return IAMStatus.isImportAsMember(); }

include/swift/AST/GenericEnvironment.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,15 @@ class alignas(1 << DeclAlignInBits) GenericEnvironment final
196196
return Mem;
197197
}
198198

199+
/// Map an interface type to a contextual type.
200+
static Type mapTypeIntoContext(ModuleDecl *M,
201+
GenericEnvironment *genericEnv,
202+
Type type);
203+
204+
/// Map a contextual type to an interface type.
205+
static Type mapTypeOutOfContext(GenericEnvironment *genericEnv,
206+
Type type);
207+
199208
/// Map a contextual type to an interface type.
200209
Type mapTypeOutOfContext(Type type) const;
201210

include/swift/AST/TypeRepr.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
#include "swift/AST/Attr.h"
2121
#include "swift/AST/DeclContext.h"
22-
#include "swift/AST/GenericEnvironment.h"
2322
#include "swift/AST/Identifier.h"
2423
#include "swift/AST/Type.h"
2524
#include "swift/AST/TypeAlignments.h"
@@ -32,6 +31,7 @@
3231
namespace swift {
3332
class ASTWalker;
3433
class DeclContext;
34+
class GenericEnvironment;
3535
class IdentTypeRepr;
3636
class ValueDecl;
3737

@@ -413,9 +413,6 @@ class FunctionTypeRepr : public TypeRepr {
413413

414414
GenericParamList *getGenericParams() const { return GenericParams; }
415415
GenericEnvironment *getGenericEnvironment() const { return GenericEnv; }
416-
GenericSignature *getGenericSignature() const {
417-
return GenericEnv ? GenericEnv->getGenericSignature() : nullptr;
418-
}
419416

420417
void setGenericEnvironment(GenericEnvironment *genericEnv) {
421418
assert(GenericEnv == nullptr);
@@ -915,9 +912,6 @@ class SILBoxTypeRepr : public TypeRepr {
915912
GenericParamList *getGenericParams() const {
916913
return GenericParams;
917914
}
918-
GenericSignature *getGenericSignature() const {
919-
return GenericEnv->getGenericSignature();
920-
}
921915
GenericEnvironment *getGenericEnvironment() const {
922916
return GenericEnv;
923917
}

include/swift/AST/Witness.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -158,15 +158,6 @@ class Witness {
158158
return getDeclRef().getSubstitutions();
159159
}
160160

161-
/// Retrieve the generic signature of the synthetic environment.
162-
GenericSignature *getSyntheticSignature() const {
163-
assert(requiresSubstitution() && "No substitutions required for witness");
164-
if (auto *env = getSyntheticEnvironment())
165-
return env->getGenericSignature();
166-
else
167-
return nullptr;
168-
}
169-
170161
/// Retrieve the synthetic generic environment.
171162
GenericEnvironment *getSyntheticEnvironment() const {
172163
assert(requiresSubstitution() && "No substitutions required for witness");

lib/AST/ASTMangler.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -586,8 +586,8 @@ void ASTMangler::appendType(Type type) {
586586

587587
// Find the archetype information.
588588
const DeclContext *DC = DeclCtx;
589-
auto GTPT = ArchetypeBuilder::mapTypeOutOfContext(DC, archetype)
590-
->castTo<GenericTypeParamType>();
589+
auto GTPT = DC->mapTypeOutOfContext(archetype)
590+
->castTo<GenericTypeParamType>();
591591

592592
if (DWARFMangling) {
593593
Buffer << 'q' << Index(GTPT->getIndex());
@@ -1390,7 +1390,7 @@ void ASTMangler::appendClosureComponents(Type Ty, unsigned discriminator,
13901390
if (!Ty)
13911391
Ty = ErrorType::get(localContext->getASTContext());
13921392

1393-
Ty = ArchetypeBuilder::mapTypeOutOfContext(parentContext, Ty);
1393+
Ty = parentContext->mapTypeOutOfContext(Ty);
13941394
appendType(Ty->getCanonicalType());
13951395
appendOperator(isImplicit ? "fu" : "fU", Index(discriminator));
13961396
}

lib/AST/ASTPrinter.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#include "swift/AST/ASTPrinter.h"
1818
#include "swift/AST/ASTContext.h"
1919
#include "swift/AST/ASTVisitor.h"
20-
#include "swift/AST/ArchetypeBuilder.h"
2120
#include "swift/AST/Attr.h"
2221
#include "swift/AST/Decl.h"
2322
#include "swift/AST/Expr.h"
@@ -855,8 +854,7 @@ class PrintAST : public ASTVisitor<PrintAST> {
855854
if (T->hasArchetype()) {
856855
// Get the interface type, since TypeLocs still have
857856
// contextual types in them.
858-
T = ArchetypeBuilder::mapTypeOutOfContext(
859-
Current->getInnermostDeclContext(), T);
857+
T = Current->getInnermostDeclContext()->mapTypeOutOfContext(T);
860858
}
861859

862860
// Get the innermost nominal type context.

lib/AST/ASTVerifier.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
#include "swift/Subsystems.h"
1818
#include "swift/AST/AccessScope.h"
19-
#include "swift/AST/ArchetypeBuilder.h"
2019
#include "swift/AST/AST.h"
2120
#include "swift/AST/ASTContext.h"
2221
#include "swift/AST/ASTWalker.h"
@@ -705,7 +704,7 @@ struct ASTNodeBase {};
705704
Type resultType;
706705
if (FuncDecl *FD = dyn_cast<FuncDecl>(func)) {
707706
resultType = FD->getResultInterfaceType();
708-
resultType = ArchetypeBuilder::mapTypeIntoContext(FD, resultType);
707+
resultType = FD->mapTypeIntoContext(resultType);
709708
} else if (auto closure = dyn_cast<AbstractClosureExpr>(func)) {
710709
resultType = closure->getResultType();
711710
} else {
@@ -1739,17 +1738,15 @@ struct ASTNodeBase {};
17391738
Type typeForAccessors =
17401739
var->getInterfaceType()->getReferenceStorageReferent();
17411740
typeForAccessors =
1742-
ArchetypeBuilder::mapTypeIntoContext(var->getDeclContext(),
1743-
typeForAccessors);
1741+
var->getDeclContext()->mapTypeIntoContext(typeForAccessors);
17441742
if (const FuncDecl *getter = var->getGetter()) {
17451743
if (getter->getParameterLists().back()->size() != 0) {
17461744
Out << "property getter has parameters\n";
17471745
abort();
17481746
}
17491747
Type getterResultType = getter->getResultInterfaceType();
17501748
getterResultType =
1751-
ArchetypeBuilder::mapTypeIntoContext(var->getDeclContext(),
1752-
getterResultType);
1749+
var->getDeclContext()->mapTypeIntoContext(getterResultType);
17531750
if (!getterResultType->isEqual(typeForAccessors)) {
17541751
Out << "property and getter have mismatched types: '";
17551752
typeForAccessors.print(Out);
@@ -1775,8 +1772,7 @@ struct ASTNodeBase {};
17751772
}
17761773
const ParamDecl *param = setter->getParameterLists().back()->get(0);
17771774
Type paramType = param->getInterfaceType();
1778-
paramType = ArchetypeBuilder::mapTypeIntoContext(var->getDeclContext(),
1779-
paramType);
1775+
paramType = var->getDeclContext()->mapTypeIntoContext(paramType);
17801776
if (!paramType->isEqual(typeForAccessors)) {
17811777
Out << "property and setter param have mismatched types: '";
17821778
typeForAccessors.print(Out);

0 commit comments

Comments
 (0)