Skip to content

[mypyc] Emit native_int instead of int64/int32 in IR test output #10446

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions mypyc/ir/rtypes.py
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 @@ -49,7 +49,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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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