mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Merge remote-tracking branch 'origin/master' into master-next
This commit is contained in:
@@ -70,7 +70,6 @@ namespace swift {
|
||||
class LazyContextData;
|
||||
class LazyIterableDeclContextData;
|
||||
class LazyMemberLoader;
|
||||
class LazyResolver;
|
||||
class PatternBindingDecl;
|
||||
class PatternBindingInitializer;
|
||||
class SourceFile;
|
||||
@@ -102,6 +101,7 @@ namespace swift {
|
||||
class SourceManager;
|
||||
class ValueDecl;
|
||||
class DiagnosticEngine;
|
||||
class TypeChecker;
|
||||
class TypeCheckerDebugConsumer;
|
||||
struct RawComment;
|
||||
class DocComment;
|
||||
@@ -404,28 +404,14 @@ public:
|
||||
/// Set a new stats reporter.
|
||||
void setStatsReporter(UnifiedStatsReporter *stats);
|
||||
|
||||
/// Creates a new lazy resolver by passing the ASTContext and the other
|
||||
/// given arguments to a newly-allocated instance of \c ResolverType.
|
||||
///
|
||||
/// \returns true if a new lazy resolver was created, false if there was
|
||||
/// already a lazy resolver registered.
|
||||
template<typename ResolverType, typename ... Args>
|
||||
bool createLazyResolverIfMissing(Args && ...args) {
|
||||
if (getLazyResolver())
|
||||
return false;
|
||||
|
||||
setLazyResolver(new ResolverType(*this, std::forward<Args>(args)...));
|
||||
return true;
|
||||
}
|
||||
|
||||
/// Retrieve the lazy resolver for this context.
|
||||
LazyResolver *getLazyResolver() const;
|
||||
|
||||
private:
|
||||
/// Set the lazy resolver for this context.
|
||||
void setLazyResolver(LazyResolver *resolver);
|
||||
friend class TypeChecker;
|
||||
|
||||
void installGlobalTypeChecker(TypeChecker *TC);
|
||||
public:
|
||||
/// Retrieve the global \c TypeChecker instance associated with this context.
|
||||
TypeChecker *getLegacyGlobalTypeChecker() const;
|
||||
|
||||
/// getIdentifier - Return the uniqued and AST-Context-owned version of the
|
||||
/// specified string.
|
||||
Identifier getIdentifier(StringRef Str) const;
|
||||
|
||||
@@ -26,6 +26,8 @@ SWIFT_TYPEID(Requirement)
|
||||
SWIFT_TYPEID(ResilienceExpansion)
|
||||
SWIFT_TYPEID(Type)
|
||||
SWIFT_TYPEID(TypePair)
|
||||
SWIFT_TYPEID(TypeWitnessAndDecl)
|
||||
SWIFT_TYPEID(Witness)
|
||||
SWIFT_TYPEID_NAMED(ConstructorDecl *, ConstructorDecl)
|
||||
SWIFT_TYPEID_NAMED(CustomAttr *, CustomAttr)
|
||||
SWIFT_TYPEID_NAMED(Decl *, Decl)
|
||||
|
||||
@@ -51,9 +51,11 @@ enum class ResilienceExpansion : unsigned;
|
||||
class Type;
|
||||
class ValueDecl;
|
||||
class VarDecl;
|
||||
class Witness;
|
||||
class TypeAliasDecl;
|
||||
class Type;
|
||||
struct TypePair;
|
||||
struct TypeWitnessAndDecl;
|
||||
enum class AncestryFlags : uint8_t;
|
||||
enum class ImplicitMemberAction : uint8_t;
|
||||
|
||||
|
||||
@@ -7326,6 +7326,11 @@ inline void simple_display(llvm::raw_ostream &out,
|
||||
simple_display(out, static_cast<const Decl *>(decl));
|
||||
}
|
||||
|
||||
inline void simple_display(llvm::raw_ostream &out,
|
||||
const AssociatedTypeDecl *decl) {
|
||||
simple_display(out, static_cast<const Decl *>(decl));
|
||||
}
|
||||
|
||||
/// Display GenericContext.
|
||||
///
|
||||
/// The template keeps this sorted down in the overload set relative to the
|
||||
|
||||
@@ -50,7 +50,6 @@ namespace swift {
|
||||
class ExtensionDecl;
|
||||
class Expr;
|
||||
class GenericParamList;
|
||||
class LazyResolver;
|
||||
class LazyMemberLoader;
|
||||
class GenericSignature;
|
||||
class GenericTypeParamDecl;
|
||||
|
||||
@@ -49,7 +49,6 @@ class DependentMemberType;
|
||||
class GenericParamList;
|
||||
class GenericSignatureBuilder;
|
||||
class GenericTypeParamType;
|
||||
class LazyResolver;
|
||||
class ModuleDecl;
|
||||
class Pattern;
|
||||
class ProtocolConformance;
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This file defines the LazyResolver abstract interface.
|
||||
// This file defines the abstract interfaces for lazily resolving declarations.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
@@ -37,23 +37,6 @@ class TypeDecl;
|
||||
class ValueDecl;
|
||||
class VarDecl;
|
||||
|
||||
/// Abstract interface used to lazily resolve aspects of the AST, such as the
|
||||
/// types of declarations or protocol conformance structures.
|
||||
class LazyResolver {
|
||||
public:
|
||||
virtual ~LazyResolver();
|
||||
|
||||
/// Resolve the type witnesses for the given associated type within the given
|
||||
/// protocol conformance.
|
||||
virtual void resolveTypeWitness(const NormalProtocolConformance *conformance,
|
||||
AssociatedTypeDecl *assocType) = 0;
|
||||
|
||||
/// Resolve the witness for the given non-type requirement within
|
||||
/// the given protocol conformance.
|
||||
virtual void resolveWitness(const NormalProtocolConformance *conformance,
|
||||
ValueDecl *requirement) = 0;
|
||||
};
|
||||
|
||||
class LazyMemberLoader;
|
||||
|
||||
/// Context data for lazy deserialization.
|
||||
|
||||
@@ -58,7 +58,6 @@ namespace swift {
|
||||
class FileUnit;
|
||||
class FuncDecl;
|
||||
class InfixOperatorDecl;
|
||||
class LazyResolver;
|
||||
class LinkLibrary;
|
||||
class ModuleLoader;
|
||||
class NominalTypeDecl;
|
||||
|
||||
@@ -52,7 +52,7 @@ typedef llvm::DenseMap<ValueDecl *, Witness> WitnessMap;
|
||||
|
||||
/// Map from associated type requirements to the corresponding type and
|
||||
/// the type declaration that was used to satisfy the requirement.
|
||||
typedef llvm::DenseMap<AssociatedTypeDecl *, std::pair<Type, TypeDecl*>>
|
||||
typedef llvm::DenseMap<AssociatedTypeDecl *, TypeWitnessAndDecl>
|
||||
TypeWitnessMap;
|
||||
|
||||
/// Describes the kind of protocol conformance structure used to encode
|
||||
@@ -157,7 +157,7 @@ public:
|
||||
|
||||
/// Retrieve the type witness and type decl (if one exists)
|
||||
/// for the given associated type.
|
||||
std::pair<Type, TypeDecl *>
|
||||
TypeWitnessAndDecl
|
||||
getTypeWitnessAndDecl(AssociatedTypeDecl *assocType,
|
||||
SubstOptions options=None) const;
|
||||
|
||||
@@ -182,7 +182,7 @@ public:
|
||||
continue;
|
||||
|
||||
const auto &TWInfo = getTypeWitnessAndDecl(assocTypeReq);
|
||||
if (f(assocTypeReq, TWInfo.first, TWInfo.second))
|
||||
if (f(assocTypeReq, TWInfo.getWitnessType(), TWInfo.getWitnessDecl()))
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -404,6 +404,9 @@ public:
|
||||
class NormalProtocolConformance : public RootProtocolConformance,
|
||||
public llvm::FoldingSetNode
|
||||
{
|
||||
friend class ValueWitnessRequest;
|
||||
friend class TypeWitnessRequest;
|
||||
|
||||
/// The protocol being conformed to and its current state.
|
||||
llvm::PointerIntPair<ProtocolDecl *, 2, ProtocolConformanceState>
|
||||
ProtocolAndState;
|
||||
@@ -588,10 +591,13 @@ public:
|
||||
|
||||
/// Retrieve the type witness and type decl (if one exists)
|
||||
/// for the given associated type.
|
||||
std::pair<Type, TypeDecl *>
|
||||
TypeWitnessAndDecl
|
||||
getTypeWitnessAndDecl(AssociatedTypeDecl *assocType,
|
||||
SubstOptions options=None) const;
|
||||
|
||||
TypeWitnessAndDecl
|
||||
getTypeWitnessUncached(AssociatedTypeDecl *requirement) const;
|
||||
|
||||
/// Determine whether the protocol conformance has a type witness for the
|
||||
/// given associated type.
|
||||
bool hasTypeWitness(AssociatedTypeDecl *assocType) const;
|
||||
@@ -610,6 +616,8 @@ public:
|
||||
/// Retrieve the value witness corresponding to the given requirement.
|
||||
Witness getWitness(ValueDecl *requirement) const;
|
||||
|
||||
Witness getWitnessUncached(ValueDecl *requirement) const;
|
||||
|
||||
/// Determine whether the protocol conformance has a witness for the given
|
||||
/// requirement.
|
||||
bool hasWitness(ValueDecl *requirement) const {
|
||||
@@ -641,7 +649,7 @@ public:
|
||||
/// Determine whether the witness for the given type requirement
|
||||
/// is the default definition.
|
||||
bool usesDefaultDefinition(AssociatedTypeDecl *requirement) const {
|
||||
TypeDecl *witnessDecl = getTypeWitnessAndDecl(requirement).second;
|
||||
TypeDecl *witnessDecl = getTypeWitnessAndDecl(requirement).getWitnessDecl();
|
||||
if (witnessDecl)
|
||||
return witnessDecl->isImplicit();
|
||||
// Conservatively assume it does not.
|
||||
@@ -713,7 +721,7 @@ public:
|
||||
llvm_unreachable("self-conformances never have associated types");
|
||||
}
|
||||
|
||||
std::pair<Type, TypeDecl *>
|
||||
TypeWitnessAndDecl
|
||||
getTypeWitnessAndDecl(AssociatedTypeDecl *assocType,
|
||||
SubstOptions options=None) const {
|
||||
llvm_unreachable("self-conformances never have associated types");
|
||||
@@ -859,7 +867,7 @@ public:
|
||||
|
||||
/// Retrieve the type witness and type decl (if one exists)
|
||||
/// for the given associated type.
|
||||
std::pair<Type, TypeDecl *>
|
||||
TypeWitnessAndDecl
|
||||
getTypeWitnessAndDecl(AssociatedTypeDecl *assocType,
|
||||
SubstOptions options=None) const;
|
||||
|
||||
@@ -971,7 +979,7 @@ public:
|
||||
|
||||
/// Retrieve the type witness and type decl (if one exists)
|
||||
/// for the given associated type.
|
||||
std::pair<Type, TypeDecl *>
|
||||
TypeWitnessAndDecl
|
||||
getTypeWitnessAndDecl(AssociatedTypeDecl *assocType,
|
||||
SubstOptions options=None) const {
|
||||
return InheritedConformance->getTypeWitnessAndDecl(assocType, options);
|
||||
@@ -1015,6 +1023,8 @@ inline bool ProtocolConformance::hasWitness(ValueDecl *requirement) const {
|
||||
return getRootConformance()->hasWitness(requirement);
|
||||
}
|
||||
|
||||
void simple_display(llvm::raw_ostream &out, const ProtocolConformance *conf);
|
||||
|
||||
} // end namespace swift
|
||||
|
||||
#endif // LLVM_SWIFT_AST_PROTOCOLCONFORMANCE_H
|
||||
|
||||
@@ -41,6 +41,8 @@ class RequirementRepr;
|
||||
class SpecializeAttr;
|
||||
class TypeAliasDecl;
|
||||
struct TypeLoc;
|
||||
class Witness;
|
||||
struct TypeWitnessAndDecl;
|
||||
class ValueDecl;
|
||||
enum class OpaqueReadOwnership: uint8_t;
|
||||
class StorageImplInfo;
|
||||
@@ -1697,6 +1699,51 @@ public:
|
||||
bool isCached() const { return true; }
|
||||
};
|
||||
|
||||
class TypeWitnessRequest
|
||||
: public SimpleRequest<TypeWitnessRequest,
|
||||
TypeWitnessAndDecl(NormalProtocolConformance *,
|
||||
AssociatedTypeDecl *),
|
||||
CacheKind::SeparatelyCached> {
|
||||
public:
|
||||
using SimpleRequest::SimpleRequest;
|
||||
|
||||
private:
|
||||
friend SimpleRequest;
|
||||
|
||||
// Evaluation.
|
||||
llvm::Expected<TypeWitnessAndDecl>
|
||||
evaluate(Evaluator &evaluator, NormalProtocolConformance *conformance,
|
||||
AssociatedTypeDecl *ATD) const;
|
||||
|
||||
public:
|
||||
// Separate caching.
|
||||
bool isCached() const { return true; }
|
||||
Optional<TypeWitnessAndDecl> getCachedResult() const;
|
||||
void cacheResult(TypeWitnessAndDecl value) const;
|
||||
};
|
||||
|
||||
class ValueWitnessRequest
|
||||
: public SimpleRequest<ValueWitnessRequest,
|
||||
Witness(NormalProtocolConformance *, ValueDecl *),
|
||||
CacheKind::SeparatelyCached> {
|
||||
public:
|
||||
using SimpleRequest::SimpleRequest;
|
||||
|
||||
private:
|
||||
friend SimpleRequest;
|
||||
|
||||
// Evaluation.
|
||||
llvm::Expected<Witness> evaluate(Evaluator &evaluator,
|
||||
NormalProtocolConformance *conformance,
|
||||
ValueDecl *VD) const;
|
||||
|
||||
public:
|
||||
// Separate caching.
|
||||
bool isCached() const { return true; }
|
||||
Optional<Witness> getCachedResult() const;
|
||||
void cacheResult(Witness value) const;
|
||||
};
|
||||
|
||||
// Allow AnyValue to compare two Type values, even though Type doesn't
|
||||
// support ==.
|
||||
template<>
|
||||
|
||||
@@ -68,6 +68,8 @@ SWIFT_REQUEST(TypeChecker, InheritedTypeRequest,
|
||||
Type(llvm::PointerUnion<TypeDecl *, ExtensionDecl *>, unsigned,
|
||||
TypeResolutionStage),
|
||||
SeparatelyCached, HasNearestLocation)
|
||||
SWIFT_REQUEST(TypeChecker, InheritsSuperclassInitializersRequest,
|
||||
bool(ClassDecl *), SeparatelyCached, NoLocationInfo)
|
||||
SWIFT_REQUEST(TypeChecker, InitKindRequest,
|
||||
CtorInitializerKind(ConstructorDecl *), Cached, NoLocationInfo)
|
||||
SWIFT_REQUEST(TypeChecker, InterfaceTypeRequest,
|
||||
@@ -183,5 +185,10 @@ SWIFT_REQUEST(TypeChecker, HasDefaultInitRequest,
|
||||
bool(NominalTypeDecl *), Cached, NoLocationInfo)
|
||||
SWIFT_REQUEST(TypeChecker, SynthesizeDefaultInitRequest,
|
||||
ConstructorDecl *(NominalTypeDecl *), Cached, NoLocationInfo)
|
||||
SWIFT_REQUEST(TypeChecker, InheritsSuperclassInitializersRequest,
|
||||
bool(ClassDecl *), SeparatelyCached, NoLocationInfo)
|
||||
SWIFT_REQUEST(TypeChecker, TypeWitnessRequest,
|
||||
TypeWitnessAndDecl(NormalProtocolConformance *,
|
||||
AssociatedTypeDecl *),
|
||||
SeparatelyCached, NoLocationInfo)
|
||||
SWIFT_REQUEST(TypeChecker, ValueWitnessRequest,
|
||||
Witness(NormalProtocolConformance *, ValueDecl *),
|
||||
SeparatelyCached, NoLocationInfo)
|
||||
|
||||
@@ -188,6 +188,40 @@ public:
|
||||
void dump(llvm::raw_ostream &out) const;
|
||||
};
|
||||
|
||||
struct TypeWitnessAndDecl {
|
||||
Type witnessType;
|
||||
TypeDecl *witnessDecl = nullptr;
|
||||
|
||||
TypeWitnessAndDecl() = default;
|
||||
TypeWitnessAndDecl(Type ty, TypeDecl *decl)
|
||||
: witnessType(ty), witnessDecl(decl) {}
|
||||
|
||||
public:
|
||||
Type getWitnessType() const {
|
||||
return witnessType;
|
||||
}
|
||||
|
||||
TypeDecl *getWitnessDecl() const {
|
||||
return witnessDecl;
|
||||
}
|
||||
|
||||
friend llvm::hash_code hash_value(const TypeWitnessAndDecl &owner) {
|
||||
return llvm::hash_combine(owner.witnessType,
|
||||
owner.witnessDecl);
|
||||
}
|
||||
|
||||
friend bool operator==(const TypeWitnessAndDecl &lhs,
|
||||
const TypeWitnessAndDecl &rhs) {
|
||||
return lhs.witnessType->isEqual(rhs.witnessType) &&
|
||||
lhs.witnessDecl == rhs.witnessDecl;
|
||||
}
|
||||
|
||||
friend bool operator!=(const TypeWitnessAndDecl &lhs,
|
||||
const TypeWitnessAndDecl &rhs) {
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
};
|
||||
|
||||
} // end namespace swift
|
||||
|
||||
#endif // SWIFT_AST_WITNESS_H
|
||||
|
||||
Reference in New Issue
Block a user