Skip to content

Commit 05c28c6

Browse files
liamappelbecommit-bot@chromium.org
authored andcommitted
Reland "Scaffolding for dart:wasm"
This reverts commit 9198813. Reason for revert: Relanding with a fix Original change's description: > Revert "Scaffolding for dart:wasm" > > This reverts commit f39a3f1. > > Reason for revert: https://golem.corp.goog/BuildInfo?target=flutter-profile&machine-type=android-armv7&revision=84750 > > Original change's description: > > Scaffolding for dart:wasm > > > > This CL doesn't have any tests because it's just boilerplate. I'll > > add a test in the follow up CLs where I add actual functionality. > > > > Bug: #37882 > > Change-Id: I47c81f5f1be724f8226e756ba5d01880a45f1ac7 > > Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/112841 > > Reviewed-by: Siva Annamalai <[email protected]> > > Reviewed-by: Liam Appelbe <[email protected]> > > Commit-Queue: Liam Appelbe <[email protected]> > > [email protected],[email protected] > > Change-Id: I0fd0f29d66a07fc29e840ddaec2d4161c8d599cb > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: #37882 > Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/114044 > Reviewed-by: Liam Appelbe <[email protected]> > Commit-Queue: Liam Appelbe <[email protected]> [email protected],[email protected] # Not skipping CQ checks because original CL landed > 1 day ago. Bug: #37882 Change-Id: Idb43cbd3a0521776ac420bfef91c8a9a4362f18e Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/114757 Reviewed-by: Liam Appelbe <[email protected]> Commit-Queue: Liam Appelbe <[email protected]>
1 parent d57a8f7 commit 05c28c6

20 files changed

+113
-4
lines changed

pkg/vm/lib/target/dart_runner.dart

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class DartRunnerTarget extends VmTarget {
3636
'dart:typed_data',
3737
'dart:nativewrappers',
3838
'dart:io',
39+
'dart:wasm',
3940

4041
// Required for dart_runner.
4142
'dart:fuchsia.builtin',

pkg/vm/lib/target/flutter.dart

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class FlutterTarget extends VmTarget {
4141
'dart:typed_data',
4242
'dart:nativewrappers',
4343
'dart:io',
44+
'dart:wasm',
4445

4546
// Required for flutter.
4647
'dart:ui',

pkg/vm/lib/target/flutter_runner.dart

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class FlutterRunnerTarget extends VmTarget {
3636
'dart:typed_data',
3737
'dart:nativewrappers',
3838
'dart:io',
39+
'dart:wasm',
3940

4041
// Required for flutter_runner.
4142
'dart:fuchsia.builtin',

pkg/vm/lib/target/vm.dart

+1
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ class VmTarget extends Target {
7777
'dart:nativewrappers',
7878
'dart:io',
7979
'dart:cli',
80+
'dart:wasm',
8081
];
8182

8283
void _patchVmConstants(CoreTypes coreTypes) {

runtime/lib/wasm.cc

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
#include "platform/unicode.h"
6+
#include "vm/bootstrap_natives.h"
7+
#include "vm/dart_entry.h"
8+
9+
namespace dart {
10+
11+
int callWasm(const char* name, int n) {
12+
return 100 * n;
13+
}
14+
15+
// This is a temporary API for prototyping.
16+
DEFINE_NATIVE_ENTRY(Wasm_callFunction, 0, 2) {
17+
GET_NON_NULL_NATIVE_ARGUMENT(String, fn_name, arguments->NativeArgAt(0));
18+
GET_NON_NULL_NATIVE_ARGUMENT(Integer, arg, arguments->NativeArgAt(1));
19+
20+
intptr_t len = Utf8::Length(fn_name);
21+
std::unique_ptr<char> name = std::unique_ptr<char>(new char[len + 1]);
22+
fn_name.ToUTF8(reinterpret_cast<uint8_t*>(name.get()), len);
23+
name.get()[len] = 0;
24+
25+
return Smi::New(callWasm(name.get(), arg.AsInt64Value()));
26+
}
27+
28+
} // namespace dart

runtime/lib/wasm_patch.dart

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import "dart:_internal" show patch;
6+
7+
@patch
8+
int _callWasm(String name, int arg) native "Wasm_callFunction";

runtime/lib/wasm_sources.gni

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
2+
# for details. All rights reserved. Use of this source code is governed by a
3+
# BSD-style license that can be found in the LICENSE file.
4+
5+
wasm_runtime_cc_files = [ "wasm.cc" ]
6+
7+
wasm_runtime_dart_files = [ "wasm_patch.dart" ]

runtime/vm/BUILD.gn

+3-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import("../../sdk/lib/mirrors/mirrors_sources.gni")
1616
import("../../sdk/lib/profiler/profiler_sources.gni")
1717
import("../../sdk/lib/typed_data/typed_data_sources.gni")
1818
import("../../sdk/lib/vmservice/vmservice_sources.gni")
19+
import("../../sdk/lib/wasm/wasm_sources.gni")
1920
import("../../utils/compile_platform.gni")
2021
import("../bin/cli_sources.gni")
2122
import("../bin/io_sources.gni")
@@ -33,6 +34,7 @@ import("../lib/mirrors_sources.gni")
3334
import("../lib/profiler_sources.gni")
3435
import("../lib/typed_data_sources.gni")
3536
import("../lib/vmservice_sources.gni")
37+
import("../lib/wasm_sources.gni")
3638
import("../runtime_args.gni")
3739
import("compiler/compiler_sources.gni")
3840
import("heap/heap_sources.gni")
@@ -106,7 +108,7 @@ library_for_all_configs("libdart_lib") {
106108
internal_runtime_cc_files + isolate_runtime_cc_files +
107109
math_runtime_cc_files + mirrors_runtime_cc_files +
108110
typed_data_runtime_cc_files + vmservice_runtime_cc_files +
109-
ffi_runtime_cc_files
111+
ffi_runtime_cc_files + wasm_runtime_cc_files
110112
sources = [ "bootstrap.cc" ] + rebase_path(allsources, ".", "../lib")
111113
snapshot_sources = []
112114
nosnapshot_sources = []

runtime/vm/bootstrap_natives.cc

+5
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,11 @@ void Bootstrap::SetupNativeResolver() {
141141
ASSERT(!library.IsNull());
142142
library.set_native_entry_resolver(resolver);
143143
library.set_native_entry_symbol_resolver(symbol_resolver);
144+
145+
library = Library::WasmLibrary();
146+
ASSERT(!library.IsNull());
147+
library.set_native_entry_resolver(resolver);
148+
library.set_native_entry_symbol_resolver(symbol_resolver);
144149
}
145150

146151
bool Bootstrap::IsBootstrapResolver(Dart_NativeEntryResolver resolver) {

runtime/vm/bootstrap_natives.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace dart {
1313

1414
// List of bootstrap native entry points used in the core dart library.
15+
// V(function_name, argument_count)
1516
#define BOOTSTRAP_NATIVE_LIST(V) \
1617
V(AsyncStarMoveNext_debuggerStepCheck, 1) \
1718
V(DartAsync_fatal, 1) \
@@ -392,7 +393,8 @@ namespace dart {
392393
V(Ffi_dl_processLibrary, 0) \
393394
V(Ffi_dl_executableLibrary, 0) \
394395
V(TransferableTypedData_factory, 2) \
395-
V(TransferableTypedData_materialize, 1)
396+
V(TransferableTypedData_materialize, 1) \
397+
V(Wasm_callFunction, 2)
396398

397399
// List of bootstrap native entry points used in the dart:mirror library.
398400
#define MIRRORS_BOOTSTRAP_NATIVE_LIST(V) \

runtime/vm/object.cc

+12
Original file line numberDiff line numberDiff line change
@@ -1918,6 +1918,14 @@ RawError* Object::Init(Isolate* isolate,
19181918
pending_classes.Add(cls);
19191919
RegisterClass(cls, Symbols::FfiDynamicLibrary(), lib);
19201920

1921+
lib = Library::LookupLibrary(thread, Symbols::DartWasm());
1922+
if (lib.IsNull()) {
1923+
lib = Library::NewLibraryHelper(Symbols::DartWasm(), true);
1924+
lib.SetLoadRequested();
1925+
lib.Register(thread);
1926+
}
1927+
object_store->set_bootstrap_library(ObjectStore::kWasm, lib);
1928+
19211929
// Finish the initialization by compiling the bootstrap scripts containing
19221930
// the base interfaces and the implementation of the internal classes.
19231931
const Error& error = Error::Handle(
@@ -11742,6 +11750,10 @@ RawLibrary* Library::VMServiceLibrary() {
1174211750
return Isolate::Current()->object_store()->_vmservice_library();
1174311751
}
1174411752

11753+
RawLibrary* Library::WasmLibrary() {
11754+
return Isolate::Current()->object_store()->wasm_library();
11755+
}
11756+
1174511757
const char* Library::ToCString() const {
1174611758
const String& name = String::Handle(url());
1174711759
return OS::SCreate(Thread::Current()->zone(), "Library:'%s'",

runtime/vm/object.h

+1
Original file line numberDiff line numberDiff line change
@@ -4274,6 +4274,7 @@ class Library : public Object {
42744274
static RawLibrary* ProfilerLibrary();
42754275
static RawLibrary* TypedDataLibrary();
42764276
static RawLibrary* VMServiceLibrary();
4277+
static RawLibrary* WasmLibrary();
42774278

42784279
// Eagerly compile all classes and functions in the library.
42794280
static RawError* CompileAll(bool ignore_error = false);

runtime/vm/object_store.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ class ObjectPointerVisitor;
2929
M(Mirrors, mirrors) \
3030
M(Profiler, profiler) \
3131
M(TypedData, typed_data) \
32-
M(VMService, _vmservice)
32+
M(VMService, _vmservice) \
33+
M(Wasm, wasm)
3334

3435
#define OBJECT_STORE_FIELD_LIST(R_, RW) \
3536
RW(Class, object_class) \
@@ -101,6 +102,7 @@ class ObjectPointerVisitor;
101102
RW(Library, root_library) \
102103
RW(Library, typed_data_library) \
103104
RW(Library, _vmservice_library) \
105+
RW(Library, wasm_library) \
104106
RW(GrowableObjectArray, libraries) \
105107
RW(Array, libraries_map) \
106108
RW(GrowableObjectArray, closure_functions) \

runtime/vm/symbols.h

+3
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ class ObjectPointerVisitor;
7272
V(DartExtensionScheme, "dart-ext:") \
7373
V(DartFfi, "dart:ffi") \
7474
V(DartFfiLibName, "ffi") \
75+
V(DartWasm, "dart:wasm") \
76+
V(DartWasmLibName, "wasm") \
77+
V(DartLibraryWasm, "dart.library.wasm") \
7578
V(DartIOLibName, "dart.io") \
7679
V(DartInternal, "dart:_internal") \
7780
V(DartIsVM, "dart.isVM") \

sdk/BUILD.gn

+2
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ declare_args() {
8484
# ......math/
8585
# ......mirrors/
8686
# ......typed_data/
87+
# ......wasm/
8788
# ......api_readme.md
8889
# ....model/
8990
# ......lexeme/
@@ -216,6 +217,7 @@ _full_sdk_libraries = [
216217
"profiler",
217218
"svg",
218219
"typed_data",
220+
"wasm",
219221
"web_audio",
220222
"web_gl",
221223
"web_sql",

sdk/lib/_internal/sdk_library_metadata/lib/libraries.dart

+2
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ const Map<String, LibraryInfo> libraries = const {
134134
categories: "Client",
135135
maturity: Maturity.WEB_STABLE,
136136
platforms: DART2JS_PLATFORM),
137+
"wasm": const LibraryInfo("wasm/wasm.dart",
138+
categories: "Server", maturity: Maturity.EXPERIMENTAL),
137139
"web_audio": const LibraryInfo("web_audio/dart2js/web_audio_dart2js.dart",
138140
categories: "Client",
139141
maturity: Maturity.WEB_STABLE,

sdk/lib/libraries.json

+7-1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@
7171
],
7272
"uri": "ffi/ffi.dart"
7373
},
74+
"wasm": {
75+
"patches": [
76+
"../../runtime/lib/wasm_patch.dart"
77+
],
78+
"uri": "wasm/wasm.dart"
79+
},
7480
"typed_data": {
7581
"patches": "../../runtime/lib/typed_data_patch.dart",
7682
"uri": "typed_data/typed_data.dart"
@@ -481,4 +487,4 @@
481487
}
482488
}
483489
}
484-
}
490+
}

sdk/lib/libraries.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@ vm:
9494
- "../../runtime/lib/ffi_dynamic_library_patch.dart"
9595
- "../../runtime/lib/ffi_native_type_patch.dart"
9696

97+
wasm:
98+
uri: "wasm/wasm.dart"
99+
patches:
100+
- "../../runtime/lib/wasm_patch.dart"
101+
97102
_http:
98103
uri: "_http/http.dart"
99104

sdk/lib/wasm/wasm.dart

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
/// {@category VM}
6+
/// {@nodoc}
7+
library dart.wasm;
8+
9+
int callWasm(String name, int arg) {
10+
return _callWasm(name, arg);
11+
}
12+
13+
external int _callWasm(String name, int arg);

sdk/lib/wasm/wasm_sources.gni

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
2+
# for details. All rights reserved. Use of this source code is governed by a
3+
# BSD-style license that can be found in the LICENSE file.
4+
5+
wasm_sdk_sources = [
6+
"wasm.dart",
7+
]

0 commit comments

Comments
 (0)