Skip to content

[mypyc] Add support for building mypyc code on WASM #13446

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 13 commits into from
Sep 16, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 1 addition & 3 deletions mypyc/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -546,10 +546,8 @@ def mypycify(
"-Wno-unused-variable",
"-Wno-unused-command-line-argument",
"-Wno-unknown-warning-option",
"-Wno-unused-but-set-variable",
]
if "gcc" in compiler.compiler[0] or "gnu-cc" in compiler.compiler[0]:
# This flag is needed for gcc but does not exist on clang.
cflags += ["-Wno-unused-but-set-variable"]
elif compiler.compiler_type == "msvc":
# msvc doesn't have levels, '/O2' is full and '/Od' is disable
if opt_level == "0":
Expand Down
13 changes: 10 additions & 3 deletions mypyc/common.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from __future__ import annotations

import math
import sys
import sysconfig
from typing import Any, Dict, Optional, Tuple
from typing_extensions import Final

Expand Down Expand Up @@ -30,7 +32,12 @@
# Maximal number of subclasses for a class to trigger fast path in isinstance() checks.
FAST_ISINSTANCE_MAX_SUBCLASSES: Final = 2

IS_32_BIT_PLATFORM: Final = sys.maxsize < (1 << 31)
# Size of size_t, if configured.
SIZEOF_SIZE_T: Final = sysconfig.get_config_var("SIZEOF_SIZE_T") or math.log2(sys.maxsize)

IS_32_BIT_PLATFORM: Final = (
sys.maxsize < (1 << 31) if SIZEOF_SIZE_T is None else int(SIZEOF_SIZE_T) == 4
)

PLATFORM_SIZE = 4 if IS_32_BIT_PLATFORM else 8

Expand All @@ -42,13 +49,13 @@
IS_MIXED_32_64_BIT_BUILD: Final = sys.platform in ["darwin"] and sys.version_info < (3, 6)

# Maximum value for a short tagged integer.
MAX_SHORT_INT: Final = sys.maxsize >> 1
MAX_SHORT_INT: Final = sys.maxsize >> 1 if SIZEOF_SIZE_T is None else 2 ** int(SIZEOF_SIZE_T)

# 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: Final = sys.maxsize >> 1 if not IS_MIXED_32_64_BIT_BUILD else 2**30 - 1
MAX_LITERAL_SHORT_INT: Final = MAX_SHORT_INT if not IS_MIXED_32_64_BIT_BUILD else 2**30 - 1
MIN_LITERAL_SHORT_INT: Final = -MAX_LITERAL_SHORT_INT - 1

# Runtime C library files
Expand Down