Repository navigation
Commit 538ac25
committed
fix(rust): fence a QN on the function's own cfg predicate, balanced
rust_cfg_qualified_name folds a function's `#[cfg(...)]` predicate into its
qualified name so two mutually-exclusive twins get distinct QNs instead of one
overwriting the other (#495). It read the attribute three ways that the QN it
minted shows are wrong.
The suffix was copied from the `cfg(` it found to the END of the decorator text.
extract_decorators stores the bracketed form, so that appended the attribute's
own `]` to every QN: `#[cfg(test)]` minted `add#cfg(test)]`. Across ripgrep
14.1.1, tokio 1.40.0 and rust-analyzer 2024-09-30 that is 332 of 335 fenced QNs.
On a multi-line attribute the copied text also carried the newline, and
cbm_defs_push cuts a qualified name at a line break by design, pinned by
defs_push_cuts_multiline_names_and_rejects_js_literal_names. What survived was
everything before the newline, so the suffix stopped mid-predicate:
`thread_rng_n#cfg(any(`. Two twins whose predicates differ only past that
newline then computed ONE qualified name and the second upsert overwrote the
first, which is the loss this function exists to prevent. 10 tokio QNs are
truncated this way. None of them happens to collide, because the visible
prefixes stay distinct there; the collision is in the test below, which drops
from two nodes to one without this commit.
`strstr(decorators[i], "cfg(")` was also unanchored, and `cfg_attr` carries its
own nested `cfg(`. In `#[cfg_attr(docsrs, doc(cfg(feature = "rt")))]` that inner
predicate gates DOCUMENTATION, not compilation: the function is compiled
unconditionally and has no twin to be told apart from, and it was fenced anyway
as `yield_now#cfg(feature=rt)))]`. 7 tokio functions are fenced solely by a
cfg_attr. rust_def_is_test, twenty lines above, already anchors on the bracketed
path and says why; this was the one Rust decorator inspector that did not.
The fix anchors on `#[cfg(` and copies the balanced span, stopping at the
paren that closes it and dropping newlines with the other whitespace. A
predicate longer than the 256-byte buffer still truncates, as before, and stays
distinct over its first 255 characters.
Measured by indexing the three corpora above with a binary built from 5df8b04
and with this one:
corpus QNs changed stop being fenced nodes added or lost
ripgrep 131 0 0
tokio 176 7 0
rust-analyzer 28 0 0
The 7 are the cfg_attr-only functions, which now carry their plain QN. Node
counts are identical in all three, and tokio's multi-line predicates are
reconstructed in full:
`main#cfg(all(tokio_unstable,tokio_taskdump,target_os=linux,any(target_arch=aarch64,target_arch=x86,target_arch=x86_64)))`.
This changes node identity for cfg-fenced Rust functions, so
CBM_INDEX_FORMAT_VERSION goes 1 -> 2 and the next index rebuilds from scratch.
The deciding case is the incremental path rather than the mixed store:
incr_capture_inbound_edge snapshots an inbound cross-file edge by its target's
qualified_name STRING, and the re-link after the purge resolves that string
again. A caller in an unchanged file would therefore lose its edge into a
re-extracted fenced function, because the QN it was snapshotted under no longer
exists, and nothing would report the loss.
The #495 comment sat above rust_def_is_test while describing this function; it
moves down with the code it documents.
tests/test_extraction.c: three tests, one per misreading, and the only coverage
this function has in the gating suite. tests/repro/repro_issue495.c exercises it
today but Makefile.cbm keeps that file out of `make test`, and it asserts only
that two QNs differ and that one contains `not(`, never the string minted. Each
of the three fails without this commit.
Signed-off-by: Chad <4307099+BobbieBarker@users.noreply.github.com>1 parent 13ce2c0 commit 538ac25
3 files changed
Lines changed: 98 additions & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2041 | 2041 | | |
2042 | 2042 | | |
2043 | 2043 | | |
2044 | | - | |
2045 | | - | |
2046 | | - | |
2047 | | - | |
2048 | | - | |
2049 | | - | |
2050 | 2044 | | |
2051 | 2045 | | |
2052 | 2046 | | |
| |||
2076 | 2070 | | |
2077 | 2071 | | |
2078 | 2072 | | |
| 2073 | + | |
| 2074 | + | |
| 2075 | + | |
| 2076 | + | |
| 2077 | + | |
| 2078 | + | |
| 2079 | + | |
| 2080 | + | |
2079 | 2081 | | |
2080 | 2082 | | |
2081 | 2083 | | |
2082 | 2084 | | |
2083 | 2085 | | |
2084 | 2086 | | |
2085 | | - | |
| 2087 | + | |
| 2088 | + | |
| 2089 | + | |
| 2090 | + | |
| 2091 | + | |
| 2092 | + | |
| 2093 | + | |
| 2094 | + | |
2086 | 2095 | | |
2087 | 2096 | | |
2088 | 2097 | | |
2089 | | - | |
2090 | | - | |
| 2098 | + | |
| 2099 | + | |
| 2100 | + | |
| 2101 | + | |
| 2102 | + | |
| 2103 | + | |
| 2104 | + | |
| 2105 | + | |
| 2106 | + | |
| 2107 | + | |
| 2108 | + | |
| 2109 | + | |
| 2110 | + | |
| 2111 | + | |
2091 | 2112 | | |
2092 | 2113 | | |
| 2114 | + | |
2093 | 2115 | | |
2094 | | - | |
| 2116 | + | |
2095 | 2117 | | |
2096 | 2118 | | |
2097 | 2119 | | |
| 2120 | + | |
| 2121 | + | |
| 2122 | + | |
| 2123 | + | |
| 2124 | + | |
2098 | 2125 | | |
2099 | 2126 | | |
2100 | 2127 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | | - | |
| 26 | + | |
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
945 | 945 | | |
946 | 946 | | |
947 | 947 | | |
| 948 | + | |
| 949 | + | |
| 950 | + | |
| 951 | + | |
| 952 | + | |
| 953 | + | |
| 954 | + | |
| 955 | + | |
| 956 | + | |
| 957 | + | |
| 958 | + | |
| 959 | + | |
| 960 | + | |
| 961 | + | |
| 962 | + | |
| 963 | + | |
| 964 | + | |
| 965 | + | |
| 966 | + | |
| 967 | + | |
| 968 | + | |
| 969 | + | |
| 970 | + | |
| 971 | + | |
| 972 | + | |
| 973 | + | |
| 974 | + | |
| 975 | + | |
| 976 | + | |
| 977 | + | |
| 978 | + | |
| 979 | + | |
| 980 | + | |
| 981 | + | |
| 982 | + | |
| 983 | + | |
| 984 | + | |
| 985 | + | |
| 986 | + | |
| 987 | + | |
| 988 | + | |
| 989 | + | |
| 990 | + | |
| 991 | + | |
| 992 | + | |
| 993 | + | |
| 994 | + | |
| 995 | + | |
| 996 | + | |
| 997 | + | |
| 998 | + | |
| 999 | + | |
| 1000 | + | |
| 1001 | + | |
| 1002 | + | |
| 1003 | + | |
| 1004 | + | |
948 | 1005 | | |
949 | 1006 | | |
950 | 1007 | | |
| |||
8701 | 8758 | | |
8702 | 8759 | | |
8703 | 8760 | | |
| 8761 | + | |
| 8762 | + | |
| 8763 | + | |
8704 | 8764 | | |
8705 | 8765 | | |
8706 | 8766 | | |
| |||
0 commit comments