Reland "Scaffolding for dart:wasm"

This reverts commit 9198813a55.

Reason for revert: Relanding with a fix

Original change's description:
> Revert "Scaffolding for dart:wasm"
> 
> This reverts commit f39a3f188e.
> 
> 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: https://github.com/dart-lang/sdk/issues/37882
> > Change-Id: I47c81f5f1be724f8226e756ba5d01880a45f1ac7
> > Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/112841
> > Reviewed-by: Siva Annamalai <asiva@google.com>
> > Reviewed-by: Liam Appelbe <liama@google.com>
> > Commit-Queue: Liam Appelbe <liama@google.com>
> 
> TBR=asiva@google.com,liama@google.com
> 
> Change-Id: I0fd0f29d66a07fc29e840ddaec2d4161c8d599cb
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Bug: https://github.com/dart-lang/sdk/issues/37882
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/114044
> Reviewed-by: Liam Appelbe <liama@google.com>
> Commit-Queue: Liam Appelbe <liama@google.com>

TBR=asiva@google.com,liama@google.com

# Not skipping CQ checks because original CL landed > 1 day ago.

Bug: https://github.com/dart-lang/sdk/issues/37882
Change-Id: Idb43cbd3a0521776ac420bfef91c8a9a4362f18e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/114757
Reviewed-by: Liam Appelbe <liama@google.com>
Commit-Queue: Liam Appelbe <liama@google.com>
This commit is contained in:
Liam Appelbe 2019-08-28 23:11:21 +00:00 committed by commit-bot@chromium.org
parent d57a8f7451
commit 05c28c6115
20 changed files with 113 additions and 4 deletions

View file

@ -36,6 +36,7 @@ class DartRunnerTarget extends VmTarget {
'dart:typed_data',
'dart:nativewrappers',
'dart:io',
'dart:wasm',
// Required for dart_runner.
'dart:fuchsia.builtin',

View file

@ -41,6 +41,7 @@ class FlutterTarget extends VmTarget {
'dart:typed_data',
'dart:nativewrappers',
'dart:io',
'dart:wasm',
// Required for flutter.
'dart:ui',

View file

@ -36,6 +36,7 @@ class FlutterRunnerTarget extends VmTarget {
'dart:typed_data',
'dart:nativewrappers',
'dart:io',
'dart:wasm',
// Required for flutter_runner.
'dart:fuchsia.builtin',

View file

@ -77,6 +77,7 @@ class VmTarget extends Target {
'dart:nativewrappers',
'dart:io',
'dart:cli',
'dart:wasm',
];
void _patchVmConstants(CoreTypes coreTypes) {

28
runtime/lib/wasm.cc Normal file
View file

@ -0,0 +1,28 @@
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
#include "platform/unicode.h"
#include "vm/bootstrap_natives.h"
#include "vm/dart_entry.h"
namespace dart {
int callWasm(const char* name, int n) {
return 100 * n;
}
// This is a temporary API for prototyping.
DEFINE_NATIVE_ENTRY(Wasm_callFunction, 0, 2) {
GET_NON_NULL_NATIVE_ARGUMENT(String, fn_name, arguments->NativeArgAt(0));
GET_NON_NULL_NATIVE_ARGUMENT(Integer, arg, arguments->NativeArgAt(1));
intptr_t len = Utf8::Length(fn_name);
std::unique_ptr<char> name = std::unique_ptr<char>(new char[len + 1]);
fn_name.ToUTF8(reinterpret_cast<uint8_t*>(name.get()), len);
name.get()[len] = 0;
return Smi::New(callWasm(name.get(), arg.AsInt64Value()));
}
} // namespace dart

View file

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

View file

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

View file

@ -16,6 +16,7 @@ import("../../sdk/lib/mirrors/mirrors_sources.gni")
import("../../sdk/lib/profiler/profiler_sources.gni")
import("../../sdk/lib/typed_data/typed_data_sources.gni")
import("../../sdk/lib/vmservice/vmservice_sources.gni")
import("../../sdk/lib/wasm/wasm_sources.gni")
import("../../utils/compile_platform.gni")
import("../bin/cli_sources.gni")
import("../bin/io_sources.gni")
@ -33,6 +34,7 @@ import("../lib/mirrors_sources.gni")
import("../lib/profiler_sources.gni")
import("../lib/typed_data_sources.gni")
import("../lib/vmservice_sources.gni")
import("../lib/wasm_sources.gni")
import("../runtime_args.gni")
import("compiler/compiler_sources.gni")
import("heap/heap_sources.gni")
@ -106,7 +108,7 @@ library_for_all_configs("libdart_lib") {
internal_runtime_cc_files + isolate_runtime_cc_files +
math_runtime_cc_files + mirrors_runtime_cc_files +
typed_data_runtime_cc_files + vmservice_runtime_cc_files +
ffi_runtime_cc_files
ffi_runtime_cc_files + wasm_runtime_cc_files
sources = [ "bootstrap.cc" ] + rebase_path(allsources, ".", "../lib")
snapshot_sources = []
nosnapshot_sources = []

View file

@ -141,6 +141,11 @@ void Bootstrap::SetupNativeResolver() {
ASSERT(!library.IsNull());
library.set_native_entry_resolver(resolver);
library.set_native_entry_symbol_resolver(symbol_resolver);
library = Library::WasmLibrary();
ASSERT(!library.IsNull());
library.set_native_entry_resolver(resolver);
library.set_native_entry_symbol_resolver(symbol_resolver);
}
bool Bootstrap::IsBootstrapResolver(Dart_NativeEntryResolver resolver) {

View file

@ -12,6 +12,7 @@
namespace dart {
// List of bootstrap native entry points used in the core dart library.
// V(function_name, argument_count)
#define BOOTSTRAP_NATIVE_LIST(V) \
V(AsyncStarMoveNext_debuggerStepCheck, 1) \
V(DartAsync_fatal, 1) \
@ -392,7 +393,8 @@ namespace dart {
V(Ffi_dl_processLibrary, 0) \
V(Ffi_dl_executableLibrary, 0) \
V(TransferableTypedData_factory, 2) \
V(TransferableTypedData_materialize, 1)
V(TransferableTypedData_materialize, 1) \
V(Wasm_callFunction, 2)
// List of bootstrap native entry points used in the dart:mirror library.
#define MIRRORS_BOOTSTRAP_NATIVE_LIST(V) \

View file

@ -1918,6 +1918,14 @@ RawError* Object::Init(Isolate* isolate,
pending_classes.Add(cls);
RegisterClass(cls, Symbols::FfiDynamicLibrary(), lib);
lib = Library::LookupLibrary(thread, Symbols::DartWasm());
if (lib.IsNull()) {
lib = Library::NewLibraryHelper(Symbols::DartWasm(), true);
lib.SetLoadRequested();
lib.Register(thread);
}
object_store->set_bootstrap_library(ObjectStore::kWasm, lib);
// Finish the initialization by compiling the bootstrap scripts containing
// the base interfaces and the implementation of the internal classes.
const Error& error = Error::Handle(
@ -11742,6 +11750,10 @@ RawLibrary* Library::VMServiceLibrary() {
return Isolate::Current()->object_store()->_vmservice_library();
}
RawLibrary* Library::WasmLibrary() {
return Isolate::Current()->object_store()->wasm_library();
}
const char* Library::ToCString() const {
const String& name = String::Handle(url());
return OS::SCreate(Thread::Current()->zone(), "Library:'%s'",

View file

@ -4274,6 +4274,7 @@ class Library : public Object {
static RawLibrary* ProfilerLibrary();
static RawLibrary* TypedDataLibrary();
static RawLibrary* VMServiceLibrary();
static RawLibrary* WasmLibrary();
// Eagerly compile all classes and functions in the library.
static RawError* CompileAll(bool ignore_error = false);

View file

@ -29,7 +29,8 @@ class ObjectPointerVisitor;
M(Mirrors, mirrors) \
M(Profiler, profiler) \
M(TypedData, typed_data) \
M(VMService, _vmservice)
M(VMService, _vmservice) \
M(Wasm, wasm)
#define OBJECT_STORE_FIELD_LIST(R_, RW) \
RW(Class, object_class) \
@ -101,6 +102,7 @@ class ObjectPointerVisitor;
RW(Library, root_library) \
RW(Library, typed_data_library) \
RW(Library, _vmservice_library) \
RW(Library, wasm_library) \
RW(GrowableObjectArray, libraries) \
RW(Array, libraries_map) \
RW(GrowableObjectArray, closure_functions) \

View file

@ -72,6 +72,9 @@ class ObjectPointerVisitor;
V(DartExtensionScheme, "dart-ext:") \
V(DartFfi, "dart:ffi") \
V(DartFfiLibName, "ffi") \
V(DartWasm, "dart:wasm") \
V(DartWasmLibName, "wasm") \
V(DartLibraryWasm, "dart.library.wasm") \
V(DartIOLibName, "dart.io") \
V(DartInternal, "dart:_internal") \
V(DartIsVM, "dart.isVM") \

View file

@ -84,6 +84,7 @@ declare_args() {
# ......math/
# ......mirrors/
# ......typed_data/
# ......wasm/
# ......api_readme.md
# ....model/
# ......lexeme/
@ -216,6 +217,7 @@ _full_sdk_libraries = [
"profiler",
"svg",
"typed_data",
"wasm",
"web_audio",
"web_gl",
"web_sql",

View file

@ -134,6 +134,8 @@ const Map<String, LibraryInfo> libraries = const {
categories: "Client",
maturity: Maturity.WEB_STABLE,
platforms: DART2JS_PLATFORM),
"wasm": const LibraryInfo("wasm/wasm.dart",
categories: "Server", maturity: Maturity.EXPERIMENTAL),
"web_audio": const LibraryInfo("web_audio/dart2js/web_audio_dart2js.dart",
categories: "Client",
maturity: Maturity.WEB_STABLE,

View file

@ -71,6 +71,12 @@
],
"uri": "ffi/ffi.dart"
},
"wasm": {
"patches": [
"../../runtime/lib/wasm_patch.dart"
],
"uri": "wasm/wasm.dart"
},
"typed_data": {
"patches": "../../runtime/lib/typed_data_patch.dart",
"uri": "typed_data/typed_data.dart"
@ -481,4 +487,4 @@
}
}
}
}
}

View file

@ -94,6 +94,11 @@ vm:
- "../../runtime/lib/ffi_dynamic_library_patch.dart"
- "../../runtime/lib/ffi_native_type_patch.dart"
wasm:
uri: "wasm/wasm.dart"
patches:
- "../../runtime/lib/wasm_patch.dart"
_http:
uri: "_http/http.dart"

13
sdk/lib/wasm/wasm.dart Normal file
View file

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

View file

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