forked from facebook/hermes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathno_capture_store.js
131 lines (113 loc) · 4.85 KB
/
no_capture_store.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
// RUN: %hermes -dump-ir %s -O | %FileCheckOrRegen %s
function bar() { }
// The first stores to k1, k2, k3 can be eliminated since the variables haven't
// been captured yet.
function main(p) {
var k1 = bar();
var k2 = bar();
var k3 = bar();
return function () { return k1 + k2 + k3 }
}
// Make sure that we are not eliminating the "store-42" in test2, because the
// call to o() may clobber it.
function outer() {
var envVar;
function setValue(v) {
envVar = v;
}
function test1() {
envVar = 42;
envVar = 87;
}
function test2(o) {
envVar = 42;
o();
envVar = 87;
}
return [setValue, test1, test2]
}
// Auto-generated content below. Please do not modify manually.
// CHECK:function global#0()#1 : undefined
// CHECK-NEXT:globals = [bar, main, outer]
// CHECK-NEXT:S{global#0()#1} = []
// CHECK-NEXT:%BB0:
// CHECK-NEXT: %0 = CreateScopeInst %S{global#0()#1}
// CHECK-NEXT: %1 = CreateFunctionInst %bar#0#1()#2 : undefined, %0
// CHECK-NEXT: %2 = StorePropertyInst %1 : closure, globalObject : object, "bar" : string
// CHECK-NEXT: %3 = CreateFunctionInst %main#0#1()#3 : closure, %0
// CHECK-NEXT: %4 = StorePropertyInst %3 : closure, globalObject : object, "main" : string
// CHECK-NEXT: %5 = CreateFunctionInst %outer#0#1()#5 : object, %0
// CHECK-NEXT: %6 = StorePropertyInst %5 : closure, globalObject : object, "outer" : string
// CHECK-NEXT: %7 = ReturnInst undefined : undefined
// CHECK-NEXT:function_end
// CHECK:function bar#0#1()#2 : undefined
// CHECK-NEXT:S{bar#0#1()#2} = []
// CHECK-NEXT:%BB0:
// CHECK-NEXT: %0 = CreateScopeInst %S{bar#0#1()#2}
// CHECK-NEXT: %1 = ReturnInst undefined : undefined
// CHECK-NEXT:function_end
// CHECK:function main#0#1(p)#3 : closure
// CHECK-NEXT:S{main#0#1()#3} = [k1#3, k2#3, k3#3]
// CHECK-NEXT:%BB0:
// CHECK-NEXT: %0 = CreateScopeInst %S{main#0#1()#3}
// CHECK-NEXT: %1 = LoadPropertyInst globalObject : object, "bar" : string
// CHECK-NEXT: %2 = CallInst %1, undefined : undefined, undefined : undefined
// CHECK-NEXT: %3 = StoreFrameInst %2, [k1#3], %0
// CHECK-NEXT: %4 = LoadPropertyInst globalObject : object, "bar" : string
// CHECK-NEXT: %5 = CallInst %4, undefined : undefined, undefined : undefined
// CHECK-NEXT: %6 = StoreFrameInst %5, [k2#3], %0
// CHECK-NEXT: %7 = LoadPropertyInst globalObject : object, "bar" : string
// CHECK-NEXT: %8 = CallInst %7, undefined : undefined, undefined : undefined
// CHECK-NEXT: %9 = StoreFrameInst %8, [k3#3], %0
// CHECK-NEXT: %10 = CreateFunctionInst %""#1#3()#4 : string|number|bigint, %0
// CHECK-NEXT: %11 = ReturnInst %10 : closure
// CHECK-NEXT:function_end
// CHECK:function ""#1#3()#4 : string|number|bigint
// CHECK-NEXT:S{""#1#3()#4} = []
// CHECK-NEXT:%BB0:
// CHECK-NEXT: %0 = CreateScopeInst %S{""#1#3()#4}
// CHECK-NEXT: %1 = LoadFrameInst [k1#3@main], %0
// CHECK-NEXT: %2 = LoadFrameInst [k2#3@main], %0
// CHECK-NEXT: %3 = BinaryOperatorInst '+', %1, %2
// CHECK-NEXT: %4 = LoadFrameInst [k3#3@main], %0
// CHECK-NEXT: %5 = BinaryOperatorInst '+', %3 : string|number|bigint, %4
// CHECK-NEXT: %6 = ReturnInst %5 : string|number|bigint
// CHECK-NEXT:function_end
// CHECK:function outer#0#1()#5 : object
// CHECK-NEXT:S{outer#0#1()#5} = []
// CHECK-NEXT:%BB0:
// CHECK-NEXT: %0 = CreateScopeInst %S{outer#0#1()#5}
// CHECK-NEXT: %1 = CreateFunctionInst %setValue#1#5()#6 : undefined, %0
// CHECK-NEXT: %2 = CreateFunctionInst %test1#1#5()#7 : undefined, %0
// CHECK-NEXT: %3 = CreateFunctionInst %test2#1#5()#8 : undefined, %0
// CHECK-NEXT: %4 = AllocArrayInst 3 : number
// CHECK-NEXT: %5 = StoreOwnPropertyInst %1 : closure, %4 : object, 0 : number, true : boolean
// CHECK-NEXT: %6 = StoreOwnPropertyInst %2 : closure, %4 : object, 1 : number, true : boolean
// CHECK-NEXT: %7 = StoreOwnPropertyInst %3 : closure, %4 : object, 2 : number, true : boolean
// CHECK-NEXT: %8 = ReturnInst %4 : object
// CHECK-NEXT:function_end
// CHECK:function setValue#1#5(v)#6 : undefined
// CHECK-NEXT:S{setValue#1#5()#6} = []
// CHECK-NEXT:%BB0:
// CHECK-NEXT: %0 = CreateScopeInst %S{setValue#1#5()#6}
// CHECK-NEXT: %1 = ReturnInst undefined : undefined
// CHECK-NEXT:function_end
// CHECK:function test1#1#5()#7 : undefined
// CHECK-NEXT:S{test1#1#5()#7} = []
// CHECK-NEXT:%BB0:
// CHECK-NEXT: %0 = CreateScopeInst %S{test1#1#5()#7}
// CHECK-NEXT: %1 = ReturnInst undefined : undefined
// CHECK-NEXT:function_end
// CHECK:function test2#1#5(o)#8 : undefined
// CHECK-NEXT:S{test2#1#5()#8} = []
// CHECK-NEXT:%BB0:
// CHECK-NEXT: %0 = CreateScopeInst %S{test2#1#5()#8}
// CHECK-NEXT: %1 = CallInst %o, undefined : undefined, undefined : undefined
// CHECK-NEXT: %2 = ReturnInst undefined : undefined
// CHECK-NEXT:function_end