Debian Codegraph @

js/src/jit-test/tests/warp/set-has-string.js

raw
1 // Similar test as "cacheir/set-has-string.js", except that we now perform
2 // duplicate lookups to ensure GVN works properly.
3
4 // Return a new set, possibly filling some dummy entries to enforce creating
5 // multiple hash buckets.
6 function createSet(values, n) {
7 var xs = [...values];
8 for (var i = 0; i < n; ++i) {
9 xs.push({});
10 }
11 return new Set(xs);
12 }
13
14 function runTest(fn) {
15 fn(0);
16 fn(100);
17 }
18
19 function testConstant_same_set(n) {
20 var xs = ["a", "b"];
21 var ys = ["c", "d"];
22 var zs = [...xs, ...ys];
23 var set = createSet(xs, n);
24
25 var N = 100;
26 var c = 0;
27 for (var i = 0; i < N; ++i) {
28 var z = zs[i & 3];
29 if (set.has(z)) c++;
30 if (set.has(z)) c++;
31 }
32 assertEq(c, N);
33 }
34 runTest(testConstant_same_set);
35
36 function testComputed_same_set(n) {
37 var xs = ["a", "b"];
38 var ys = ["c", "d"];
39 var zs = [...xs, ...ys];
40 var set = createSet(xs, n);
41
42 var N = 100;
43 var c = 0;
44 for (var i = 0; i < N; ++i) {
45 var z = zs[i & 3];
46 z = String.fromCharCode(z.charCodeAt(0));
47 if (set.has(z)) c++;
48 if (set.has(z)) c++;
49 }
50 assertEq(c, N);
51 }
52 runTest(testComputed_same_set);
53
54 function testRope_same_set(n) {
55 var xs = ["a", "b"];
56 var ys = ["c", "d"];
57 var zs = [...xs, ...ys];
58 var set = createSet(xs.map(x => x.repeat(100)), n);
59
60 var N = 100;
61 var c = 0;
62 for (var i = 0; i < N; ++i) {
63 var z = zs[i & 3].repeat(100);
64 if (set.has(z)) c++;
65 if (set.has(z)) c++;
66 }
67 assertEq(c, N);
68 }
69 runTest(testRope_same_set);
70
71 // Duplicate the above tests, but this time use a different set.
72
73 function testConstant_different_set(n) {
74 var xs = ["a", "b"];
75 var ys = ["c", "d"];
76 var zs = [...xs, ...ys];
77 var set1 = createSet(xs, n);
78 var set2 = createSet(xs, n);
79
80 var N = 100;
81 var c = 0;
82 for (var i = 0; i < N; ++i) {
83 var z = zs[i & 3];
84 if (set1.has(z)) c++;
85 if (set2.has(z)) c++;
86 }
87 assertEq(c, N);
88 }
89 runTest(testConstant_different_set);
90
91 function testComputed_different_set(n) {
92 var xs = ["a", "b"];
93 var ys = ["c", "d"];
94 var zs = [...xs, ...ys];
95 var set1 = createSet(xs, n);
96 var set2 = createSet(xs, n);
97
98 var N = 100;
99 var c = 0;
100 for (var i = 0; i < N; ++i) {
101 var z = zs[i & 3];
102 z = String.fromCharCode(z.charCodeAt(0));
103 if (set1.has(z)) c++;
104 if (set2.has(z)) c++;
105 }
106 assertEq(c, N);
107 }
108 runTest(testComputed_different_set);
109
110 function testRope_different_set(n) {
111 var xs = ["a", "b"];
112 var ys = ["c", "d"];
113 var zs = [...xs, ...ys];
114 var set1 = createSet(xs.map(x => x.repeat(100)), n);
115 var set2 = createSet(xs.map(x => x.repeat(100)), n);
116
117 var N = 100;
118 var c = 0;
119 for (var i = 0; i < N; ++i) {
120 var z = zs[i & 3].repeat(100);
121 if (set1.has(z)) c++;
122 if (set2.has(z)) c++;
123 }
124 assertEq(c, N);
125 }
126 runTest(testRope_different_set);
127
128 // Test the alias information is correct.
129
130 function test_alias(n) {
131 var xs = ["a", "b"];
132 var set = createSet([], n);
133
134 var N = 100;
135 var c = 0;
136 for (var i = 0; i < N; ++i) {
137 var x = xs[i & 1];
138
139 set.add(x);
140 if (set.has(x)) c++;
141
142 set.delete(x);
143 if (set.has(x)) c++;
144 }
145 assertEq(c, N);
146 }
147 runTest(test_alias);