Skip to content
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

Value stack tag mismatch with the fast interpreter #271

Open
vouillon opened this issue Feb 3, 2025 · 6 comments
Open

Value stack tag mismatch with the fast interpreter #271

vouillon opened this issue Feb 3, 2025 · 6 comments

Comments

@vouillon
Copy link
Contributor

vouillon commented Feb 3, 2025

With #269, I still get an error with the fast interpreter on the attached program:

$ ./bin/wizeng.x86-64-linux  -ext:gc -ext:exception-handling ./print_array.wasm 
!X86_64StackError: value stack tag mismatch, expected ref, got 00
	in X86_64Stack.fatal() [src/engine/x86-64/X86_64Stack.v3 @ 462:29]
	in X86_64Stack.peekRef() [src/engine/x86-64/X86_64Stack.v3 @ 326:62]
	in X86_64Stack.popRef() [src/engine/x86-64/X86_64Stack.v3 @ 319:34]
	in X86_64Stack.pop() [src/engine/x86-64/X86_64Stack.v3 @ 310:70]
	in X86_64Stack.popV() [src/engine/x86-64/X86_64Stack.v3 @ 293:27]
	in Runtime.STRUCT_NEW() [src/engine/Runtime.v3 @ 42:47]
	in X86_64Runtime.runtime_STRUCT_NEW() [src/engine/x86-64/X86_64Runtime.v3 @ 244:42]
	in [fast-int] "toplevel"
	in [fast-int] "caml_main"
	in [fast-int] "entry_point"
	in [fast-int] #117
	in [return-parent-stub]
	in X86_64Stack.resume() [src/engine/x86-64/X86_64Stack.v3 @ 73:56]
	in X86_64StackManager.runOnFreshStack() [src/engine/x86-64/X86_64Stack.v3 @ 1009:62]
	in X86_64InterpreterOnlyStrategy.call() [src/engine/x86-64/X86_64Target.v3 @ 150:58]
	in Execute.call() [src/engine/Execute.v3 @ 18:36]
	in main() [src/wizeng.main.v3 @ 176:45]

The slow interpreter seems to work fine (after providing a dummy implementation for the WASI function random_get):

$ ./bin/wizeng.x86-linux -ext:gc -ext:exception-handling ./print_array.wasm 
empty
 0
misc
 1 2 3
end of tests

All tests succeeded.
@titzer
Copy link
Owner

titzer commented Feb 3, 2025

Thanks, I'll take a look at this soon.

@titzer
Copy link
Owner

titzer commented Feb 4, 2025

Looks like it was overwriting a register while decoding an unused part of a reference type local. With this change, the test program fails later with a failed cast (which I hope is right! :-))

@titzer titzer closed this as completed Feb 4, 2025
@vouillon
Copy link
Contributor Author

vouillon commented Feb 4, 2025

Well, looking at the diff between the traces of the slow and fast interpreter, it seems there is also an off by one error somewhere :)

--- ok.txt      2025-02-04 04:04:29.420647490 +0100
+++ bug.txt     2025-02-04 04:04:18.412609428 +0100
@@ -115698,21188 +115698,15 @@
         +67:  local.get[2]
         +69:  local.get[4]
         +71:  select[(ref eq)]
+        +74:  i32.div_s
         +75:  local.tee[1]
         +77:  call[func=24]
           +3:   local.get[0]
           +5:   ref.cast[i31]
-          +8:   i31.get_s
-          +10:  local.tee[1]
-          +12:  i32.const[0]
[...]
+<wasm func #117> +65
+  <wasm func "entry_point"> +1
+    <wasm func "caml_main"> +11
+      <wasm func "toplevel"> +936
+        <wasm func "create$1"> +77
+          <wasm func "caml_create_bytes"> +5
+            !trap[FAILED_CAST]

@vouillon vouillon changed the title Value stack tag mismatch with the faster interpreter Value stack tag mismatch with the fast interpreter Feb 4, 2025
@titzer
Copy link
Owner

titzer commented Feb 4, 2025

Oh, yes, I see now the fast interpreter does not decode value types in select properly (https://github.com/titzer/wizard-engine/blob/master/src/engine/x86-64/X86_64Interpreter.v3#L1008). I'll see if I can get a fix in later today or tomorrow.

@titzer
Copy link
Owner

titzer commented Feb 6, 2025

See #277 .

@titzer
Copy link
Owner

titzer commented Feb 6, 2025

Looks like I fixed the interpreter but the JIT still fails with a value tag mismatch.

% wizeng.x86-64-linux -mode=jit -ext:gc -ext:exception-handling print_array.wasm 
!X86_64StackError: value stack tag mismatch, expected: 7F, got 64
	in X86_64Stack.fatal() [src/engine/x86-64/X86_64Stack.v3 @ 462:29]
	in X86_64Stack.checkTopTag() [src/engine/x86-64/X86_64Stack.v3 @ 366:22]
	in X86_64Stack.popb32() [src/engine/x86-64/X86_64Stack.v3 @ 343:28]
	in X86_64Stack.pop() [src/engine/x86-64/X86_64Stack.v3 @ 297:55]
	in X86_64Stack.popV() [src/engine/x86-64/X86_64Stack.v3 @ 293:27]
	in Runtime.STRUCT_NEW() [src/engine/Runtime.v3 @ 42:47]
	in X86_64Runtime.runtime_STRUCT_NEW() [src/engine/x86-64/X86_64Runtime.v3 @ 244:42]
	in [spc-module] "caml_ml_open_descriptor_out"
	in [spc-module] "toplevel"
	in [fast-int] "caml_main"
	in [spc-module] "entry_point"
	in [spc-module] #117
	in [return-parent-stub]
	in X86_64Stack.resume() [src/engine/x86-64/X86_64Stack.v3 @ 73:56]
	in X86_64StackManager.runOnFreshStack() [src/engine/x86-64/X86_64Stack.v3 @ 1009:62]
	in X86_64ExecutionStrategy.call() [src/engine/x86-64/X86_64Target.v3 @ 136:58]
	in Execute.call() [src/engine/Execute.v3 @ 18:36]
	in main() [src/wizeng.main.v3 @ 176:45]

@titzer titzer reopened this Feb 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants