diff --git a/pkg/dart2wasm/lib/constants.dart b/pkg/dart2wasm/lib/constants.dart index 50368ea545d7..7114318dcf6c 100644 --- a/pkg/dart2wasm/lib/constants.dart +++ b/pkg/dart2wasm/lib/constants.dart @@ -243,7 +243,8 @@ class Constants { ...type.named.map((named) => named.type), ]); final names = makeArrayOf(coreTypes.stringNonNullableRawType, - type.named.map((t) => StringConstant(t.name)).toList()); + type.named.map((t) => StringConstant(t.name)).toList(), + mutable: false); return _makeTypeConstant(translator.recordTypeClass, type.nullability, { translator.recordTypeFieldTypesField.fieldReference: fieldTypes, translator.recordTypeNamesField.fieldReference: names, diff --git a/pkg/dart2wasm/lib/record_class_generator.dart b/pkg/dart2wasm/lib/record_class_generator.dart index e4dda8c1af8d..b3be7c51da27 100644 --- a/pkg/dart2wasm/lib/record_class_generator.dart +++ b/pkg/dart2wasm/lib/record_class_generator.dart @@ -30,9 +30,9 @@ import 'records.dart'; /// Record_2_a(this.$1, this.$2, this.a); /// /// @pragma('wasm:entry-point') -/// bool _checkRecordType(WasmArray<_Type> types, WasmArray names) { +/// bool _checkRecordType(WasmArray<_Type> types, ImmutableWasmArray names) { /// if (types.length != 3) return false; -/// if (!identical(names, const WasmArray(["a"]))) return false; +/// if (!identical(names, const ImmutableWasmArray(["a"]))) return false; /// /// if (!_isSubtype($1, types[0])) return false; /// if (!_isSubtype($2, types[1])) return false; @@ -44,7 +44,7 @@ import 'records.dart'; /// @pragma('wasm:entry-point') /// _Type get _masqueradedRecordRuntimeType => /// _RecordType( -/// const WasmArray(["a"]), +/// const ImmutableWasmArray(["a"]), /// WasmArray.literal([ /// _getMasqueradedRuntimeTypeNullable($1), /// _getMasqueradedRuntimeTypeNullable($2), @@ -54,7 +54,7 @@ import 'records.dart'; /// @pragma('wasm:entry-point') /// _Type get _recordRuntimeType => /// _RecordType( -/// const WasmArray(["a"]), +/// const ImmutableWasmArray(["a"]), /// WasmArray.literal([ /// _getActualRuntimeTypeNullable($1), /// _getActualRuntimeTypeNullable($2), @@ -126,6 +126,9 @@ class _RecordClassGenerator { late final Class wasmArrayClass = coreTypes.index.getClass('dart:_wasm', 'WasmArray'); + late final Class immutableWasmArrayClass = + coreTypes.index.getClass('dart:_wasm', 'ImmutableWasmArray'); + late final Procedure wasmArrayRefLength = coreTypes.index.getProcedure('dart:_wasm', 'WasmArrayRef', 'get:length'); @@ -144,11 +147,16 @@ class _RecordClassGenerator { late final Field wasmArrayValueField = coreTypes.index.getField("dart:_wasm", "WasmArray", "_value"); + late final Field immutableWasmArrayValueField = + coreTypes.index.getField("dart:_wasm", "ImmutableWasmArray", "_value"); + late final InterfaceType wasmArrayOfType = InterfaceType( wasmArrayClass, Nullability.nonNullable, [nonNullableTypeType]); - late final InterfaceType wasmArrayOfString = InterfaceType( - wasmArrayClass, Nullability.nonNullable, [nonNullableStringType]); + late final InterfaceType immutableWasmArrayOfString = InterfaceType( + immutableWasmArrayClass, + Nullability.nonNullable, + [nonNullableStringType]); late final InterfaceType runtimeTypeType = InterfaceType(typeRuntimetypeTypeClass, Nullability.nonNullable); @@ -414,7 +422,7 @@ class _RecordClassGenerator { Procedure _generateCheckRecordType(RecordShape shape, List fields) { final typesParameter = VariableDeclaration('types', type: wasmArrayOfType); final namesParameter = - VariableDeclaration('names', type: wasmArrayOfString); + VariableDeclaration('names', type: immutableWasmArrayOfString); final List statements = []; @@ -502,7 +510,7 @@ class _RecordClassGenerator { String name, Procedure target, RecordShape shape, List fields) { final List statements = []; - // const WasmArray(["name1", "name2", ...]) + // const ImmutableWasmArray(["name1", "name2", ...]) final fieldNamesList = ConstantExpression(_fieldNamesConstant(shape)); Expression fieldRuntimeTypeExpr(Field field) => StaticInvocation( @@ -548,10 +556,11 @@ class _RecordClassGenerator { } Constant _fieldNamesConstant(RecordShape shape) { - return InstanceConstant(wasmArrayClass.reference, [ + return InstanceConstant(immutableWasmArrayClass.reference, [ nonNullableStringType ], { - wasmArrayValueField.fieldReference: ListConstant(nonNullableStringType, + immutableWasmArrayValueField.fieldReference: ListConstant( + nonNullableStringType, shape.names.map((name) => StringConstant(name)).toList()) }); } diff --git a/pkg/dart2wasm/lib/types.dart b/pkg/dart2wasm/lib/types.dart index dff41e81e69b..7a1b4d759307 100644 --- a/pkg/dart2wasm/lib/types.dart +++ b/pkg/dart2wasm/lib/types.dart @@ -202,7 +202,8 @@ class Types { final names = translator.constants.makeArrayOf( translator.coreTypes.stringNonNullableRawType, - type.named.map((t) => StringConstant(t.name)).toList()); + type.named.map((t) => StringConstant(t.name)).toList(), + mutable: false); translator.constants.instantiateConstant( codeGen.b, names, recordTypeNamesFieldExpectedType); diff --git a/sdk/lib/_internal/wasm/lib/convert_patch.dart b/sdk/lib/_internal/wasm/lib/convert_patch.dart index fed6f6cc8e60..1c05832f99fd 100644 --- a/sdk/lib/_internal/wasm/lib/convert_patch.dart +++ b/sdk/lib/_internal/wasm/lib/convert_patch.dart @@ -1067,8 +1067,7 @@ mixin _ChunkedJsonParser on _JsonParserWithListener { * } * ``` */ - static const WasmArray _characterAttributes = - WasmArray.literal([ + static const _characterAttributes = ImmutableWasmArray.literal([ 33, 33, 33, 33, 33, 33, 33, 33, 33, 35, 35, 33, 33, 35, 33, 33, 33, 33, // 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 34, 32, 33, 32, // 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, // @@ -1776,7 +1775,7 @@ class _Utf8Decoder { // Non-BMP 'R' = 64 + (2 | flagNonLatin1); // Illegal 'a' = 64 + (1 | flagIllegal); // Illegal 'b' = 64 + (2 | flagIllegal); - static const WasmArray scanTable = WasmArray.literal([ + static const scanTable = ImmutableWasmArray.literal([ // 00-1F 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, diff --git a/sdk/lib/_internal/wasm/lib/int_patch.dart b/sdk/lib/_internal/wasm/lib/int_patch.dart index 6eafbe19c10f..f51504ee67b4 100644 --- a/sdk/lib/_internal/wasm/lib/int_patch.dart +++ b/sdk/lib/_internal/wasm/lib/int_patch.dart @@ -210,7 +210,7 @@ class int { } // For each radix, 2-36, how many digits are guaranteed to fit in an `int`. - static const _PARSE_LIMITS = const WasmArray.literal([ + static const _PARSE_LIMITS = const ImmutableWasmArray.literal([ 0, // unused 0, // unused 63, // radix: 2 diff --git a/sdk/lib/_internal/wasm/lib/record_patch.dart b/sdk/lib/_internal/wasm/lib/record_patch.dart index 2c7c85fa55ee..891fd4c9a319 100644 --- a/sdk/lib/_internal/wasm/lib/record_patch.dart +++ b/sdk/lib/_internal/wasm/lib/record_patch.dart @@ -12,7 +12,8 @@ abstract class Record { _RecordType get _masqueradedRecordRuntimeType; _RecordType get _recordRuntimeType; - bool _checkRecordType(WasmArray<_Type> types, WasmArray names); + bool _checkRecordType( + WasmArray<_Type> types, ImmutableWasmArray names); @pragma("wasm:prefer-inline") static _RecordType _getRecordRuntimeType(Record record) => diff --git a/sdk/lib/_internal/wasm/lib/string.dart b/sdk/lib/_internal/wasm/lib/string.dart index f3a7dac31dad..735eb8d82737 100644 --- a/sdk/lib/_internal/wasm/lib/string.dart +++ b/sdk/lib/_internal/wasm/lib/string.dart @@ -1452,7 +1452,7 @@ final class OneByteString extends StringBase { // Lower-case conversion table for Latin-1 as string. // Upper-case ranges: 0x41-0x5a ('A' - 'Z'), 0xc0-0xd6, 0xd8-0xde. // Conversion to lower case performed by adding 0x20. - static const WasmArray _LC_TABLE = WasmArray.literal([ + static const _LC_TABLE = ImmutableWasmArray.literal([ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, // 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, // 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, // @@ -1484,7 +1484,7 @@ final class OneByteString extends StringBase { // The German "sharp s" \xdf (ß) should be converted into two characters (SS), // and is also marked with 0x00. // Conversion to lower case performed by subtracting 0x20. - static const WasmArray _UC_TABLE = WasmArray.literal([ + static const _UC_TABLE = ImmutableWasmArray.literal([ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, // 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, // 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, // diff --git a/sdk/lib/_internal/wasm/lib/type.dart b/sdk/lib/_internal/wasm/lib/type.dart index 091af887d8f5..4311977d93f1 100644 --- a/sdk/lib/_internal/wasm/lib/type.dart +++ b/sdk/lib/_internal/wasm/lib/type.dart @@ -57,7 +57,7 @@ extension on WasmArray<_NamedParameter> { } } -extension on WasmArray { +extension on ImmutableWasmArray { @pragma("wasm:prefer-inline") bool get isNotEmpty => length != 0; } @@ -544,7 +544,7 @@ class _AbstractRecordType extends _Type { @pragma("wasm:entry-point") class _RecordType extends _Type { - final WasmArray names; + final ImmutableWasmArray names; final WasmArray<_Type> fieldTypes; @pragma("wasm:entry-point")