Repository navigation
Read a machine integer as an integer - #26
Merged
daniel-larraz merged 1 commit intoSep 22, 2026
Merged
Conversation
Kind 2 has two surface syntaxes for machine integers: the keywords `uint8` through `int64`, and `uint<N>`/`sint<N>` for a width of any size. Its JSON output names every one of them in the general form, including the eight that have a keyword, so the `case "int8":` arms of `Type.getType` never matched anything it printed. A machine integer therefore fell to the default of that switch, which treats a name it does not know as an enumeration, and arrived as an `Enum` holding an `EnumValue`: a consumer got the name of a constant where it wanted a number, with no `IntValue` and no `BigInteger` to do arithmetic with. Reading the general form gives back an `Int` holding an `IntValue`. Like the cases for the eight keywords, it gives the width up rather than carrying it, which also means a width with no keyword of its own, such as `uint<24>`, reads like any other. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Kind 2 has two surface syntaxes for machine integers: the keywords
uint8through
int64, anduint<N>andsint<N>for a width of any size. Its JSON output names every one of them in the
general form, the eight that have a keyword included, so the
arms of
Type.getTypenever match anything Kind 2 prints. A machine integerfalls through to the default of that switch, which treats a name it does not
recognise as an enumeration:
So a consumer reading a counterexample over machine integers gets the name of
an enumeration constant where it wanted a number: no
IntValue, noBigInteger, nothing to do arithmetic with.What changes
One more pattern in the default branch, beside the
subrange […] of intandarray offallbacks already there, reading the general form as an integer:Like the eight keyword cases, it gives the width up rather than carrying it,
so a stream reports as an integer and nothing more. Reporting the width would
mean a type of its own, which is a larger change and not what those cases do
today. The keyword cases are left in place: Kind 2's JSON does not produce
them, but
getTypeis public and cheap to keep permissive.A width that has no keyword of its own,
uint<24>say, now reads like anyother rather than as a name.
Tests
machineIntegerCounterExampleinKind2ResultTestsreads a counterexampleholding a
uint<8>, asint<8>and auint<24>, and checks each is anInt, that the values come back asBigInteger, and that a negative one(
-128) survives. Without the change it fails withThe existing 32 result tests and 10 pretty printer tests still pass,
javadoc -Xdoclint:allis clean over the main sources, and it compiles atthe Java 8 language level that CI builds with.
Compatibility
This is independent of kind2-mc/kind2#1550 and can merge before or after it:
the
uint<N>spelling is what Kind 2's JSON has always written, and that PRdoes not change it — it widens the schema to admit it.
Checked by reading the output of every model in the Kind 2 regression tree
(639) through
Result.analyzeJsonResult, both as Kind 2 prints it today andwith
isCandidateput back to the quoted form releases before #1550 wrote.One model fails in both runs,
test-div-by-zero.lus, for the unrelatedreason recorded in #25: Kind 2 reports a real produced by a division by zero
as
{"num": 1, "den": 0}andRealValuedivides by that denominator.Worth knowing
The XML output names the four widths it knows as
uint8andint8, so thetwo formats disagree for the same model, and
pp_print_typeraises on anyother width rather than printing it. That is Kind 2's to settle, and is
written up in kind2-mc/kind2#1550.
🤖 Generated with Claude Code