markused: mark mut-receiver interface implementors (fix -skip-unused dropping anon fn)#27380
Open
medvednikov wants to merge 1 commit into
Open
markused: mark mut-receiver interface implementors (fix -skip-unused dropping anon fn)#27380medvednikov wants to merge 1 commit into
-skip-unused dropping anon fn)#27380medvednikov wants to merge 1 commit into
Conversation
…ropping anon fn) An anon fn passed to a C callback inside a method reached only via interface dispatch on a `mut` receiver was dropped by -skip-unused (the default), so the generated C failed with `use of undeclared identifier 'anon_fn_...'`. markused's interface walk iterated only `isym.info.types`, but the checker stores implementors that require a mutable receiver (e.g. `fn (mut i Impl) setup()`) in `isym.info.mut_types`. Those method bodies were therefore never walked, and symbols they reference (here, the anon fn argument) were pruned. Walk `isym.info.implementor_types(true)` instead, which merges `types` and `mut_types` (deduplicated by idx). This only ever adds implementors to the walk, so it cannot cause new undeclared-symbol errors. Fixes #27354
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
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.
Description
Fixes #27354.
An anonymous function passed as a C callback argument inside a method that is reached only via interface dispatch on a
mutreceiver was dropped by-skip-unused(the default), so the C compiler failed:Building with
-no-skip-unusedworked, pinning the fault to the used-functions analysis.Root cause
markused's interface walk (mark_by_sym, theast.Interfacearm) iterated onlyisym.info.typesto find implementing types and walk their interface-method bodies. But the checker stores implementors that require a mutable receiver (e.g.fn (mut i Impl) setup()) inisym.info.mut_types, nottypes. Those method bodies were therefore never walked, and the symbols they reference (here, the anon fn argument) were pruned, even though cgen still emits the method via the interface vtable adapter.Fix
Walk
isym.info.implementor_types(true)instead, the existing helper that mergestypeswithmut_types(deduplicated by idx). This only ever adds implementors to the walk, so it cannot introduce new undeclared-symbol errors — worst case is marginally less aggressive pruning for some mut-receiver interface methods that were incorrectly skipped.Verification
-skip-unused, printingdone.vlib/v/tests/skip_unused/interface_mut_receiver_anon_fn.{vv,run.out}(run bycompiler_errors_test.v).vlib/v/tests/interfaces/tests pass, plusgeneric_fn_instantiation_pruning_test.vandunused_fn_fixed_array_ret_test.v.