Open sim642 opened 6 years ago
Turns out this is a problem with configuration under emscripten: https://github.com/Z3Prover/z3/issues/1298#issuecomment-400999214.
Wonder if you think this new effort might help (alternate strategy) ? https://github.com/kripken/emscripten/wiki/Pthreads-with-WebAssembly
Thanks for the report. It looks like rebuilding with thread support disable should fix this.
I tried building with --single-threaded and had no success running z3.wasm with timeouts. I published a release of that build at https://github.com/mgree/z3.wasm/releases/tag/v0.1.1 if anyone wants to try it.
The error messages I got were obscure. Using -T:2
, I got "exception thrown: 5607968"; using -t:2000
, I got "exception thrown: 7517160".
Has anyone been able to fix this? Here's the smallest case I've got this error on:
(declare-const i Int)
(declare-const n Int)
(assert (not (=> (< i n) (<= (+ i 1) n))))
(check-sat)
(exit)
I am also facing the same issue, the smallest case I can get (running at https://people.csail.mit.edu/cpitcla/z3.wasm/z3.html) is
(declare-fun y () Int)
(declare-fun x () Int)
(assert (or (= y 1) (= y 2)))
(assert (or (= x 3) (= x 4)))
(check-sat)
(exit)
Failed to verify: pthread_create(&m_thread_id, NULL, &thread_func, this) == 0
-- Verification complete (55ms)
Removing any of the four equalities causes the solver to return sat
.
However, this formulation returns sat
((= y 1) changed to (= y 0)):
(declare-fun y () Int)
(declare-fun x () Int)
(assert (or (= y 0) (= y 2)))
(assert (or (= x 3) (= x 4)))
(check-sat)
(exit)
sat
-- Verification complete (56ms)
Not sure what to make of it since I'm not familiar with the internals of Z3 and Emscripten, is there anything significant about the differences between these two examples?
I found a temporary hack around this. Since my use-case involves optimization, adding a set of declarations such as:
(declare-fun z () Int)
(assert-soft (= z 10))
bypasses this issue. Full working example:
(declare-fun y () Int)
(declare-fun x () Int)
(declare-fun z () Int)
(assert (or (= y 1) (= y 2)))
(assert (or (= x 3) (= x 4)))
(assert-soft (= z 10))
(check-sat)
(exit)
I expect this is due to the solve technique changing completely, which bypasses the pthread
creation by extension, so it might tank performance.
There are now official bindings of z3 which support threads, so this use case should work. Check #6.
EDIT: I can confirm that all "broken" expressions in this issue work correctly on the official bindings.
I experimented around with this and with nontrivial examples I'm getting an error:
Example of code causing that: