Skip to content

Commit

Permalink
Cleanup the loader code to remove some unused pieces.
Browse files Browse the repository at this point in the history
Change-Id: I026b2b0dfb964c2dd67a9022260e4aba9c019e9c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/125444
Commit-Queue: Siva Annamalai <asiva@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
  • Loading branch information
a-siva authored and commit-bot@chromium.org committed Dec 5, 2019
1 parent b8dbaaa commit 5ff9a2e
Show file tree
Hide file tree
Showing 6 changed files with 2 additions and 268 deletions.
15 changes: 0 additions & 15 deletions runtime/bin/vmservice/loader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -957,8 +957,6 @@ const _Dart_kCanonicalizeUrl = 0; // Canonicalize the URL.

// Extra requests. Keep these in sync between loader.dart and builtin.dart.
const _Dart_kInitLoader = 4; // Initialize the loader.
const _Dart_kResourceLoad = 5; // Resource class support.
const _Dart_kGetPackageRootUri = 6; // Uri of the packages/ directory.
const _Dart_kGetPackageConfigUri = 7; // Uri of the .packages file.
const _Dart_kResolvePackageUri = 8; // Resolve a package: uri.

Expand Down Expand Up @@ -1009,19 +1007,6 @@ _processLoadRequest(request) {
assert(isolateEmbedderData[isolateId] == loaderState);
}
break;
case _Dart_kResourceLoad:
{
Uri uri = Uri.parse(request[4]);
_handleResourceRequest(
loaderState, sp, traceLoading, tag, uri, uri, null);
}
break;
case _Dart_kGetPackageRootUri:
loaderState._triggerPackageResolution(() {
// The package root is deprecated and now always returns null.
sp.send(null);
});
break;
case _Dart_kGetPackageConfigUri:
loaderState._triggerPackageResolution(() {
// Respond with the packages config (if any) after package resolution.
Expand Down
135 changes: 0 additions & 135 deletions runtime/vm/unit_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,6 @@ void SetupCoreLibrariesForUnitTest() {
RELEASE_ASSERT(!Dart_IsError(result));
}

static const char* kPackageScheme = "package:";

static bool IsPackageSchemeURL(const char* url_name) {
static const intptr_t kPackageSchemeLen = strlen(kPackageScheme);
return (strncmp(url_name, kPackageScheme, kPackageSchemeLen) == 0);
}

struct TestLibEntry {
const char* url;
const char* source;
Expand Down Expand Up @@ -212,13 +205,6 @@ static const char* IsolateReloadTestLibUri() {
return "test:isolate_reload_helper";
}

static bool IsIsolateReloadTestLib(const char* url_name) {
static const intptr_t kIsolateReloadTestLibUriLen =
strlen(IsolateReloadTestLibUri());
return (strncmp(url_name, IsolateReloadTestLibUri(),
kIsolateReloadTestLibUriLen) == 0);
}

static void ReloadTest(Dart_NativeArguments native_args) {
Dart_Handle result = TestCase::TriggerReload(/* kernel_buffer= */ NULL,
/* kernel_buffer_size= */ 0);
Expand All @@ -241,15 +227,6 @@ static Dart_Handle LoadIsolateReloadTestLib() {
}
#endif // !PRODUCT

static Dart_Handle ResolvePackageUri(const char* uri_chars) {
const int kNumArgs = 1;
Dart_Handle dart_args[kNumArgs];
dart_args[0] = DartUtils::NewString(uri_chars);
return Dart_Invoke(DartUtils::LookupBuiltinLib(),
DartUtils::NewString("_filePathFromUri"), kNumArgs,
dart_args);
}

char* TestCase::CompileTestScriptWithDFE(const char* url,
const char* source,
const uint8_t** kernel_buffer,
Expand All @@ -273,54 +250,6 @@ char* TestCase::CompileTestScriptWithDFE(const char* url,
multiroot_filepaths, multiroot_scheme);
}

#if 0

char* TestCase::CompileTestScriptWithDFE(const char* url,
int sourcefiles_count,
Dart_SourceFile sourcefiles[],
void** kernel_pgm,
bool incrementally,
bool allow_compile_errors) {
Zone* zone = Thread::Current()->zone();
Dart_KernelCompilationResult compilation_result = Dart_CompileSourcesToKernel(
url, platform_strong_dill, platform_strong_dill_size,
sourcefiles_count, sourcefiles, incrementally, NULL);
return ValidateCompilationResult(zone, compilation_result, kernel_pgm);
}

char* TestCase::ValidateCompilationResult(
Zone* zone,
Dart_KernelCompilationResult compilation_result,
void** kernel_pgm,
bool allow_compile_errors) {
if (!allow_compile_errors &&
(compilation_result.status != Dart_KernelCompilationStatus_Ok)) {
char* result =
OS::SCreate(zone, "Compilation failed %s", compilation_result.error);
free(compilation_result.error);
return result;
}

const uint8_t* kernel_file = compilation_result.kernel;
intptr_t kernel_length = compilation_result.kernel_size;
if (kernel_file == NULL) {
return OS::SCreate(zone, "front end generated a NULL kernel file");
}
*kernel_pgm =
Dart_ReadKernelBinary(kernel_file, kernel_length, ReleaseFetchedBytes);
if (*kernel_pgm == NULL) {
return OS::SCreate(zone, "Failed to read generated kernel binary");
}
if (compilation_result.status != Dart_KernelCompilationStatus_Ok) {
char* result =
OS::SCreate(zone, "Compilation failed %s", compilation_result.error);
free(compilation_result.error);
return result;
}
return NULL;
}
#endif

char* TestCase::CompileTestScriptWithDFE(const char* url,
int sourcefiles_count,
Dart_SourceFile sourcefiles[],
Expand Down Expand Up @@ -377,70 +306,6 @@ static Dart_Handle LibraryTagHandler(Dart_LibraryTag tag,
}
return Dart_DefaultCanonicalizeUrl(library_url, url);
}
if (!Dart_IsLibrary(library)) {
return Dart_NewApiError("not a library");
}
if (!Dart_IsString(url)) {
return Dart_NewApiError("url is not a string");
}
const char* url_chars = NULL;
Dart_Handle result = Dart_StringToCString(url, &url_chars);
if (Dart_IsError(result)) {
return Dart_NewApiError("accessing url characters failed");
}
Dart_Handle library_url = Dart_LibraryUrl(library);
const char* library_url_string = NULL;
result = Dart_StringToCString(library_url, &library_url_string);
if (Dart_IsError(result)) {
return result;
}

bool is_dart_scheme_url = DartUtils::IsDartSchemeURL(url_chars);
bool is_io_library = DartUtils::IsDartIOLibURL(library_url_string);
bool is_standalone_library = DartUtils::IsDartCLILibURL(library_url_string);
if (is_dart_scheme_url) {
ASSERT(tag == Dart_kImportTag);
// Handle imports of other built-in libraries present in the SDK.
if (DartUtils::IsDartIOLibURL(url_chars)) {
return Builtin::LoadAndCheckLibrary(Builtin::kIOLibrary);
} else if (DartUtils::IsDartBuiltinLibURL(url_chars)) {
return Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary);
} else if (DartUtils::IsDartCLILibURL(url_chars)) {
return Builtin::LoadAndCheckLibrary(Builtin::kCLILibrary);
} else {
return DartUtils::NewError("Do not know how to load '%s'", url_chars);
}
}
const char* lib_source = TestCase::GetTestLib(url_chars);
if (lib_source != NULL) {
UNREACHABLE();
}
#if !defined(PRODUCT)
if (IsIsolateReloadTestLib(url_chars)) {
UNREACHABLE();
return Dart_Null();
}
#endif
if (is_io_library) {
UNREACHABLE();
return Dart_Null();
}
if (is_standalone_library) {
UNREACHABLE();
return Dart_Null();
}
Dart_Handle resolved_url = url;
const char* resolved_url_chars = url_chars;
if (IsPackageSchemeURL(url_chars)) {
resolved_url = ResolvePackageUri(url_chars);
EXPECT_VALID(resolved_url);
if (Dart_IsError(Dart_StringToCString(resolved_url, &resolved_url_chars))) {
return Dart_NewApiError("unable to convert resolved uri to string");
}
}
// Do sync loading since unit_test doesn't support async.
Dart_Handle source = DartUtils::ReadStringFromFile(resolved_url_chars);
EXPECT_VALID(source);
UNREACHABLE();
return Dart_Null();
}
Expand Down
54 changes: 0 additions & 54 deletions sdk/lib/_internal/vm/bin/builtin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ int _isolateId;
// Requests made to the service isolate over the load port.

// Extra requests. Keep these in sync between loader.dart and builtin.dart.
const _Dart_kResourceLoad = 5; // Resource class support.
const _Dart_kGetPackageRootUri = 6; // Uri of the packages/ directory.
const _Dart_kGetPackageConfigUri = 7; // Uri of the .packages file.
const _Dart_kResolvePackageUri = 8; // Resolve a package: uri.

Expand Down Expand Up @@ -254,66 +252,14 @@ Uri _resolvePackageUri(Uri uri) {
return _packageRoot.resolve(uri.path);
}

// Returns either a file path or a URI starting with http[s]:, as a String.
String _filePathFromUri(String userUri) {
var uri = Uri.parse(userUri);
if (_traceLoading) {
_log('Getting file path from: $uri');
}

var path;
switch (uri.scheme) {
case '':
case 'file':
return uri.toFilePath();
case 'package':
return _filePathFromUri(_resolvePackageUri(uri).toString());
case 'data':
case 'http':
case 'https':
return uri.toString();
default:
// Only handling file, http, and package URIs
// in standalone binary.
if (_traceLoading) {
_log('Unknown scheme (${uri.scheme}) in $uri.');
}
throw 'Not a known scheme: $uri';
}
}

// Register callbacks and hooks with the rest of the core libraries.
@pragma("vm:entry-point")
_setupHooks() {
_setupCompleted = true;
VMLibraryHooks.resourceReadAsBytes = _resourceReadAsBytes;

VMLibraryHooks.packageRootUriFuture = _getPackageRootFuture;
VMLibraryHooks.packageConfigUriFuture = _getPackageConfigFuture;
VMLibraryHooks.resolvePackageUriFuture = _resolvePackageUriFuture;
}

// Handling of Resource class by dispatching to the load port.
Future<List<int>> _resourceReadAsBytes(Uri uri) async {
List response =
await _makeLoaderRequest<List<int>>(_Dart_kResourceLoad, uri.toString());
if (response[4] is String) {
// Throw the error.
throw response[4];
} else {
return response[4];
}
}

// TODO(mfairhurst): remove this
Future<Uri> _getPackageRootFuture() {
if (_traceLoading) {
_log("Request for package root from user code.");
}
// Return null, as the `packages/` directory is not supported in dart 2.
return new Future.value(null);
}

Future<Uri> _getPackageConfigFuture() {
if (_traceLoading) {
_log("Request for package config from user code.");
Expand Down
6 changes: 1 addition & 5 deletions sdk/lib/_internal/vm/lib/isolate_patch.dart
Original file line number Diff line number Diff line change
Expand Up @@ -327,11 +327,7 @@ class Isolate {

@patch
static Future<Uri> get packageRoot {
var hook = VMLibraryHooks.packageRootUriFuture;
if (hook == null) {
throw new UnsupportedError("Isolate.packageRoot");
}
return hook();
return null;
}

@patch
Expand Down
54 changes: 0 additions & 54 deletions sdk_nnbd/lib/_internal/vm/bin/builtin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ int _isolateId;
// Requests made to the service isolate over the load port.

// Extra requests. Keep these in sync between loader.dart and builtin.dart.
const _Dart_kResourceLoad = 5; // Resource class support.
const _Dart_kGetPackageRootUri = 6; // Uri of the packages/ directory.
const _Dart_kGetPackageConfigUri = 7; // Uri of the .packages file.
const _Dart_kResolvePackageUri = 8; // Resolve a package: uri.

Expand Down Expand Up @@ -254,66 +252,14 @@ Uri _resolvePackageUri(Uri uri) {
return _packageRoot.resolve(uri.path);
}

// Returns either a file path or a URI starting with http[s]:, as a String.
String _filePathFromUri(String userUri) {
var uri = Uri.parse(userUri);
if (_traceLoading) {
_log('Getting file path from: $uri');
}

var path;
switch (uri.scheme) {
case '':
case 'file':
return uri.toFilePath();
case 'package':
return _filePathFromUri(_resolvePackageUri(uri).toString());
case 'data':
case 'http':
case 'https':
return uri.toString();
default:
// Only handling file, http, and package URIs
// in standalone binary.
if (_traceLoading) {
_log('Unknown scheme (${uri.scheme}) in $uri.');
}
throw 'Not a known scheme: $uri';
}
}

// Register callbacks and hooks with the rest of the core libraries.
@pragma("vm:entry-point")
_setupHooks() {
_setupCompleted = true;
VMLibraryHooks.resourceReadAsBytes = _resourceReadAsBytes;

VMLibraryHooks.packageRootUriFuture = _getPackageRootFuture;
VMLibraryHooks.packageConfigUriFuture = _getPackageConfigFuture;
VMLibraryHooks.resolvePackageUriFuture = _resolvePackageUriFuture;
}

// Handling of Resource class by dispatching to the load port.
Future<List<int>> _resourceReadAsBytes(Uri uri) async {
List response =
await _makeLoaderRequest<List<int>>(_Dart_kResourceLoad, uri.toString());
if (response[4] is String) {
// Throw the error.
throw response[4];
} else {
return response[4];
}
}

// TODO(mfairhurst): remove this
Future<Uri> _getPackageRootFuture() {
if (_traceLoading) {
_log("Request for package root from user code.");
}
// Return null, as the `packages/` directory is not supported in dart 2.
return new Future.value(null);
}

Future<Uri> _getPackageConfigFuture() {
if (_traceLoading) {
_log("Request for package config from user code.");
Expand Down
6 changes: 1 addition & 5 deletions sdk_nnbd/lib/_internal/vm/lib/isolate_patch.dart
Original file line number Diff line number Diff line change
Expand Up @@ -327,11 +327,7 @@ class Isolate {

@patch
static Future<Uri> get packageRoot {
var hook = VMLibraryHooks.packageRootUriFuture;
if (hook == null) {
throw new UnsupportedError("Isolate.packageRoot");
}
return hook();
return null;
}

@patch
Expand Down

0 comments on commit 5ff9a2e

Please sign in to comment.