[dart2wasm] Add option and target for stringref.

This adds basic infrastructure for a stringref implementation in
dart2wasm:

- A `--[no-]stringref` option to the compiler
- An option in the `WasmTarget`, controlling the name of the target
- Separate sets of patch files for the two targets
- Separate platform dill files for the two targets

For now, the patch file contents are the same, and the compiler flag
is not used by the backend (only by the `dart2wasm` script to select
the appropriate platform dill file). Both of these will change as the
implementation progresses.

Tested: ci + manual check that the option selects the correct dill
Change-Id: I2c9bb95ba06fd3de3f7007703ef545e3f0c728ba
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/310621
Commit-Queue: Aske Simon Christensen <askesc@google.com>
Reviewed-by: Ömer Ağacan <omersa@google.com>
This commit is contained in:
Aske Simon Christensen 2023-06-21 14:25:38 +00:00 committed by Commit Queue
parent 21d45c0268
commit 5838562040
18 changed files with 1717 additions and 42 deletions

View file

@ -111,6 +111,7 @@ group("dart2wasm_platform") {
deps = [
":runtime_precompiled",
"utils/dart2wasm:compile_dart2wasm_platform",
"utils/dart2wasm:compile_dart2wasm_stringref_platform",
"utils/dart2wasm:dart2wasm_snapshot",
]
if (defined(is_product)) {

View file

@ -4500,7 +4500,7 @@ const MessageCode messageFastaUsageLong =
Read the SDK platform from <file>, which should be in Dill/Kernel IR format
and contain the Dart SDK.
--target=dart2js|dart2js_server|dart2wasm|dart_runner|dartdevc|flutter|flutter_runner|none|vm
--target=dart2js|dart2js_server|dart2wasm|dart2wasm_stringref|dart_runner|dartdevc|flutter|flutter_runner|none|vm
Specify the target configuration.
--enable-asserts

View file

@ -37,6 +37,7 @@ where *options* include:
| `--`[`no-`]`polymorphic-specialization` | no | Do virtual calls by switching on the class ID instead of using `call_indirect`.
| `--`[`no-`]`print-kernel` | no | Print IR for each function before compiling it.
| `--`[`no-`]`print-wasm` | no | Print Wasm instructions of each compiled function.
| `--`[`no-`]`stringref` | no | Use the experimental stringref Wasm proposal.
| `--`[`no-`]`enable-asserts` | no | Enable assertions at runtime.
| `--shared-memory-max-pages` *pagecount* | | Max size of the imported memory buffer. If `--shared-import-memory` is specified, this must also be specified.
| `--watch` *offset* | | Print stack trace leading to the byte at offset *offset* in the `.wasm` output file. Can be specified multiple times.

View file

@ -34,6 +34,8 @@ final List<Option> options = [
defaultsTo: _d.translatorOptions.printKernel),
Flag("print-wasm", (o, value) => o.translatorOptions.printWasm = value,
defaultsTo: _d.translatorOptions.printWasm),
Flag("stringref", (o, value) => o.translatorOptions.useStringref = value,
defaultsTo: _d.translatorOptions.useStringref),
Flag(
"enable-asserts", (o, value) => o.translatorOptions.enableAsserts = value,
defaultsTo: _d.translatorOptions.enableAsserts),

View file

@ -35,9 +35,10 @@ import 'package:dart2wasm/records.dart' show RecordShape;
import 'package:dart2wasm/transformers.dart' as wasmTrans;
class WasmTarget extends Target {
WasmTarget({this.removeAsserts = true});
WasmTarget({this.removeAsserts = true, this.useStringref = false});
bool removeAsserts;
bool useStringref;
Class? _growableList;
Class? _immutableList;
Class? _wasmDefaultMap;
@ -58,7 +59,7 @@ class WasmTarget extends Target {
Verification get verification => const WasmVerification();
@override
String get name => 'wasm';
String get name => useStringref ? 'wasm_stringref' : 'wasm';
@override
TargetFlags get flags => TargetFlags();

View file

@ -39,6 +39,9 @@ class TranslatorOptions {
bool polymorphicSpecialization = false;
bool printKernel = false;
bool printWasm = false;
// If the default value for [useStringref] is changed, also update the
// `sdk/bin/dart2wasm` script.
bool useStringref = false;
int inliningLimit = 0;
int? sharedMemoryMaxPages;
List<int>? watchPoints = null;

View file

@ -75,6 +75,17 @@ String? computePlatformDillName(
break;
}
break;
case 'wasm_stringref':
switch (nnbdMode) {
case NnbdMode.Strong:
return 'dart2wasm_stringref_outline.dill';
//TODO(johnniwinther): Support using the full dill.
//return 'dart2wasm_stringref_platform.dill';
case NnbdMode.Weak:
case NnbdMode.Agnostic:
break;
}
break;
default:
break;
}

View file

@ -2271,7 +2271,7 @@ FastaUsageLong:
Read the SDK platform from <file>, which should be in Dill/Kernel IR format
and contain the Dart SDK.
--target=dart2js|dart2js_server|dart2wasm|dart_runner|dartdevc|flutter|flutter_runner|none|vm
--target=dart2js|dart2js_server|dart2wasm|dart2wasm_stringref|dart_runner|dartdevc|flutter|flutter_runner|none|vm
Specify the target configuration.
--enable-asserts

View file

@ -736,6 +736,7 @@ cyclic
dart
dart2js
dart2wasm
dart2wasm_stringref
dartdevc
data
date
@ -2917,6 +2918,7 @@ stray
stream
strictly
string
stringref
strings
stripped
strong

View file

@ -24,5 +24,7 @@ void installAdditionalTargets() {
(TargetFlags flags) => new Dart2jsTarget("dart2js_server", flags);
targets["dartdevc"] = (TargetFlags flags) => new DevCompilerTarget(flags);
targets["dart2wasm"] = (TargetFlags flags) => new WasmTarget();
targets["dart2wasm_stringref"] =
(TargetFlags flags) => new WasmTarget(useStringref: true);
vm_target_install.installAdditionalTargets();
}

View file

@ -37,7 +37,9 @@ Future<Component> compileTestCaseToKernelProgram(Uri sourceUri,
Directory? tempDirectory;
try {
final platformFileName = (target is WasmTarget)
? 'dart2wasm_platform.dill'
? target.useStringref
? 'dart2wasm_stringref_platform.dill'
: 'dart2wasm_platform.dill'
: 'vm_platform_strong.dill';
final platformKernel =
computePlatformBinariesLocation().resolve(platformFileName);

View file

@ -66,8 +66,10 @@ declare_args() {
# ........dart2js_platform_unsound.dill
# ........dart2js_server_platform.dill
# ........dart2js_server_platform_unsound.dill
# ........dart2wasm_platform.dill (if not on ia32)
# ........dart2wasm_outline.dill (if not on ia32)
# ........dart2wasm_platform.dill (if not on ia32)
# ........dart2wasm_stringref_outline.dill (if not on ia32)
# ........dart2wasm_stringref_platform.dill (if not on ia32)
# ........ddc_outline.dill
# ........ddc_platform.dill
# ........vm_platform_strong.dill
@ -473,10 +475,13 @@ copy("copy_dart2wasm_platform") {
":copy_libraries",
"../:dart2wasm_platform",
"../utils/dart2wasm:compile_dart2wasm_platform",
"../utils/dart2wasm:compile_dart2wasm_stringref_platform",
]
sources = [
"$root_out_dir/dart2wasm_outline.dill",
"$root_out_dir/dart2wasm_platform.dill",
"$root_out_dir/dart2wasm_stringref_outline.dill",
"$root_out_dir/dart2wasm_stringref_platform.dill",
]
outputs =
[ "$root_out_dir/$dart_sdk_output/lib/_internal/{{source_file_part}}" ]

View file

@ -65,6 +65,13 @@ SDK_ARG="--dart-sdk=$SDK_DIR"
# Point to built platform dill.
PLATFORM="$BIN_DIR/dart2wasm_platform.dill"
# Not the prettiest way to check for stringref, and it doesn't support changing
# the default, but it will do for the experiment.
for arg in "$@"; do
if [[ "$arg" == "--stringref" ]]; then
PLATFORM="$BIN_DIR/dart2wasm_stringref_platform.dill"
fi
done
PLATFORM_ARG="--platform=$PLATFORM"
unset EXTRA_VM_OPTIONS

File diff suppressed because it is too large Load diff

View file

@ -120,6 +120,62 @@
}
},
"wasm": {
"include": [
{
"target": "wasm_common"
}
],
"libraries": {
"core": {
"uri": "core/core.dart",
"patches": [
"_internal/wasm/lib/core_patch.dart",
"_internal/vm_shared/lib/array_patch.dart",
"_internal/vm_shared/lib/bigint_patch.dart",
"_internal/vm_shared/lib/bool_patch.dart",
"_internal/vm_shared/lib/date_patch.dart",
"_internal/vm_shared/lib/integers_patch.dart",
"_internal/vm_shared/lib/map_patch.dart",
"_internal/vm_shared/lib/null_patch.dart",
"_internal/vm_shared/lib/string_buffer_patch.dart",
"_internal/wasm/lib/date_patch_patch.dart",
"_internal/wasm/lib/string_buffer_create.dart",
"_internal/wasm/lib/string_patch.dart",
"_internal/wasm/lib/sync_star_patch.dart",
"_internal/wasm/lib/weak_patch.dart"
]
}
}
},
"wasm_stringref": {
"include": [
{
"target": "wasm_common"
}
],
"libraries": {
"core": {
"uri": "core/core.dart",
"patches": [
"_internal/wasm/lib/core_patch.dart",
"_internal/vm_shared/lib/array_patch.dart",
"_internal/vm_shared/lib/bigint_patch.dart",
"_internal/vm_shared/lib/bool_patch.dart",
"_internal/vm_shared/lib/date_patch.dart",
"_internal/vm_shared/lib/integers_patch.dart",
"_internal/vm_shared/lib/map_patch.dart",
"_internal/vm_shared/lib/null_patch.dart",
"_internal/vm_shared/lib/string_buffer_patch.dart",
"_internal/wasm/lib/date_patch_patch.dart",
"_internal/wasm/lib/string_buffer_create.dart",
"_internal/wasm/lib/string_stringref_patch.dart",
"_internal/wasm/lib/sync_star_patch.dart",
"_internal/wasm/lib/weak_patch.dart"
]
}
}
},
"wasm_common": {
"libraries": {
"_http": {
"uri": "_http/http.dart"
@ -163,25 +219,6 @@
"_internal/wasm/lib/convert_patch.dart"
]
},
"core": {
"uri": "core/core.dart",
"patches": [
"_internal/wasm/lib/core_patch.dart",
"_internal/vm_shared/lib/array_patch.dart",
"_internal/vm_shared/lib/bigint_patch.dart",
"_internal/vm_shared/lib/bool_patch.dart",
"_internal/vm_shared/lib/date_patch.dart",
"_internal/vm_shared/lib/integers_patch.dart",
"_internal/vm_shared/lib/map_patch.dart",
"_internal/vm_shared/lib/null_patch.dart",
"_internal/vm_shared/lib/string_buffer_patch.dart",
"_internal/wasm/lib/date_patch_patch.dart",
"_internal/wasm/lib/string_buffer_create.dart",
"_internal/wasm/lib/string_patch.dart",
"_internal/wasm/lib/sync_star_patch.dart",
"_internal/wasm/lib/weak_patch.dart"
]
},
"developer": {
"uri": "developer/developer.dart",
"patches": [

View file

@ -113,6 +113,50 @@ vm:
- "_internal/vm/bin/cli_patch.dart"
wasm:
include:
- target: "wasm_common"
libraries:
core:
uri: core/core.dart
patches:
- _internal/wasm/lib/core_patch.dart
- _internal/vm_shared/lib/array_patch.dart
- _internal/vm_shared/lib/bigint_patch.dart
- _internal/vm_shared/lib/bool_patch.dart
- _internal/vm_shared/lib/date_patch.dart
- _internal/vm_shared/lib/integers_patch.dart
- _internal/vm_shared/lib/map_patch.dart
- _internal/vm_shared/lib/null_patch.dart
- _internal/vm_shared/lib/string_buffer_patch.dart
- _internal/wasm/lib/date_patch_patch.dart
- _internal/wasm/lib/string_buffer_create.dart
- _internal/wasm/lib/string_patch.dart
- _internal/wasm/lib/sync_star_patch.dart
- _internal/wasm/lib/weak_patch.dart
wasm_stringref:
include:
- target: "wasm_common"
libraries:
core:
uri: core/core.dart
patches:
- _internal/wasm/lib/core_patch.dart
- _internal/vm_shared/lib/array_patch.dart
- _internal/vm_shared/lib/bigint_patch.dart
- _internal/vm_shared/lib/bool_patch.dart
- _internal/vm_shared/lib/date_patch.dart
- _internal/vm_shared/lib/integers_patch.dart
- _internal/vm_shared/lib/map_patch.dart
- _internal/vm_shared/lib/null_patch.dart
- _internal/vm_shared/lib/string_buffer_patch.dart
- _internal/wasm/lib/date_patch_patch.dart
- _internal/wasm/lib/string_buffer_create.dart
- _internal/wasm/lib/string_stringref_patch.dart
- _internal/wasm/lib/sync_star_patch.dart
- _internal/wasm/lib/weak_patch.dart
wasm_common:
libraries:
_http:
uri: _http/http.dart
@ -143,23 +187,6 @@ wasm:
patches:
- _internal/vm_shared/lib/convert_patch.dart
- _internal/wasm/lib/convert_patch.dart
core:
uri: core/core.dart
patches:
- _internal/wasm/lib/core_patch.dart
- _internal/vm_shared/lib/array_patch.dart
- _internal/vm_shared/lib/bigint_patch.dart
- _internal/vm_shared/lib/bool_patch.dart
- _internal/vm_shared/lib/date_patch.dart
- _internal/vm_shared/lib/integers_patch.dart
- _internal/vm_shared/lib/map_patch.dart
- _internal/vm_shared/lib/null_patch.dart
- _internal/vm_shared/lib/string_buffer_patch.dart
- _internal/wasm/lib/date_patch_patch.dart
- _internal/wasm/lib/string_buffer_create.dart
- _internal/wasm/lib/string_patch.dart
- _internal/wasm/lib/sync_star_patch.dart
- _internal/wasm/lib/weak_patch.dart
developer:
uri: developer/developer.dart
patches:

View file

@ -124,6 +124,8 @@
"out/ReleaseX64/dart2wasm_asserts.snapshot",
"out/ReleaseX64/dart2wasm_outline.dill",
"out/ReleaseX64/dart2wasm_platform.dill",
"out/ReleaseX64/dart2wasm_stringref_outline.dill",
"out/ReleaseX64/dart2wasm_stringref_platform.dill",
"out/ReleaseX64/wasm/",
"pkg/",
"runtime/tests/",

View file

@ -59,6 +59,24 @@ compile_platform("compile_dart2wasm_platform") {
]
}
compile_platform("compile_dart2wasm_stringref_platform") {
single_root_scheme = "org-dartlang-sdk"
single_root_base = rebase_path("$sdk_root/")
libraries_specification_uri = "org-dartlang-sdk:///lib/libraries.json"
outputs = [
"$root_out_dir/dart2wasm_stringref_platform.dill",
"$root_out_dir/dart2wasm_stringref_outline.dill",
]
args = [
"--target=dart2wasm_stringref",
"--no-defines",
"dart:core",
"--nnbd-strong",
]
}
wasm_module("ffi_native_test_wasm_module") {
module_name = "ffi_native_test_module"
}