Skip to content

Commit 3e4a1de

Browse files
jensjohacommit-bot@chromium.org
authored andcommitted
Use dart:foo-patch import uri for patches; remove VM workaround for sdk uris
Closes #32087. Change-Id: I93a757125bf29bc283bf6536fa5e53a4f9334891 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/97311 Commit-Queue: Jens Johansen <[email protected]> Reviewed-by: Vyacheslav Egorov <[email protected]>
1 parent cf76825 commit 3e4a1de

File tree

3 files changed

+17
-103
lines changed

3 files changed

+17
-103
lines changed

pkg/front_end/lib/src/fasta/source/source_loader.dart

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,11 +203,22 @@ class SourceLoader extends Loader<Library> {
203203
Token token = result.tokens;
204204
if (!suppressLexicalErrors) {
205205
List<int> source = getSource(bytes);
206+
Uri importUri = library.uri;
207+
if (library.isPatch) {
208+
// For patch files we create a "fake" import uri.
209+
// We cannot use the import uri from the patched libarary because
210+
// several different files would then have the same import uri,
211+
// and the VM does not support that. Also, what would, for instance,
212+
// setting a breakpoint on line 42 of some import uri mean, if the uri
213+
// represented several files?
214+
List<String> newPathSegments =
215+
new List<String>.from(importUri.pathSegments);
216+
newPathSegments.add(library.fileUri.pathSegments.last);
217+
newPathSegments[0] = "${newPathSegments[0]}-patch";
218+
importUri = importUri.replace(pathSegments: newPathSegments);
219+
}
206220
target.addSourceInformation(
207-
library.isPatch ? library.fileUri : library.uri,
208-
library.fileUri,
209-
result.lineStarts,
210-
source);
221+
importUri, library.fileUri, result.lineStarts, source);
211222
}
212223
while (token is ErrorToken) {
213224
if (!suppressLexicalErrors) {

runtime/vm/kernel_loader.cc

Lines changed: 2 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,11 +1018,9 @@ RawLibrary* KernelLoader::LoadLibrary(intptr_t index) {
10181018
library.SetLoadInProgress();
10191019
}
10201020

1021-
StringIndex import_uri_index =
1022-
H.CanonicalNameString(library_helper.canonical_name_);
10231021
library_helper.ReadUntilIncluding(LibraryHelper::kSourceUriIndex);
1024-
const Script& script = Script::Handle(
1025-
Z, ScriptAt(library_helper.source_uri_index_, library, import_uri_index));
1022+
const Script& script =
1023+
Script::Handle(Z, ScriptAt(library_helper.source_uri_index_));
10261024

10271025
library_helper.ReadUntilExcluding(LibraryHelper::kAnnotations);
10281026
intptr_t annotations_kernel_offset =
@@ -1357,80 +1355,6 @@ void KernelLoader::LoadPreliminaryClass(ClassHelper* class_helper,
13571355
}
13581356
}
13591357

1360-
// Workaround for http://dartbug.com/32087: currently Kernel front-end
1361-
// embeds absolute build-time paths to core library sources into Kernel
1362-
// binaries this introduces discrepancy between how stack traces were
1363-
// looked like in legacy pipeline and how they look in Dart 2 pipeline and
1364-
// breaks users' code that attempts to pattern match and filter various
1365-
// irrelevant frames (e.g. frames from dart:async).
1366-
// This also breaks debugging experience in external debuggers because
1367-
// debugger attempts to open files that don't exist in the local file
1368-
// system.
1369-
// To work around this issue we reformat urls of scripts belonging to
1370-
// dart:-scheme libraries to look like they looked like in legacy pipeline:
1371-
//
1372-
// dart:libname/filename.dart
1373-
// dart:libname/runtime/lib/filename.dart
1374-
// dart:libname/runtime/bin/filename.dart
1375-
//
1376-
void KernelLoader::FixCoreLibraryScriptUri(const Library& library,
1377-
const Script& script) {
1378-
struct Helper {
1379-
static bool EndsWithCString(const String& haystack,
1380-
const char* needle,
1381-
intptr_t needle_length,
1382-
intptr_t end_pos) {
1383-
const intptr_t start = end_pos - needle_length + 1;
1384-
if (start >= 0) {
1385-
for (intptr_t i = 0; i < needle_length; i++) {
1386-
if (haystack.CharAt(start + i) != needle[i]) {
1387-
return false;
1388-
}
1389-
}
1390-
return true;
1391-
}
1392-
return false;
1393-
}
1394-
};
1395-
1396-
if (library.is_dart_scheme()) {
1397-
String& url = String::Handle(zone_, script.url());
1398-
if (!url.StartsWith(Symbols::DartScheme())) {
1399-
// Search backwards until '/' is found. That gives us the filename.
1400-
// Note: can't use reusable handle in the code below because
1401-
// concat also needs it.
1402-
intptr_t pos = url.Length() - 1;
1403-
while (pos >= 0 && url.CharAt(pos) != '/') {
1404-
pos--;
1405-
}
1406-
1407-
static const char* kRuntimeLib = "runtime/lib/";
1408-
static const intptr_t kRuntimeLibLen = strlen(kRuntimeLib);
1409-
const bool inside_runtime_lib =
1410-
Helper::EndsWithCString(url, kRuntimeLib, kRuntimeLibLen, pos);
1411-
1412-
static const char* kRuntimeBin = "runtime/bin/";
1413-
static const intptr_t kRuntimeBinLen = strlen(kRuntimeBin);
1414-
const bool inside_runtime_bin =
1415-
Helper::EndsWithCString(url, kRuntimeBin, kRuntimeBinLen, pos);
1416-
1417-
String& tmp = String::Handle(zone_);
1418-
url = String::SubString(url, pos + 1);
1419-
if (inside_runtime_lib) {
1420-
tmp = String::New(kRuntimeLib, Heap::kNew);
1421-
url = String::Concat(tmp, url);
1422-
} else if (inside_runtime_bin) {
1423-
tmp = String::New(kRuntimeBin, Heap::kNew);
1424-
url = String::Concat(tmp, url);
1425-
}
1426-
tmp = library.url();
1427-
url = String::Concat(Symbols::Slash(), url);
1428-
url = String::Concat(tmp, url);
1429-
script.set_url(url);
1430-
}
1431-
}
1432-
}
1433-
14341358
void KernelLoader::LoadClass(const Library& library,
14351359
const Class& toplevel_class,
14361360
intptr_t class_end,
@@ -1452,7 +1376,6 @@ void KernelLoader::LoadClass(const Library& library,
14521376
const Script& script =
14531377
Script::Handle(Z, ScriptAt(class_helper.source_uri_index_));
14541378
out_class->set_script(script);
1455-
FixCoreLibraryScriptUri(library, script);
14561379
}
14571380
if (out_class->token_pos() == TokenPosition::kNoSource) {
14581381
class_helper.ReadUntilIncluding(ClassHelper::kStartPosition);
@@ -2011,7 +1934,6 @@ const Object& KernelLoader::ClassForScriptAt(const Class& klass,
20111934
patch_class ^= patch_classes_.At(source_uri_index);
20121935
if (patch_class.IsNull() || patch_class.origin_class() != klass.raw()) {
20131936
ASSERT(!library_kernel_data_.IsNull());
2014-
FixCoreLibraryScriptUri(Library::Handle(klass.library()), correct_script);
20151937
patch_class = PatchClass::New(klass, correct_script);
20161938
patch_class.set_library_kernel_data(library_kernel_data_);
20171939
patch_class.set_library_kernel_offset(library_kernel_offset_);
@@ -2078,20 +2000,6 @@ RawScript* KernelLoader::LoadScriptAt(intptr_t index,
20782000
return script.raw();
20792001
}
20802002

2081-
RawScript* KernelLoader::ScriptAt(intptr_t index,
2082-
const Library& library,
2083-
StringIndex import_uri) {
2084-
ASSERT(!library.IsNull());
2085-
const Script& script =
2086-
Script::Handle(Z, kernel_program_info_.ScriptAt(index));
2087-
if (library.is_dart_scheme()) {
2088-
FixCoreLibraryScriptUri(library, script);
2089-
} else if (import_uri != -1) {
2090-
script.set_url(H.DartString(import_uri, Heap::kOld));
2091-
}
2092-
return script.raw();
2093-
}
2094-
20952003
void KernelLoader::GenerateFieldAccessors(const Class& klass,
20962004
const Field& field,
20972005
FieldHelper* field_helper) {

runtime/vm/kernel_loader.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -294,8 +294,6 @@ class KernelLoader : public ValueObject {
294294
void ReadInferredType(const Field& field, intptr_t kernel_offset);
295295
void CheckForInitializer(const Field& field);
296296

297-
void FixCoreLibraryScriptUri(const Library& library, const Script& script);
298-
299297
void LoadClass(const Library& library,
300298
const Class& toplevel_class,
301299
intptr_t class_end,
@@ -327,9 +325,6 @@ class KernelLoader : public ValueObject {
327325
RawScript* ScriptAt(intptr_t source_uri_index) {
328326
return kernel_program_info_.ScriptAt(source_uri_index);
329327
}
330-
RawScript* ScriptAt(intptr_t source_uri_index,
331-
const Library& lib,
332-
StringIndex import_uri);
333328

334329
void GenerateFieldAccessors(const Class& klass,
335330
const Field& field,

0 commit comments

Comments
 (0)