| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
|
awesome, you already got the key parts |
Sorry, something went wrong.
|
It almost finishes codegen, the only problem faced right now is this error: D:/Documents/Programming/GitHub/RustPython/target/debug/rustpython.exe match_test.py
thread 'main' panicked at compiler\codegen\src\compile.rs:3287:9:
assertion `left == right` failed: switching to completed block
left: BlockIdx(2)
right: BlockIdx(4294967295)
stack backtrace:
0: std::panicking::begin_panic_handler
at /rustc/9fc6b43126469e3858e2fe86cafb4f0fd5068869\library/std\src\panicking.rs:665
1: core::panicking::panic_fmt
at /rustc/9fc6b43126469e3858e2fe86cafb4f0fd5068869\library/core\src\panicking.rs:76
2: core::panicking::assert_failed_inner
at /rustc/9fc6b43126469e3858e2fe86cafb4f0fd5068869\library/core\src\panicking.rs:413
3: core::panicking::assert_failed<rustpython_codegen::ir::BlockIdx,rustpython_codegen::ir::BlockIdx>
at C:\Users\ariha\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\panicking.rs:373
4: rustpython_codegen::compile::Compiler::switch_to_block
at .\compiler\codegen\src\compile.rs:3287
5: rustpython_codegen::compile::Compiler::compile_match_inner
at .\compiler\codegen\src\compile.rs:1997
6: rustpython_codegen::compile::Compiler::compile_match
at .\compiler\codegen\src\compile.rs:2012
7: rustpython_codegen::compile::Compiler::compile_statement
at .\compiler\codegen\src\compile.rs:771
8: rustpython_codegen::compile::Compiler::compile_statements
at .\compiler\codegen\src\compile.rs:501
9: rustpython_codegen::compile::Compiler::compile_program
at .\compiler\codegen\src\compile.rs:416
10: core::ops::function::FnOnce::call_once<enum2$<core::result::Result<tuple$<>,rustpython_parser_core::source_code::LocatedError<enum2$<rustpython_codegen::error::CodegenErrorType> > > > (*)(ref_mut$<rustpython_codegen::compile::Compiler>,ref$<slice2$<enum2$<
at C:\Users\ariha\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\ops\function.rs:250
11: rustpython_codegen::compile::compile_impl<slice2$<enum2$<rustpython_ast::generic::Stmt<rustpython_parser_core::source_code::SourceRange> > >,enum2$<core::result::Result<rustpython_codegen::symboltable::SymbolTable,rustpython_codegen::symboltable::SymbolTab
at .\compiler\codegen\src\compile.rs:138
12: rustpython_codegen::compile::compile_program
at .\compiler\codegen\src\compile.rs:150
13: rustpython_codegen::compile::compile_top
at .\compiler\codegen\src\compile.rs:110
14: rustpython_compiler::compile
at .\compiler\src\lib.rs:66
15: rustpython_vm::vm::VirtualMachine::compile_with_opts
at .\vm\src\vm\compile.rs:26
16: rustpython_vm::vm::VirtualMachine::compile
at .\vm\src\vm\compile.rs:16
17: rustpython_vm::vm::VirtualMachine::run_code_string
at .\vm\src\vm\compile.rs:61
18: rustpython_vm::vm::VirtualMachine::run_script
at .\vm\src\vm\compile.rs:49
19: rustpython::run_rustpython
at .\src\lib.rs:206
20: rustpython::run::closure$0<rustpython::main::closure_env$0>
at .\src\lib.rs:99
21: rustpython_vm::vm::interpreter::impl$0::run::closure$0<rustpython::run::closure_env$0<rustpython::main::closure_env$0> >
at .\vm\src\vm\interpreter.rs:104
22: rustpython_vm::vm::interpreter::impl$0::enter::closure$0<rustpython_vm::vm::interpreter::impl$0::run::closure_env$0<rustpython::run::closure_env$0<rustpython::main::closure_env$0> >,enum2$<core::result::Result<tuple$<>,rustpython_vm::object::core::PyRef<ru
at .\vm\src\vm\interpreter.rs:72
23: core::panic::unwind_safe::impl$25::call_once<enum2$<core::result::Result<tuple$<>,rustpython_vm::object::core::PyRef<rustpython_vm::exceptions::types::PyBaseException> > >,rustpython_vm::vm::interpreter::impl$0::enter::closure_env$0<rustpython_vm::vm::inte
at C:\Users\ariha\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\panic\unwind_safe.rs:272
24: std::panicking::try::do_call<core::panic::unwind_safe::AssertUnwindSafe<rustpython_vm::vm::interpreter::impl$0::enter::closure_env$0<rustpython_vm::vm::interpreter::impl$0::run::closure_env$0<rustpython::run::closure_env$0<rustpython::main::closure_env$0>
at C:\Users\ariha\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\std\src\panicking.rs:557
25: std::panic::catch_unwind<core::panic::unwind_safe::AssertUnwindSafe<rustpython_vm::vm::interpreter::impl$0::enter::closure_env$0<rustpython_vm::vm::interpreter::impl$0::run::closure_env$0<rustpython::run::closure_env$0<rustpython::main::closure_env$0> >,en
26: std::panicking::try
at C:\Users\ariha\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\std\src\panicking.rs:520
27: std::panic::catch_unwind<core::panic::unwind_safe::AssertUnwindSafe<rustpython_vm::vm::interpreter::impl$0::enter::closure_env$0<rustpython_vm::vm::interpreter::impl$0::run::closure_env$0<rustpython::run::closure_env$0<rustpython::main::closure_env$0> >,en
at C:\Users\ariha\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\std\src\panic.rs:358
28: rustpython_vm::vm::thread::enter_vm::closure$0<enum2$<core::result::Result<tuple$<>,rustpython_vm::object::core::PyRef<rustpython_vm::exceptions::types::PyBaseException> > >,rustpython_vm::vm::interpreter::impl$0::enter::closure_env$0<rustpython_vm::vm::in
at .\vm\src\vm\thread.rs:31
29: std::thread::local::LocalKey<core::cell::RefCell<alloc::vec::Vec<core::ptr::non_null::NonNull<rustpython_vm::vm::VirtualMachine>,alloc::alloc::Global> > >::try_with<core::cell::RefCell<alloc::vec::Vec<core::ptr::non_null::NonNull<rustpython_vm::vm::Virtual
at C:\Users\ariha\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\std\src\thread\local.rs:283
30: std::thread::local::LocalKey<core::cell::RefCell<alloc::vec::Vec<core::ptr::non_null::NonNull<rustpython_vm::vm::VirtualMachine>,alloc::alloc::Global> > >::with<core::cell::RefCell<alloc::vec::Vec<core::ptr::non_null::NonNull<rustpython_vm::vm::VirtualMach
at C:\Users\ariha\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\std\src\thread\local.rs:260
31: rustpython_vm::vm::thread::enter_vm<enum2$<core::result::Result<tuple$<>,rustpython_vm::object::core::PyRef<rustpython_vm::exceptions::types::PyBaseException> > >,rustpython_vm::vm::interpreter::impl$0::enter::closure_env$0<rustpython_vm::vm::interpreter::
at .\vm\src\vm\thread.rs:28
32: rustpython_vm::vm::interpreter::Interpreter::enter<rustpython_vm::vm::interpreter::impl$0::run::closure_env$0<rustpython::run::closure_env$0<rustpython::main::closure_env$0> >,enum2$<core::result::Result<tuple$<>,rustpython_vm::object::core::PyRef<rustpyth
at .\vm\src\vm\interpreter.rs:72
33: rustpython_vm::vm::interpreter::Interpreter::run<rustpython::run::closure_env$0<rustpython::main::closure_env$0> >
at .\vm\src\vm\interpreter.rs:104
34: rustpython::run<rustpython::main::closure_env$0>
at .\src\lib.rs:99
35: rustpython::main
at .\src\main.rs:2
36: core::ops::function::FnOnce::call_once<std::process::ExitCode (*)(),tuple$<> >
at C:\Users\ariha\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\ops\function.rs:250
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
What seems to be happening is the self.switch_to_block(end_block); from the let end_block = self.new_block(); isn't working because of a previous block having been completed. I tried moving instantiation around but it didn't fix it. @youknowone how should I proceed? |
Sorry, something went wrong.
|
When I encountered similar issue before, it was related to wrong order of value stack/block stack operations. #5275 was one of them |
Sorry, something went wrong.
|
Currently there is a test in compile.rs called test_match that reproduces the issue (the code is identical). |
Sorry, something went wrong.
|
Though I don't know well how this blocks are working, switch_to_block in jump_to_fail_pop doesn't look safe. |
Sorry, something went wrong.
|
I merged #5489 for easier debug. |
Sorry, something went wrong.
|
The cpython implementation also has a hacky way of popping things off the stack (by repeatedly switching to blocks) and I'm not sure that's going to run without panicking anymore |
Sorry, something went wrong.
|
Seems like codegen almost works, it's currently getting an u32::MAX mixed in somewhere it's not supposed to be however. Debug printing: ===BLOCK 0===
LoadConst("one"): 0 +1 => 1
StoreLocal(0, v): 1 -1 => 0
LoadNameAny(0, v): 0 +1 => 1
Duplicate: 1 +1 => 2
LoadConst("one"): 2 +1 => 3
CompareOperation(Equal): 3 -1 => 2
Pop: 2 -1 => 1
LoadConst("two"): 1 +1 => 2
StoreLocal(0, v): 2 -1 => 1
Jump(5): 1 +0 => 1
===BLOCK 5===
index out of bounds: the len is 7 but the index is 4294967295
thread 'compile::tests::test_match' panicked at compiler\codegen\src\ir.rs:311:28:
index out of bounds: the len is 7 but the index is 4294967295
stack backtrace:
0: std::panicking::begin_panic_handler
at /rustc/9fc6b43126469e3858e2fe86cafb4f0fd5068869\library/std\src\panicking.rs:665
1: core::panicking::panic_fmt
at /rustc/9fc6b43126469e3858e2fe86cafb4f0fd5068869\library/core\src\panicking.rs:76
2: core::panicking::panic_bounds_check
at /rustc/9fc6b43126469e3858e2fe86cafb4f0fd5068869\library/core\src\panicking.rs:281
3: rustpython_codegen::ir::stackdepth_push
at .\src\ir.rs:311
4: rustpython_codegen::ir::CodeInfo::max_stackdepth
at .\src\ir.rs:277
5: rustpython_codegen::ir::CodeInfo::finalize_code
at .\src\ir.rs:88
6: rustpython_codegen::compile::Compiler::pop_code_object
at .\src\compile.rs:365
7: rustpython_codegen::compile::tests::compile_exec
at .\src\compile.rs:3675
8: rustpython_codegen::compile::tests::test_match
at .\src\compile.rs:3737
9: rustpython_codegen::compile::tests::test_match::closure$0
at .\src\compile.rs:3736
10: core::ops::function::FnOnce::call_once<rustpython_codegen::compile::tests::test_match::closure_env$0,tuple$<> >
at C:\Users\ariha\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\ops\function.rs:250
11: core::ops::function::FnOnce::call_once
at /rustc/9fc6b43126469e3858e2fe86cafb4f0fd5068869\library/core\src\ops\function.rs:250
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
|
Sorry, something went wrong.
|
Seems like all the blocks target u32::MAX as their next block. I modified them to point at the next block as their target and string together that way. |
Sorry, something went wrong.
Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
|
Currently the output is as follows: ===BLOCK 0===
LoadConst(0): 0 +1 => 1
LoadConst(None): 1 +1 => 2
ImportName(0, sys): 2 -1 => 1
StoreLocal(0, sys): 1 -1 => 0
LoadNameAny(0, sys): 0 +1 => 1
LoadAttr(1, path): 1 +0 => 1
LoadMethod(2, insert): 1 +2 => 3
LoadConst(0): 3 +1 => 4
LoadConst(""): 4 +1 => 5
CallMethodPositional(2): 5 -4 => 1
Pop: 1 -1 => 0
ReturnConst(None): 0 +0 => 0
DONE: 5
created pattern_blocks: BlockIdx(1) - BlockIdx(5)(end block)
linking: 1 -> 2
linking: 2 -> 3
linking: 3 -> 4
linking: 4 -> 5
linking: 5 -> 7
0
0: 4294967295 28
1: 2 0
2: 3 0
3: 4 0
4: 5 0
5: 7 0
6: 4294967295 0
7: 4294967295 0
switch_to_block BlockIdx(0) -> BlockIdx(7)
block: 1 -> 2
block: 2 -> 3
block: 3 -> 4
block: 4 -> 5
block: 5 -> 7
block: 7 -> 4294967295
===BLOCK 0===
LoadConst("one"): 0 +1 => 1
StoreLocal(0, v): 1 -1 => 0
LoadNameAny(0, v): 0 +1 => 1
Duplicate: 1 +1 => 2
LoadConst("one"): 2 +1 => 3
CompareOperation(Equal): 3 -1 => 2
Pop: 2 -1 => 1
LoadConst("two"): 1 +1 => 2
StoreLocal(0, v): 2 -1 => 1
Jump(5): 1 +0 => 1
===BLOCK 5===
===BLOCK 7===
ReturnConst(None): 1 +0 => 1
DONE: 3
[vm\src\frame.rs:2103:9] self = ExecutingFrame {
code: code: <code object <module> at ??? file "match_test.py", line 1>,
state: FrameState {
stack: [
[PyObject PyStr { value: "one", kind: Ascii, hash: -1 }],
[PyObject PyStr { value: "one", kind: Ascii, hash: -1 }],
[PyObject PyStr { value: "one", kind: Ascii, hash: -1 }],
],
blocks: [],
lasti: 5,
},
}
thread 'main' panicked at vm\src\frame.rs:522:22:
tried to push value onto stack but overflowed max_stackdepth
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
error: process didn't exit successfully: `target\debug\rustpython.exe match_test.py` (exit code: 101)
for # match_test.py
v = "one"
match v:
case "one":
v = "two"
case "two":
v = "three"
case "three":
v = "one"
case _:
v = "one" |
Sorry, something went wrong.
|
If you'd like to investigate how stackdepth work, trying this issue probably be helpful #5154 |
Sorry, something went wrong.
|
I think I will try solving this by carefully checking the generated instructions |
Sorry, something went wrong.
Expression: compile_exec(
r#"\
match v:
case "one":
v = "two"
case "two":
v = "three"
case "three":
v = "one"
case _:
v = "one"
"#,
)
───────────────────────────────────────────────────────────────────────────────
+new results
────────────┬──────────────────────────────────────────────────────────────────
0 │+ 2 >> 0 LoadNameAny (0, v)
1 │+ 1 Duplicate
2 │+
3 │+ 3 2 LoadConst ("one")
4 │+ 3 CompareOperation (Equal)
5 │+ 4 Pop
6 │+
7 │+ 4 5 LoadConst ("two")
8 │+ 6 StoreLocal (0, v)
9 │+ 7 Jump (0)
10 │+ 8 Duplicate
11 │+
12 │+ 5 9 LoadConst ("two")
13 │+ 10 CompareOperation (Equal)
14 │+ 11 Pop
15 │+
16 │+ 6 12 LoadConst ("three")
17 │+ 13 StoreLocal (0, v)
18 │+ 14 Jump (0)
19 │+ 15 Duplicate
20 │+
21 │+ 7 16 LoadConst ("three")
22 │+ 17 CompareOperation (Equal)
23 │+ 18 Pop
24 │+
25 │+ 8 19 LoadConst ("one")
26 │+ 20 StoreLocal (0, v)
27 │+ 21 Jump (0)
28 │+ 22 Pop
29 │+
30 │+ 10 23 LoadConst ("one")
31 │+ 24 StoreLocal (0, v)
32 │+ 25 Jump (0)
33 │+ 26 ReturnConst (None)
────────────┴──────────────────────────────────────────────────────────────────
the issue is that everything is jumping to line 0 for no reason (see line 21, line 9, and line 32 of the bytecode) |
Sorry, something went wrong.
Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
|
Ok I rewrote some parts of it and it works for basic match statements now. @youknowone do I have to pop stuff from the stack when I'm done with it? |
Sorry, something went wrong.
Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
|
If there are redundant stack elements for other purpose, yes, I guess so. |
Sorry, something went wrong.
Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
|
Due to the other functions being much more complicated than expected I think we can let this PR be merged for now and I can follow up with more PRs that fix the unimplemented sections. |
Sorry, something went wrong.
Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
See compile_pattern_inner and compile_pattern_value, the values are not popped at the end. |
Sorry, something went wrong.
Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
|
I agree to merge it. It compiles without panic. It is already a big progress |
Sorry, something went wrong.
|
@arihant2math I removed unused nop, swap op in this merge. Please cherry-pick this commit to get it back |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
This pr turns the parsed AST of a match-case statement into bytecode for the VM.
Progress:
Resolves: #4770