Skip to content

Commit 06378ae

Browse files
authored
Merge pull request swiftlang#28092 from CodaFi/typing-of-the-dead
Kill the LazyResolver
2 parents 86ee000 + 2b08d1b commit 06378ae

Some content is hidden

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

41 files changed

+343
-225
lines changed

include/swift/AST/ASTContext.h

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ namespace swift {
7070
class LazyContextData;
7171
class LazyIterableDeclContextData;
7272
class LazyMemberLoader;
73-
class LazyResolver;
7473
class PatternBindingDecl;
7574
class PatternBindingInitializer;
7675
class SourceFile;
@@ -102,6 +101,7 @@ namespace swift {
102101
class SourceManager;
103102
class ValueDecl;
104103
class DiagnosticEngine;
104+
class TypeChecker;
105105
class TypeCheckerDebugConsumer;
106106
struct RawComment;
107107
class DocComment;
@@ -404,28 +404,14 @@ class ASTContext final {
404404
/// Set a new stats reporter.
405405
void setStatsReporter(UnifiedStatsReporter *stats);
406406

407-
/// Creates a new lazy resolver by passing the ASTContext and the other
408-
/// given arguments to a newly-allocated instance of \c ResolverType.
409-
///
410-
/// \returns true if a new lazy resolver was created, false if there was
411-
/// already a lazy resolver registered.
412-
template<typename ResolverType, typename ... Args>
413-
bool createLazyResolverIfMissing(Args && ...args) {
414-
if (getLazyResolver())
415-
return false;
416-
417-
setLazyResolver(new ResolverType(*this, std::forward<Args>(args)...));
418-
return true;
419-
}
420-
421-
/// Retrieve the lazy resolver for this context.
422-
LazyResolver *getLazyResolver() const;
423-
424407
private:
425-
/// Set the lazy resolver for this context.
426-
void setLazyResolver(LazyResolver *resolver);
408+
friend class TypeChecker;
427409

410+
void installGlobalTypeChecker(TypeChecker *TC);
428411
public:
412+
/// Retrieve the global \c TypeChecker instance associated with this context.
413+
TypeChecker *getLegacyGlobalTypeChecker() const;
414+
429415
/// getIdentifier - Return the uniqued and AST-Context-owned version of the
430416
/// specified string.
431417
Identifier getIdentifier(StringRef Str) const;

include/swift/AST/ASTTypeIDZone.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ SWIFT_TYPEID(Requirement)
2626
SWIFT_TYPEID(ResilienceExpansion)
2727
SWIFT_TYPEID(Type)
2828
SWIFT_TYPEID(TypePair)
29+
SWIFT_TYPEID(TypeWitnessAndDecl)
30+
SWIFT_TYPEID(Witness)
2931
SWIFT_TYPEID_NAMED(ConstructorDecl *, ConstructorDecl)
3032
SWIFT_TYPEID_NAMED(CustomAttr *, CustomAttr)
3133
SWIFT_TYPEID_NAMED(Decl *, Decl)

include/swift/AST/ASTTypeIDs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,11 @@ enum class ResilienceExpansion : unsigned;
5151
class Type;
5252
class ValueDecl;
5353
class VarDecl;
54+
class Witness;
5455
class TypeAliasDecl;
5556
class Type;
5657
struct TypePair;
58+
struct TypeWitnessAndDecl;
5759
enum class AncestryFlags : uint8_t;
5860
enum class ImplicitMemberAction : uint8_t;
5961

include/swift/AST/Decl.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7326,6 +7326,11 @@ inline void simple_display(llvm::raw_ostream &out,
73267326
simple_display(out, static_cast<const Decl *>(decl));
73277327
}
73287328

7329+
inline void simple_display(llvm::raw_ostream &out,
7330+
const AssociatedTypeDecl *decl) {
7331+
simple_display(out, static_cast<const Decl *>(decl));
7332+
}
7333+
73297334
/// Display GenericContext.
73307335
///
73317336
/// The template keeps this sorted down in the overload set relative to the

include/swift/AST/DeclContext.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ namespace swift {
5050
class ExtensionDecl;
5151
class Expr;
5252
class GenericParamList;
53-
class LazyResolver;
5453
class LazyMemberLoader;
5554
class GenericSignature;
5655
class GenericTypeParamDecl;

include/swift/AST/GenericSignatureBuilder.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ class DependentMemberType;
4949
class GenericParamList;
5050
class GenericSignatureBuilder;
5151
class GenericTypeParamType;
52-
class LazyResolver;
5352
class ModuleDecl;
5453
class Pattern;
5554
class ProtocolConformance;

include/swift/AST/LazyResolver.h

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212
//
13-
// This file defines the LazyResolver abstract interface.
13+
// This file defines the abstract interfaces for lazily resolving declarations.
1414
//
1515
//===----------------------------------------------------------------------===//
1616

@@ -37,23 +37,6 @@ class TypeDecl;
3737
class ValueDecl;
3838
class VarDecl;
3939

40-
/// Abstract interface used to lazily resolve aspects of the AST, such as the
41-
/// types of declarations or protocol conformance structures.
42-
class LazyResolver {
43-
public:
44-
virtual ~LazyResolver();
45-
46-
/// Resolve the type witnesses for the given associated type within the given
47-
/// protocol conformance.
48-
virtual void resolveTypeWitness(const NormalProtocolConformance *conformance,
49-
AssociatedTypeDecl *assocType) = 0;
50-
51-
/// Resolve the witness for the given non-type requirement within
52-
/// the given protocol conformance.
53-
virtual void resolveWitness(const NormalProtocolConformance *conformance,
54-
ValueDecl *requirement) = 0;
55-
};
56-
5740
class LazyMemberLoader;
5841

5942
/// Context data for lazy deserialization.

include/swift/AST/Module.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ namespace swift {
5858
class FileUnit;
5959
class FuncDecl;
6060
class InfixOperatorDecl;
61-
class LazyResolver;
6261
class LinkLibrary;
6362
class ModuleLoader;
6463
class NominalTypeDecl;

include/swift/AST/ProtocolConformance.h

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ typedef llvm::DenseMap<ValueDecl *, Witness> WitnessMap;
5252

5353
/// Map from associated type requirements to the corresponding type and
5454
/// the type declaration that was used to satisfy the requirement.
55-
typedef llvm::DenseMap<AssociatedTypeDecl *, std::pair<Type, TypeDecl*>>
55+
typedef llvm::DenseMap<AssociatedTypeDecl *, TypeWitnessAndDecl>
5656
TypeWitnessMap;
5757

5858
/// Describes the kind of protocol conformance structure used to encode
@@ -157,7 +157,7 @@ class alignas(1 << DeclAlignInBits) ProtocolConformance {
157157

158158
/// Retrieve the type witness and type decl (if one exists)
159159
/// for the given associated type.
160-
std::pair<Type, TypeDecl *>
160+
TypeWitnessAndDecl
161161
getTypeWitnessAndDecl(AssociatedTypeDecl *assocType,
162162
SubstOptions options=None) const;
163163

@@ -182,7 +182,7 @@ class alignas(1 << DeclAlignInBits) ProtocolConformance {
182182
continue;
183183

184184
const auto &TWInfo = getTypeWitnessAndDecl(assocTypeReq);
185-
if (f(assocTypeReq, TWInfo.first, TWInfo.second))
185+
if (f(assocTypeReq, TWInfo.getWitnessType(), TWInfo.getWitnessDecl()))
186186
return true;
187187
}
188188

@@ -404,6 +404,9 @@ class RootProtocolConformance : public ProtocolConformance {
404404
class NormalProtocolConformance : public RootProtocolConformance,
405405
public llvm::FoldingSetNode
406406
{
407+
friend class ValueWitnessRequest;
408+
friend class TypeWitnessRequest;
409+
407410
/// The protocol being conformed to and its current state.
408411
llvm::PointerIntPair<ProtocolDecl *, 2, ProtocolConformanceState>
409412
ProtocolAndState;
@@ -588,10 +591,13 @@ class NormalProtocolConformance : public RootProtocolConformance,
588591

589592
/// Retrieve the type witness and type decl (if one exists)
590593
/// for the given associated type.
591-
std::pair<Type, TypeDecl *>
594+
TypeWitnessAndDecl
592595
getTypeWitnessAndDecl(AssociatedTypeDecl *assocType,
593596
SubstOptions options=None) const;
594597

598+
TypeWitnessAndDecl
599+
getTypeWitnessUncached(AssociatedTypeDecl *requirement) const;
600+
595601
/// Determine whether the protocol conformance has a type witness for the
596602
/// given associated type.
597603
bool hasTypeWitness(AssociatedTypeDecl *assocType) const;
@@ -610,6 +616,8 @@ class NormalProtocolConformance : public RootProtocolConformance,
610616
/// Retrieve the value witness corresponding to the given requirement.
611617
Witness getWitness(ValueDecl *requirement) const;
612618

619+
Witness getWitnessUncached(ValueDecl *requirement) const;
620+
613621
/// Determine whether the protocol conformance has a witness for the given
614622
/// requirement.
615623
bool hasWitness(ValueDecl *requirement) const {
@@ -641,7 +649,7 @@ class NormalProtocolConformance : public RootProtocolConformance,
641649
/// Determine whether the witness for the given type requirement
642650
/// is the default definition.
643651
bool usesDefaultDefinition(AssociatedTypeDecl *requirement) const {
644-
TypeDecl *witnessDecl = getTypeWitnessAndDecl(requirement).second;
652+
TypeDecl *witnessDecl = getTypeWitnessAndDecl(requirement).getWitnessDecl();
645653
if (witnessDecl)
646654
return witnessDecl->isImplicit();
647655
// Conservatively assume it does not.
@@ -713,7 +721,7 @@ class SelfProtocolConformance : public RootProtocolConformance {
713721
llvm_unreachable("self-conformances never have associated types");
714722
}
715723

716-
std::pair<Type, TypeDecl *>
724+
TypeWitnessAndDecl
717725
getTypeWitnessAndDecl(AssociatedTypeDecl *assocType,
718726
SubstOptions options=None) const {
719727
llvm_unreachable("self-conformances never have associated types");
@@ -859,7 +867,7 @@ class SpecializedProtocolConformance : public ProtocolConformance,
859867

860868
/// Retrieve the type witness and type decl (if one exists)
861869
/// for the given associated type.
862-
std::pair<Type, TypeDecl *>
870+
TypeWitnessAndDecl
863871
getTypeWitnessAndDecl(AssociatedTypeDecl *assocType,
864872
SubstOptions options=None) const;
865873

@@ -971,7 +979,7 @@ class InheritedProtocolConformance : public ProtocolConformance,
971979

972980
/// Retrieve the type witness and type decl (if one exists)
973981
/// for the given associated type.
974-
std::pair<Type, TypeDecl *>
982+
TypeWitnessAndDecl
975983
getTypeWitnessAndDecl(AssociatedTypeDecl *assocType,
976984
SubstOptions options=None) const {
977985
return InheritedConformance->getTypeWitnessAndDecl(assocType, options);
@@ -1015,6 +1023,8 @@ inline bool ProtocolConformance::hasWitness(ValueDecl *requirement) const {
10151023
return getRootConformance()->hasWitness(requirement);
10161024
}
10171025

1026+
void simple_display(llvm::raw_ostream &out, const ProtocolConformance *conf);
1027+
10181028
} // end namespace swift
10191029

10201030
#endif // LLVM_SWIFT_AST_PROTOCOLCONFORMANCE_H

include/swift/AST/TypeCheckRequests.h

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ class RequirementRepr;
4141
class SpecializeAttr;
4242
class TypeAliasDecl;
4343
struct TypeLoc;
44+
class Witness;
45+
struct TypeWitnessAndDecl;
4446
class ValueDecl;
4547
enum class OpaqueReadOwnership: uint8_t;
4648
class StorageImplInfo;
@@ -1697,6 +1699,51 @@ class ResolveImplicitMemberRequest
16971699
bool isCached() const { return true; }
16981700
};
16991701

1702+
class TypeWitnessRequest
1703+
: public SimpleRequest<TypeWitnessRequest,
1704+
TypeWitnessAndDecl(NormalProtocolConformance *,
1705+
AssociatedTypeDecl *),
1706+
CacheKind::SeparatelyCached> {
1707+
public:
1708+
using SimpleRequest::SimpleRequest;
1709+
1710+
private:
1711+
friend SimpleRequest;
1712+
1713+
// Evaluation.
1714+
llvm::Expected<TypeWitnessAndDecl>
1715+
evaluate(Evaluator &evaluator, NormalProtocolConformance *conformance,
1716+
AssociatedTypeDecl *ATD) const;
1717+
1718+
public:
1719+
// Separate caching.
1720+
bool isCached() const { return true; }
1721+
Optional<TypeWitnessAndDecl> getCachedResult() const;
1722+
void cacheResult(TypeWitnessAndDecl value) const;
1723+
};
1724+
1725+
class ValueWitnessRequest
1726+
: public SimpleRequest<ValueWitnessRequest,
1727+
Witness(NormalProtocolConformance *, ValueDecl *),
1728+
CacheKind::SeparatelyCached> {
1729+
public:
1730+
using SimpleRequest::SimpleRequest;
1731+
1732+
private:
1733+
friend SimpleRequest;
1734+
1735+
// Evaluation.
1736+
llvm::Expected<Witness> evaluate(Evaluator &evaluator,
1737+
NormalProtocolConformance *conformance,
1738+
ValueDecl *VD) const;
1739+
1740+
public:
1741+
// Separate caching.
1742+
bool isCached() const { return true; }
1743+
Optional<Witness> getCachedResult() const;
1744+
void cacheResult(Witness value) const;
1745+
};
1746+
17001747
// Allow AnyValue to compare two Type values, even though Type doesn't
17011748
// support ==.
17021749
template<>

0 commit comments

Comments
 (0)