Skip to content

Commit b860d9e

Browse files
alexmarkovCommit Queue
authored and
Commit Queue
committed
[vm] Support record types and record constants in IL serialization
TEST=language/records/simple/constants_and_field_access_test Issue: #49719 Change-Id: I47b1c300195249d0e07e2adfdeeba0c4e44f5de7 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/261480 Commit-Queue: Alexander Markov <[email protected]> Reviewed-by: Ryan Macnak <[email protected]>
1 parent ae7e351 commit b860d9e

File tree

2 files changed

+36
-10
lines changed

2 files changed

+36
-10
lines changed

runtime/vm/compiler/backend/il_serializer.cc

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1599,13 +1599,26 @@ void FlowGraphSerializer::WriteObjectImpl(const Object& x,
15991599
break;
16001600
}
16011601
case kRecordCid: {
1602-
// TODO(dartbug.com/49719)
1603-
UNIMPLEMENTED();
1602+
ASSERT(x.IsCanonical());
1603+
const auto& record = Record::Cast(x);
1604+
const intptr_t num_fields = record.num_fields();
1605+
Write<intptr_t>(num_fields);
1606+
Write<const Array&>(Array::Handle(Z, record.field_names()));
1607+
auto& field = Object::Handle(Z);
1608+
for (intptr_t i = 0; i < num_fields; ++i) {
1609+
field = record.FieldAt(i);
1610+
Write<const Object&>(field);
1611+
}
16041612
break;
16051613
}
16061614
case kRecordTypeCid: {
1607-
// TODO(dartbug.com/49719)
1608-
UNIMPLEMENTED();
1615+
const auto& rec = RecordType::Cast(x);
1616+
ASSERT(rec.IsFinalized());
1617+
TypeScope type_scope(this, rec.IsRecursive());
1618+
Write<int8_t>(static_cast<int8_t>(rec.nullability()));
1619+
Write<const Array&>(Array::Handle(Z, rec.field_names()));
1620+
Write<const Array&>(Array::Handle(Z, rec.field_types()));
1621+
Write<bool>(type_scope.CanBeCanonicalized());
16091622
break;
16101623
}
16111624
case kSentinelCid:
@@ -1869,14 +1882,25 @@ const Object& FlowGraphDeserializer::ReadObjectImpl(intptr_t cid,
18691882
Symbols::FromLatin1(thread(), latin1, length));
18701883
}
18711884
case kRecordCid: {
1872-
// TODO(dartbug.com/49719)
1873-
UNIMPLEMENTED();
1874-
break;
1885+
const intptr_t num_fields = Read<intptr_t>();
1886+
const auto& field_names = Read<const Array&>();
1887+
auto& record =
1888+
Record::ZoneHandle(Z, Record::New(num_fields, field_names));
1889+
for (intptr_t i = 0; i < num_fields; ++i) {
1890+
record.SetFieldAt(i, Read<const Object&>());
1891+
}
1892+
record ^= record.Canonicalize(thread());
1893+
return record;
18751894
}
18761895
case kRecordTypeCid: {
1877-
// TODO(dartbug.com/49719)
1878-
UNIMPLEMENTED();
1879-
break;
1896+
const Nullability nullability = static_cast<Nullability>(Read<int8_t>());
1897+
const Array& field_names = Read<const Array&>();
1898+
const Array& field_types = Read<const Array&>();
1899+
RecordType& rec = RecordType::ZoneHandle(
1900+
Z, RecordType::New(field_types, field_names, nullability));
1901+
rec.SetIsFinalized();
1902+
rec ^= MaybeCanonicalize(rec, object_index, Read<bool>());
1903+
return rec;
18801904
}
18811905
case kSentinelCid:
18821906
return Read<bool>() ? Object::sentinel() : Object::transition_sentinel();

tests/language/records/simple/constants_and_field_access_test.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
// BSD-style license that can be found in the LICENSE file.
44

55
// SharedOptions=--enable-experiment=records
6+
// VMOptions=
7+
// VMOptions=--test_il_serialization
68

79
import "package:expect/expect.dart";
810

0 commit comments

Comments
 (0)