Skip to content

Commit 779cd47

Browse files
authored
Merge branch 'main' into fix-documentation-typos
2 parents 68344f3 + 6b5511d commit 779cd47

File tree

5 files changed

+57
-2
lines changed

5 files changed

+57
-2
lines changed

Lib/test/test_capi/test_opt.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2832,6 +2832,18 @@ def testfunc(n):
28322832
self.assertIn("_GUARD_TYPE_VERSION", uops)
28332833
self.assertNotIn("_CHECK_ATTR_CLASS", uops)
28342834

2835+
def test_load_common_constant(self):
2836+
def testfunc(n):
2837+
for _ in range(n):
2838+
x = list(i for i in ())
2839+
return x
2840+
res, ex = self._run_with_optimizer(testfunc, TIER2_THRESHOLD)
2841+
self.assertEqual(res, list(()))
2842+
self.assertIsNotNone(ex)
2843+
uops = get_opnames(ex)
2844+
self.assertIn("_BUILD_LIST", uops)
2845+
self.assertNotIn("_LOAD_COMMON_CONSTANT", uops)
2846+
28352847
def test_load_small_int(self):
28362848
def testfunc(n):
28372849
x = 0

Platforms/emscripten/__main__.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,11 @@ def make_mpdec(context, working_dir):
413413
write_library_config(prefix, "mpdec", mpdec_config, context.quiet)
414414

415415

416+
def make_dependencies(context):
417+
make_emscripten_libffi(context)
418+
make_mpdec(context)
419+
420+
416421
def calculate_node_path():
417422
node_version = os.environ.get("PYTHON_NODE_VERSION", None)
418423
if node_version is None:
@@ -573,7 +578,10 @@ def run_emscripten_python(context):
573578
if args and args[0] == "--":
574579
args = args[1:]
575580

576-
os.execv(str(exec_script), [str(exec_script)] + args)
581+
if context.test:
582+
args = load_config_toml()["test-args"] + args
583+
584+
os.execv(str(exec_script), [str(exec_script), *args])
577585

578586

579587
def build_target(context):
@@ -665,6 +673,11 @@ def main():
665673
help="Clone libffi repo, configure and build it for emscripten",
666674
)
667675

676+
make_dependencies_cmd = subcommands.add_parser(
677+
"make-dependencies",
678+
help="Build all static library dependencies",
679+
)
680+
668681
make_build = subcommands.add_parser(
669682
"make-build-python", help="Run `make` for the build Python"
670683
)
@@ -685,6 +698,15 @@ def main():
685698
"run",
686699
help="Run the built emscripten Python",
687700
)
701+
run.add_argument(
702+
"--test",
703+
action="store_true",
704+
default=False,
705+
help=(
706+
"If passed, will add the default test arguments to the beginning of the command. "
707+
"Default arguments loaded from Platforms/emscripten/config.toml"
708+
)
709+
)
688710
run.add_argument(
689711
"args",
690712
nargs=argparse.REMAINDER,
@@ -694,6 +716,7 @@ def main():
694716
)
695717
)
696718
add_cross_build_dir_option(run)
719+
697720
clean = subcommands.add_parser(
698721
"clean", help="Delete files and directories created by this script"
699722
)
@@ -714,6 +737,7 @@ def main():
714737
configure_build,
715738
make_libffi_cmd,
716739
make_mpdec_cmd,
740+
make_dependencies_cmd,
717741
make_build,
718742
configure_host,
719743
make_host,
@@ -781,6 +805,7 @@ def main():
781805
"install-emscripten": install_emscripten,
782806
"make-libffi": make_emscripten_libffi,
783807
"make-mpdec": make_mpdec,
808+
"make-dependencies": make_dependencies,
784809
"configure-build-python": configure_build_python,
785810
"make-build-python": make_build_python,
786811
"configure-host": configure_emscripten_python,

Platforms/emscripten/config.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33
# Python versions.
44
emscripten-version = "4.0.12"
55
node-version = "24"
6+
test-args = [
7+
"-m", "test",
8+
"-v",
9+
"-uall",
10+
"--rerun",
11+
"--single-process",
12+
"-W",
13+
]
614

715
[libffi]
816
url = "https://github.com/libffi/libffi/releases/download/v{version}/libffi-{version}.tar.gz"

Python/optimizer_bytecodes.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,13 @@ dummy_func(void) {
631631
value = PyJitRef_Borrow(sym_new_const(ctx, val));
632632
}
633633

634+
op(_LOAD_COMMON_CONSTANT, (-- value)) {
635+
assert(oparg < NUM_COMMON_CONSTANTS);
636+
PyObject *val = _PyInterpreterState_GET()->common_consts[oparg];
637+
ADD_OP(_LOAD_CONST_INLINE_BORROW, 0, (uintptr_t)val);
638+
value = PyJitRef_Borrow(sym_new_const(ctx, val));
639+
}
640+
634641
op(_LOAD_SMALL_INT, (-- value)) {
635642
PyObject *val = PyLong_FromLong(oparg);
636643
assert(val);

Python/optimizer_cases.c.h

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)