Test fixes and review feedback

This commit is contained in:
Alejandro Alonso
2025-01-09 15:54:54 -08:00
parent f76d841540
commit cedea94b4c
9 changed files with 58 additions and 42 deletions

View File

@@ -1123,27 +1123,28 @@ public:
};
class BuiltinFixedArrayTypeRef final : public TypeRef {
intptr_t Size;
const TypeRef *Size;
const TypeRef *Element;
static TypeRefID Profile(const intptr_t &Size, const TypeRef *Element) {
static TypeRefID Profile(const TypeRef *Size, const TypeRef *Element) {
TypeRefID ID;
ID.addInteger((uint64_t)Size);
ID.addPointer(Size);
ID.addPointer(Element);
return ID;
}
public:
BuiltinFixedArrayTypeRef(const intptr_t &Size, const TypeRef *Element)
BuiltinFixedArrayTypeRef(const TypeRef *Size, const TypeRef *Element)
: TypeRef(TypeRefKind::BuiltinFixedArray), Size(Size), Element(Element) {}
template <typename Allocator>
static const BuiltinFixedArrayTypeRef *create(Allocator &A, intptr_t Size,
static const BuiltinFixedArrayTypeRef *create(Allocator &A,
const TypeRef *Size,
const TypeRef *Element) {
FIND_OR_CREATE_TYPEREF(A, BuiltinFixedArrayTypeRef, Size, Element);
}
const intptr_t &getSize() const {
const TypeRef *getSizeType() const {
return Size;
}

View File

@@ -938,9 +938,7 @@ public:
const TypeRef *createBuiltinFixedArrayType(const TypeRef *size,
const TypeRef *element) {
auto integer = cast<IntegerTypeRef>(size);
return BuiltinFixedArrayTypeRef::create(*this, integer->getValue(),
element);
return BuiltinFixedArrayTypeRef::create(*this, size, element);
}
// Construct a bound generic type ref along with the parent type info

View File

@@ -958,6 +958,7 @@ void Serializer::writeBlockInfoBlock() {
BLOCK_RECORD(sil_block, SIL_OPEN_PACK_ELEMENT);
BLOCK_RECORD(sil_block, SIL_PACK_ELEMENT_GET);
BLOCK_RECORD(sil_block, SIL_PACK_ELEMENT_SET);
BLOCK_RECORD(sil_block, SIL_TYPE_VALUE);
BLOCK_RECORD(sil_block, SIL_DEBUG_SCOPE);
BLOCK_RECORD(sil_block, SIL_DEBUG_SCOPE_REF);
BLOCK_RECORD(sil_block, SIL_SOURCE_LOC);

View File

@@ -2595,8 +2595,9 @@ public:
const TypeInfo *visitBuiltinFixedArrayTypeRef(const BuiltinFixedArrayTypeRef *BA) {
auto elementTI = visit(BA->getElementType());
auto size = cast<IntegerTypeRef>(BA->getSizeType())->getValue();
return TC.makeTypeInfo<ArrayTypeInfo>(BA->getSize(), elementTI);
return TC.makeTypeInfo<ArrayTypeInfo>(size, elementTI);
}
};

View File

@@ -404,7 +404,7 @@ public:
void visitBuiltinFixedArrayTypeRef(const BuiltinFixedArrayTypeRef *BA) {
printHeader("builtin_fixed_array");
printField("size", std::to_string(BA->getSize()));
printRec(BA->getSizeType());
printRec(BA->getElementType());
stream << ")";
}
@@ -1086,10 +1086,7 @@ public:
Demangle::NodePointer visitBuiltinFixedArrayTypeRef(const BuiltinFixedArrayTypeRef *BA) {
auto ba = Dem.createNode(Node::Kind::BuiltinFixedArray);
auto size = Dem.createNode(Node::Kind::Type);
size->addChild(createInteger(BA->getSize()), Dem);
ba->addChild(size, Dem);
ba->addChild(visit(BA->getSizeType()), Dem);
ba->addChild(visit(BA->getElementType()), Dem);
return ba;
@@ -1327,7 +1324,7 @@ public:
}
const TypeRef *visitBuiltinFixedArrayTypeRef(const BuiltinFixedArrayTypeRef *BA) {
return BuiltinFixedArrayTypeRef::create(Builder, BA->getSize(),
return BuiltinFixedArrayTypeRef::create(Builder, visit(BA->getSizeType()),
visit(BA->getElementType()));
}
};
@@ -1590,7 +1587,7 @@ public:
}
const TypeRef *visitBuiltinFixedArrayTypeRef(const BuiltinFixedArrayTypeRef *BA) {
return BuiltinFixedArrayTypeRef::create(Builder, BA->getSize(),
return BuiltinFixedArrayTypeRef::create(Builder, visit(BA->getSizeType()),
visit(BA->getElementType()));
}
};

View File

@@ -15,7 +15,7 @@
@frozen
public struct Slab<let count: Int, Element: ~Copyable>: ~Copyable {
@usableFromInline
let storage: Builtin.FixedArray<count, Element>
internal let _storage: Builtin.FixedArray<count, Element>
}
@available(SwiftStdlib 6.1, *)
@@ -37,7 +37,7 @@ extension Slab where Element: ~Copyable {
@available(SwiftStdlib 6.1, *)
@_alwaysEmitIntoClient
@_transparent
var address: UnsafePointer<Element> {
internal var _address: UnsafePointer<Element> {
UnsafePointer<Element>(Builtin.unprotectedAddressOfBorrow(self))
}
@@ -45,15 +45,15 @@ extension Slab where Element: ~Copyable {
@available(SwiftStdlib 6.1, *)
@_alwaysEmitIntoClient
@_transparent
var buffer: UnsafeBufferPointer<Element> {
UnsafeBufferPointer<Element>(start: address, count: count)
internal var _buffer: UnsafeBufferPointer<Element> {
UnsafeBufferPointer<Element>(start: _address, count: count)
}
/// Returns a mutable pointer to the first element in the vector.
@available(SwiftStdlib 6.1, *)
@_alwaysEmitIntoClient
@_transparent
var mutableAddress: UnsafeMutablePointer<Element> {
internal var _mutableAddress: UnsafeMutablePointer<Element> {
mutating get {
UnsafeMutablePointer<Element>(Builtin.unprotectedAddressOf(&self))
}
@@ -63,9 +63,9 @@ extension Slab where Element: ~Copyable {
@available(SwiftStdlib 6.1, *)
@_alwaysEmitIntoClient
@_transparent
var mutableBuffer: UnsafeMutableBufferPointer<Element> {
internal var _mutableBuffer: UnsafeMutableBufferPointer<Element> {
mutating get {
UnsafeMutableBufferPointer<Element>(start: mutableAddress, count: count)
UnsafeMutableBufferPointer<Element>(start: _mutableAddress, count: count)
}
}
@@ -74,7 +74,7 @@ extension Slab where Element: ~Copyable {
@available(SwiftStdlib 6.1, *)
@_alwaysEmitIntoClient
@_transparent
static func _initializationBuffer(
internal static func _initializationBuffer(
start: Builtin.RawPointer
) -> UnsafeMutableBufferPointer<Element> {
UnsafeMutableBufferPointer<Element>(
@@ -197,7 +197,7 @@ extension Slab where Element: Copyable {
@available(SwiftStdlib 6.1, *)
extension Slab where Element: ~Copyable {
/// A type representing the collection's elements.
/// The type of the container's elements.
@available(SwiftStdlib 6.1, *)
public typealias Element = Element
@@ -292,7 +292,7 @@ extension Slab where Element: ~Copyable {
@_alwaysEmitIntoClient
@_transparent
public borrowing func index(after i: Int) -> Int {
i + 1
i &+ 1
}
/// Returns the position immediately before the given index.
@@ -304,7 +304,7 @@ extension Slab where Element: ~Copyable {
@_alwaysEmitIntoClient
@_transparent
public borrowing func index(before i: Int) -> Int {
i - 1
i &- 1
}
/// Accesses the element at the specified position.
@@ -334,14 +334,14 @@ extension Slab where Element: ~Copyable {
unsafeAddress {
_precondition(indices.contains(i), "Index out of bounds")
return address + i
return _address + i
}
@_transparent
unsafeMutableAddress {
_precondition(indices.contains(i), "Index out of bounds")
return mutableAddress + i
return _mutableAddress + i
}
}
}
@@ -369,14 +369,17 @@ extension Slab where Element: ~Copyable {
_ i: Int,
_ j: Int
) {
guard i != j, indices.contains(i), indices.contains(j) else {
guard i != j else {
return
}
let ithElement = mutableBuffer.moveElement(from: i)
let jthElement = mutableBuffer.moveElement(from: j)
mutableBuffer.initializeElement(at: i, to: jthElement)
mutableBuffer.initializeElement(at: j, to: ithElement)
_precondition(indices.contains(i), "Index out of bounds")
_precondition(indices.contains(j), "Index out of bounds")
let ithElement = _mutableBuffer.moveElement(from: i)
let jthElement = _mutableBuffer.moveElement(from: j)
_mutableBuffer.initializeElement(at: i, to: jthElement)
_mutableBuffer.initializeElement(at: j, to: ithElement)
}
}
@@ -422,10 +425,10 @@ extension Slab where Element: ~Copyable {
@available(SwiftStdlib 6.1, *)
@_alwaysEmitIntoClient
@_transparent
public borrowing func _withUnsafeBufferPointer<Result, E: Error>(
public borrowing func _withUnsafeBufferPointer<Result: ~Copyable, E: Error>(
_ body: (UnsafeBufferPointer<Element>) throws(E) -> Result
) throws(E) -> Result {
try body(buffer)
try body(_buffer)
}
/// Calls the given closure with a pointer to the vector's mutable contiguous
@@ -471,9 +474,9 @@ extension Slab where Element: ~Copyable {
@available(SwiftStdlib 6.1, *)
@_alwaysEmitIntoClient
@_transparent
public mutating func _withUnsafeMutableBufferPointer<Result, E: Error>(
public mutating func _withUnsafeMutableBufferPointer<Result: ~Copyable, E: Error>(
_ body: (UnsafeMutableBufferPointer<Element>) throws(E) -> Result
) throws(E) -> Result {
try body(mutableBuffer)
try body(_mutableBuffer)
}
}

View File

@@ -1,6 +1,7 @@
// RUN: %target-swift-frontend %s -target %target-cpu-apple-macos14 -emit-ir -g -enable-experimental-feature ValueGenerics -enable-experimental-feature Embedded -wmo -disable-availability-checking -o - | %FileCheck %s
// REQUIR123ES: swift_feature_ValueGenerics
// REQUIRES: swift_feature_Embedded
// REQUIRES: swift_feature_ValueGenerics
// CHECK-DAG: !DICompositeType({{.*}}templateParams: ![[SLAB_PARAMS:.*]], {{.*}}identifier: "$es4SlabVy$0_4main8MySpriteVGD"
// CHECK-DAG: ![[SLAB_PARAMS]] = !{![[COUNT_PARAM:.*]], ![[ELEMENT_PARAM:.*]]}

View File

@@ -1271,10 +1271,12 @@ BD
// CHECK-32-NEXT: (builtin size=48 alignment=8 stride=48 num_extra_inhabitants=0 bitwise_takable=1)
$1_SiBV
// CHECK-64: (builtin_fixed_array size=2
// CHECK-64: (builtin_fixed_array
// CHECK-64-NEXT: (integer value=2)
// CHECK-64-NEXT: (struct Swift.Int))
// CHECK-64-NEXT: (array size=16 alignment=8 stride=16 num_extra_inhabitants=0 bitwise_takable=1)
// CHECK-32: (builtin_fixed_array size=2
// CHECK-32: (builtin_fixed_array
// CHECK-32-NEXT: (integer value=2)
// CHECK-32-NEXT: (struct Swift.Int))
// CHECK-32-NEXT: (array size=8 alignment=4 stride=8 num_extra_inhabitants=0 bitwise_takable=1)

View File

@@ -809,3 +809,15 @@ Added: _$ss13_SwiftifyInfoON
// Eager-lazy Array bridging
Added: _$ss12_ArrayBufferV14associationKeySVvpZMV
// Slab metadata accessor
Added: _$ss4SlabVMa
// Slab nominal type descriptor
Added: _$ss4SlabVMn
// Slab.count property descriptor
Added: _$ss4SlabVsRi__rlE5countSivpZMV
// Slab._storage _read accessor
Added: _$ss4SlabVsRi__rlE8_storagexq_BVvr