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

Side by Side Diff: tests/compiler/dart2js/cps_ir/expected/optimize_indexers.js

Issue 1685893002: cpsir: insert guard and force specialization for [] and []= (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 10 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
OLDNEW
1 // Expectation for test: 1 // Expectation for test:
2 // // Method to test: function(test) 2 // // Method to test: function(test)
3 // import 'package:expect/expect.dart'; 3 // import 'package:expect/expect.dart';
4 // 4 //
5 // // This example illustrates a case we wish to do better in terms of inlining and 5 // // This example illustrates a case we wish to do better in terms of inlining and
6 // // code generation. 6 // // code generation.
7 // // 7 // //
8 // // Today this function is compiled without inlining Wrapper.[], JSArray.[] an d 8 // // Naively this function would be compiled without inlining Wrapper.[],
9 // // Wrapper.[]= because: 9 // // JSArray.[] and Wrapper.[]= because:
10 // // JSArray.[] is too big (14 nodes) 10 // // JSArray.[] is too big (14 nodes)
11 // // Wrapper.[] is too big if we force inlining of JSArray (15 nodes) 11 // // Wrapper.[] is too big if we force inlining of JSArray (15 nodes)
12 // // Wrapper.[]= is even bigger (46 nodes) 12 // // Wrapper.[]= is even bigger (46 nodes)
13 // // 13 // //
14 // // See #25478 for ideas on how to make this better. 14 // // We now do specialization of [] and []= by adding guards and injecting buil tin
15 // // operators. This made it possible to inline []. We still don't see []= inli ned
16 // // yet, that might require that we improve the inlining counting heuristics a
17 // // bit.
15 // @NoInline() 18 // @NoInline()
16 // test(data, x) { 19 // test(data, x) {
17 // data[x + 1] = data[x]; 20 // data[x + 1] = data[x];
18 // } 21 // }
19 // 22 //
20 // main() { 23 // main() {
21 // var wrapper = new Wrapper(); 24 // var wrapper = new Wrapper();
22 // wrapper[33] = wrapper[1]; // make Wrapper.[]= and [] used more than once. 25 // wrapper[33] = wrapper[1]; // make Wrapper.[]= and [] used more than once.
23 // print(test(new Wrapper(), int.parse('2'))); 26 // print(test(new Wrapper(), int.parse('2')));
24 // } 27 // }
25 // 28 //
26 // class Wrapper { 29 // class Wrapper {
27 // final List arr = <bool>[true, false, false, true]; 30 // final List arr = <bool>[true, false, false, true];
28 // operator[](int i) => this.arr[i]; 31 // operator[](int i) => this.arr[i];
29 // operator[]=(int i, v) { 32 // operator[]=(int i, v) {
30 // if (i > arr.length - 1) arr.length = i + 1; 33 // if (i > arr.length - 1) arr.length = i + 1;
31 // return arr[i] = v; 34 // return arr[i] = v;
32 // } 35 // }
33 // } 36 // }
34 37
35 function(data, x) { 38 function(data, x) {
36 data.$indexSet(0, J.$add$ns(x, 1), C.JSArray_methods.$index(data.arr, x)); 39 var v0 = J.$add$ns(x, 1), v1 = data.arr, v2 = v1.length;
40 if (typeof x !== "number" || Math.floor(x) !== x)
41 return H.iae(x);
42 if (x < 0 || x >= v2)
43 return H.ioore(v1, x);
44 data.$indexSet(0, v0, v1[x]);
37 } 45 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698