From 76717f293016ea22a7c45c3378f111bcbaf09fd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Sinan=20A=C4=9Facan?= Date: Wed, 6 Nov 2024 13:06:06 +0000 Subject: [PATCH] [dart2wasm] Make int and double fields immutable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Slava Egorov Reviewed-by: Martin Kustermann --- pkg/dart2wasm/lib/class_info.dart | 4 +++- sdk/lib/_internal/wasm/lib/boxed_double.dart | 8 ++++---- sdk/lib/_internal/wasm/lib/boxed_int.dart | 8 ++++---- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/pkg/dart2wasm/lib/class_info.dart b/pkg/dart2wasm/lib/class_info.dart index 92373550f95..bd1d7869442 100644 --- a/pkg/dart2wasm/lib/class_info.dart +++ b/pkg/dart2wasm/lib/class_info.dart @@ -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) || diff --git a/sdk/lib/_internal/wasm/lib/boxed_double.dart b/sdk/lib/_internal/wasm/lib/boxed_double.dart index 60e166314a5..a1f57702514 100644 --- a/sdk/lib/_internal/wasm/lib/boxed_double.dart +++ b/sdk/lib/_internal/wasm/lib/boxed_double.dart @@ -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; diff --git a/sdk/lib/_internal/wasm/lib/boxed_int.dart b/sdk/lib/_internal/wasm/lib/boxed_int.dart index 20df3992327..14bdc1dc477 100644 --- a/sdk/lib/_internal/wasm/lib/boxed_int.dart +++ b/sdk/lib/_internal/wasm/lib/boxed_int.dart @@ -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);