Skip to content

Commit 7b8b06d

Browse files
jensjohaCommit Bot
authored and
Commit Bot
committed
[CFE] Fix crash when serializing expression compilation procedure with deferred import
#48587 Change-Id: I37cc8313886d626edafbe04acfef90b0fe666622 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/238043 Reviewed-by: Johnni Winther <[email protected]> Commit-Queue: Jens Johansen <[email protected]>
1 parent cd10bb1 commit 7b8b06d

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed

pkg/front_end/lib/src/fasta/kernel/utils.dart

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,20 @@ Uint8List serializeComponent(Component component,
9696

9797
const String kDebugClassName = "#DebugClass";
9898

99+
class _CollectLibraryDependencies extends RecursiveVisitor {
100+
Set<LibraryDependency> foundLibraryDependencies = {};
101+
102+
@override
103+
void visitLoadLibrary(LoadLibrary node) {
104+
foundLibraryDependencies.add(node.import);
105+
}
106+
107+
@override
108+
void visitCheckLibraryIsLoaded(CheckLibraryIsLoaded node) {
109+
foundLibraryDependencies.add(node.import);
110+
}
111+
}
112+
99113
Component createExpressionEvaluationComponent(Procedure procedure) {
100114
Library realLibrary = procedure.enclosingLibrary;
101115

@@ -106,6 +120,17 @@ Component createExpressionEvaluationComponent(Procedure procedure) {
106120
..nonNullableByDefaultCompiledMode =
107121
realLibrary.nonNullableByDefaultCompiledMode;
108122

123+
// Add deferred library dependencies. They are needed for serializing
124+
// references to deferred libraries. We can just claim ownership of the ones
125+
// we find as they were created when doing the expression compilation.
126+
_CollectLibraryDependencies collectLibraryDependencies =
127+
new _CollectLibraryDependencies();
128+
procedure.accept(collectLibraryDependencies);
129+
for (LibraryDependency libraryDependency
130+
in collectLibraryDependencies.foundLibraryDependencies) {
131+
fakeLibrary.addDependency(libraryDependency);
132+
}
133+
109134
TreeNode? realClass = procedure.parent;
110135
if (realClass is Class) {
111136
Class fakeClass = new Class(name: kDebugClassName, fileUri: uri)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Copyright (c) 2018, 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+
# Check the expression compilation (including serialization) of usage of a
6+
# deferred import works.
7+
8+
sources:
9+
main.dart: |
10+
import 'import.dart' deferred as d;
11+
12+
void main() {
13+
print('hello');
14+
}
15+
16+
Future<void> printDeferred() async {
17+
d.deferredPrintLocal();
18+
}
19+
20+
import.dart: |
21+
void deferredPrintLocal() {
22+
print('hello from deferred library');
23+
}
24+
definitions: []
25+
position: "main.dart"
26+
expression: |
27+
d.deferredPrintLocal()
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Errors: {
2+
}
3+
method /* from org-dartlang-debug:synthetic_debug_expression */ debugExpr() → dynamic
4+
return let final dynamic #t1 = CheckLibraryIsLoaded(d) in #lib1::deferredPrintLocal();

0 commit comments

Comments
 (0)