Skip to content

Commit 32b70ce

Browse files
mkustermanncommit-bot@chromium.org
authored andcommitted
[protobuf] Remove constants transformation from protobuf-aware treeshaker, ensure we always clean metadata
Change-Id: Ifb9e5bd3530ba6cfd78455f3ae380a36f60f31d2 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/112720 Reviewed-by: Sigurd Meldgaard <[email protected]> Commit-Queue: Martin Kustermann <[email protected]>
1 parent c912633 commit 32b70ce

File tree

2 files changed

+20
-20
lines changed

2 files changed

+20
-20
lines changed

pkg/vm/lib/transformations/protobuf_aware_treeshaker/transformer.dart

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,9 @@
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 'package:front_end/src/api_prototype/constant_evaluator.dart'
6-
as constants;
75
import 'package:kernel/kernel.dart';
86
import 'package:kernel/target/targets.dart';
97
import 'package:kernel/core_types.dart';
10-
import 'package:kernel/vm/constants_native_effects.dart' as vm_constants;
118
import 'package:meta/meta.dart';
129
import 'package:vm/transformations/type_flow/transformer.dart' as globalTypeFlow
1310
show transformComponent;
@@ -25,14 +22,6 @@ TransformationInfo transformComponent(
2522
final coreTypes = new CoreTypes(component);
2623
component.computeCanonicalNames();
2724

28-
// Evaluate constants to ensure @pragma("vm:entry-point") is seen by the
29-
// type-flow analysis.
30-
final vmConstants = new vm_constants.VmConstantsBackend(coreTypes);
31-
constants.transformComponent(component, vmConstants, environment, null,
32-
keepFields: true,
33-
evaluateAnnotations: true,
34-
desugarSets: !target.supportsSetLiterals);
35-
3625
TransformationInfo info = collectInfo ? TransformationInfo() : null;
3726

3827
_treeshakeProtos(target, component, coreTypes, info);
@@ -42,19 +31,21 @@ TransformationInfo transformComponent(
4231
void _treeshakeProtos(Target target, Component component, CoreTypes coreTypes,
4332
TransformationInfo info) {
4433
globalTypeFlow.transformComponent(target, coreTypes, component);
34+
4535
final collector = removeUnusedProtoReferences(component, coreTypes, info);
46-
if (collector == null) {
47-
return;
48-
}
49-
globalTypeFlow.transformComponent(target, coreTypes, component);
50-
if (info != null) {
51-
for (Class gmSubclass in collector.gmSubclasses) {
52-
if (!gmSubclass.enclosingLibrary.classes.contains(gmSubclass)) {
53-
info.removedMessageClasses.add(gmSubclass);
36+
if (collector != null) {
37+
globalTypeFlow.transformComponent(target, coreTypes, component);
38+
if (info != null) {
39+
for (Class gmSubclass in collector.gmSubclasses) {
40+
if (!gmSubclass.enclosingLibrary.classes.contains(gmSubclass)) {
41+
info.removedMessageClasses.add(gmSubclass);
42+
}
5443
}
5544
}
5645
}
57-
// Remove metadata added by the typeflow analysis.
46+
47+
// Remove metadata added by the typeflow analysis (even if the code doesn't
48+
// use any protos).
5849
component.metadata.clear();
5950
}
6051

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Copyright (c) 2019, 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+
main() {
6+
// Ensures the protobuf-aware tree shaker can also transform non-protobuf
7+
// using code.
8+
print("hello world");
9+
}

0 commit comments

Comments
 (0)