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

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

Issue 21242002: Retain elements a finer granularity than library. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Address review comments 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
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
(...skipping 30 matching lines...) Expand all
41 for (var element in generatedCode) { 41 for (var element in generatedCode) {
42 print(element); 42 print(element);
43 } 43 }
44 print(''); 44 print('');
45 45
46 // This assertion can fail for two reasons: 46 // This assertion can fail for two reasons:
47 // 1. Too many elements retained for reflection. 47 // 1. Too many elements retained for reflection.
48 // 2. Some code was refactored, and there are more methods. 48 // 2. Some code was refactored, and there are more methods.
49 // Either situation could be problematic, but in situation 2, it is often 49 // Either situation could be problematic, but in situation 2, it is often
50 // acceptable to increase [expectedMethodCount] a little. 50 // acceptable to increase [expectedMethodCount] a little.
51 int expectedMethodCount = 315; 51 int expectedMethodCount = 317;
52 Expect.isTrue( 52 Expect.isTrue(
53 generatedCode.length <= expectedMethodCount, 53 generatedCode.length <= expectedMethodCount,
54 'Too many compiled methods: ' 54 'Too many compiled methods: '
55 '${generatedCode.length} > $expectedMethodCount'); 55 '${generatedCode.length} > $expectedMethodCount');
56 56
57 for (var library in compiler.libraries.values) { 57 for (var library in compiler.libraries.values) {
58 library.forEachLocalMember((member) { 58 library.forEachLocalMember((member) {
59 if (library == compiler.mainApp) { 59 if (library == compiler.mainApp
60 // TODO(ahe): We currently retain the entire library. Update this test 60 && member.name == const SourceString('Foo')) {
61 // to test that only Foo is retained.
62 Expect.isTrue( 61 Expect.isTrue(
63 compiler.backend.isNeededForReflection(member), '$member'); 62 compiler.backend.isNeededForReflection(member), '$member');
63 member.forEachLocalMember((classMember) {
64 Expect.isTrue(
65 compiler.backend.isNeededForReflection(classMember),
66 '$classMember');
67 });
64 } else { 68 } else {
65 Expect.isFalse( 69 Expect.isFalse(
66 compiler.backend.isNeededForReflection(member), '$member'); 70 compiler.backend.isNeededForReflection(member), '$member');
67 } 71 }
68 }); 72 });
69 } 73 }
70 } 74 }
71 75
72 const MEMORY_SOURCE_FILES = const <String, String> { 76 const MEMORY_SOURCE_FILES = const <String, String> {
73 'main.dart': """ 77 'main.dart': """
74 @MirrorsUsed(targets: const [Foo], override: '*') 78 @MirrorsUsed(targets: const [Foo], override: '*')
75 import 'dart:mirrors'; 79 import 'dart:mirrors';
76 80
77 import 'library.dart'; 81 import 'library.dart';
78 82
79 class Foo {} 83 class Foo {
84 int field;
85 instanceMethod() {}
86 static staticMethod() {}
87 }
88
89 unusedFunction() {
90 }
80 91
81 main() { 92 main() {
82 useReflect(Foo); 93 useReflect(Foo);
83 } 94 }
84 """, 95 """,
85 'library.dart': """ 96 'library.dart': """
86 library lib; 97 library lib;
87 98
88 import 'dart:mirrors'; 99 import 'dart:mirrors';
89 100
90 useReflect(type) { 101 useReflect(type) {
91 print(new Symbol('Foo')); 102 print(new Symbol('Foo'));
92 print(MirrorSystem.getName(reflectClass(type).owner.qualifiedName)); 103 print(MirrorSystem.getName(reflectClass(type).owner.qualifiedName));
93 } 104 }
94 """, 105 """,
95 }; 106 };
OLDNEW
« no previous file with comments | « dart/tests/compiler/dart2js/message_kind_test.dart ('k') | dart/tests/compiler/dart2js/mock_compiler.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698