/
irbuild-glue-methods.test
437 lines (409 loc) · 9.48 KB
/
irbuild-glue-methods.test
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
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
# Test cases for glue methods.
#
# These are used when subclass method signature has a different representation
# compared to the base class.
[case testSubclassSpecialize2]
class A:
def foo(self, x: int) -> object:
return str(x)
class B(A):
def foo(self, x: object) -> object:
return x
class C(B):
def foo(self, x: object) -> int:
return id(x)
def use_a(x: A, y: int) -> object:
return x.foo(y)
def use_b(x: B, y: object) -> object:
return x.foo(y)
def use_c(x: C, y: object) -> int:
return x.foo(y)
[out]
def A.foo(self, x):
self :: __main__.A
x :: int
r0 :: str
L0:
r0 = CPyTagged_Str(x)
return r0
def B.foo(self, x):
self :: __main__.B
x :: object
L0:
return x
def B.foo__A_glue(self, x):
self :: __main__.B
x :: int
r0, r1 :: object
L0:
r0 = box(int, x)
r1 = B.foo(self, r0)
return r1
def C.foo(self, x):
self :: __main__.C
x :: object
r0 :: int
L0:
r0 = CPyTagged_Id(x)
return r0
def C.foo__B_glue(self, x):
self :: __main__.C
x :: object
r0 :: int
r1 :: object
L0:
r0 = C.foo(self, x)
r1 = box(int, r0)
return r1
def C.foo__A_glue(self, x):
self :: __main__.C
x :: int
r0 :: object
r1 :: int
r2 :: object
L0:
r0 = box(int, x)
r1 = C.foo(self, r0)
r2 = box(int, r1)
return r2
def use_a(x, y):
x :: __main__.A
y :: int
r0 :: object
L0:
r0 = x.foo(y)
return r0
def use_b(x, y):
x :: __main__.B
y, r0 :: object
L0:
r0 = x.foo(y)
return r0
def use_c(x, y):
x :: __main__.C
y :: object
r0 :: int
L0:
r0 = x.foo(y)
return r0
[case testPropertyDerivedGen]
from typing import Callable
class BaseProperty:
@property
def value(self) -> object:
return self._incrementer
@property
def bad_value(self) -> object:
return self._incrementer
@property
def next(self) -> BaseProperty:
return BaseProperty(self._incrementer + 1)
def __init__(self, value: int) -> None:
self._incrementer = value
class DerivedProperty(BaseProperty):
@property
def value(self) -> int:
return self._incrementer
@property
def bad_value(self) -> object:
return self._incrementer
@property
def next(self) -> DerivedProperty:
return DerivedProperty(self._incr_func, self._incr_func(self.value))
def __init__(self, incr_func: Callable[[int], int], value: int) -> None:
BaseProperty.__init__(self, value)
self._incr_func = incr_func
class AgainProperty(DerivedProperty):
@property
def next(self) -> AgainProperty:
return AgainProperty(self._incr_func, self._incr_func(self._incr_func(self.value)))
@property
def bad_value(self) -> int:
return self._incrementer
[out]
def BaseProperty.value(self):
self :: __main__.BaseProperty
r0 :: int
r1 :: object
L0:
r0 = self._incrementer
r1 = box(int, r0)
return r1
def BaseProperty.bad_value(self):
self :: __main__.BaseProperty
r0 :: int
r1 :: object
L0:
r0 = self._incrementer
r1 = box(int, r0)
return r1
def BaseProperty.next(self):
self :: __main__.BaseProperty
r0, r1 :: int
r2 :: __main__.BaseProperty
L0:
r0 = borrow self._incrementer
r1 = CPyTagged_Add(r0, 2)
keep_alive self
r2 = BaseProperty(r1)
return r2
def BaseProperty.__init__(self, value):
self :: __main__.BaseProperty
value :: int
L0:
self._incrementer = value
return 1
def DerivedProperty.value(self):
self :: __main__.DerivedProperty
r0 :: int
L0:
r0 = self._incrementer
return r0
def DerivedProperty.value__BaseProperty_glue(__mypyc_self__):
__mypyc_self__ :: __main__.DerivedProperty
r0 :: int
r1 :: object
L0:
r0 = __mypyc_self__.value
r1 = box(int, r0)
return r1
def DerivedProperty.bad_value(self):
self :: __main__.DerivedProperty
r0 :: int
r1 :: object
L0:
r0 = self._incrementer
r1 = box(int, r0)
return r1
def DerivedProperty.next(self):
self :: __main__.DerivedProperty
r0 :: object
r1 :: int
r2, r3, r4 :: object
r5 :: int
r6 :: __main__.DerivedProperty
L0:
r0 = self._incr_func
r1 = self.value
r2 = self._incr_func
r3 = box(int, r1)
r4 = PyObject_CallFunctionObjArgs(r2, r3, 0)
r5 = unbox(int, r4)
r6 = DerivedProperty(r0, r5)
return r6
def DerivedProperty.next__BaseProperty_glue(__mypyc_self__):
__mypyc_self__, r0 :: __main__.DerivedProperty
L0:
r0 = __mypyc_self__.next
return r0
def DerivedProperty.__init__(self, incr_func, value):
self :: __main__.DerivedProperty
incr_func :: object
value :: int
r0 :: None
L0:
r0 = BaseProperty.__init__(self, value)
self._incr_func = incr_func
return 1
def AgainProperty.next(self):
self :: __main__.AgainProperty
r0 :: object
r1 :: int
r2, r3, r4 :: object
r5 :: int
r6, r7, r8 :: object
r9 :: int
r10 :: __main__.AgainProperty
L0:
r0 = self._incr_func
r1 = self.value
r2 = self._incr_func
r3 = box(int, r1)
r4 = PyObject_CallFunctionObjArgs(r2, r3, 0)
r5 = unbox(int, r4)
r6 = self._incr_func
r7 = box(int, r5)
r8 = PyObject_CallFunctionObjArgs(r6, r7, 0)
r9 = unbox(int, r8)
r10 = AgainProperty(r0, r9)
return r10
def AgainProperty.next__DerivedProperty_glue(__mypyc_self__):
__mypyc_self__, r0 :: __main__.AgainProperty
L0:
r0 = __mypyc_self__.next
return r0
def AgainProperty.next__BaseProperty_glue(__mypyc_self__):
__mypyc_self__, r0 :: __main__.AgainProperty
L0:
r0 = __mypyc_self__.next
return r0
def AgainProperty.bad_value(self):
self :: __main__.AgainProperty
r0 :: int
L0:
r0 = self._incrementer
return r0
def AgainProperty.bad_value__DerivedProperty_glue(__mypyc_self__):
__mypyc_self__ :: __main__.AgainProperty
r0 :: int
r1 :: object
L0:
r0 = __mypyc_self__.bad_value
r1 = box(int, r0)
return r1
def AgainProperty.bad_value__BaseProperty_glue(__mypyc_self__):
__mypyc_self__ :: __main__.AgainProperty
r0 :: int
r1 :: object
L0:
r0 = __mypyc_self__.bad_value
r1 = box(int, r0)
return r1
[case testPropertyTraitSubclassing]
from mypy_extensions import trait
@trait
class SubclassedTrait:
@property
def this(self) -> SubclassedTrait:
return self
@property
def boxed(self) -> object:
return 3
class DerivingObject(SubclassedTrait):
@property
def this(self) -> DerivingObject:
return self
@property
def boxed(self) -> int:
return 5
[out]
def SubclassedTrait.this(self):
self :: __main__.SubclassedTrait
L0:
return self
def SubclassedTrait.boxed(self):
self :: __main__.SubclassedTrait
r0 :: object
L0:
r0 = object 3
return r0
def DerivingObject.this(self):
self :: __main__.DerivingObject
L0:
return self
def DerivingObject.this__SubclassedTrait_glue(__mypyc_self__):
__mypyc_self__, r0 :: __main__.DerivingObject
L0:
r0 = __mypyc_self__.this
return r0
def DerivingObject.boxed(self):
self :: __main__.DerivingObject
L0:
return 10
def DerivingObject.boxed__SubclassedTrait_glue(__mypyc_self__):
__mypyc_self__ :: __main__.DerivingObject
r0 :: int
r1 :: object
L0:
r0 = __mypyc_self__.boxed
r1 = box(int, r0)
return r1
[case testI64GlueWithExtraDefaultArg]
from mypy_extensions import i64
class C:
def f(self) -> None: pass
class D(C):
def f(self, x: i64 = 44) -> None: pass
[out]
def C.f(self):
self :: __main__.C
L0:
return 1
def D.f(self, x, __bitmap):
self :: __main__.D
x :: int64
__bitmap, r0 :: uint32
r1 :: bit
L0:
r0 = __bitmap & 1
r1 = r0 == 0
if r1 goto L1 else goto L2 :: bool
L1:
x = 44
L2:
return 1
def D.f__C_glue(self):
self :: __main__.D
r0 :: None
L0:
r0 = D.f(self, 0, 0)
return r0
[case testI64GlueWithSecondDefaultArg]
from mypy_extensions import i64
class C:
def f(self, x: i64 = 11) -> None: pass
class D(C):
def f(self, x: i64 = 12, y: i64 = 13) -> None: pass
[out]
def C.f(self, x, __bitmap):
self :: __main__.C
x :: int64
__bitmap, r0 :: uint32
r1 :: bit
L0:
r0 = __bitmap & 1
r1 = r0 == 0
if r1 goto L1 else goto L2 :: bool
L1:
x = 11
L2:
return 1
def D.f(self, x, y, __bitmap):
self :: __main__.D
x, y :: int64
__bitmap, r0 :: uint32
r1 :: bit
r2 :: uint32
r3 :: bit
L0:
r0 = __bitmap & 1
r1 = r0 == 0
if r1 goto L1 else goto L2 :: bool
L1:
x = 12
L2:
r2 = __bitmap & 2
r3 = r2 == 0
if r3 goto L3 else goto L4 :: bool
L3:
y = 13
L4:
return 1
def D.f__C_glue(self, x, __bitmap):
self :: __main__.D
x :: int64
__bitmap :: uint32
r0 :: None
L0:
r0 = D.f(self, x, 0, __bitmap)
return r0
[case testI64GlueWithInvalidOverride]
from mypy_extensions import i64
class C:
def f(self, x: i64, y: i64 = 5) -> None: pass
def ff(self, x: int) -> None: pass
class CC(C):
def f(self, x: i64 = 12, y: i64 = 5) -> None: pass # Line 7
def ff(self, x: int = 12) -> None: pass
class D:
def f(self, x: int) -> None: pass
class DD(D):
def f(self, x: i64) -> None: pass # Line 13
class E:
def f(self, x: i64) -> None: pass
class EE(E):
def f(self, x: int) -> None: pass # Line 18
[out]
main:7: error: An argument with type "int64" cannot be given a default value in a method override
main:13: error: Incompatible argument type "int64" (base class has type "int")
main:18: error: Incompatible argument type "int" (base class has type "int64")