File: irbuild-singledispatch.test

package info (click to toggle)
mypy 1.19.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 22,412 kB
  • sloc: python: 114,754; ansic: 13,343; cpp: 11,380; makefile: 257; sh: 28
file content (331 lines) | stat: -rw-r--r-- 7,424 bytes parent folder | download
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
[case testNativeCallsUsedInDispatchFunction]
from functools import singledispatch
@singledispatch
def f(arg) -> bool:
    return False

@f.register
def g(arg: int) -> bool:
    return True
[out]
def __mypyc_singledispatch_main_function_f__(arg):
    arg :: object
L0:
    return 0
def f_obj.__init__(__mypyc_self__):
    __mypyc_self__ :: __main__.f_obj
    r0, r1 :: dict
    r2 :: str
    r3 :: i32
    r4 :: bit
L0:
    r0 = PyDict_New()
    __mypyc_self__.registry = r0
    r1 = PyDict_New()
    r2 = 'dispatch_cache'
    r3 = PyObject_SetAttr(__mypyc_self__, r2, r1)
    r4 = r3 >= 0 :: signed
    return 1
def f_obj.__call__(__mypyc_self__, arg):
    __mypyc_self__ :: __main__.f_obj
    arg :: object
    r0 :: ptr
    r1 :: object
    r2 :: dict
    r3, r4 :: object
    r5 :: bit
    r6, r7 :: object
    r8 :: str
    r9 :: object
    r10 :: dict
    r11 :: object[2]
    r12 :: object_ptr
    r13 :: object
    r14 :: i32
    r15 :: bit
    r16 :: object
    r17 :: ptr
    r18 :: object
    r19 :: bit
    r20 :: int
    r21 :: bit
    r22 :: int
    r23 :: bool
    r24 :: object[1]
    r25 :: object_ptr
    r26 :: object
    r27 :: bool
L0:
    r0 = get_element_ptr arg ob_type :: PyObject
    r1 = borrow load_mem r0 :: builtins.object*
    keep_alive arg
    r2 = __mypyc_self__.dispatch_cache
    r3 = CPyDict_GetWithNone(r2, r1)
    r4 = load_address _Py_NoneStruct
    r5 = r3 != r4
    if r5 goto L1 else goto L2 :: bool
L1:
    r6 = r3
    goto L3
L2:
    r7 = functools :: module
    r8 = '_find_impl'
    r9 = CPyObject_GetAttr(r7, r8)
    r10 = __mypyc_self__.registry
    r11 = [r1, r10]
    r12 = load_address r11
    r13 = PyObject_Vectorcall(r9, r12, 2, 0)
    keep_alive r1, r10
    r14 = PyDict_SetItem(r2, r1, r13)
    r15 = r14 >= 0 :: signed
    r6 = r13
L3:
    r16 = load_address PyLong_Type
    r17 = get_element_ptr r6 ob_type :: PyObject
    r18 = borrow load_mem r17 :: builtins.object*
    keep_alive r6
    r19 = r18 == r16
    if r19 goto L4 else goto L7 :: bool
L4:
    r20 = unbox(int, r6)
    r21 = int_eq r20, 0
    if r21 goto L5 else goto L6 :: bool
L5:
    r22 = unbox(int, arg)
    r23 = g(r22)
    return r23
L6:
    unreachable
L7:
    r24 = [arg]
    r25 = load_address r24
    r26 = PyObject_Vectorcall(r6, r25, 1, 0)
    keep_alive arg
    r27 = unbox(bool, r26)
    return r27
def f_obj.__get__(__mypyc_self__, instance, owner):
    __mypyc_self__, instance, owner, r0 :: object
    r1 :: bit
    r2 :: object
L0:
    r0 = load_address _Py_NoneStruct
    r1 = instance == r0
    if r1 goto L1 else goto L2 :: bool
L1:
    return __mypyc_self__
L2:
    r2 = PyMethod_New(__mypyc_self__, instance)
    return r2
def f_obj.register(__mypyc_self__, cls, func):
    __mypyc_self__ :: __main__.f_obj
    cls, func, r0 :: object
L0:
    r0 = CPySingledispatch_RegisterFunction(__mypyc_self__, cls, func)
    return r0
def f(arg):
    arg :: object
    r0 :: dict
    r1 :: str
    r2 :: object
    r3 :: bool
L0:
    r0 = __main__.globals :: static
    r1 = 'f'
    r2 = CPyDict_GetItem(r0, r1)
    r3 = f_obj.__call__(r2, arg)
    return r3
def g(arg):
    arg :: int
L0:
    return 1

[case testCallsToSingledispatchFunctionsAreNative]
from functools import singledispatch

@singledispatch
def f(x: object) -> None:
    pass

def test():
    f('a')
[out]
def __mypyc_singledispatch_main_function_f__(x):
    x :: object
L0:
    return 1
def f_obj.__init__(__mypyc_self__):
    __mypyc_self__ :: __main__.f_obj
    r0, r1 :: dict
    r2 :: str
    r3 :: i32
    r4 :: bit
L0:
    r0 = PyDict_New()
    __mypyc_self__.registry = r0
    r1 = PyDict_New()
    r2 = 'dispatch_cache'
    r3 = PyObject_SetAttr(__mypyc_self__, r2, r1)
    r4 = r3 >= 0 :: signed
    return 1
def f_obj.__call__(__mypyc_self__, x):
    __mypyc_self__ :: __main__.f_obj
    x :: object
    r0 :: ptr
    r1 :: object
    r2 :: dict
    r3, r4 :: object
    r5 :: bit
    r6, r7 :: object
    r8 :: str
    r9 :: object
    r10 :: dict
    r11 :: object[2]
    r12 :: object_ptr
    r13 :: object
    r14 :: i32
    r15 :: bit
    r16 :: object
    r17 :: ptr
    r18 :: object
    r19 :: bit
    r20 :: int
    r21 :: object[1]
    r22 :: object_ptr
    r23 :: object
    r24 :: None
L0:
    r0 = get_element_ptr x ob_type :: PyObject
    r1 = borrow load_mem r0 :: builtins.object*
    keep_alive x
    r2 = __mypyc_self__.dispatch_cache
    r3 = CPyDict_GetWithNone(r2, r1)
    r4 = load_address _Py_NoneStruct
    r5 = r3 != r4
    if r5 goto L1 else goto L2 :: bool
L1:
    r6 = r3
    goto L3
L2:
    r7 = functools :: module
    r8 = '_find_impl'
    r9 = CPyObject_GetAttr(r7, r8)
    r10 = __mypyc_self__.registry
    r11 = [r1, r10]
    r12 = load_address r11
    r13 = PyObject_Vectorcall(r9, r12, 2, 0)
    keep_alive r1, r10
    r14 = PyDict_SetItem(r2, r1, r13)
    r15 = r14 >= 0 :: signed
    r6 = r13
L3:
    r16 = load_address PyLong_Type
    r17 = get_element_ptr r6 ob_type :: PyObject
    r18 = borrow load_mem r17 :: builtins.object*
    keep_alive r6
    r19 = r18 == r16
    if r19 goto L4 else goto L5 :: bool
L4:
    r20 = unbox(int, r6)
    unreachable
L5:
    r21 = [x]
    r22 = load_address r21
    r23 = PyObject_Vectorcall(r6, r22, 1, 0)
    keep_alive x
    r24 = unbox(None, r23)
    return r24
def f_obj.__get__(__mypyc_self__, instance, owner):
    __mypyc_self__, instance, owner, r0 :: object
    r1 :: bit
    r2 :: object
L0:
    r0 = load_address _Py_NoneStruct
    r1 = instance == r0
    if r1 goto L1 else goto L2 :: bool
L1:
    return __mypyc_self__
L2:
    r2 = PyMethod_New(__mypyc_self__, instance)
    return r2
def f_obj.register(__mypyc_self__, cls, func):
    __mypyc_self__ :: __main__.f_obj
    cls, func, r0 :: object
L0:
    r0 = CPySingledispatch_RegisterFunction(__mypyc_self__, cls, func)
    return r0
def f(x):
    x :: object
    r0 :: dict
    r1 :: str
    r2 :: object
    r3 :: None
L0:
    r0 = __main__.globals :: static
    r1 = 'f'
    r2 = CPyDict_GetItem(r0, r1)
    r3 = f_obj.__call__(r2, x)
    return r3
def test():
    r0 :: str
    r1 :: None
    r2 :: object
L0:
    r0 = 'a'
    r1 = f(r0)
    r2 = box(None, 1)
    return r2

[case registerNestedFunctionError]
from functools import singledispatch
from typing import Any, overload

def dec(x: Any) -> Any:
    return x

def f() -> None:
    @singledispatch  # E: Nested singledispatch functions not supported
    def singledispatch_in_func(x: Any) -> None:
        pass

@dec
def g() -> None:
    @singledispatch  # E: Nested singledispatch functions not supported
    def singledispatch_in_decorated(x: Any) -> None:
        pass

@overload
def h(x: int) -> None:
    pass
@overload
def h(x: str) -> None:
    pass
def h(x: Any) -> None:
    @singledispatch  # E: Nested singledispatch functions not supported
    def singledispatch_in_overload(x: Any) -> None:
        pass

@singledispatch
def outside(x: Any) -> None:
    pass

def i() -> None:
    @outside.register  # E: Registering nested functions not supported
    def register_in_func(x: int) -> None:
        pass

@dec
def j() -> None:
    @outside.register  # E: Registering nested functions not supported
    def register_in_decorated(x: int) -> None:
        pass

@overload
def k(x: int) -> None:
    pass
@overload
def k(x: str) -> None:
    pass
def k(x: Any) -> None:
    @outside.register  # E: Registering nested functions not supported
    def register_in_overload(x: int) -> None:
        pass