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

Overhaul Z3-level Datatype API #351

Merged
merged 5 commits into from
Sep 23, 2024
Merged

Overhaul Z3-level Datatype API #351

merged 5 commits into from
Sep 23, 2024

Conversation

shingarov
Copy link
Owner

No description provided.

The Z3 C API to Datatypes, is rather cumbersome and unpleasant to
program to.  The Z3 Python API attempts to improve this using Python's
"dynamic" features, synthesizing dynamic attributes for constructors,
recognizers and projections.  Our Smalltalk API so far was inspired by
the Python API; the result was somewhat awkward.  PR 338 proposes one
approach to improve on that.

This commit takes a different approach.  Instead of trying to sweeten
the pill, we stay 100% faithful to Nikolaj's C API.  For higher-level
use we jump up to Fixpoint's DataDecl; the latter mirrors the Haskell
API.  We skip the "mid-level" compromises altogether.
shingarov and others added 3 commits September 20, 2024 08:37
Earlier commit

    Replace Z3Datatype pythonism in favor of Fixpoint-level API

introduced test `Z3DatatypeTest >> testUniqueVoidNeg2` which was
crashing on Smalltalk/X but not Pharo. It turned out that the problem
was that `sort_refs` passed down to `Z3_mk_constructor` was an empty
array while the Z3 API assumes (requires) that it is of the same size
as `sorts` array.

The reason why this was crashing on Smalltalk/X and not on Pharo is
a subtle difference in `externalU32ArrayFrom:` (and externalArrayFrom:`)
- on Smalltalk/X this returns `null` pointer if the (smalltalk) array
is empty whereas on Pharo it returned valid pointer.

This commit fixes the test and adds an assert in
`mkConstructor:recognizer:fields:referencing:` to avoid a hard crash
should anyone pass `sorts` and `sort_refs` of different sizes.
@shingarov shingarov merged commit e05e8f9 into pure-z3 Sep 23, 2024
3 checks passed
@shingarov shingarov deleted the z3-datatype-api branch September 23, 2024 15:32
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

Successfully merging this pull request may close these issues.

2 participants