Skip to content

Commit

Permalink
[vm] Don't write LibraryPrefix::importer_ in AOT snapshots.
Browse files Browse the repository at this point in the history
This field won't be used at runtime and is not accounted for during tree-shaking.

Bug: dart-lang#41974
Bug: dart-lang#43245
Change-Id: Ie5a669608e896aa8cee74a3a4249ba99ec6f980a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/161220
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
  • Loading branch information
rmacnak-google authored and commit-bot@chromium.org committed Sep 1, 2020
1 parent c3298e5 commit c1bb9a5
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 4 deletions.
9 changes: 5 additions & 4 deletions runtime/vm/raw_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -2143,15 +2143,16 @@ class LibraryPrefixLayout : public InstanceLayout {

VISIT_FROM(ObjectPtr, name_)
StringPtr name_; // Library prefix name.
LibraryPtr importer_; // Library which declares this prefix.
ArrayPtr imports_; // Libraries imported with this prefix.
VISIT_TO(ObjectPtr, imports_)
LibraryPtr importer_; // Library which declares this prefix.
VISIT_TO(ObjectPtr, importer_)
ObjectPtr* to_snapshot(Snapshot::Kind kind) {
switch (kind) {
case Snapshot::kFull:
case Snapshot::kFullJIT:
case Snapshot::kFullAOT:
return reinterpret_cast<ObjectPtr*>(&imports_);
case Snapshot::kFull:
case Snapshot::kFullJIT:
return reinterpret_cast<ObjectPtr*>(&importer_);
case Snapshot::kMessage:
case Snapshot::kNone:
case Snapshot::kInvalid:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Copyright (c) 2020, 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.

@pragma("vm:never-inline")
bar() {
return "bar";
}
11 changes: 11 additions & 0 deletions tests/language/deferred/prefix_importer_tree_shaken_immediate.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright (c) 2020, 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 "prefix_importer_tree_shaken_deferred.dart" deferred as d;

@pragma("vm:prefer-inline")
load() => d.loadLibrary();

@pragma("vm:prefer-inline")
foo() => d.bar();
13 changes: 13 additions & 0 deletions tests/language/deferred/prefix_importer_tree_shaken_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright (c) 2020, 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.

/// VMOptions=--dwarf_stack_traces=true
/// VMOptions=--dwarf_stack_traces=false
import "prefix_importer_tree_shaken_immediate.dart" as i;

main() async {
await i.load();
print(await i.foo());
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Copyright (c) 2020, 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.

@pragma("vm:never-inline")
bar() {
return "bar";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright (c) 2020, 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 "prefix_importer_tree_shaken_deferred.dart" deferred as d;

@pragma("vm:prefer-inline")
load() => d.loadLibrary();

@pragma("vm:prefer-inline")
foo() => d.bar();
13 changes: 13 additions & 0 deletions tests/language_2/deferred/prefix_importer_tree_shaken_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright (c) 2020, 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.

/// VMOptions=--dwarf_stack_traces=true
/// VMOptions=--dwarf_stack_traces=false
import "prefix_importer_tree_shaken_immediate.dart" as i;

main() async {
await i.load();
print(await i.foo());
}

0 comments on commit c1bb9a5

Please sign in to comment.