Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d204479

Browse files
authored
[mypyc] Make LoadGlobal print full name during pretty IR printing (#9331)
LoadGlobal used to have this hack to print partial name to keep consistent with the old LoadStatic behavior.
1 parent c231ee4 commit d204479

12 files changed

Lines changed: 220 additions & 223 deletions

mypyc/ir/ops.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1253,10 +1253,7 @@ def sources(self) -> List[Value]:
12531253

12541254
def to_str(self, env: Environment) -> str:
12551255
ann = ' ({})'.format(repr(self.ann)) if self.ann else ''
1256-
# return env.format('%r = %s%s', self, self.identifier, ann)
1257-
# TODO: a hack to prevent lots of failed IR tests when developing prototype
1258-
# eventually we will change all the related tests
1259-
return env.format('%r = %s :: static%s', self, self.identifier[10:], ann)
1256+
return env.format('%r = load_global %s :: static%s', self, self.identifier, ann)
12601257

12611258
def accept(self, visitor: 'OpVisitor[T]') -> T:
12621259
return visitor.visit_load_global(self)

mypyc/test-data/analysis.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,7 @@ L1:
732732
L2:
733733
r1 = CPy_CatchError()
734734
r2 = builtins :: module
735-
r3 = unicode_1 :: static ('Exception')
735+
r3 = load_global CPyStatic_unicode_1 :: static ('Exception')
736736
r4 = CPyObject_GetAttr(r2, r3)
737737
if is_error(r4) goto L8 (error at lol:4) else goto L3
738738
L3:

mypyc/test-data/exceptions.test

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ def g():
188188
L0:
189189
L1:
190190
r0 = builtins :: module
191-
r1 = unicode_1 :: static ('object')
191+
r1 = load_global CPyStatic_unicode_1 :: static ('object')
192192
r2 = CPyObject_GetAttr(r0, r1)
193193
if is_error(r2) goto L3 (error at g:3) else goto L2
194194
L2:
@@ -197,9 +197,9 @@ L2:
197197
if is_error(r3) goto L3 (error at g:3) else goto L10
198198
L3:
199199
r4 = CPy_CatchError()
200-
r5 = unicode_2 :: static ('weeee')
200+
r5 = load_global CPyStatic_unicode_2 :: static ('weeee')
201201
r6 = builtins :: module
202-
r7 = unicode_3 :: static ('print')
202+
r7 = load_global CPyStatic_unicode_3 :: static ('print')
203203
r8 = CPyObject_GetAttr(r6, r7)
204204
if is_error(r8) goto L6 (error at g:5) else goto L4
205205
L4:
@@ -256,15 +256,15 @@ def a():
256256
L0:
257257
L1:
258258
r0 = builtins :: module
259-
r1 = unicode_1 :: static ('print')
259+
r1 = load_global CPyStatic_unicode_1 :: static ('print')
260260
r2 = CPyObject_GetAttr(r0, r1)
261261
if is_error(r2) goto L5 (error at a:3) else goto L2
262262
L2:
263263
r3 = py_call(r2)
264264
dec_ref r2
265265
if is_error(r3) goto L5 (error at a:3) else goto L20
266266
L3:
267-
r4 = unicode_2 :: static ('hi')
267+
r4 = load_global CPyStatic_unicode_2 :: static ('hi')
268268
inc_ref r4
269269
r5 = r4
270270
L4:
@@ -277,9 +277,9 @@ L5:
277277
r10 = CPy_CatchError()
278278
r6 = r10
279279
L6:
280-
r11 = unicode_3 :: static ('goodbye!')
280+
r11 = load_global CPyStatic_unicode_3 :: static ('goodbye!')
281281
r12 = builtins :: module
282-
r13 = unicode_1 :: static ('print')
282+
r13 = load_global CPyStatic_unicode_1 :: static ('print')
283283
r14 = CPyObject_GetAttr(r12, r13)
284284
if is_error(r14) goto L13 (error at a:6) else goto L7
285285
L7:
@@ -357,15 +357,15 @@ def lol(x):
357357
r5 :: object
358358
L0:
359359
L1:
360-
r0 = unicode_3 :: static ('foo')
360+
r0 = load_global CPyStatic_unicode_3 :: static ('foo')
361361
r1 = CPyObject_GetAttr(x, r0)
362362
if is_error(r1) goto L3 (error at lol:4) else goto L2
363363
L2:
364364
st = r1
365365
goto L4
366366
L3:
367367
r2 = CPy_CatchError()
368-
r3 = unicode_4 :: static
368+
r3 = load_global CPyStatic_unicode_4 :: static
369369
CPy_RestoreExcInfo(r2)
370370
dec_ref r2
371371
inc_ref r3
@@ -397,12 +397,12 @@ def lol(x):
397397
r9 :: object
398398
L0:
399399
L1:
400-
r0 = unicode_3 :: static ('foo')
400+
r0 = load_global CPyStatic_unicode_3 :: static ('foo')
401401
r1 = CPyObject_GetAttr(x, r0)
402402
if is_error(r1) goto L4 (error at lol:4) else goto L15
403403
L2:
404404
a = r1
405-
r2 = unicode_4 :: static ('bar')
405+
r2 = load_global CPyStatic_unicode_4 :: static ('bar')
406406
r3 = CPyObject_GetAttr(x, r2)
407407
if is_error(r3) goto L4 (error at lol:5) else goto L16
408408
L3:
@@ -469,21 +469,21 @@ def f(b):
469469
r8 :: bool
470470
r9 :: None
471471
L0:
472-
r0 = unicode_1 :: static ('a')
472+
r0 = load_global CPyStatic_unicode_1 :: static ('a')
473473
inc_ref r0
474474
u = r0
475475
L1:
476476
if b goto L10 else goto L11 :: bool
477477
L2:
478-
r1 = unicode_2 :: static ('b')
478+
r1 = load_global CPyStatic_unicode_2 :: static ('b')
479479
inc_ref r1
480480
v = r1
481481
r2 = v == u
482482
r3 = !r2
483483
if r3 goto L11 else goto L1 :: bool
484484
L3:
485485
r4 = builtins :: module
486-
r5 = unicode_3 :: static ('print')
486+
r5 = load_global CPyStatic_unicode_3 :: static ('print')
487487
r6 = CPyObject_GetAttr(r4, r5)
488488
if is_error(r6) goto L12 (error at f:7) else goto L4
489489
L4:

mypyc/test-data/irbuild-any.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ L0:
6161
a = r4
6262
r5 = unbox(int, a)
6363
n = r5
64-
r6 = unicode_6 :: static ('a')
64+
r6 = load_global CPyStatic_unicode_6 :: static ('a')
6565
r7 = box(int, n)
6666
r8 = PyObject_SetAttr(a, r6, r7)
6767
return 1

0 commit comments

Comments
 (0)