Skip to content

Commit 82743d7

Browse files
committed
Add TypeDecoding for Builtin.FixedArray
1 parent 32259c1 commit 82743d7

File tree

6 files changed

+58
-0
lines changed

6 files changed

+58
-0
lines changed

include/swift/AST/ASTDemangler.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,8 @@ class ASTBuilder {
250250

251251
Type createNegativeIntegerType(intptr_t value);
252252

253+
Type createBuiltinFixedArrayType(Type size, Type element);
254+
253255
BuiltGenericSignature
254256
createGenericSignature(ArrayRef<BuiltType> params,
255257
ArrayRef<BuiltRequirement> requirements);

include/swift/Demangling/TypeDecoder.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1530,6 +1530,23 @@ class TypeDecoder {
15301530
return Builder.createNegativeIntegerType((intptr_t)Node->getIndex());
15311531
}
15321532

1533+
case NodeKind::BuiltinFixedArray: {
1534+
if (Node->getNumChildren() < 2)
1535+
return MAKE_NODE_TYPE_ERROR(Node,
1536+
"fewer children (%zu) than required (2)",
1537+
Node->getNumChildren());
1538+
1539+
auto size = decodeMangledType(Node->getChild(0), depth + 1);
1540+
if (size.isError())
1541+
return size;
1542+
1543+
auto element = decodeMangledType(Node->getChild(1), depth + 1);
1544+
if (element.isError())
1545+
return element;
1546+
1547+
return Builder.createBuiltinFixedArrayType(size.getType(), element.getType());
1548+
}
1549+
15331550
// TODO: Handle OpaqueReturnType, when we're in the middle of reconstructing
15341551
// the defining decl
15351552
default:

include/swift/RemoteInspection/TypeRefBuilder.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -933,6 +933,12 @@ class TypeRefBuilder {
933933
return nullptr;
934934
}
935935

936+
const TypeRef *createBuiltinFixedArrayType(const TypeRef *size,
937+
const TypeRef *element) {
938+
// FIXME: implement
939+
return nullptr;
940+
}
941+
936942
// Construct a bound generic type ref along with the parent type info
937943
// The parent list contains every parent type with at least 1 generic
938944
// type parameter.

lib/AST/ASTDemangler.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,6 +1065,11 @@ Type ASTBuilder::createNegativeIntegerType(intptr_t value) {
10651065
return IntegerType::get(std::to_string(value), /*isNegative*/ true, Ctx);
10661066
}
10671067

1068+
Type ASTBuilder::createBuiltinFixedArrayType(Type size, Type element) {
1069+
return BuiltinFixedArrayType::get(size->getCanonicalType(),
1070+
element->getCanonicalType());
1071+
}
1072+
10681073
GenericSignature
10691074
ASTBuilder::createGenericSignature(ArrayRef<BuiltType> builtParams,
10701075
ArrayRef<BuiltRequirement> requirements) {

stdlib/public/runtime/MetadataLookup.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2454,6 +2454,13 @@ class DecodedMetadataBuilder {
24542454
TypeLookupErrorOr<BuiltType> createNegativeIntegerType(intptr_t value) {
24552455
return BuiltType(value);
24562456
}
2457+
2458+
TypeLookupErrorOr<BuiltType> createBuiltinFixedArrayType(BuiltType size,
2459+
BuiltType element) {
2460+
return BuiltType(swift_getFixedArrayTypeMetadata(MetadataState::Abstract,
2461+
size.getValue(),
2462+
element.getMetadata()));
2463+
}
24572464
};
24582465

24592466
}

test/DebugInfo/value-generics.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// RUN: %target-swift-frontend %s -emit-ir -g -enable-builtin-module -enable-experimental-feature ValueGenerics -disable-experimental-parser-round-trip -disable-availability-checking -o - | %FileCheck %s
2+
3+
import Builtin
4+
5+
struct Vector<let N: Int, Element: ~Copyable>: ~Copyable {
6+
let storage: Builtin.FixedArray<N, Element>
7+
}
8+
9+
extension Vector: Copyable where Element: Copyable {}
10+
11+
// CHECK-DAG: !DICompositeType({{.*}}name: "Builtin.FixedArray", {{.*}}identifier: "$sxq_BVD"
12+
func genericBA<let N: Int, Element>(_: Builtin.FixedArray<N, Element>) {}
13+
14+
// CHECK-DAG: !DICompositeType({{.*}}name: "$s4main6VectorVyxq_GD"
15+
func genericV<let N: Int, Element>(_: Vector<N, Element>) {}
16+
17+
// CHECK-DAG: !DICompositeType({{.*}}name: "Builtin.FixedArray", {{.*}}identifier: "$s$4SiBVD"
18+
func concreteBA(_: Builtin.FixedArray<4, Int>) {}
19+
20+
// CHECK-DAG: !DICompositeType({{.*}}name: "$s4main6VectorVy$2SiGD"
21+
func concreteV(_: Vector<2, Int>) {}

0 commit comments

Comments
 (0)