Skip to content

Commit 09d122a

Browse files
authored
Merge pull request #76438 from Azoy/vector
[stdlib] Slab
2 parents 999669c + 7f5f2dc commit 09d122a

Some content is hidden

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

49 files changed

+1342
-74
lines changed

include/swift/AST/Decl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3948,7 +3948,7 @@ class GenericTypeParamDecl final
39483948
/// type parameter.
39493949
///
39503950
/// \code
3951-
/// struct Vector<Element, let N: Int>
3951+
/// struct Slab<let count: Int, Element: ~Copyable>
39523952
/// \endcode
39533953
bool isValue() const {
39543954
return getParamKind() == GenericTypeParamKind::Value;

include/swift/AST/DiagnosticsSema.def

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8165,6 +8165,13 @@ ERROR(availability_value_generic_type_only_version_newer, none,
81658165
ERROR(invalid_value_for_type_same_type,none,
81668166
"cannot constrain type parameter %0 to be integer %1", (Type, Type))
81678167

8168+
//===----------------------------------------------------------------------===//
8169+
// MARK: Slab
8170+
//===----------------------------------------------------------------------===//
8171+
8172+
ERROR(slab_literal_incorrect_count,none,
8173+
"expected %0 elements in slab literal, but got %1", (Type, Type))
8174+
81688175
//===----------------------------------------------------------------------===//
81698176
// MARK: @abi Attribute
81708177
//===----------------------------------------------------------------------===//

include/swift/AST/KnownStdlibTypes.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,6 @@ KNOWN_STDLIB_TYPE_DECL(DecodingError, NominalTypeDecl, 0)
9797

9898
KNOWN_STDLIB_TYPE_DECL(Result, NominalTypeDecl, 2)
9999

100+
KNOWN_STDLIB_TYPE_DECL(Slab, NominalTypeDecl, 2)
101+
100102
#undef KNOWN_STDLIB_TYPE_DECL

include/swift/AST/Types.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7246,7 +7246,7 @@ class GenericTypeParamType : public SubstitutableType,
72467246
/// Returns \c true if this type parameter is declared as a value.
72477247
///
72487248
/// \code
7249-
/// struct Vector<Element, let N: Int>
7249+
/// struct Slab<let count: Int, Element: ~Copyable>
72507250
/// \endcode
72517251
bool isValue() const {
72527252
return ParamKind == GenericTypeParamKind::Value;

include/swift/RemoteInspection/TypeLowering.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ enum class TypeInfoKind : unsigned {
117117
Reference,
118118
Invalid,
119119
Enum,
120+
Array,
120121
};
121122

122123
class TypeInfo {
@@ -350,6 +351,24 @@ class ReferenceTypeInfo : public TypeInfo {
350351
}
351352
};
352353

354+
/// Array based layouts like Builtin.FixedArray<N, T>
355+
class ArrayTypeInfo : public TypeInfo {
356+
const TypeInfo *ElementTI;
357+
358+
public:
359+
explicit ArrayTypeInfo(intptr_t size, const TypeInfo *elementTI);
360+
361+
bool readExtraInhabitantIndex(remote::MemoryReader &reader,
362+
remote::RemoteAddress address,
363+
int *extraInhabitantIndex) const override;
364+
365+
BitMask getSpareBits(TypeConverter &TC, bool &hasAddrOnly) const override;
366+
367+
static bool classof(const TypeInfo *TI) {
368+
return TI->getKind() == TypeInfoKind::Array;
369+
}
370+
};
371+
353372
/// This class owns the memory for all TypeInfo instances that it vends.
354373
class TypeConverter {
355374
TypeRefBuilder &Builder;

include/swift/RemoteInspection/TypeRef.h

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,6 +1095,68 @@ class SILBoxTypeWithLayoutTypeRef final : public TypeRef {
10951095
}
10961096
};
10971097

1098+
class IntegerTypeRef final : public TypeRef {
1099+
intptr_t Value;
1100+
1101+
static TypeRefID Profile(const intptr_t &Value) {
1102+
TypeRefID ID;
1103+
ID.addInteger((uint64_t)Value);
1104+
return ID;
1105+
}
1106+
1107+
public:
1108+
IntegerTypeRef(const intptr_t &Value)
1109+
: TypeRef(TypeRefKind::Integer), Value(Value) {}
1110+
1111+
template <typename Allocator>
1112+
static const IntegerTypeRef *create(Allocator &A, intptr_t Value) {
1113+
FIND_OR_CREATE_TYPEREF(A, IntegerTypeRef, Value);
1114+
}
1115+
1116+
const intptr_t &getValue() const {
1117+
return Value;
1118+
}
1119+
1120+
static bool classof(const TypeRef *TR) {
1121+
return TR->getKind() == TypeRefKind::Integer;
1122+
}
1123+
};
1124+
1125+
class BuiltinFixedArrayTypeRef final : public TypeRef {
1126+
const TypeRef *Size;
1127+
const TypeRef *Element;
1128+
1129+
static TypeRefID Profile(const TypeRef *Size, const TypeRef *Element) {
1130+
TypeRefID ID;
1131+
ID.addPointer(Size);
1132+
ID.addPointer(Element);
1133+
return ID;
1134+
}
1135+
1136+
public:
1137+
BuiltinFixedArrayTypeRef(const TypeRef *Size, const TypeRef *Element)
1138+
: TypeRef(TypeRefKind::BuiltinFixedArray), Size(Size), Element(Element) {}
1139+
1140+
template <typename Allocator>
1141+
static const BuiltinFixedArrayTypeRef *create(Allocator &A,
1142+
const TypeRef *Size,
1143+
const TypeRef *Element) {
1144+
FIND_OR_CREATE_TYPEREF(A, BuiltinFixedArrayTypeRef, Size, Element);
1145+
}
1146+
1147+
const TypeRef *getSizeType() const {
1148+
return Size;
1149+
}
1150+
1151+
const TypeRef *getElementType() const {
1152+
return Element;
1153+
}
1154+
1155+
static bool classof(const TypeRef *TR) {
1156+
return TR->getKind() == TypeRefKind::BuiltinFixedArray;
1157+
}
1158+
};
1159+
10981160
template <typename ImplClass, typename RetTy = void, typename... Args>
10991161
class TypeRefVisitor {
11001162
public:

include/swift/RemoteInspection/TypeRefBuilder.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -929,19 +929,16 @@ class TypeRefBuilder {
929929
}
930930

931931
const TypeRef *createIntegerType(intptr_t value) {
932-
// FIXME: implement
933-
return nullptr;
932+
return IntegerTypeRef::create(*this, value);
934933
}
935934

936935
const TypeRef *createNegativeIntegerType(intptr_t value) {
937-
// FIXME: implement
938-
return nullptr;
936+
return IntegerTypeRef::create(*this, value);
939937
}
940938

941939
const TypeRef *createBuiltinFixedArrayType(const TypeRef *size,
942940
const TypeRef *element) {
943-
// FIXME: implement
944-
return nullptr;
941+
return BuiltinFixedArrayTypeRef::create(*this, size, element);
945942
}
946943

947944
// Construct a bound generic type ref along with the parent type info

include/swift/RemoteInspection/TypeRefs.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,7 @@ TYPEREF(OpaqueArchetype, TypeRef)
3737
#include "swift/AST/ReferenceStorage.def"
3838
TYPEREF(SILBox, TypeRef)
3939
TYPEREF(SILBoxTypeWithLayout, TypeRef)
40+
TYPEREF(Integer, TypeRef)
41+
TYPEREF(BuiltinFixedArray, TypeRef)
4042

4143
#undef TYPEREF

include/swift/Sema/CSFix.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,10 @@ enum class FixKind : uint8_t {
483483
/// sending result, but is passed a function typed parameter without a sending
484484
/// result.
485485
AllowSendingMismatch,
486+
487+
/// Ignore when a 'Slab' literal has mismatched number of elements to the
488+
/// type it's attempting to bind to.
489+
AllowSlabLiteralCountMismatch,
486490
};
487491

488492
class ConstraintFix {
@@ -3837,6 +3841,30 @@ class IgnoreKeyPathSubscriptIndexMismatch final : public ConstraintFix {
38373841
}
38383842
};
38393843

3844+
class AllowSlabLiteralCountMismatch final : public ConstraintFix {
3845+
Type lhsCount, rhsCount;
3846+
3847+
AllowSlabLiteralCountMismatch(ConstraintSystem &cs, Type lhsCount,
3848+
Type rhsCount, ConstraintLocator *locator)
3849+
: ConstraintFix(cs, FixKind::AllowSlabLiteralCountMismatch, locator),
3850+
lhsCount(lhsCount), rhsCount(rhsCount) {}
3851+
3852+
public:
3853+
std::string getName() const override {
3854+
return "allow vector literal count mismatch";
3855+
}
3856+
3857+
bool diagnose(const Solution &solution, bool asNote = false) const override;
3858+
3859+
static AllowSlabLiteralCountMismatch *
3860+
create(ConstraintSystem &cs, Type lhsCount, Type rhsCount,
3861+
ConstraintLocator *locator);
3862+
3863+
static bool classof(const ConstraintFix *fix) {
3864+
return fix->getKind() == FixKind::AllowSlabLiteralCountMismatch;
3865+
}
3866+
};
3867+
38403868
} // end namespace constraints
38413869
} // end namespace swift
38423870

include/swift/SwiftRemoteMirror/SwiftRemoteMirrorTypes.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,9 @@ typedef enum swift_layout_kind {
143143
// swift_reflection_infoForTypeRef().
144144
SWIFT_CLASS_INSTANCE,
145145
SWIFT_CLOSURE_CONTEXT,
146+
147+
// A contiguous list of N Ts, typically for Builtin.FixedArray<N, T>.
148+
SWIFT_ARRAY,
146149
} swift_layout_kind_t;
147150

148151
struct swift_childinfo;

0 commit comments

Comments
 (0)