Commit Graph
32 Commits
Author SHA1 Message Date
Jeong, YunWon 3b4c5f65dd Align compiler and AST behavior with CPython (#8138)
* Align compiler and AST behavior with CPython

Update the compiler pipeline, AST module support, and related VM compile/eval paths toward CPython 3.14 behavior.

Use upstream Ruff parser crates directly and keep RustPython-specific syntax preflight handling in the compile path.

Refresh opcode metadata, snapshots, and targeted tests for the aligned bytecode and AST behavior.

* fix

* Fix PR 8138 CI failures

* Fix match mapping wildcard scan complexity

* fixes

* Use Ruff runtime AST fields

* Minimize residual patch diff

* refactor error handling

* Remove _ast conversion context wrappers

* Clean up _ast conversion glue and compiler warning escalation

Rename the Node conversion parameter `ctx` to `vm` throughout the _ast
module.

Remove the unused compile_program, compile_program_single,
compile_block_expression, and compile_expression forwarders; compile_top
stays as the entry point.

Stash an escalated compiler SyntaxWarning so a non-SyntaxWarning category
propagates unchanged instead of being rewritten to SyntaxError, matching
PyErr_ExceptionMatches(SyntaxWarning) in compiler_warn. Drop the now-unused
CompileWarningError::into_codegen_error.

Replace the PositionalArguments two-variant enum with a struct holding a
shared range and a PositionalArgumentsKind enum.

Assisted-by: Claude

* Represent compiler flags as a CompilerFlags bitflags

Replace the loose PY_CF_*/CO_* i32 constants in compile_mode with a
CompilerFlags bitflags covering the PyCF_* flags and __future__
CO_FUTURE_* bits. The Python-visible ast.PyCF_* attribute values are
derived from it via bits(); parser input modes stay plain consts.

builtins::compile and the compile_string flag handling test flags
through CompilerFlags::contains instead of raw bit math.

Assisted-by: Claude

* Fix PR 8138 test regressions

* Fix PR 8138 CI failures

* Avoid shell interpolation in Linux deps action

* Fix review findings in compiler/AST changes

- frame.rs: compute the MATCH_CLASS class name lazily so a successful
  match no longer takes the type name lock or allocates; the
  __match_args__-not-a-tuple branch reuses it instead of recomputing.
- _ast/constant.rs: add the missing leading space to the with_recursion
  label ("maximum recursion depth exceeded during compilation").
- sys.set_int_max_str_digits: restore the "maxdigits must be 0 or larger
  than {n}" error text.
- codegen: set CO_MAXBLOCKS to 20 in both ir.rs and compile.rs.
- _ast/exception.rs: extract the duplicated excepthandler node guard
  into ensure_excepthandler_node.
- codegen: correct the validate_keywords doc comment.
- Drop redundant "CPython" qualifiers from comments added in this branch.

Assisted-by: Claude
2026-06-26 18:22:08 +09:00
Shahar Naveh c0e306688a Reduce number of string clones when compiling python source code (#8103) 2026-06-15 11:20:48 +09:00
Noa 6b72d2ef5d Check+lint examples, tests, and benches in CI 2025-03-28 11:26:12 +09:00
Jeong YunWon bac1cdc55f Remove compiler_core::CompileError 2023-05-06 18:22:25 +09:00
Jeong YunWon 98eef0804e Method overhaul with PyMethodDef 2023-04-30 17:33:23 +09:00
Jeong YunWon 55061c7b6a new_syntax_error working without full compiler
Fix #4100
2022-08-23 05:08:24 +09:00
Jeong YunWon fc6d614bf4 rustpython-bytecode -> rustpython-compiler-core 2022-08-22 08:42:20 +09:00
Jeong Yunwon 93d1438345 PyObjBag refers Context instead of vm 2022-05-16 04:45:13 +09:00
Jeong Yunwon 6fd5094c05 Remove Interpreter::default() not to trap users init without stdlib 2022-04-30 05:09:33 +09:00
Kangzhi Shi 9a2eef6fab fix compile 2021-11-27 13:49:05 +02:00
Jeong YunWon 256de1eb46 Move free functions in vm::exceptions to vm methods 2021-10-13 05:53:43 +09:00
Jeong YunWon 5cd375aaa9 clean up functions and methods 2021-10-11 16:10:01 +09:00
Jeong YunWon cb9bfce007 clean up use statements 2021-09-26 04:05:53 +09:00
Noah 99104faaf7 Re-export pyobject::* from the root of the crate 2021-05-20 10:24:07 -05:00
Noah a4aef93327 Make all builtin functions have names 2020-12-17 16:29:43 -06:00
Noah b30ca99a09 Implement string interning 2020-11-08 21:35:04 -06:00
Noah 70907babe6 Fix wasm + examples 2020-11-07 15:43:23 -06:00
Noah e74a8ec9fb Fix mini_repl and make ctx.new_code_object() more ergonomic 2020-10-19 23:55:55 -05:00
Jeong YunWon ca9326f95d expose bulitins items on builtins module and hide submodules 2020-10-12 11:43:24 +09:00
Jeong YunWon 9e6dfca9e9 Fix build with new builtins path 2020-10-11 21:16:16 +09:00
Ben Lewis c54b4bb833 Split py_compile_bytecode into py_compile and py_freeze. 2020-09-18 18:59:58 +12:00
Noah 18273da108 Interpreter struct for managing thread-local vm stack 2020-09-15 16:44:39 -05:00
Jeong YunWon f8a5cc4b23 Remove type clone functions from vm.ctx
which misleads to clone types when we don't need.
2020-08-23 20:26:37 +09:00
Jeong YunWon 1249fab930 Merge pull request #2035 from youknowone/dictkey
Refactor DictKey
2020-08-04 02:45:05 +09:00
Jeong YunWon 67b5d61d1f Refactor DictKey 2020-08-04 02:12:56 +09:00
Noah ba8c0d9a82 Use sys.excepthook when exceptions bubble to the top level 2020-08-02 12:23:12 -05:00
Aviv Palivoda 3eaa8307a1 Make mini_repl thread safe 2020-04-29 12:44:15 +03:00
Jeong YunWon 1bac582921 &str::to_string -> &str::to_owned for literals 2020-02-05 22:55:33 +09:00
Cedric Hutchings 93ccc69d7d Replace 'pointer' with 'memory' 2020-01-26 15:40:01 -05:00
Cedric Hutchings d1f74f90cd Make suggested improvements to mini_repl.rs 2020-01-26 15:29:58 -05:00
Cedric Hutchings c6aed0464a Add note about when output is printed to mini_repl.rs 2020-01-26 01:04:53 -05:00
Cedric Hutchings 9beb44251d Add examples showcasing how to embed RustPython in Rust applications 2020-01-26 00:42:35 -05:00