Repository navigation
Open
Conversation
…dule is recompiled Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
|
This fixes the reported issue, but nimlangserver then fails in a different place (than devel). You can reproduce the "new" nimlangserver.nim (commit b5050c5) issue like this:
I think #26381 may contain other reproductions as I went down a similar path. |
Contributor
|
Possible reproduction:
type Box*[T] = object
name: string
val*: T
proc box*[T](v: T): Box[T] = Box[T](name: "box", val: v)
import fixtures/mlifted_hook_inst
proc useBox(): int {.compileTime.} =
let b = box(1)
b.val
const c0 = useBox()
proc p1(): string {.compileTime.} = "s1"
const c1 = (let f = p1; f())
proc foo*(): int = 1
# `box[int]` and the `=destroy` lifted for `Box[int]` are minted with this
# module's ids, but are cached under the generics of the fixture, so a
# recompilation of this module reuses them while `p1` gets the id the hook
# had. The VM must not hand `p1` the hook's proc handle (or the other way
# around): calling `f` then runs `=destroy`.
discard """
$nimsuggest --tester --v4 $file
>chk $file
chk;;skUnknown;;;;Hint;;$file;;6;;6;;"\'c0\' is declared but not used [XDeclaredButNotUsed]";;0
>changed $file
>chk $file
chk;;skUnknown;;;;Hint;;$file;;6;;6;;"\'c0\' is declared but not used [XDeclaredButNotUsed]";;0
chk;;skUnknown;;;;Hint;;$file;;9;;6;;"\'c1\' is declared but not used [XDeclaredButNotUsed]";;0
"""
gives: If it's like in #26381 we'll keep finding these, though. I gave up on #26381 after finding more issues that are not fixed in that branch. |
Symbols and types of a module's previous compilation can still be alive (generic instances and lifted hooks cached by other modules, the VM's caches), so the module's IdGenerator now resumes where it stopped instead of restarting. This replaces the VM cache invalidation of the previous commit, which missed these other stale references. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
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.
fixes #26457
When nimsuggest recompiles a dirty module, the module's
IdGeneratorrestarted from scratch, so its new symbols and types got the sameItemIds as the previous compilation's. But the old ones can still be alive: the VM caches compiled procs, proc handles, globals, consts and layouts byItemId, and generic instances and lifted hooks minted with the module's ids are cached by other modules (the generic's owner). After an edit, these collided with new symbols. For example,let f = p1; f()ran a different proc, and you got "VM produced a value that refers to invalid memory", "constant expression expected" and similar errors, and nimsuggest stopped answering.Now the module's id generator is stored in its
Iface(moduleIdgen), and a recompilation continues where the last one stopped, so ids are never reused. A full recompile (resetAllModules) still starts fresh. The first commit of this PR invalidated the VM caches instead; that missed the instance/hook caches (see the review comment), so it was replaced.Tests:
nimsuggest/tests/t26457.nim: the issue's examplenimsuggest/tests/tlifted_hook_inst.nim: the reproduction from the review (generic instance and lifted=destroycached by the fixture)Both fail on devel and pass now. The nimsuggest suite and the
icandvmtest categories pass.🤖 Generated with Claude Code