Skip to content

Commit 61c3462

Browse files
authored
[mypyc] Emit native_int instead of int64/int32 in IR test output (#10446)
Fixes mypyc/mypyc#776. This is a super quick workaround. So far the issue mostly (if not completely) occurs in c_pyssize_t so making this rtype emits native_int would solve the issue. As a result, the replace_native_int pass in IR test is now removed.
1 parent 7780482 commit 61c3462

File tree

6 files changed

+12
-18
lines changed

6 files changed

+12
-18
lines changed

mypyc/ir/rtypes.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -276,10 +276,12 @@ def __hash__(self) -> int:
276276

277277
if IS_32_BIT_PLATFORM:
278278
c_size_t_rprimitive = uint32_rprimitive
279-
c_pyssize_t_rprimitive = int32_rprimitive
279+
c_pyssize_t_rprimitive = RPrimitive('native_int', is_unboxed=True, is_refcounted=False,
280+
ctype='int32_t', size=4)
280281
else:
281282
c_size_t_rprimitive = uint64_rprimitive
282-
c_pyssize_t_rprimitive = int64_rprimitive
283+
c_pyssize_t_rprimitive = RPrimitive('native_int', is_unboxed=True, is_refcounted=False,
284+
ctype='int64_t', size=8)
283285

284286
# Low level pointer, represented as integer in C backends
285287
pointer_rprimitive = RPrimitive('ptr', is_unboxed=True, is_refcounted=False,
@@ -338,11 +340,13 @@ def is_short_int_rprimitive(rtype: RType) -> bool:
338340

339341

340342
def is_int32_rprimitive(rtype: RType) -> bool:
341-
return rtype is int32_rprimitive
343+
return (rtype is int32_rprimitive or
344+
(rtype is c_pyssize_t_rprimitive and rtype._ctype == 'int32_t'))
342345

343346

344347
def is_int64_rprimitive(rtype: RType) -> bool:
345-
return rtype is int64_rprimitive
348+
return (rtype is int64_rprimitive or
349+
(rtype is c_pyssize_t_rprimitive and rtype._ctype == 'int64_t'))
346350

347351

348352
def is_uint32_rprimitive(rtype: RType) -> bool:

mypyc/test/test_analysis.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from mypyc.ir.func_ir import all_values
1616
from mypyc.test.testutil import (
1717
ICODE_GEN_BUILTINS, use_custom_builtins, MypycDataSuite, build_ir_for_single_file,
18-
assert_test_output, replace_native_int
18+
assert_test_output
1919
)
2020

2121
files = [
@@ -32,7 +32,6 @@ def run_case(self, testcase: DataDrivenTestCase) -> None:
3232
"""Perform a data-flow analysis test case."""
3333

3434
with use_custom_builtins(os.path.join(self.data_prefix, ICODE_GEN_BUILTINS), testcase):
35-
testcase.output = replace_native_int(testcase.output)
3635
try:
3736
ir = build_ir_for_single_file(testcase.input)
3837
except CompileError as e:

mypyc/test/test_exceptions.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from mypyc.transform.refcount import insert_ref_count_opcodes
1717
from mypyc.test.testutil import (
1818
ICODE_GEN_BUILTINS, use_custom_builtins, MypycDataSuite, build_ir_for_single_file,
19-
assert_test_output, remove_comment_lines, replace_native_int
19+
assert_test_output, remove_comment_lines
2020
)
2121

2222
files = [
@@ -32,7 +32,6 @@ def run_case(self, testcase: DataDrivenTestCase) -> None:
3232
"""Perform a runtime checking transformation test case."""
3333
with use_custom_builtins(os.path.join(self.data_prefix, ICODE_GEN_BUILTINS), testcase):
3434
expected_output = remove_comment_lines(testcase.output)
35-
expected_output = replace_native_int(expected_output)
3635
try:
3736
ir = build_ir_for_single_file(testcase.input)
3837
except CompileError as e:

mypyc/test/test_irbuild.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from mypyc.ir.pprint import format_func
1111
from mypyc.test.testutil import (
1212
ICODE_GEN_BUILTINS, use_custom_builtins, MypycDataSuite, build_ir_for_single_file,
13-
assert_test_output, remove_comment_lines, replace_native_int, replace_word_size,
13+
assert_test_output, remove_comment_lines, replace_word_size,
1414
infer_ir_build_options_from_test_name
1515
)
1616

@@ -50,7 +50,6 @@ def run_case(self, testcase: DataDrivenTestCase) -> None:
5050
return
5151
with use_custom_builtins(os.path.join(self.data_prefix, ICODE_GEN_BUILTINS), testcase):
5252
expected_output = remove_comment_lines(testcase.output)
53-
expected_output = replace_native_int(expected_output)
5453
expected_output = replace_word_size(expected_output)
5554
name = testcase.name
5655
try:

mypyc/test/test_refcount.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from mypyc.transform.uninit import insert_uninit_checks
1717
from mypyc.test.testutil import (
1818
ICODE_GEN_BUILTINS, use_custom_builtins, MypycDataSuite, build_ir_for_single_file,
19-
assert_test_output, remove_comment_lines, replace_native_int, replace_word_size,
19+
assert_test_output, remove_comment_lines, replace_word_size,
2020
infer_ir_build_options_from_test_name
2121
)
2222

@@ -38,7 +38,6 @@ def run_case(self, testcase: DataDrivenTestCase) -> None:
3838
return
3939
with use_custom_builtins(os.path.join(self.data_prefix, ICODE_GEN_BUILTINS), testcase):
4040
expected_output = remove_comment_lines(testcase.output)
41-
expected_output = replace_native_int(expected_output)
4241
expected_output = replace_word_size(expected_output)
4342
try:
4443
ir = build_ir_for_single_file(testcase.input, options)

mypyc/test/testutil.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -215,12 +215,6 @@ def fudge_dir_mtimes(dir: str, delta: int) -> None:
215215
os.utime(path, times=(new_mtime, new_mtime))
216216

217217

218-
def replace_native_int(text: List[str]) -> List[str]:
219-
"""Replace native_int with platform specific ints"""
220-
int_format_str = 'int32' if IS_32_BIT_PLATFORM else 'int64'
221-
return [s.replace('native_int', int_format_str) for s in text]
222-
223-
224218
def replace_word_size(text: List[str]) -> List[str]:
225219
"""Replace WORDSIZE with platform specific word sizes"""
226220
result = []

0 commit comments

Comments
 (0)