Skip to content

Commit 44f8e21

Browse files
sigmundchCommit Queue
authored andcommitted
[kernel] Adds helper to trim dill files for modular dependencies.
Introduce a helper library to trim components based on what we believe it is needed for modular bytecode compilation. The script is configured to accept a set of entry points, so unreachable libraries can be removed entirely. The contents of the retained libraries is trimmed to remove method bodies, constructor bodies, and initializers, except for where they may be needed. In the near future, this should be expanded to: * include proper unit testing in the CFE * review whether additional trimming operations can be made * consider an explicit representation of trimmed content, to help the CFE recover when assumptions are not met (e.g. sentinel markers to establish whether a value has been trimmed) * CFE produces trimmed data directly if needed, without having to first produce the full dill. Tests that specifically stress that we don't over-trim include: apply_mixin (requires preserving method bodies), const_body (requires preserving initializers). TEST=existing and new e2e dynamic module aot tests. b/394936876 Change-Id: I26db8385bdfe1664b2aea234ec8bb896c7c21230 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/418702 Reviewed-by: Alexander Markov <[email protected]> Commit-Queue: Sigmund Cherem <[email protected]> Reviewed-by: Johnni Winther <[email protected]>
1 parent b46ee2c commit 44f8e21

File tree

17 files changed

+498
-14
lines changed

17 files changed

+498
-14
lines changed

pkg/dynamic_modules/pubspec.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,7 @@ resolution: workspace
1111
dev_dependencies:
1212
args: any
1313
expect: any
14+
front_end: any
15+
kernel: any
1416
lints: any
17+
vm: any
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Copyright (c) 2024, 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+
callable:
6+
- library: 'shared/shared.dart'
7+
class: 'B'
8+
member: ''
9+
# TODO(sigmund): This should be included by default
10+
- library: 'dart:core'
11+
class: 'Object'
12+
- library: 'dart:core'
13+
class: 'pragma'
14+
member: '_'
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright (c) 2025, 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+
import '../../common/testing.dart' as helper;
6+
import 'shared/shared.dart';
7+
8+
import 'package:expect/expect.dart';
9+
10+
// Constants with a constructor body can be used from dynamic modules.
11+
void main() async {
12+
final c1 = (await helper.load('entry1.dart'));
13+
final c2 = (await helper.load('entry2.dart'));
14+
15+
Expect.identical((c1 as B).x, 2);
16+
Expect.identical(c1, c2);
17+
helper.done();
18+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Copyright (c) 2025, 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+
import '../shared/shared.dart';
6+
7+
@pragma('dyn-module:entry-point')
8+
Object? dynamicModuleEntrypoint() => const B(1);
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Copyright (c) 2025, 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+
import '../shared/shared.dart';
6+
7+
@pragma('dyn-module:entry-point')
8+
Object? dynamicModuleEntrypoint() => const B(1);
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Copyright (c) 2025, 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+
class B {
6+
final int x;
7+
const B(int y) : x = y + 1;
8+
}

pkg/dynamic_modules/test/data/shared_const/dynamic_interface.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# BSD-style license that can be found in the LICENSE file.
44

55
callable:
6-
- library: 'main.dart'
6+
- library: 'shared/shared.dart'
77
class: 'B'
88
member: ''
99
# TODO(sigmund): This should be included by default

pkg/dynamic_modules/test/data/shared_const/main.dart

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,16 @@
33
// BSD-style license that can be found in the LICENSE file.
44

55
import '../../common/testing.dart' as helper;
6-
import 'package:expect/expect.dart';
6+
import 'shared/shared.dart';
77

8-
class B {
9-
final int x;
10-
const B(this.x);
11-
}
8+
import 'package:expect/expect.dart';
129

13-
// Similar to `isolated_shared`, constant canonicalization distinguishes
14-
// two constnats, even if they are created from a common library that was
15-
// not part of the original application.
10+
// Constants are properly canonicalized across dynamic modules.
1611
void main() async {
1712
final c1 = (await helper.load('entry1.dart'));
1813
final c2 = (await helper.load('entry2.dart'));
1914

15+
Expect.identical((c1 as B).x, 1);
2016
Expect.identical(c1, c2);
2117
helper.done();
2218
}

pkg/dynamic_modules/test/data/shared_const/modules/entry1.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
import '../main.dart';
5+
import '../shared/shared.dart';
66

77
@pragma('dyn-module:entry-point')
88
Object? dynamicModuleEntrypoint() => const B(1);

pkg/dynamic_modules/test/data/shared_const/modules/entry2.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
import '../main.dart';
5+
import '../shared/shared.dart';
66

77
@pragma('dyn-module:entry-point')
88
Object? dynamicModuleEntrypoint() => const B(1);

0 commit comments

Comments
 (0)