Skip to content

Commit

Permalink
[mypyc] Try to fix mypy mac build failure on Python 3.5 on Travis (#9508
Browse files Browse the repository at this point in the history
)

We may be building a mixed 32/64-bit binary, so restrict the maximum integer
literal to what's supported on a 32-bit platform, since the same C code
needs to compile on both 32-bit and 64-bit architectures.

This will make some slicing operations a bit slower in 32/64-bit mode
(Python 3.5 on mac).

Work on #9500.
  • Loading branch information
JukkaL committed Sep 30, 2020
1 parent 538d364 commit be1a005
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
22 changes: 17 additions & 5 deletions mypyc/common.py
Expand Up @@ -24,11 +24,6 @@
# Max short int we accept as a literal is based on 32-bit platforms,
# so that we can just always emit the same code.

# Maximum value for a short tagged integer.
#
# Note: Assume that the compiled code uses the same bit width as mypyc.
MAX_LITERAL_SHORT_INT = sys.maxsize >> 1 # type: Final

TOP_LEVEL_NAME = '__top_level__' # type: Final # Special function representing module top level

# Maximal number of subclasses for a class to trigger fast path in isinstance() checks.
Expand All @@ -38,6 +33,23 @@

PLATFORM_SIZE = 4 if IS_32_BIT_PLATFORM else 8

# Python 3.5 on macOS uses a hybrid 32/64-bit build that requires some workarounds.
# The same generated C will be compiled in both 32 and 64 bit modes when building mypy
# wheels (for an unknown reason).
#
# Note that we use "in ['darwin']" because of https://github.com/mypyc/mypyc/issues/761.
IS_MIXED_32_64_BIT_BUILD = sys.platform in ['darwin'] and sys.version_info < (3, 6) # type: Final

# Maximum value for a short tagged integer.
MAX_SHORT_INT = sys.maxsize >> 1 # type: Final

# Maximum value for a short tagged integer represented as a C integer literal.
#
# Note: Assume that the compiled code uses the same bit width as mypyc, except for
# Python 3.5 on macOS.
MAX_LITERAL_SHORT_INT = (sys.maxsize >> 1 if not IS_MIXED_32_64_BIT_BUILD
else 2**30 - 1) # type: Final

# Runtime C library files
RUNTIME_C_FILES = [
'init.c',
Expand Down
4 changes: 2 additions & 2 deletions mypyc/irbuild/expression.py
Expand Up @@ -15,7 +15,7 @@
)
from mypy.types import TupleType, get_proper_type, Instance

from mypyc.common import MAX_LITERAL_SHORT_INT
from mypyc.common import MAX_SHORT_INT
from mypyc.ir.ops import (
Value, TupleGet, TupleSet, BasicBlock, Assign, LoadAddress
)
Expand Down Expand Up @@ -373,7 +373,7 @@ def try_gen_slice_op(builder: IRBuilder, base: Value, index: SliceExpr) -> Optio
else:
# Replace missing end index with the largest short integer
# (a sequence can't be longer).
end = builder.load_static_int(MAX_LITERAL_SHORT_INT)
end = builder.load_static_int(MAX_SHORT_INT)
candidates = [list_slice_op, tuple_slice_op, str_slice_op]
return builder.builder.matching_call_c(candidates, [base, begin, end], index.line)

Expand Down

0 comments on commit be1a005

Please sign in to comment.