3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2026-02-23 16:57:51 +00:00

Fix memory lifetime bug in async array parameter handling for JS API (#8125)

* Initial plan

* Fix async array parameter handling in JS API wrappers

Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>

* Add test for solver.check() with assumptions

Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>

* Address code review feedback: add null checks and improve readability

Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>

* Add unsatCore() method to Solver class

Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>
This commit is contained in:
Copilot 2026-01-08 18:43:58 -08:00 committed by Nikolaj Bjorner
parent d8fe997368
commit 3be56ff27b
5 changed files with 159 additions and 13 deletions

View file

@ -174,6 +174,29 @@ describe('high-level', () => {
expect(await solver.check()).toStrictEqual('unsat');
});
it('can check with assumptions and get unsat core', async () => {
const { Bool, Solver } = api.Context('main');
const solver = new Solver();
solver.set('unsat_core', true);
const x = Bool.const('x');
const y = Bool.const('y');
const z = Bool.const('z');
// Add conflicting assertions
solver.add(x.or(y));
solver.add(x.or(z));
// Check with assumptions that create a conflict
// This tests the async array parameter fix
const result = await solver.check(x.not(), y.not(), z.not());
expect(result).toStrictEqual('unsat');
// Verify we can get the unsat core
const core = solver.unsatCore();
expect(core.length()).toBeGreaterThan(0);
});
it("proves De Morgan's Law", async () => {
const { Bool, Not, And, Eq, Or } = api.Context('main');
const [x, y] = [Bool.const('x'), Bool.const('y')];

View file

@ -1463,6 +1463,10 @@ export function createApi(Z3: Z3Core): Z3HighLevel {
return new ModelImpl(check(Z3.solver_get_model(contextPtr, this.ptr)));
}
unsatCore(): AstVector<Name, Bool<Name>> {
return new AstVectorImpl(check(Z3.solver_get_unsat_core(contextPtr, this.ptr)));
}
toString() {
return check(Z3.solver_to_string(contextPtr, this.ptr));
}

View file

@ -713,6 +713,8 @@ export interface Solver<Name extends string = 'main'> {
model(): Model<Name>;
unsatCore(): AstVector<Name, Bool<Name>>;
/**
* Manually decrease the reference count of the solver
* This is automatically done when the solver is garbage collected,