[dart2wasm] Make int and double fields immutable

Make the `value` fields of `BoxedInt` and `BoxedDouble` `final`, to
generate immutable Wasm fields for them.

Immutable fields can potentially generate better code, as loads from the
same object will always generate the same value.

To allow making the `value` fields `final`, add a constructor.

To allow adding a constructor, "implement` base classes instead of
extending them. With `extends` the front-end wants us to call the
superclass constructors, even though they don't have any constructors.

This CL does not do the same to `BoxedBool`. We did that in a previous
iteration of the CL[1], but it caused regressions in post-TFA kernels.

[1]: https://dart-review.googlesource.com/c/sdk/+/393320

Change-Id: Ib44c25d09dcd84d999aa1d92dc9c38632454e443
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/393842
Commit-Queue: Ömer Ağacan <omersa@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
This commit is contained in:
Ömer Sinan Ağacan
2024-11-06 13:06:06 +00:00
committed by Commit Queue
parent c30f961f13
commit 76717f2930
3 changed files with 11 additions and 9 deletions
+3 -1
View File
@@ -311,7 +311,9 @@ class ClassInfoCollector {
// directly below the public classes they implement.
// All other classes sit below their superclass.
ClassInfo superInfo = cls == translator.coreTypes.boolClass ||
cls == translator.coreTypes.numClass
cls == translator.coreTypes.numClass ||
cls == translator.boxedIntClass ||
cls == translator.boxedDoubleClass
? topInfo
: (!translator.options.jsCompatibility &&
cls == translator.wasmStringBaseClass) ||
+4 -4
View File
@@ -9,13 +9,13 @@ import 'dart:_string';
import 'dart:_wasm';
@pragma("wasm:entry-point")
final class BoxedDouble extends double {
final class BoxedDouble implements double {
// A boxed double contains an unboxed double.
@pragma("wasm:entry-point")
double value = 0.0;
final double value;
/// Dummy factory to silence error about missing superclass constructor.
external factory BoxedDouble();
@pragma("wasm:entry-point")
BoxedDouble._(this.value);
static const int _mantissaBits = 52;
static const int _exponentBits = 11;
+4 -4
View File
@@ -7,13 +7,13 @@ import 'dart:_internal';
import 'dart:_wasm';
@pragma("wasm:entry-point")
final class BoxedInt extends int {
final class BoxedInt implements int {
// A boxed int contains an unboxed int.
@pragma("wasm:entry-point")
int value = 0;
final int value;
/// Dummy factory to silence error about missing superclass constructor.
external factory BoxedInt();
@pragma("wasm:entry-point")
BoxedInt._(this.value);
external num operator +(num other);
external num operator -(num other);