Skip to content

Commit

Permalink
Merge branch 'main' into clinic-remove-varpos_object_converter
Browse files Browse the repository at this point in the history
  • Loading branch information
serhiy-storchaka authored Nov 8, 2024
2 parents 19cf74e + c222441 commit 40b37be
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 71 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/reusable-wasi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
WASI_SDK_VERSION: 24
WASI_SDK_PATH: /opt/wasi-sdk
CROSS_BUILD_PYTHON: cross-build/build
CROSS_BUILD_WASI: cross-build/wasm32-wasi
CROSS_BUILD_WASI: cross-build/wasm32-wasip1
steps:
- uses: actions/checkout@v4
# No problem resolver registered as one doesn't currently exist for Clang.
Expand All @@ -31,7 +31,7 @@ jobs:
with:
path: ${{ env.WASI_SDK_PATH }}
key: ${{ runner.os }}-wasi-sdk-${{ env.WASI_SDK_VERSION }}
- name: "Install WASI SDK"
- name: "Install WASI SDK" # Hard-coded to x64.
if: steps.cache-wasi-sdk.outputs.cache-hit != 'true'
run: |
mkdir ${{ env.WASI_SDK_PATH }} && \
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Use ``wasm32-wasip1`` as the target triple for WASI instead of
``wasm32-wasi``. The latter will eventually be reclaimed for WASI 1.0 while
CPython currently only supports WASI preview1.
126 changes: 67 additions & 59 deletions Python/codegen.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,19 @@
#define ERROR -1

#define RETURN_IF_ERROR(X) \
if ((X) == -1) { \
return ERROR; \
}

#define RETURN_IF_ERROR_IN_SCOPE(C, CALL) { \
if ((CALL) < 0) { \
_PyCompile_ExitScope((C)); \
return ERROR; \
} \
}
do { \
if ((X) == -1) { \
return ERROR; \
} \
} while (0)

#define RETURN_IF_ERROR_IN_SCOPE(C, CALL) \
do { \
if ((CALL) < 0) { \
_PyCompile_ExitScope((C)); \
return ERROR; \
} \
} while (0)

struct _PyCompiler;
typedef struct _PyCompiler compiler;
Expand Down Expand Up @@ -261,7 +264,7 @@ codegen_addop_i(instr_sequence *seq, int opcode, Py_ssize_t oparg, location loc)
RETURN_IF_ERROR(codegen_addop_i(INSTR_SEQUENCE(C), (OP), (O), (LOC)))

#define ADDOP_I_IN_SCOPE(C, LOC, OP, O) \
RETURN_IF_ERROR_IN_SCOPE(C, codegen_addop_i(INSTR_SEQUENCE(C), (OP), (O), (LOC)));
RETURN_IF_ERROR_IN_SCOPE(C, codegen_addop_i(INSTR_SEQUENCE(C), (OP), (O), (LOC)))

static int
codegen_addop_noarg(instr_sequence *seq, int opcode, location loc)
Expand Down Expand Up @@ -303,17 +306,18 @@ codegen_addop_load_const(compiler *c, location loc, PyObject *o)
RETURN_IF_ERROR_IN_SCOPE((C), codegen_addop_load_const((C), (LOC), (O)))

/* Same as ADDOP_LOAD_CONST, but steals a reference. */
#define ADDOP_LOAD_CONST_NEW(C, LOC, O) { \
PyObject *__new_const = (O); \
if (__new_const == NULL) { \
return ERROR; \
} \
if (codegen_addop_load_const((C), (LOC), __new_const) < 0) { \
Py_DECREF(__new_const); \
return ERROR; \
} \
Py_DECREF(__new_const); \
}
#define ADDOP_LOAD_CONST_NEW(C, LOC, O) \
do { \
PyObject *__new_const = (O); \
if (__new_const == NULL) { \
return ERROR; \
} \
if (codegen_addop_load_const((C), (LOC), __new_const) < 0) { \
Py_DECREF(__new_const); \
return ERROR; \
} \
Py_DECREF(__new_const); \
} while (0)

static int
codegen_addop_o(compiler *c, location loc,
Expand All @@ -325,19 +329,23 @@ codegen_addop_o(compiler *c, location loc,
return SUCCESS;
}

#define ADDOP_N(C, LOC, OP, O, TYPE) { \
assert(!OPCODE_HAS_CONST(OP)); /* use ADDOP_LOAD_CONST_NEW */ \
int ret = codegen_addop_o((C), (LOC), (OP), METADATA(C)->u_ ## TYPE, (O)); \
Py_DECREF((O)); \
RETURN_IF_ERROR(ret); \
}

#define ADDOP_N_IN_SCOPE(C, LOC, OP, O, TYPE) { \
assert(!OPCODE_HAS_CONST(OP)); /* use ADDOP_LOAD_CONST_NEW */ \
int ret = codegen_addop_o((C), (LOC), (OP), METADATA(C)->u_ ## TYPE, (O)); \
Py_DECREF((O)); \
RETURN_IF_ERROR_IN_SCOPE((C), ret); \
}
#define ADDOP_N(C, LOC, OP, O, TYPE) \
do { \
assert(!OPCODE_HAS_CONST(OP)); /* use ADDOP_LOAD_CONST_NEW */ \
int ret = codegen_addop_o((C), (LOC), (OP), \
METADATA(C)->u_ ## TYPE, (O)); \
Py_DECREF((O)); \
RETURN_IF_ERROR(ret); \
} while (0)

#define ADDOP_N_IN_SCOPE(C, LOC, OP, O, TYPE) \
do { \
assert(!OPCODE_HAS_CONST(OP)); /* use ADDOP_LOAD_CONST_NEW */ \
int ret = codegen_addop_o((C), (LOC), (OP), \
METADATA(C)->u_ ## TYPE, (O)); \
Py_DECREF((O)); \
RETURN_IF_ERROR_IN_SCOPE((C), ret); \
} while (0)

#define LOAD_METHOD -1
#define LOAD_SUPER_METHOD -2
Expand Down Expand Up @@ -426,31 +434,31 @@ codegen_addop_j(instr_sequence *seq, location loc,
*/

#define VISIT(C, TYPE, V) \
RETURN_IF_ERROR(codegen_visit_ ## TYPE((C), (V)));
RETURN_IF_ERROR(codegen_visit_ ## TYPE((C), (V)))

#define VISIT_IN_SCOPE(C, TYPE, V) \
RETURN_IF_ERROR_IN_SCOPE((C), codegen_visit_ ## TYPE((C), (V)))

#define VISIT_SEQ(C, TYPE, SEQ) { \
int _i; \
asdl_ ## TYPE ## _seq *seq = (SEQ); /* avoid variable capture */ \
for (_i = 0; _i < asdl_seq_LEN(seq); _i++) { \
TYPE ## _ty elt = (TYPE ## _ty)asdl_seq_GET(seq, _i); \
RETURN_IF_ERROR(codegen_visit_ ## TYPE((C), elt)); \
} \
}

#define VISIT_SEQ_IN_SCOPE(C, TYPE, SEQ) { \
int _i; \
asdl_ ## TYPE ## _seq *seq = (SEQ); /* avoid variable capture */ \
for (_i = 0; _i < asdl_seq_LEN(seq); _i++) { \
TYPE ## _ty elt = (TYPE ## _ty)asdl_seq_GET(seq, _i); \
if (codegen_visit_ ## TYPE((C), elt) < 0) { \
_PyCompile_ExitScope(C); \
return ERROR; \
} \
} \
}
#define VISIT_SEQ(C, TYPE, SEQ) \
do { \
asdl_ ## TYPE ## _seq *seq = (SEQ); /* avoid variable capture */ \
for (int _i = 0; _i < asdl_seq_LEN(seq); _i++) { \
TYPE ## _ty elt = (TYPE ## _ty)asdl_seq_GET(seq, _i); \
RETURN_IF_ERROR(codegen_visit_ ## TYPE((C), elt)); \
} \
} while (0)

#define VISIT_SEQ_IN_SCOPE(C, TYPE, SEQ) \
do { \
asdl_ ## TYPE ## _seq *seq = (SEQ); /* avoid variable capture */ \
for (int _i = 0; _i < asdl_seq_LEN(seq); _i++) { \
TYPE ## _ty elt = (TYPE ## _ty)asdl_seq_GET(seq, _i); \
if (codegen_visit_ ## TYPE((C), elt) < 0) { \
_PyCompile_ExitScope(C); \
return ERROR; \
} \
} \
} while (0)

static int
codegen_call_exit_with_nones(compiler *c, location loc)
Expand Down Expand Up @@ -2866,7 +2874,7 @@ codegen_visit_stmt(compiler *c, stmt_ty s)
case Return_kind:
return codegen_return(c, s);
case Delete_kind:
VISIT_SEQ(c, expr, s->v.Delete.targets)
VISIT_SEQ(c, expr, s->v.Delete.targets);
break;
case Assign_kind:
{
Expand Down Expand Up @@ -4759,7 +4767,7 @@ codegen_async_with(compiler *c, stmt_ty s, int pos)
pos++;
if (pos == asdl_seq_LEN(s->v.AsyncWith.items)) {
/* BLOCK code */
VISIT_SEQ(c, stmt, s->v.AsyncWith.body)
VISIT_SEQ(c, stmt, s->v.AsyncWith.body);
}
else {
RETURN_IF_ERROR(codegen_async_with(c, s, pos));
Expand Down Expand Up @@ -4858,7 +4866,7 @@ codegen_with(compiler *c, stmt_ty s, int pos)
pos++;
if (pos == asdl_seq_LEN(s->v.With.items)) {
/* BLOCK code */
VISIT_SEQ(c, stmt, s->v.With.body)
VISIT_SEQ(c, stmt, s->v.With.body);
}
else {
RETURN_IF_ERROR(codegen_with(c, s, pos));
Expand Down
8 changes: 5 additions & 3 deletions Python/compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@
#define ERROR -1

#define RETURN_IF_ERROR(X) \
if ((X) == -1) { \
return ERROR; \
}
do { \
if ((X) == -1) { \
return ERROR; \
} \
} while (0)

typedef _Py_SourceLocation location;
typedef _PyJumpTargetLabel jump_target_label;
Expand Down
2 changes: 1 addition & 1 deletion Tools/wasm/wasi.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ def main():
"(default designed for wasmtime 14 or newer: "
f"`{default_host_runner}`)")
for subcommand in build, configure_host, make_host:
subcommand.add_argument("--host-triple", action="store", default="wasm32-wasi",
subcommand.add_argument("--host-triple", action="store", default="wasm32-wasip1",
help="The target triple for the WASI host build")

context = parser.parse_args()
Expand Down
6 changes: 3 additions & 3 deletions configure

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ then
*-*-emscripten)
ac_sys_system=Emscripten
;;
*-*-wasi)
*-*-wasi*)
ac_sys_system=WASI
;;
*)
Expand Down Expand Up @@ -1201,7 +1201,7 @@ AS_CASE([$host/$ac_cv_cc_name],
[aarch64-*-linux-gnu/gcc], [PY_SUPPORT_TIER=2], dnl Linux ARM64, glibc, gcc+clang
[aarch64-*-linux-gnu/clang], [PY_SUPPORT_TIER=2],
[powerpc64le-*-linux-gnu/gcc], [PY_SUPPORT_TIER=2], dnl Linux on PPC64 little endian, glibc, gcc
[wasm32-unknown-wasi/clang], [PY_SUPPORT_TIER=2], dnl WebAssembly System Interface, clang
[wasm32-unknown-wasip1/clang], [PY_SUPPORT_TIER=2], dnl WebAssembly System Interface preview1, clang
[x86_64-*-linux-gnu/clang], [PY_SUPPORT_TIER=2], dnl Linux on AMD64, any vendor, glibc, clang

[aarch64-pc-windows-msvc/msvc], [PY_SUPPORT_TIER=3], dnl Windows ARM64, MSVC
Expand Down Expand Up @@ -1647,7 +1647,7 @@ then
dnl TODO: support other WASI runtimes
dnl wasmtime starts the process with "/" as CWD. For OOT builds add the
dnl directory containing _sysconfigdata to PYTHONPATH.
[WASI/*], [HOSTRUNNER='wasmtime run --wasm max-wasm-stack=16777216 --wasi preview2 --env PYTHONPATH=/$(shell realpath --relative-to $(abs_srcdir) $(abs_builddir))/$(shell cat pybuilddir.txt):/Lib --dir $(srcdir)::/'],
[WASI/*], [HOSTRUNNER='wasmtime run --wasm max-wasm-stack=16777216 --wasi preview2=n --env PYTHONPATH=/$(shell realpath --relative-to $(abs_srcdir) $(abs_builddir))/$(shell cat pybuilddir.txt):/Lib --dir $(srcdir)::/'],
[HOSTRUNNER='']
)
fi
Expand Down

0 comments on commit 40b37be

Please sign in to comment.