Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions include/swift/AST/ASTContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,9 @@ class ASTContext final {
/// Retrieve the type Swift.AnyObject as a constraint.
CanType getAnyObjectConstraint() const;

/// Retrieve the type Swift.Reflectable as a constraint.
CanType getReflectableConstraint() const;

/// Retrieve the type Swift.AnyObject as an existential type.
CanType getAnyObjectType() const;

Expand Down
2 changes: 2 additions & 0 deletions include/swift/AST/Decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -5143,6 +5143,8 @@ class ProtocolDecl final : public NominalTypeDecl {
/// True if this protocol can only be conformed to by class types.
bool requiresClass() const;

bool inheritsReflectable() const;

/// Determine whether an existential conforming to this protocol can be
/// matched with a generic type parameter constrained to this protocol.
/// This is only permitted if there is nothing "non-trivial" that we
Expand Down
8 changes: 8 additions & 0 deletions include/swift/AST/DiagnosticsSema.def
Original file line number Diff line number Diff line change
Expand Up @@ -7708,5 +7708,13 @@ ERROR(referencebindings_binding_must_be_to_lvalue,none,
ERROR(result_depends_on_no_result,none,
"Incorrect use of %0 with no result", (StringRef))

//------------------------------------------------------------------------------
// MARK: Reflectable
//------------------------------------------------------------------------------

ERROR(type_does_not_conform_reflectable_decl_owner,none,
"%kind0 requires that %1 be a Reflectable type",
(const ValueDecl *, Type, Type))

#define UNDEFINE_DIAGNOSTIC_MACROS
#include "DefineDiagnosticMacros.h"
6 changes: 6 additions & 0 deletions include/swift/AST/ExistentialLayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ struct ExistentialLayout {

ExistentialLayout() {
hasExplicitAnyObject = false;
hasExplicitReflectable = false;
hasInverseCopyable = false;
containsNonObjCProtocol = false;
containsParameterized = false;
Expand All @@ -47,6 +48,9 @@ struct ExistentialLayout {
/// Whether the existential contains an explicit '& AnyObject' constraint.
bool hasExplicitAnyObject : 1;

/// Whether the existential contains an explicit '& Reflectable' constraint.
bool hasExplicitReflectable : 1;

/// Whether the existential contains an explicit '& ~Copyable' constraint.
bool hasInverseCopyable : 1;

Expand All @@ -71,6 +75,8 @@ struct ExistentialLayout {

bool isAnyObject() const;

bool isReflectable() const;

bool isObjC() const {
// FIXME: Does the superclass have to be @objc?
return ((explicitSuperclass ||
Expand Down
2 changes: 1 addition & 1 deletion include/swift/AST/IRGenOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ enum class SwiftAsyncFramePointerKind : unsigned {
};

enum class ReflectionMetadataMode : unsigned {
None, ///< Don't emit reflection metadata at all.
OptIn, ///< Reflection is emitted only for Reflectable nominal types.
DebuggerOnly, ///< Emit reflection metadata for the debugger, don't link them
/// into runtime metadata and don't force them to stay alive.
Runtime, ///< Make reflection metadata fully available.
Expand Down
1 change: 1 addition & 0 deletions include/swift/AST/KnownIdentifiers.def
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ IDENTIFIER_WITH_NAME(RefCountedObjectLayout, "_RefCountedObject")
IDENTIFIER_WITH_NAME(NativeRefCountedObjectLayout, "_NativeRefCountedObject")
IDENTIFIER_WITH_NAME(ClassLayout, "_Class")
IDENTIFIER_WITH_NAME(NativeClassLayout, "_NativeClass")
IDENTIFIER_WITH_NAME(Reflectable, "Reflectable")

// Operators
IDENTIFIER_WITH_NAME(MatchOperator, "~=")
Expand Down
7 changes: 7 additions & 0 deletions include/swift/AST/LayoutConstraint.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ class LayoutConstraintInfo
return isClass(Kind);
}

bool isReflectable() const {
return isReflectable(Kind);
}

bool isNativeClass() const {
return isNativeClass(Kind);
}
Expand Down Expand Up @@ -194,6 +198,8 @@ class LayoutConstraintInfo

static bool isClass(LayoutConstraintKind Kind);

static bool isReflectable(LayoutConstraintKind Kind);

static bool isNativeClass(LayoutConstraintKind Kind);

static bool isRefCounted(LayoutConstraintKind Kind);
Expand All @@ -217,6 +223,7 @@ class LayoutConstraintInfo
static LayoutConstraintInfo ClassConstraintInfo;
static LayoutConstraintInfo NativeClassConstraintInfo;
static LayoutConstraintInfo TrivialConstraintInfo;
static LayoutConstraintInfo ReflectableConstraintInfo;
};

/// A wrapper class containing a reference to the actual LayoutConstraintInfo
Expand Down
4 changes: 3 additions & 1 deletion include/swift/AST/LayoutConstraintKind.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ enum class LayoutConstraintKind : uint8_t {
RefCountedObject,
// It is a layout constraint representing a native reference counted object.
NativeRefCountedObject,
LastLayout = NativeRefCountedObject,
// It is a layout constraint representing type that has reflection metadata available at runtime.
Reflectable,
LastLayout = Reflectable,
};

#endif
4 changes: 2 additions & 2 deletions include/swift/AST/NameLookup.h
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ struct InheritedNominalEntry : Located<NominalTypeDecl *> {
void getDirectlyInheritedNominalTypeDecls(
llvm::PointerUnion<const TypeDecl *, const ExtensionDecl *> decl,
unsigned i, llvm::SmallVectorImpl<InheritedNominalEntry> &result,
bool &anyObject);
bool &anyObject, bool &reflectable);

/// Retrieve the set of nominal type declarations that are directly
/// "inherited" by the given declaration, looking through typealiases
Expand All @@ -608,7 +608,7 @@ void getDirectlyInheritedNominalTypeDecls(
/// If we come across the AnyObject type, set \c anyObject true.
SmallVector<InheritedNominalEntry, 4> getDirectlyInheritedNominalTypeDecls(
llvm::PointerUnion<const TypeDecl *, const ExtensionDecl *> decl,
bool &anyObject);
bool &anyObject, bool &reflectable);

/// Retrieve the set of nominal type declarations that appear as the
/// constraint type of any "Self" constraints in the where clause of the
Expand Down
18 changes: 18 additions & 0 deletions include/swift/AST/TypeCheckRequests.h
Original file line number Diff line number Diff line change
Expand Up @@ -4644,6 +4644,24 @@ class UniqueUnderlyingTypeSubstitutionsRequest
void cacheResult(llvm::Optional<SubstitutionMap>) const;
};

/// Determine if protocol inherits Reflectable.
class InheritsReflectableProtocolRequest
: public SimpleRequest<InheritsReflectableProtocolRequest,
bool(ProtocolDecl *),
RequestFlags::Cached> {
public:
using SimpleRequest::SimpleRequest;

private:
friend SimpleRequest;

bool evaluate(Evaluator &evaluator, ProtocolDecl *decl) const;

public:
// Separate caching.
bool isCached() const { return true; }
};

#define SWIFT_TYPEID_ZONE TypeChecker
#define SWIFT_TYPEID_HEADER "swift/AST/TypeCheckerTypeIDZone.def"
#include "swift/Basic/DefineTypeIDZone.h"
Expand Down
2 changes: 2 additions & 0 deletions include/swift/AST/TypeCheckerTypeIDZone.def
Original file line number Diff line number Diff line change
Expand Up @@ -530,3 +530,5 @@ SWIFT_REQUEST(TypeChecker, SemanticDeclAttrsRequest,
SWIFT_REQUEST(TypeChecker, UniqueUnderlyingTypeSubstitutionsRequest,
llvm::Optional<SubstitutionMap>(const Decl *),
SeparatelyCached, NoLocationInfo)
SWIFT_REQUEST(TypeChecker, InheritsReflectableProtocolRequest, bool(ProtocolDecl *),
Cached, NoLocationInfo)
Loading