Skip to content

Make uniqueName deterministic for shared constants#602

Open
nirmaltm26 wants to merge 1 commit intoleanprover:mainfrom
nirmaltm26:nirmaltm-NKI-shared-const-deterministic
Open

Make uniqueName deterministic for shared constants#602
nirmaltm26 wants to merge 1 commit intoleanprover:mainfrom
nirmaltm26:nirmaltm-NKI-shared-const-deterministic

Conversation

@nirmaltm26
Copy link

Replace non-deterministic IO.rand suffix generation with a deterministic approach: count existing matching files in the directory and seed a StdGen RNG with that count. This ensures repeated compilations produce the same filenames for shared constants with duplicate base names.

KLR/Compile.lean Outdated
let gen := mkStdGen count
let (suffix, _) := RandomGen.next gen
let suffix := suffix % (2^64)
return s!"{base}_{suffix}"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we check if this file exists?
Unlikely, but catastrophic.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. Note how original function is recursive. It's unlikely that you will hit the randomly existing file twice, but maybe keep original recursive logic?

Replace non-deterministic IO.rand suffix generation with a
deterministic approach: count existing matching files in the
directory and seed a StdGen RNG with that count. This ensures
repeated compilations produce the same filenames for shared
constants with duplicate base names.

Also removes `partial` since the function is no longer recursive.
@nirmaltm26 nirmaltm26 force-pushed the nirmaltm-NKI-shared-const-deterministic branch from 5c8d79d to 7b1bdba Compare February 24, 2026 18:25
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.

3 participants