cgen: skip _v_type_idx_ emission for invalid-C-identifier cnames (fix v build-module vlib/orm) - #27891
Open
eptx wants to merge 1 commit into
Open
cgen: skip _v_type_idx_ emission for invalid-C-identifier cnames (fix v build-module vlib/orm)#27891eptx wants to merge 1 commit into
eptx wants to merge 1 commit into
Conversation
Anonymous sum-type symbols (e.g. orm's `[]Primitive | []bool | ...`)
carry a cname containing literal `[]`, which is not a valid C
identifier. The build-module / -usecache type-idx emission wrote it
verbatim:
u32 _v_type_idx_orm__[]orm__Primitive___orm__[]bool___...();
producing uncompilable C, so `v build-module vlib/orm` (and any module
importing orm) failed with 'expected ; after top level declarator'.
Such a cname can never be *referenced* through `_v_type_idx_<cname>()`
either — the call site would be equally invalid C — so skipping the
emission for cnames containing `[` loses nothing. Both emission loops
(the build-module path and the -usecache path) get the same guard.
Repro before this change: `v build-module vlib/orm`. After: builds
clean; `v test vlib/orm` 38/38.
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.
Problem
v build-module vlib/orm(andbuild-moduleof any module importing orm) fails with a C compilation error on current master:Anonymous sum-type symbols (orm's
[]Primitive | []bool | …family) carry a cname containing literal[]— not a valid C identifier — and the build-module / -usecache type-idx emission writes it verbatim into the helper declaration.Fix
Skip
_v_type_idx_emission for cnames containing[, in both emission loops. Such a cname can never be referenced through_v_type_idx_<cname>()either (the call site would be equally invalid C), so the skip loses nothing.Verification
./v build-module vlib/orm→ the C error above. After: builds clean../v test vlib/orm→ 38/38 passed.-usecacheduplicate-symbols link failure on hello_world reproduces identically on unpatched master — pre-existing and unrelated to this change.)