Skip to content

Commit

Permalink
[mypyc] Emit native_int instead of int64/int32 in IR test output (#10446
Browse files Browse the repository at this point in the history
)

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.
  • Loading branch information
TH3CHARLie committed May 25, 2021
1 parent 7780482 commit 61c3462
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 18 deletions.
12 changes: 8 additions & 4 deletions mypyc/ir/rtypes.py
Expand Up @@ -276,10 +276,12 @@ def __hash__(self) -> int:

if IS_32_BIT_PLATFORM:
c_size_t_rprimitive = uint32_rprimitive
c_pyssize_t_rprimitive = int32_rprimitive
c_pyssize_t_rprimitive = RPrimitive('native_int', is_unboxed=True, is_refcounted=False,
ctype='int32_t', size=4)
else:
c_size_t_rprimitive = uint64_rprimitive
c_pyssize_t_rprimitive = int64_rprimitive
c_pyssize_t_rprimitive = RPrimitive('native_int', is_unboxed=True, is_refcounted=False,
ctype='int64_t', size=8)

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


def is_int32_rprimitive(rtype: RType) -> bool:
return rtype is int32_rprimitive
return (rtype is int32_rprimitive or
(rtype is c_pyssize_t_rprimitive and rtype._ctype == 'int32_t'))


def is_int64_rprimitive(rtype: RType) -> bool:
return rtype is int64_rprimitive
return (rtype is int64_rprimitive or
(rtype is c_pyssize_t_rprimitive and rtype._ctype == 'int64_t'))


def is_uint32_rprimitive(rtype: RType) -> bool:
Expand Down
3 changes: 1 addition & 2 deletions mypyc/test/test_analysis.py
Expand Up @@ -15,7 +15,7 @@
from mypyc.ir.func_ir import all_values
from mypyc.test.testutil import (
ICODE_GEN_BUILTINS, use_custom_builtins, MypycDataSuite, build_ir_for_single_file,
assert_test_output, replace_native_int
assert_test_output
)

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

with use_custom_builtins(os.path.join(self.data_prefix, ICODE_GEN_BUILTINS), testcase):
testcase.output = replace_native_int(testcase.output)
try:
ir = build_ir_for_single_file(testcase.input)
except CompileError as e:
Expand Down
3 changes: 1 addition & 2 deletions mypyc/test/test_exceptions.py
Expand Up @@ -16,7 +16,7 @@
from mypyc.transform.refcount import insert_ref_count_opcodes
from mypyc.test.testutil import (
ICODE_GEN_BUILTINS, use_custom_builtins, MypycDataSuite, build_ir_for_single_file,
assert_test_output, remove_comment_lines, replace_native_int
assert_test_output, remove_comment_lines
)

files = [
Expand All @@ -32,7 +32,6 @@ def run_case(self, testcase: DataDrivenTestCase) -> None:
"""Perform a runtime checking transformation test case."""
with use_custom_builtins(os.path.join(self.data_prefix, ICODE_GEN_BUILTINS), testcase):
expected_output = remove_comment_lines(testcase.output)
expected_output = replace_native_int(expected_output)
try:
ir = build_ir_for_single_file(testcase.input)
except CompileError as e:
Expand Down
3 changes: 1 addition & 2 deletions mypyc/test/test_irbuild.py
Expand Up @@ -10,7 +10,7 @@
from mypyc.ir.pprint import format_func
from mypyc.test.testutil import (
ICODE_GEN_BUILTINS, use_custom_builtins, MypycDataSuite, build_ir_for_single_file,
assert_test_output, remove_comment_lines, replace_native_int, replace_word_size,
assert_test_output, remove_comment_lines, replace_word_size,
infer_ir_build_options_from_test_name
)

Expand Down Expand Up @@ -50,7 +50,6 @@ def run_case(self, testcase: DataDrivenTestCase) -> None:
return
with use_custom_builtins(os.path.join(self.data_prefix, ICODE_GEN_BUILTINS), testcase):
expected_output = remove_comment_lines(testcase.output)
expected_output = replace_native_int(expected_output)
expected_output = replace_word_size(expected_output)
name = testcase.name
try:
Expand Down
3 changes: 1 addition & 2 deletions mypyc/test/test_refcount.py
Expand Up @@ -16,7 +16,7 @@
from mypyc.transform.uninit import insert_uninit_checks
from mypyc.test.testutil import (
ICODE_GEN_BUILTINS, use_custom_builtins, MypycDataSuite, build_ir_for_single_file,
assert_test_output, remove_comment_lines, replace_native_int, replace_word_size,
assert_test_output, remove_comment_lines, replace_word_size,
infer_ir_build_options_from_test_name
)

Expand All @@ -38,7 +38,6 @@ def run_case(self, testcase: DataDrivenTestCase) -> None:
return
with use_custom_builtins(os.path.join(self.data_prefix, ICODE_GEN_BUILTINS), testcase):
expected_output = remove_comment_lines(testcase.output)
expected_output = replace_native_int(expected_output)
expected_output = replace_word_size(expected_output)
try:
ir = build_ir_for_single_file(testcase.input, options)
Expand Down
6 changes: 0 additions & 6 deletions mypyc/test/testutil.py
Expand Up @@ -215,12 +215,6 @@ def fudge_dir_mtimes(dir: str, delta: int) -> None:
os.utime(path, times=(new_mtime, new_mtime))


def replace_native_int(text: List[str]) -> List[str]:
"""Replace native_int with platform specific ints"""
int_format_str = 'int32' if IS_32_BIT_PLATFORM else 'int64'
return [s.replace('native_int', int_format_str) for s in text]


def replace_word_size(text: List[str]) -> List[str]:
"""Replace WORDSIZE with platform specific word sizes"""
result = []
Expand Down

0 comments on commit 61c3462

Please sign in to comment.