diff --git a/lib/Serialization/ModuleFile.cpp b/lib/Serialization/ModuleFile.cpp index 92d722cc2b6..bab1602adee 100644 --- a/lib/Serialization/ModuleFile.cpp +++ b/lib/Serialization/ModuleFile.cpp @@ -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(); diff --git a/lib/Serialization/ModuleFormat.h b/lib/Serialization/ModuleFormat.h index 2c1f8f322e7..a582fa20e8f 100644 --- a/lib/Serialization/ModuleFormat.h +++ b/lib/Serialization/ModuleFormat.h @@ -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 diff --git a/lib/Serialization/Serialization.cpp b/lib/Serialization/Serialization.cpp index c5c4d78538d..de8f9b29428 100644 --- a/lib/Serialization/Serialization.cpp +++ b/lib/Serialization/Serialization.cpp @@ -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(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(ty.getPointer()); @@ -1309,6 +1318,7 @@ void Serializer::writeAllDeclsAndTypes() { registerDeclTypeAbbr(); registerDeclTypeAbbr(); registerDeclTypeAbbr(); + registerDeclTypeAbbr(); registerDeclTypeAbbr(); registerDeclTypeAbbr(); diff --git a/test/Serialization/Inputs/has_array.swift b/test/Serialization/Inputs/has_array.swift new file mode 100644 index 00000000000..0ea9f695fb8 --- /dev/null +++ b/test/Serialization/Inputs/has_array.swift @@ -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. diff --git a/test/Serialization/array.swift b/test/Serialization/array.swift new file mode 100644 index 00000000000..da462f0297e --- /dev/null +++ b/test/Serialization/array.swift @@ -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.