From 36d9e4e77b9ebf7fc20866b14aa60bf5c21fa0bd Mon Sep 17 00:00:00 2001 From: Martin Kustermann Date: Tue, 28 Oct 2025 06:57:54 -0700 Subject: [PATCH] [dart2wasm] Make string globals non-nullable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Those globals should never be able to old a `null` value. Strictly speaking the `js-string-builtin` spec also says ``` If an import refers to the imported string namespace, then the import type is matched against an extern type of (global (ref extern)) ``` And `ref extern` is non-nullable (compared with `externref` which is shorthand for `ref null extern`) Change-Id: I0e2638fbfeb6d59f740320c7d4167fcff3d793e1 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/457980 Commit-Queue: Martin Kustermann Reviewed-by: Ömer Ağacan --- pkg/dart2wasm/lib/translator.dart | 4 ++-- pkg/dart2wasm/test/ir_tests/deferred.constant.wat | 4 ++-- pkg/dart2wasm/test/ir_tests/hello.wat | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pkg/dart2wasm/lib/translator.dart b/pkg/dart2wasm/lib/translator.dart index d39958f4cb9..b1e5cdb12b2 100644 --- a/pkg/dart2wasm/lib/translator.dart +++ b/pkg/dart2wasm/lib/translator.dart @@ -1860,13 +1860,13 @@ class Translator with KernelNodes { // runtime. final i = internalizedStringsForJSRuntime.length; internalizedString = module.globals.import('s', '$i', - w.GlobalType(w.RefType.extern(nullable: true), mutable: false)); + w.GlobalType(w.RefType.extern(nullable: false), mutable: false)); internalizedStringsForJSRuntime.add(s); } else { internalizedString = module.globals.import( 'S', s, - w.GlobalType(w.RefType.extern(nullable: true), mutable: false), + w.GlobalType(w.RefType.extern(nullable: false), mutable: false), ); } _internalizedStringGlobals[(module, s)] = internalizedString; diff --git a/pkg/dart2wasm/test/ir_tests/deferred.constant.wat b/pkg/dart2wasm/test/ir_tests/deferred.constant.wat index d9f9f943f8f..2e3a54604a1 100644 --- a/pkg/dart2wasm/test/ir_tests/deferred.constant.wat +++ b/pkg/dart2wasm/test/ir_tests/deferred.constant.wat @@ -25,8 +25,8 @@ (field $fun (ref $#Closure-0-1))))) (type $type256 <...>) (type $#DummyStruct <...>) - (global $S.globalH1Bar< (import "S" "globalH1Bar<") externref) - (global $S.globalH0Foo (import "S" "globalH0Foo") externref) + (global $S.globalH1Bar< (import "S" "globalH1Bar<") (ref extern)) + (global $S.globalH0Foo (import "S" "globalH0Foo") (ref extern)) (global $global29 (ref $#DummyStruct) <...>) (global $"C28 _InterfaceType" (ref $_InterfaceType) <...>) (global $"C334 \"h0\"" (ref $JSStringImpl) <...>) diff --git a/pkg/dart2wasm/test/ir_tests/hello.wat b/pkg/dart2wasm/test/ir_tests/hello.wat index e94dde2d52f..6b9c5277f06 100644 --- a/pkg/dart2wasm/test/ir_tests/hello.wat +++ b/pkg/dart2wasm/test/ir_tests/hello.wat @@ -4,7 +4,7 @@ (type $JSStringImpl (sub final $#Top (struct (field $field0 i32) (field $_ref externref)))) - (global $"S.hello world" (import "S" "hello world") externref) + (global $"S.hello world" (import "S" "hello world") (ref extern)) (global $"C329 \"hello world\"" (ref $JSStringImpl) (i32.const 4) (global.get $"S.hello world")