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

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

Issue 14120008: Add special rules in the inferrer that some int operations return an int. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 8 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 | « tests/compiler/dart2js/mock_compiler.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 import 'package:expect/expect.dart'; 5 import 'package:expect/expect.dart';
6 import 6 import
7 '../../../sdk/lib/_internal/compiler/implementation/types/types.dart' 7 '../../../sdk/lib/_internal/compiler/implementation/types/types.dart'
8 show TypeMask; 8 show TypeMask;
9 9
10 import 'compiler_helper.dart'; 10 import 'compiler_helper.dart';
(...skipping 23 matching lines...) Expand all
34 returnGiveUp(a) { 34 returnGiveUp(a) {
35 if (a) return 1; 35 if (a) return 1;
36 else return 'foo'; 36 else return 'foo';
37 } 37 }
38 38
39 returnInt2() { 39 returnInt2() {
40 var a = 42; 40 var a = 42;
41 return a++; 41 return a++;
42 } 42 }
43 43
44 returnNum3() { 44 returnInt5() {
45 var a = 42; 45 var a = 42;
46 return ++a; 46 return ++a;
47 } 47 }
48 48
49 returnNum4() { 49 returnInt6() {
50 var a = 42; 50 var a = 42;
51 a++; 51 a++;
52 return a; 52 return a;
53 } 53 }
54 54
55 returnIntOrNull(a) { 55 returnIntOrNull(a) {
56 if (a) return 42; 56 if (a) return 42;
57 } 57 }
58 58
59 returnInt3(a) { 59 returnInt3(a) {
60 if (a) return 42; 60 if (a) return 42;
61 throw 42; 61 throw 42;
62 } 62 }
63 63
64 returnInt4() { 64 returnInt4() {
65 return (42); 65 return (42);
66 } 66 }
67 67
68 returnInt7() {
69 return 42.abs();
70 }
71
72 returnInt8() {
73 return 42.remainder(54);
74 }
75
76 returnDynamic1() {
77 // Ensure that we don't intrisify a wrong call to [int.remainder].
78 return 42.remainder();
79 }
80
81 returnDynamic2() {
82 // Ensure that we don't intrisify a wrong call to [int.abs].
83 return 42.abs(42);
84 }
85
68 get topLevelGetter => 42; 86 get topLevelGetter => 42;
69 returnDynamic() => topLevelGetter(42); 87 returnDynamic() => topLevelGetter(42);
70 88
71 class A { 89 class A {
72 factory A() = A.generative; 90 factory A() = A.generative;
73 A.generative(); 91 A.generative();
74 operator==(other) => 42; 92 operator==(other) => 42;
75 93
76 get myField => 42; 94 get myField => 42;
77 set myField(a) {} 95 set myField(a) {}
78 returnNum1() => ++myField; 96 returnInt1() => ++myField;
79 returnNum2() => ++this.myField; 97 returnInt2() => ++this.myField;
80 returnNum3() => this.myField += 42; 98 returnInt3() => this.myField += 42;
81 returnNum4() => myField += 42; 99 returnInt4() => myField += 42;
82 operator[](index) => 42; 100 operator[](index) => 42;
83 operator[]= (index, value) {} 101 operator[]= (index, value) {}
84 returnNum5() => ++this[0]; 102 returnInt5() => ++this[0];
85 returnNum6() => this[0] += 1; 103 returnInt6() => this[0] += 1;
86 } 104 }
87 105
88 class B extends A { 106 class B extends A {
89 B() : super.generative(); 107 B() : super.generative();
90 returnNum1() => ++new A().myField; 108 returnInt1() => ++new A().myField;
91 returnNum2() => new A().myField += 4; 109 returnInt2() => new A().myField += 4;
92 returnNum3() => ++new A()[0]; 110 returnInt3() => ++new A()[0];
93 returnNum4() => new A()[0] += 42; 111 returnInt4() => new A()[0] += 42;
94 returnNum5() => ++super.myField; 112 returnInt5() => ++super.myField;
95 returnNum6() => super.myField += 4; 113 returnInt6() => super.myField += 4;
96 returnNum7() => ++super[0]; 114 returnInt7() => ++super[0];
97 returnNum8() => super[0] += 54; 115 returnInt8() => super[0] += 54;
98 } 116 }
99 117
100 main() { 118 main() {
101 returnNum1(true); 119 returnNum1(true);
102 returnNum2(true); 120 returnNum2(true);
103 returnInt1(true); 121 returnInt1(true);
104 returnInt2(true); 122 returnInt2(true);
105 returnInt3(true); 123 returnInt3(true);
106 returnInt4(); 124 returnInt4();
107 returnDouble(true); 125 returnDouble(true);
108 returnGiveUp(true); 126 returnGiveUp(true);
109 returnNum3(); 127 returnInt5();
110 returnNum4(); 128 returnInt6();
129 returnInt7();
130 returnInt8();
111 returnIntOrNull(true); 131 returnIntOrNull(true);
112 returnDynamic(); 132 returnDynamic();
133 returnDynamic1();
134 returnDynamic2();
113 new A() == null; 135 new A() == null;
114 new A()..returnNum1() 136 new A()..returnInt1()
115 ..returnNum2() 137 ..returnInt2()
116 ..returnNum3() 138 ..returnInt3()
117 ..returnNum4() 139 ..returnInt4()
118 ..returnNum5() 140 ..returnInt5()
119 ..returnNum6(); 141 ..returnInt6();
120 142
121 new B()..returnNum1() 143 new B()..returnInt1()
122 ..returnNum2() 144 ..returnInt2()
123 ..returnNum3() 145 ..returnInt3()
124 ..returnNum4() 146 ..returnInt4()
125 ..returnNum5() 147 ..returnInt5()
126 ..returnNum6() 148 ..returnInt6()
127 ..returnNum7() 149 ..returnInt7()
128 ..returnNum8(); 150 ..returnInt8();
129 } 151 }
130 """; 152 """;
131 153
132 void main() { 154 void main() {
133 Uri uri = new Uri.fromComponents(scheme: 'source'); 155 Uri uri = new Uri.fromComponents(scheme: 'source');
134 var compiler = compilerFor(TEST, uri); 156 var compiler = compilerFor(TEST, uri);
135 compiler.runCompiler(uri); 157 compiler.runCompiler(uri);
136 var typesInferrer = compiler.typesTask.typesInferrer; 158 var typesInferrer = compiler.typesTask.typesInferrer;
137 159
138 checkReturn(String name, type) { 160 checkReturn(String name, type) {
139 var element = findElement(compiler, name); 161 var element = findElement(compiler, name);
140 Expect.equals(type, typesInferrer.internal.returnTypeOf[element], name); 162 Expect.equals(type, typesInferrer.internal.returnTypeOf[element], name);
141 } 163 }
142 var interceptorType = 164 var interceptorType =
143 findTypeMask(compiler, 'Interceptor', 'nonNullSubclass'); 165 findTypeMask(compiler, 'Interceptor', 'nonNullSubclass');
144 166
145 checkReturn('returnNum1', typesInferrer.numType); 167 checkReturn('returnNum1', typesInferrer.numType);
146 checkReturn('returnNum2', typesInferrer.numType); 168 checkReturn('returnNum2', typesInferrer.numType);
147 checkReturn('returnInt1', typesInferrer.intType); 169 checkReturn('returnInt1', typesInferrer.intType);
148 checkReturn('returnInt2', typesInferrer.intType); 170 checkReturn('returnInt2', typesInferrer.intType);
149 checkReturn('returnDouble', typesInferrer.doubleType); 171 checkReturn('returnDouble', typesInferrer.doubleType);
150 checkReturn('returnGiveUp', interceptorType); 172 checkReturn('returnGiveUp', interceptorType);
151 checkReturn('returnNum3', typesInferrer.numType); 173 checkReturn('returnInt5', typesInferrer.intType);
152 checkReturn('returnNum4', typesInferrer.numType); 174 checkReturn('returnInt6', typesInferrer.intType);
153 checkReturn('returnIntOrNull', typesInferrer.intType.nullable()); 175 checkReturn('returnIntOrNull', typesInferrer.intType.nullable());
154 checkReturn('returnInt3', typesInferrer.intType); 176 checkReturn('returnInt3', typesInferrer.intType);
155 checkReturn('returnDynamic', typesInferrer.dynamicType); 177 checkReturn('returnDynamic', typesInferrer.dynamicType);
156 checkReturn('returnInt4', typesInferrer.intType); 178 checkReturn('returnInt4', typesInferrer.intType);
179 checkReturn('returnInt7', typesInferrer.intType);
180 checkReturn('returnInt8', typesInferrer.intType);
181 checkReturn('returnDynamic1', typesInferrer.dynamicType);
182 checkReturn('returnDynamic2', typesInferrer.dynamicType);
157 183
158 checkReturnInClass(String className, String methodName, type) { 184 checkReturnInClass(String className, String methodName, type) {
159 var cls = findElement(compiler, className); 185 var cls = findElement(compiler, className);
160 var element = cls.lookupLocalMember(buildSourceString(methodName)); 186 var element = cls.lookupLocalMember(buildSourceString(methodName));
161 Expect.equals(type, typesInferrer.internal.returnTypeOf[element]); 187 Expect.equals(type, typesInferrer.internal.returnTypeOf[element]);
162 } 188 }
163 189
164 checkReturnInClass('A', 'returnNum1', typesInferrer.numType); 190 checkReturnInClass('A', 'returnInt1', typesInferrer.intType);
165 checkReturnInClass('A', 'returnNum2', typesInferrer.numType); 191 checkReturnInClass('A', 'returnInt2', typesInferrer.intType);
166 checkReturnInClass('A', 'returnNum3', typesInferrer.numType); 192 checkReturnInClass('A', 'returnInt3', typesInferrer.intType);
167 checkReturnInClass('A', 'returnNum4', typesInferrer.numType); 193 checkReturnInClass('A', 'returnInt4', typesInferrer.intType);
168 checkReturnInClass('A', 'returnNum5', typesInferrer.numType); 194 checkReturnInClass('A', 'returnInt5', typesInferrer.intType);
169 checkReturnInClass('A', 'returnNum6', typesInferrer.numType); 195 checkReturnInClass('A', 'returnInt6', typesInferrer.intType);
170 checkReturnInClass('A', '==', interceptorType); 196 checkReturnInClass('A', '==', interceptorType);
171 197
172 checkReturnInClass('B', 'returnNum1', typesInferrer.numType); 198 checkReturnInClass('B', 'returnInt1', typesInferrer.intType);
173 checkReturnInClass('B', 'returnNum2', typesInferrer.numType); 199 checkReturnInClass('B', 'returnInt2', typesInferrer.intType);
174 checkReturnInClass('B', 'returnNum3', typesInferrer.numType); 200 checkReturnInClass('B', 'returnInt3', typesInferrer.intType);
175 checkReturnInClass('B', 'returnNum4', typesInferrer.numType); 201 checkReturnInClass('B', 'returnInt4', typesInferrer.intType);
176 checkReturnInClass('B', 'returnNum5', typesInferrer.numType); 202 checkReturnInClass('B', 'returnInt5', typesInferrer.intType);
177 checkReturnInClass('B', 'returnNum6', typesInferrer.numType); 203 checkReturnInClass('B', 'returnInt6', typesInferrer.intType);
178 checkReturnInClass('B', 'returnNum7', typesInferrer.numType); 204 checkReturnInClass('B', 'returnInt7', typesInferrer.intType);
179 checkReturnInClass('B', 'returnNum8', typesInferrer.numType); 205 checkReturnInClass('B', 'returnInt8', typesInferrer.intType);
180 206
181 checkFactoryConstructor(String className) { 207 checkFactoryConstructor(String className) {
182 var cls = findElement(compiler, className); 208 var cls = findElement(compiler, className);
183 var element = cls.localLookup(buildSourceString(className)); 209 var element = cls.localLookup(buildSourceString(className));
184 Expect.equals(new TypeMask.nonNullExact(cls.rawType), 210 Expect.equals(new TypeMask.nonNullExact(cls.rawType),
185 typesInferrer.internal.returnTypeOf[element]); 211 typesInferrer.internal.returnTypeOf[element]);
186 } 212 }
187 checkFactoryConstructor('A'); 213 checkFactoryConstructor('A');
188 } 214 }
OLDNEW
« no previous file with comments | « tests/compiler/dart2js/mock_compiler.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698