Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(221)

Side by Side Diff: dart/tests/compiler/dart2js/mirrors_used_test.dart

Issue 22896003: Only retain needed metadata constants. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fix copyAll bug Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « dart/sdk/lib/_internal/compiler/implementation/js_backend/backend.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 /// Test that the @MirrorsUsed annotation suppress hints and that only 5 /// Test that the @MirrorsUsed annotation suppress hints and that only
6 /// requested elements are retained for reflection. 6 /// requested elements are retained for reflection.
7 library dart2js.test.mirrors_used_test; 7 library dart2js.test.mirrors_used_test;
8 8
9 import 'package:expect/expect.dart'; 9 import 'package:expect/expect.dart';
10 10
11 import 'memory_compiler.dart' show 11 import 'memory_compiler.dart' show
12 compilerFor; 12 compilerFor;
13 13
14 import '../../../sdk/lib/_internal/compiler/implementation/apiimpl.dart' show 14 import '../../../sdk/lib/_internal/compiler/implementation/apiimpl.dart' show
15 Compiler; 15 Compiler;
16 16
17 import '../../../sdk/lib/_internal/compiler/implementation/dart2jslib.dart' show 17 import '../../../sdk/lib/_internal/compiler/implementation/dart2jslib.dart' show
18 SourceString; 18 Constant,
19 SourceString,
20 TypeConstant;
19 21
20 import 22 import
21 '../../../sdk/lib/_internal/compiler/implementation/elements/elements.dart' 23 '../../../sdk/lib/_internal/compiler/implementation/elements/elements.dart'
22 show 24 show
23 Elements; 25 Elements;
24 26
25 void expectOnlyVerboseInfo(Uri uri, int begin, int end, String message, kind) { 27 void expectOnlyVerboseInfo(Uri uri, int begin, int end, String message, kind) {
26 if (kind.name == 'verbose info') { 28 if (kind.name == 'verbose info') {
27 print(message); 29 print(message);
28 return; 30 return;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 Expect.isTrue( 79 Expect.isTrue(
78 compiler.backend.isNeededForReflection(classMember), 80 compiler.backend.isNeededForReflection(classMember),
79 '$classMember'); 81 '$classMember');
80 }); 82 });
81 } else { 83 } else {
82 Expect.isFalse( 84 Expect.isFalse(
83 compiler.backend.isNeededForReflection(member), '$member'); 85 compiler.backend.isNeededForReflection(member), '$member');
84 } 86 }
85 }); 87 });
86 } 88 }
89
90 // There should at least be three metadata constants:
91 // 1. The type literal 'Foo'.
92 // 2. The list 'const [Foo]'.
93 // 3. The constructed constant for 'MirrorsUsed'.
94 Expect.isTrue(compiler.metadataHandler.compiledConstants.length >= 3);
95
96 // Make sure that most of the metadata constants aren't included in the
97 // generated code.
98 for (Constant constant in compiler.metadataHandler.compiledConstants) {
99 if (constant is TypeConstant && '${constant.representedType}' == 'Foo') {
100 // The type literal 'Foo' is retained as a constant because it is being
101 // passed to reflectClass.
102 continue;
103 }
104 Expect.isFalse(
105 compiler.constantHandler.compiledConstants.contains(constant),
106 '$constant');
107 }
108
109 // The type literal 'Foo' is both used as metadata, and as a plain value in
110 // the program. Make sure that it isn't duplicated.
111 int fooConstantCount = 0;
112 for (Constant constant in compiler.metadataHandler.compiledConstants) {
113 if (constant is TypeConstant && '${constant.representedType}' == 'Foo') {
114 fooConstantCount++;
115 }
116 }
117 Expect.equals(
118 1, fooConstantCount, "The type literal 'Foo' is duplicated or missing.");
87 } 119 }
88 120
89 const MEMORY_SOURCE_FILES = const <String, String> { 121 const MEMORY_SOURCE_FILES = const <String, String> {
90 'main.dart': """ 122 'main.dart': """
91 @MirrorsUsed(targets: const [Foo], override: '*') 123 @MirrorsUsed(targets: const [Foo], override: '*')
92 import 'dart:mirrors'; 124 import 'dart:mirrors';
93 125
94 import 'library.dart'; 126 import 'library.dart';
95 127
96 class Foo { 128 class Foo {
(...skipping 13 matching lines...) Expand all
110 library lib; 142 library lib;
111 143
112 import 'dart:mirrors'; 144 import 'dart:mirrors';
113 145
114 useReflect(type) { 146 useReflect(type) {
115 print(new Symbol('Foo')); 147 print(new Symbol('Foo'));
116 print(MirrorSystem.getName(reflectClass(type).owner.qualifiedName)); 148 print(MirrorSystem.getName(reflectClass(type).owner.qualifiedName));
117 } 149 }
118 """, 150 """,
119 }; 151 };
OLDNEW
« no previous file with comments | « dart/sdk/lib/_internal/compiler/implementation/js_backend/backend.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698