mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[serialization] Add support for ArrayTypes.
...in a quest for completeness. ArrayTypes don't actually work yet (single-dimensional arrays are typed as slices), but when they do the test that is currently XFAIL'd should start passing. With this, all non-transient types can now be serialized and deserialized. Swift SVN r6101
This commit is contained in:
@@ -1356,6 +1356,15 @@ Type ModuleFile::getType(TypeID TID) {
|
||||
break;
|
||||
}
|
||||
|
||||
case decls_block::ARRAY_TYPE: {
|
||||
TypeID baseID;
|
||||
uint64_t size;
|
||||
decls_block::ArrayTypeLayout::readRecord(scratch, baseID, size);
|
||||
|
||||
typeOrOffset = ArrayType::get(getType(baseID), size, ctx);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
// We don't know how to deserialize this kind of type.
|
||||
error();
|
||||
|
||||
@@ -215,6 +215,7 @@ namespace decls_block {
|
||||
BOUND_GENERIC_SUBSTITUTION,
|
||||
POLYMORPHIC_FUNCTION_TYPE,
|
||||
ARRAY_SLICE_TYPE,
|
||||
ARRAY_TYPE,
|
||||
REFERENCE_STORAGE_TYPE,
|
||||
|
||||
TYPE_ALIAS_DECL = 100,
|
||||
@@ -358,6 +359,12 @@ namespace decls_block {
|
||||
TypeIDField // implementation type
|
||||
>;
|
||||
|
||||
using ArrayTypeLayout = BCRecordLayout<
|
||||
ARRAY_TYPE,
|
||||
TypeIDField, // element type
|
||||
BCVBR<8> // size
|
||||
>;
|
||||
|
||||
using ReferenceStorageTypeLayout = BCRecordLayout<
|
||||
REFERENCE_STORAGE_TYPE,
|
||||
BCFixed<1>, // ownership
|
||||
|
||||
@@ -410,6 +410,7 @@ void Serializer::writeBlockInfoBlock() {
|
||||
RECORD(decls_block, BOUND_GENERIC_SUBSTITUTION);
|
||||
RECORD(decls_block, POLYMORPHIC_FUNCTION_TYPE);
|
||||
RECORD(decls_block, ARRAY_SLICE_TYPE);
|
||||
RECORD(decls_block, ARRAY_TYPE);
|
||||
RECORD(decls_block, REFERENCE_STORAGE_TYPE);
|
||||
|
||||
RECORD(decls_block, TYPE_ALIAS_DECL);
|
||||
@@ -1211,8 +1212,16 @@ bool Serializer::writeType(Type ty) {
|
||||
return true;
|
||||
}
|
||||
|
||||
case TypeKind::Array:
|
||||
return false;
|
||||
case TypeKind::Array: {
|
||||
auto arrayTy = cast<ArrayType>(ty.getPointer());
|
||||
|
||||
Type base = arrayTy->getBaseType();
|
||||
|
||||
unsigned abbrCode = DeclTypeAbbrCodes[ArrayTypeLayout::Code];
|
||||
ArrayTypeLayout::emitRecord(Out, ScratchRecord, abbrCode,
|
||||
addTypeRef(base), arrayTy->getSize());
|
||||
return true;
|
||||
}
|
||||
|
||||
case TypeKind::ArraySlice: {
|
||||
auto sliceTy = cast<ArraySliceType>(ty.getPointer());
|
||||
@@ -1309,6 +1318,7 @@ void Serializer::writeAllDeclsAndTypes() {
|
||||
registerDeclTypeAbbr<BoundGenericSubstitutionLayout>();
|
||||
registerDeclTypeAbbr<PolymorphicFunctionTypeLayout>();
|
||||
registerDeclTypeAbbr<ArraySliceTypeLayout>();
|
||||
registerDeclTypeAbbr<ArrayTypeLayout>();
|
||||
|
||||
registerDeclTypeAbbr<TypeAliasLayout>();
|
||||
registerDeclTypeAbbr<StructLayout>();
|
||||
|
||||
5
test/Serialization/Inputs/has_array.swift
Normal file
5
test/Serialization/Inputs/has_array.swift
Normal file
@@ -0,0 +1,5 @@
|
||||
var fourByFour = new Int[4][4]
|
||||
|
||||
// NOTE: Do not add anything else to this test. It is intended to be a bare
|
||||
// minimum test for serializing ArrayType that should start passing as soon as
|
||||
// Parse, Sema, and SILGen can handle ArrayTypes.
|
||||
16
test/Serialization/array.swift
Normal file
16
test/Serialization/array.swift
Normal file
@@ -0,0 +1,16 @@
|
||||
// RUN: rm -rf %t
|
||||
// RUN: mkdir %t
|
||||
// RUN: %swift -emit-module -o %t/has_array.swiftmodule %S/Inputs/has_array.swift
|
||||
// RUN: llvm-bcanalyzer %t/has_array.swiftmodule | FileCheck %s
|
||||
// RUN: %swift -emit-silgen -I=%t %s -o /dev/null
|
||||
// XFAIL: *
|
||||
|
||||
// CHECK-NOT: FALL_BACK_TO_TRANSLATION_UNIT
|
||||
|
||||
import has_array
|
||||
|
||||
fourByFour[3][3] = 42
|
||||
|
||||
// NOTE: Do not add anything else to this test. It is intended to be a bare
|
||||
// minimum test for serializing ArrayType that should start passing as soon as
|
||||
// Parse, Sema, and SILGen can handle ArrayTypes.
|
||||
Reference in New Issue
Block a user