Skip to content

Revert "Builtin.FixedArray" #77201

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
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
1 change: 0 additions & 1 deletion docs/ABI/Mangling.rst
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,6 @@ Types
type ::= 'Bp' // Builtin.RawPointer
type ::= 'Bt' // Builtin.SILToken
type ::= type 'Bv' NATURAL '_' // Builtin.Vec<n>x<type>
type ::= type type 'BV' // Builtin.FixedArray<N, T>
type ::= 'Bw' // Builtin.Word
type ::= function-signature 'c' // function type (escaping)
type ::= function-signature 'X' FUNCTION-KIND // special function type
Expand Down
21 changes: 0 additions & 21 deletions include/swift/ABI/Metadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -1665,27 +1665,6 @@ struct TargetMetatypeMetadata : public TargetMetadata<Runtime> {
};
using MetatypeMetadata = TargetMetatypeMetadata<InProcess>;

/// The structure of `Builtin.FixedArray` type metadata.
template <typename Runtime>
struct TargetFixedArrayTypeMetadata : public TargetMetadata<Runtime> {
using StoredPointerDifference = typename Runtime::StoredPointerDifference;

StoredPointerDifference Count;
ConstTargetMetadataPointer<Runtime, swift::TargetMetadata> Element;

// Returns the number of elements for which storage is reserved.
// A type that is instantiated with negative size cannot have values
// instantiated, so is laid out with zero size like an uninhabited type.
StoredPointerDifference getRealizedCount() const {
return Count < 0 ? 0 : Count;
}

static bool classof(const TargetMetadata<Runtime> *metadata) {
return metadata->getKind() == MetadataKind::FixedArray;
}
};
using FixedArrayTypeMetadata = TargetFixedArrayTypeMetadata<InProcess>;

/// The structure of tuple type metadata.
template <typename Runtime>
struct TargetTupleTypeMetadata : public TargetMetadata<Runtime> {
Expand Down
5 changes: 1 addition & 4 deletions include/swift/ABI/MetadataKind.def
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ NOMINALTYPEMETADATAKIND(Class, 0)
NOMINALTYPEMETADATAKIND(Struct, 0 | MetadataKindIsNonHeap)

/// An enum type.
/// If we add reference enums, that needs to go here.
NOMINALTYPEMETADATAKIND(Enum, 1 | MetadataKindIsNonHeap)

/// An optional type.
Expand Down Expand Up @@ -79,10 +80,6 @@ METADATAKIND(ExistentialMetatype, 6 | MetadataKindIsRuntimePrivate | MetadataKin
/// An extended existential type.
METADATAKIND(ExtendedExistential, 7 | MetadataKindIsRuntimePrivate | MetadataKindIsNonHeap)

/// A `Builtin.FixedArray`.
METADATAKIND(FixedArray, 8 | MetadataKindIsRuntimePrivate | MetadataKindIsNonHeap)


/// A heap-allocated local variable using statically-generated metadata.
METADATAKIND(HeapLocalVariable, 0 | MetadataKindIsNonType)

Expand Down
7 changes: 0 additions & 7 deletions include/swift/AST/Builtins.def
Original file line number Diff line number Diff line change
Expand Up @@ -1126,13 +1126,6 @@ BUILTIN_MISC_OPERATION_WITH_SILGEN(DistributedActorAsAnyActor, "distributedActor
/// lowered away at IRGen, no sooner.
BUILTIN_MISC_OPERATION_WITH_SILGEN(AddressOfRawLayout, "addressOfRawLayout", "n", Special)

/// emplace<T>((Builtin.RawPointer) -> Void) -> T
///
/// Passes a pointer to an uninitialized result value to the given function,
/// which must initialize the memory before finishing execution. The value in
/// memory becomes the result of the call.
BUILTIN_SIL_OPERATION(Emplace, "emplace", Special)

/// Builtins for instrumentation added by sanitizers during SILGen.
#ifndef BUILTIN_SANITIZER_OPERATION
#define BUILTIN_SANITIZER_OPERATION(Id, Name, Attrs) BUILTIN(Id, Name, Attrs)
Expand Down
2 changes: 0 additions & 2 deletions include/swift/AST/DiagnosticsSema.def
Original file line number Diff line number Diff line change
Expand Up @@ -4641,8 +4641,6 @@ ERROR(cannot_explicitly_specialize_function,none,
"cannot explicitly specialize %kind0", (ValueDecl *))
ERROR(not_a_generic_type,none,
"cannot specialize non-generic type %0", (Type))
ERROR(invalid_generic_builtin_type,none,
"invalid generic arguments to builtin type %0", (Type))
ERROR(not_a_generic_macro,none,
"cannot specialize a non-generic external macro %0", (const ValueDecl *))
ERROR(protocol_declares_unknown_primary_assoc_type,none,
Expand Down
13 changes: 0 additions & 13 deletions include/swift/AST/TypeDifferenceVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,19 +129,6 @@ class CanTypeDifferenceVisitor : public CanTypePairVisitor<Impl, bool> {
return asImpl().visitDifferentTypeStructure(type1, type2);
return asImpl().visit(type1.getElementType(), type2.getElementType());
}

bool visitBuiltinUnboundGenericType(CanBuiltinUnboundGenericType type1,
CanBuiltinUnboundGenericType type2) {
return asImpl().visitDifferentTypeStructure(type1, type2);
}

bool visitBuiltinFixedArrayType(CanBuiltinFixedArrayType type1,
CanBuiltinFixedArrayType type2) {
if (asImpl().visit(type1->getSize(), type2->getSize())) {
return true;
}
return asImpl().visit(type1->getElementType(), type2->getElementType());
}

bool visitPackType(CanPackType type1, CanPackType type2) {
return visitComponentArray(type1, type2,
Expand Down
2 changes: 0 additions & 2 deletions include/swift/AST/TypeMatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,6 @@ class TypeMatcher {
TRIVIAL_CASE(BuiltinIntegerType)
TRIVIAL_CASE(BuiltinFloatType)
TRIVIAL_CASE(BuiltinVectorType)
TRIVIAL_CASE(BuiltinUnboundGenericType)
TRIVIAL_CASE(BuiltinFixedArrayType)
TRIVIAL_CASE(IntegerType)
#define SINGLETON_TYPE(SHORT_ID, ID) TRIVIAL_CASE(ID##Type)
#include "swift/AST/TypeNodes.def"
Expand Down
50 changes: 15 additions & 35 deletions include/swift/AST/TypeNodes.def
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,6 @@
/// This type is a builtin type. The default behavior is
/// ALWAYS_CANONICAL_TYPE(id, parent).

/// BUILTIN_CONCRETE_TYPE(id, parent)
/// This type is a builtin type without generic parameters. The default
/// behavior is BUILTIN_TYPE(id, parent).

/// BUILTIN_GENERIC_TYPE(id, parent)
/// This type is a builtin type with generic parameters. The default
/// behavior is BUILTIN_TYPE(id, parent).

/// SUGARED_TYPE(id, parent)
/// This type is never canonical. It provides an efficient accessor,
/// getSinglyDesugaredType(), which removes one level of sugar. This
Expand Down Expand Up @@ -80,14 +72,6 @@
#define BUILTIN_TYPE(id, parent) ALWAYS_CANONICAL_TYPE(id, parent)
#endif

#ifndef BUILTIN_CONCRETE_TYPE
#define BUILTIN_CONCRETE_TYPE(id, parent) BUILTIN_TYPE(id, parent)
#endif

#ifndef BUILTIN_GENERIC_TYPE
#define BUILTIN_GENERIC_TYPE(id, parent) BUILTIN_TYPE(id, parent)
#endif

#ifndef SUGARED_TYPE
#define SUGARED_TYPE(id, parent) TYPE(id, parent)
#endif
Expand Down Expand Up @@ -127,24 +111,22 @@ UNCHECKED_TYPE(Unresolved, Type)
UNCHECKED_TYPE(Placeholder, Type)
ABSTRACT_TYPE(Builtin, Type)
ABSTRACT_TYPE(AnyBuiltinInteger, BuiltinType)
BUILTIN_CONCRETE_TYPE(BuiltinInteger, AnyBuiltinIntegerType)
BUILTIN_CONCRETE_TYPE(BuiltinIntegerLiteral, AnyBuiltinIntegerType)
BUILTIN_TYPE(BuiltinInteger, AnyBuiltinIntegerType)
BUILTIN_TYPE(BuiltinIntegerLiteral, AnyBuiltinIntegerType)
TYPE_RANGE(AnyBuiltinInteger, BuiltinInteger, BuiltinIntegerLiteral)
BUILTIN_CONCRETE_TYPE(BuiltinExecutor, BuiltinType)
BUILTIN_CONCRETE_TYPE(BuiltinFloat, BuiltinType)
BUILTIN_CONCRETE_TYPE(BuiltinJob, BuiltinType)
BUILTIN_CONCRETE_TYPE(BuiltinPackIndex, BuiltinType)
BUILTIN_CONCRETE_TYPE(BuiltinRawPointer, BuiltinType)
BUILTIN_CONCRETE_TYPE(BuiltinRawUnsafeContinuation, BuiltinType)
BUILTIN_CONCRETE_TYPE(BuiltinNativeObject, BuiltinType)
BUILTIN_CONCRETE_TYPE(BuiltinBridgeObject, BuiltinType)
BUILTIN_CONCRETE_TYPE(BuiltinUnsafeValueBuffer, BuiltinType)
BUILTIN_CONCRETE_TYPE(BuiltinDefaultActorStorage, BuiltinType)
BUILTIN_CONCRETE_TYPE(BuiltinNonDefaultDistributedActorStorage, BuiltinType)
BUILTIN_CONCRETE_TYPE(BuiltinVector, BuiltinType)
BUILTIN_GENERIC_TYPE(BuiltinFixedArray, BuiltinType)
BUILTIN_CONCRETE_TYPE(BuiltinUnboundGeneric, BuiltinType)
TYPE_RANGE(Builtin, BuiltinInteger, BuiltinUnboundGeneric)
BUILTIN_TYPE(BuiltinExecutor, BuiltinType)
BUILTIN_TYPE(BuiltinFloat, BuiltinType)
BUILTIN_TYPE(BuiltinJob, BuiltinType)
BUILTIN_TYPE(BuiltinPackIndex, BuiltinType)
BUILTIN_TYPE(BuiltinRawPointer, BuiltinType)
BUILTIN_TYPE(BuiltinRawUnsafeContinuation, BuiltinType)
BUILTIN_TYPE(BuiltinNativeObject, BuiltinType)
BUILTIN_TYPE(BuiltinBridgeObject, BuiltinType)
BUILTIN_TYPE(BuiltinUnsafeValueBuffer, BuiltinType)
BUILTIN_TYPE(BuiltinDefaultActorStorage, BuiltinType)
BUILTIN_TYPE(BuiltinNonDefaultDistributedActorStorage, BuiltinType)
BUILTIN_TYPE(BuiltinVector, BuiltinType)
TYPE_RANGE(Builtin, BuiltinInteger, BuiltinVector)
TYPE(Tuple, Type)
ABSTRACT_TYPE(ReferenceStorage, Type)
#define REF_STORAGE(Name, ...) \
Expand Down Expand Up @@ -246,8 +228,6 @@ SINGLETON_TYPE(SILToken, SILToken)
#undef UNCHECKED_TYPE
#undef ARTIFICIAL_TYPE
#undef SUGARED_TYPE
#undef BUILTIN_GENERIC_TYPE
#undef BUILTIN_CONCRETE_TYPE
#undef BUILTIN_TYPE
#undef ALWAYS_CANONICAL_TYPE
#undef ALWAYS_CANONICAL_ARTIFICIAL_TYPE
Expand Down
27 changes: 1 addition & 26 deletions include/swift/AST/TypeTransform.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class TypeTransform {
TypeBase *base = t.getPointer();

switch (base->getKind()) {
#define BUILTIN_CONCRETE_TYPE(Id, Parent) \
#define BUILTIN_TYPE(Id, Parent) \
case TypeKind::Id:
#define TYPE(Id, Parent)
#include "swift/AST/TypeNodes.def"
Expand All @@ -120,31 +120,6 @@ case TypeKind::Id:
case TypeKind::Integer:
return t;

case TypeKind::BuiltinFixedArray: {
auto bfaTy = cast<BuiltinFixedArrayType>(base);

Type transSize = doIt(bfaTy->getSize(),
TypePosition::Invariant);
if (!transSize) {
return Type();
}

Type transElement = doIt(bfaTy->getElementType(),
TypePosition::Invariant);
if (!transElement) {
return Type();
}

CanType canTransSize = transSize->getCanonicalType();
CanType canTransElement = transElement->getCanonicalType();
if (canTransSize != bfaTy->getSize()
|| canTransElement != bfaTy->getElementType()) {
return BuiltinFixedArrayType::get(canTransSize, canTransElement);
}

return bfaTy;
}

case TypeKind::PrimaryArchetype:
case TypeKind::PackArchetype: {
auto *archetype = cast<ArchetypeType>(base);
Expand Down
116 changes: 2 additions & 114 deletions include/swift/AST/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ class ArgumentList;
class AssociatedTypeDecl;
class ASTContext;
enum BufferPointerTypeKind : unsigned;
struct BuiltinNameStringLiteral;
class BuiltinTupleDecl;
class ClassDecl;
class ClangModuleLoader;
Expand Down Expand Up @@ -1509,9 +1508,6 @@ class alignas(1 << TypeAlignInBits) TypeBase
/// return `None`.
std::optional<TangentSpace>
getAutoDiffTangentSpace(LookupConformanceFn lookupConformance);

/// Return the kind of generic parameter that this type can be matched to.
GenericTypeParamKind getMatchingParamKind();
};

/// AnyGenericType - This abstract class helps types ensure that fields
Expand Down Expand Up @@ -1652,9 +1648,8 @@ DEFINE_EMPTY_CAN_TYPE_WRAPPER(UnresolvedType, Type)
/// BuiltinType - An abstract class for all the builtin types.
class BuiltinType : public TypeBase {
protected:
BuiltinType(TypeKind kind, const ASTContext &canTypeCtx,
RecursiveTypeProperties properties = {})
: TypeBase(kind, &canTypeCtx, properties) {}
BuiltinType(TypeKind kind, const ASTContext &canTypeCtx)
: TypeBase(kind, &canTypeCtx, RecursiveTypeProperties()) {}
public:
static bool classof(const TypeBase *T) {
return T->getKind() >= TypeKind::First_BuiltinType &&
Expand All @@ -1677,113 +1672,6 @@ class BuiltinType : public TypeBase {
};
DEFINE_EMPTY_CAN_TYPE_WRAPPER(BuiltinType, Type)

/// BuiltinUnboundGenericType - the base declaration of a generic builtin type
/// that has not yet had generic parameters applied.
///
/// Referring to an unbound generic type by itself is invalid, but this
/// representation is used as an intermediate during type resolution when
/// resolving a type reference such as `Builtin.Int<31>`. Applying
/// the generic parameters produces the actual builtin type based on the
/// kind of the base.
class BuiltinUnboundGenericType : public BuiltinType {
friend class ASTContext;
TypeKind BoundGenericTypeKind;

BuiltinUnboundGenericType(const ASTContext &C,
TypeKind genericTypeKind)
: BuiltinType(TypeKind::BuiltinUnboundGeneric, C),
BoundGenericTypeKind(genericTypeKind)
{}

public:
static bool classof(const TypeBase *T) {
return T->getKind() == TypeKind::BuiltinUnboundGeneric;
}

/// Produce the unqualified name of the type.
BuiltinNameStringLiteral getBuiltinTypeName() const;
StringRef getBuiltinTypeNameString() const;

static BuiltinUnboundGenericType *get(TypeKind genericTypeKind,
const ASTContext &C);

/// Get the generic signature with which to substitute this type.
GenericSignature getGenericSignature() const;

/// Get the type that results from binding the generic parameters of this
/// builtin to the given substitutions.
///
/// Produces an ErrorType if the substitution is invalid.
Type getBound(SubstitutionMap subs) const;
};
DEFINE_EMPTY_CAN_TYPE_WRAPPER(BuiltinUnboundGenericType, BuiltinType)

/// BuiltinFixedArrayType - The builtin type representing N values stored
/// inline contiguously.
///
/// All elements of a value of this type must be fully initialized any time the
/// value may be copied, moved, or destroyed.
class BuiltinFixedArrayType : public BuiltinType, public llvm::FoldingSetNode {
friend class ASTContext;

CanType Size;
CanType ElementType;

static RecursiveTypeProperties
getRecursiveTypeProperties(CanType Size, CanType Element) {
RecursiveTypeProperties properties;
properties |= Size->getRecursiveProperties();
properties |= Element->getRecursiveProperties();
return properties;
}

BuiltinFixedArrayType(CanType Size,
CanType ElementType)
: BuiltinType(TypeKind::BuiltinFixedArray, ElementType->getASTContext(),
getRecursiveTypeProperties(Size, ElementType)),
Size(Size),
ElementType(ElementType)
{}

public:
/// Arrays with more elements than this are always treated as in-memory values.
///
/// (4096 is the hardcoded limit above which we refuse to import C arrays
/// as tuples. From first principles, a much lower threshold would probably
/// make sense, but we don't want to break the type lowering of C types
/// as they appear in existing Swift code.)
static constexpr const uint64_t MaximumLoadableSize = 4096;

static bool classof(const TypeBase *T) {
return T->getKind() == TypeKind::BuiltinFixedArray;
}

static BuiltinFixedArrayType *get(CanType Size,
CanType ElementType);

/// Get the integer generic parameter representing the number of elements.
CanType getSize() const { return Size; }

/// Get the fixed integer number of elements if known and zero or greater.
std::optional<uint64_t> getFixedInhabitedSize() const;

/// True if the type is statically negative-sized (and therefore uninhabited).
bool isFixedNegativeSize() const;

/// Get the element type.
CanType getElementType() const { return ElementType; }

void Profile(llvm::FoldingSetNodeID &ID) const {
Profile(ID, getSize(), getElementType());
}
static void Profile(llvm::FoldingSetNodeID &ID,
CanType Size, CanType ElementType) {
ID.AddPointer(Size.getPointer());
ID.AddPointer(ElementType.getPointer());
}
};
DEFINE_EMPTY_CAN_TYPE_WRAPPER(BuiltinFixedArrayType, BuiltinType)

/// BuiltinRawPointerType - The builtin raw (and dangling) pointer type. This
/// pointer is completely unmanaged and is equivalent to i8* in LLVM IR.
class BuiltinRawPointerType : public BuiltinType {
Expand Down
1 change: 0 additions & 1 deletion include/swift/Demangling/DemangleNodes.def
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ NODE(BoundGenericTypeAlias)
NODE(BoundGenericFunction)
NODE(BuiltinTypeName)
NODE(BuiltinTupleType)
NODE(BuiltinFixedArray)
NODE(CFunctionPointer)
NODE(ClangType)
CONTEXT_NODE(Class)
Expand Down
8 changes: 0 additions & 8 deletions include/swift/Runtime/Metadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -573,14 +573,6 @@ MetadataResponse
swift_getForeignTypeMetadata(MetadataRequest request,
ForeignTypeMetadata *nonUnique);

/// Fetch a metadata record representing a `Builtin.FixedArray`
/// of a given count and element type.
SWIFT_RUNTIME_EXPORT SWIFT_CC(swift)
MetadataResponse
swift_getFixedArrayTypeMetadata(MetadataRequest request,
intptr_t count,
const Metadata *element);

/// Fetch a uniqued metadata for a tuple type.
///
/// The labels argument is null if and only if there are no element
Expand Down
Loading