Make fresh names unique across sorts - #123
Open
daniel-larraz wants to merge 1 commit into
Open
Conversation
daniel-larraz
force-pushed
the
fresh-const-unique-names
branch
2 times, most recently
from
September 4, 2026 21:48
ecd8635 to
f106a9f
Compare
next_fresh checked (name, sort) against ctx.vars and only advanced its counter on a collision, so a name was free as long as no constant of that same sort held it. Two FreshConst calls at different sorts could therefore be handed the same name: a = FreshConst(Float16()) # c0 b = FreshConst(Float16()) # c1, after colliding on (c0, Float16) c = FreshConst(Float32()) # c1 again -- (c1, Float32) is not in vars The terms stay distinct, so solving is unaffected, but a name is all that identifies a constant once printed. sexpr() then renders b and c alike, and the result is not merely ambiguous: c1 appears applied at both Float16 and Float32, so no set of declarations could make it parse back. Track the names in use in ctx.var_names and check that instead, and advance the counter on every call so a number is never handed out twice. Mixing prefixes now skips numbers, which is what z3 does. The sort argument is gone from next_fresh and its callers. It was doing no work in FreshFunction either, which passed a raw cvc5 Sort where the others passed a SortRef, so that lookup could never have matched a vars entry keyed the other way. Fixes cvc5/cvc5#12912. Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
daniel-larraz
force-pushed
the
fresh-const-unique-names
branch
from
September 7, 2026 15:46
f106a9f to
84e0431
Compare
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.
next_freshchecked(name, sort)againstctx.varsand only advanced its counter on a collision, so a name counted as free as long as no constant of that same sort held it. TwoFreshConstcalls at different sorts could therefore be handed the same name:The terms stay distinct, so solving is unaffected, but a name is all that identifies a constant once printed.
sexpr()rendersbandcalike, and the result is not merely ambiguous —c1appears applied at bothFloat16andFloat32, so no set of declarations could make it parse back:This tracks the names in use in
ctx.var_namesand checks that instead, and advances the counter on every call so a number is never handed out twice. The same script now prints:FreshBool,FreshInt,FreshRealandFreshFunctionwere affected the same way and are covered by the same fix.The
sortargument is gone fromnext_freshand its callers. It was doing no work inFreshFunctioneither, which passed a raw cvc5Sortwhere the others passed aSortRef, so that lookup could never have matched avarsentry keyed the other way.One behavioral note for reviewers: the counter is shared across prefixes, so mixing them now skips numbers —
FreshBool()after twoFreshConst()calls givesb2, notb0. z3 behaves the same way, and no test depends on generated names.Fixes cvc5/cvc5#12912.
🤖 Generated with Claude Code