Skip to content

Commit 3e6e34b

Browse files
janvranyshingarov
authored andcommitted
[Z3] Fix Z3FuncDeclKind for Z3 <= 4.8.15
Commit `58ece73` introduced pool `Z3FuncDeclKind`. (Integer) values of those "decl kinds" were taken from Z3 4.13.0. However, it turned out that Z3 commit 9fa00aec1 [1] introduced new kind - Z3_OP_RECURSIVE - that did not exist before. Unfortunately it was done in a way that that the integer value is the same as what USED TO BE value of `Z3_OP_UNINTERPRETED` and `Z3_OP_UNINTERPRETED` got assigned new value This means that the value of `Z3_OP_UNINTERPRETED` differ, depending on version. This commit works around the problem by updating value depending on actual Z3 version at runtime. An obvious place to do so would be in pool `initialize` but that does not work for two reasons: (i) initialize is called at the time package is loaded, meaning before user have a chance to specify which library to use (`LibZ3 class >> libraryName:`). So it may or may not update to correct values. Worse, it may bind to the wrong library too early, making `LibZ3 class >> libraryName:` useless. (ii) for the same reason, if something goes wrong it'd difficult to debug. So instead, this code updates values just before the very first context is create and/or when image is restarted. [1]: Z3Prover/z3@c9fa00aec1
1 parent 3df11e1 commit 3e6e34b

File tree

2 files changed

+46
-3
lines changed

2 files changed

+46
-3
lines changed

src/Z3/Z3Context.class.st

+12-1
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,19 @@ Z3Context class >> current [
2626

2727
{ #category : #'instance creation' }
2828
Z3Context class >> from: aZ3Config [
29-
^Z3 mk_context: aZ3Config
29+
"Create and return new Z3Context"
3030

31+
"And now something horrible. We need to update (some or)
32+
Z3FuncDeclKind values, depending on a version. Rather than
33+
doing it at class initialization time, we do it lazily,
34+
just before first context is created and/or when image
35+
is restarted. This makes it easier to debug when something
36+
goes wrong. Sigh."
37+
38+
(Global isNil or:[ Global isNull ]) ifTrue:[
39+
Z3FuncDeclKind update.
40+
].
41+
^Z3 mk_context: aZ3Config
3142
]
3243

3344
{ #category : #'instance creation' }

src/Z3/Z3FuncDeclKind.class.st

+34-2
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,39 @@ Z3FuncDeclKind class >> initialize02 [
586586
Z3_OP_FPA_BVWRAP := 45098 .
587587
Z3_OP_FPA_BV2RM := 45099 .
588588
Z3_OP_INTERNAL := 45100 .
589-
Z3_OP_RECURSIVE := 45101 .
590-
Z3_OP_UNINTERPRETED := 45102 .
589+
Z3_OP_RECURSIVE := 'Z3FuncDeclKind class >> #update not called' copy.
590+
Z3_OP_UNINTERPRETED := 'Z3FuncDeclKind class >> #update not called' copy.
591+
]
592+
593+
{ #category : #private }
594+
Z3FuncDeclKind class >> update [
595+
"Update enum values depending on version of Z3 we're
596+
using - ugly indeed."
597+
598+
| ver |
599+
600+
ver := Z3 getVersion.
601+
602+
"Z3 commit c9fa00aec1 introduced new kind - Z3_OP_RECURSIVE.
603+
Unfortunately it was done in a way that that the integer
604+
value is the same as what USED TO BE value of Z3_OP_UNINTERPRETED
605+
and Z3_OP_UNINTERPRETED got assigned new value, making this
606+
change not compatible. Therefore, here we check the version
607+
and try to update pool values accordingly. Sigh.
591608
609+
[1]: https://github.com/Z3Prover/z3/commit/c9fa00aec1
610+
"
611+
(ver first > 4 or: [ ver second > 8 or: [ver third > 15 ]]) ifTrue: [
612+
"Z3 > 4.8.15"
613+
Z3_OP_RECURSIVE := 45101 .
614+
Z3_OP_UNINTERPRETED := 45102 .
615+
] ifFalse: [
616+
"Z3 <= 4.8.15"
617+
Z3_OP_RECURSIVE := 'Not defined for Z3 <= 4.8.15' copy.
618+
Z3_OP_UNINTERPRETED := 45101 .
619+
].
620+
621+
"
622+
Z3FuncDeclKind update
623+
"
592624
]

0 commit comments

Comments
 (0)