Repository navigation
Commit 4d21c3b
committed
An Elixir module attribute parses as `unary_operator(@, call(<attr>, args))`,
so the typespec family reaches the unified walk in exactly the shape real code
has. `@spec foo(t) :: t` puts `foo(t)` in the same `call` node an invocation
would occupy, and `@type entry :: String.t()` does the same to a type name. The
walk then reads a declaration as code and mints reference edges from it,
sourced at the enclosing Module.
Measured on a fixture of three typespec lines (`@type state :: map()`,
`@spec fetch(opts) :: state`, `@spec load(User.t()) :: :ok`) beside `def state`,
`def opts` and a remote `MyApp.User.t/0`: seven edges, every one phantom and
every one landing on a Function. CALLS onto each specified function;
CALLS + USAGE + WRITES onto `state`, the WRITES asserting a mutation that does
not exist; and USAGE onto `opts` and onto `MyApp.User.t/0`, because a bare or
remote TYPE name resolves to the same-named FUNCTION.
On a codebase whose convention is @SPEC on every public function, every specced
function carries an inbound edge from its own module, so fan_in never reaches 0
and "which exported functions does nothing call" is unanswerable. Measured by
indexing one 970-file Elixir lib tree before and after: every specced function
loses the inbound reference its own typespec minted, and no node is added or
removed.
This is one of two mechanisms. It removes the phantom a typespec line mints;
the def-head phantom is removed by the calls walk recognising a `when`-wrapped
head as a declaration, earlier in this stack. A function carrying both an @SPEC
and a `when` clause needs both, which is why this commit is ordered after that
one and its test can assert 0 references onto such a function rather than
pinning a remaining 1.
The skip covers the whole subtree, and two costs come with that. Both were
measured by indexing a fixture repo (a declaring file per attribute head plus
the file each one reaches) with the pristine binary and with this one:
A typespec's type references are not indexed at all. That loses nothing
correct: a type declaration mints no node, so such a reference resolves onto
nothing or onto a same-named FUNCTION, which is itself the pollution.
`@spec build(MyApp.User.t())` where that module's `t` is a `@type` produced
no edge in either build; the ones that did resolve landed on a same-named
Function, cross-file included.
@callback and @macrocallback lose a real relationship. The declared name is a
function name, so it resolved cross-file onto the functions implementing the
behaviour, and nothing replaces that edge: `@behaviour MyBehaviour` mints none
of its own. It goes anyway because it is only name resolution: on a fixture
with one @callback and three same-named `handle_it/1` defs, the single edge
landed on the one module that implements nothing, leaving both real
implementors at fan_in 0. Recording that relationship correctly means minting
it from `@behaviour`, which is a separate change.
A typespec head a widened span covers was also being read as a self-call, which
is the other half of the cost the multi-clause span commit disclosed. Same
970-file tree, same method it used (each flagged node's own source span, counting
a one-line clause's body after `, do:` as a line that names the function):
self_recursive Function nodes 430 -> 389
...with no self-call form in span 48 -> 8
The base is 129 and 6. All 8 that remain are the phantom a local variable
sharing the function's name mints (`defp slug(value) do slug = ...`), which
nothing in this stack touches: 6 are on the base as well, and the other 2 are
guarded clauses that only have a node of their own to be flagged on because of
the earlier commits here.
`unquote(...)` inside a typespec does execute at compile time, so
`@type t :: unquote(build_type())` loses its genuine `build_type` edge too.
Every other attribute VALUE is ordinary compile-time code
(`@timeout Application.compile_env(:app, :timeout)` really does call
compile_env), so those subtrees are deliberately walked exactly as before, and
their attribute NAME still mints one phantom onto a same-named Function. That
half of the defect class needs its own fix.
tests/test_extraction.c: extract_elixir_typespec_attribute_is_not_code
exercises all six heads in the skip list, so deleting any one entry breaks it.
It pins the two accepted costs as decisions, and it carries a control name
(`without_spec`) that reads 0 on the pristine build too, so an instrument that
scored a definition as a reference could not make the other zeroes vacuous.
extract_elixir_declaration_head_mints_no_reference_of_any_kind tightens from a
relation to 0: with both mechanisms present, a function with an @SPEC and a
guard carries no reference of any kind.
Depends on the guarded call-scope commit, for the ordering above. It touches no file
the earlier commits in this stack touch except extract_unified.c, and none of
their lines.
Signed-off-by: Chad <4307099+BobbieBarker@users.noreply.github.com>
1 parent 198e211 commit 4d21c3b
3 files changed
Lines changed: 235 additions & 25 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5477 | 5477 | | |
5478 | 5478 | | |
5479 | 5479 | | |
5480 | | - | |
5481 | | - | |
5482 | | - | |
| 5480 | + | |
| 5481 | + | |
| 5482 | + | |
| 5483 | + | |
| 5484 | + | |
| 5485 | + | |
| 5486 | + | |
| 5487 | + | |
| 5488 | + | |
| 5489 | + | |
| 5490 | + | |
| 5491 | + | |
5483 | 5492 | | |
5484 | 5493 | | |
5485 | 5494 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2041 | 2041 | | |
2042 | 2042 | | |
2043 | 2043 | | |
| 2044 | + | |
| 2045 | + | |
| 2046 | + | |
| 2047 | + | |
| 2048 | + | |
| 2049 | + | |
| 2050 | + | |
| 2051 | + | |
| 2052 | + | |
| 2053 | + | |
| 2054 | + | |
| 2055 | + | |
| 2056 | + | |
| 2057 | + | |
| 2058 | + | |
| 2059 | + | |
| 2060 | + | |
| 2061 | + | |
| 2062 | + | |
| 2063 | + | |
| 2064 | + | |
| 2065 | + | |
| 2066 | + | |
| 2067 | + | |
| 2068 | + | |
| 2069 | + | |
| 2070 | + | |
| 2071 | + | |
| 2072 | + | |
| 2073 | + | |
| 2074 | + | |
| 2075 | + | |
| 2076 | + | |
| 2077 | + | |
| 2078 | + | |
| 2079 | + | |
| 2080 | + | |
| 2081 | + | |
| 2082 | + | |
| 2083 | + | |
| 2084 | + | |
| 2085 | + | |
| 2086 | + | |
| 2087 | + | |
| 2088 | + | |
| 2089 | + | |
| 2090 | + | |
| 2091 | + | |
| 2092 | + | |
| 2093 | + | |
| 2094 | + | |
| 2095 | + | |
| 2096 | + | |
| 2097 | + | |
| 2098 | + | |
| 2099 | + | |
| 2100 | + | |
| 2101 | + | |
| 2102 | + | |
| 2103 | + | |
| 2104 | + | |
| 2105 | + | |
| 2106 | + | |
| 2107 | + | |
| 2108 | + | |
| 2109 | + | |
| 2110 | + | |
| 2111 | + | |
| 2112 | + | |
| 2113 | + | |
| 2114 | + | |
| 2115 | + | |
| 2116 | + | |
| 2117 | + | |
| 2118 | + | |
| 2119 | + | |
| 2120 | + | |
| 2121 | + | |
| 2122 | + | |
| 2123 | + | |
| 2124 | + | |
| 2125 | + | |
| 2126 | + | |
| 2127 | + | |
| 2128 | + | |
| 2129 | + | |
| 2130 | + | |
| 2131 | + | |
| 2132 | + | |
| 2133 | + | |
| 2134 | + | |
| 2135 | + | |
| 2136 | + | |
| 2137 | + | |
| 2138 | + | |
| 2139 | + | |
| 2140 | + | |
| 2141 | + | |
| 2142 | + | |
| 2143 | + | |
| 2144 | + | |
| 2145 | + | |
| 2146 | + | |
| 2147 | + | |
| 2148 | + | |
2044 | 2149 | | |
2045 | 2150 | | |
2046 | 2151 | | |
| |||
2631 | 2736 | | |
2632 | 2737 | | |
2633 | 2738 | | |
2634 | | - | |
| 2739 | + | |
| 2740 | + | |
2635 | 2741 | | |
2636 | 2742 | | |
2637 | 2743 | | |
| |||
2661 | 2767 | | |
2662 | 2768 | | |
2663 | 2769 | | |
2664 | | - | |
| 2770 | + | |
2665 | 2771 | | |
2666 | 2772 | | |
2667 | 2773 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1847 | 1847 | | |
1848 | 1848 | | |
1849 | 1849 | | |
1850 | | - | |
1851 | | - | |
1852 | | - | |
1853 | | - | |
1854 | | - | |
1855 | | - | |
| 1850 | + | |
| 1851 | + | |
| 1852 | + | |
| 1853 | + | |
| 1854 | + | |
| 1855 | + | |
1856 | 1856 | | |
1857 | | - | |
1858 | | - | |
1859 | | - | |
1860 | | - | |
1861 | | - | |
1862 | | - | |
1863 | | - | |
1864 | | - | |
1865 | | - | |
1866 | | - | |
1867 | | - | |
| 1857 | + | |
| 1858 | + | |
| 1859 | + | |
| 1860 | + | |
| 1861 | + | |
| 1862 | + | |
| 1863 | + | |
| 1864 | + | |
| 1865 | + | |
1868 | 1866 | | |
1869 | 1867 | | |
1870 | 1868 | | |
| |||
1886 | 1884 | | |
1887 | 1885 | | |
1888 | 1886 | | |
1889 | | - | |
1890 | | - | |
1891 | | - | |
| 1887 | + | |
| 1888 | + | |
| 1889 | + | |
| 1890 | + | |
1892 | 1891 | | |
1893 | 1892 | | |
| 1893 | + | |
| 1894 | + | |
| 1895 | + | |
| 1896 | + | |
| 1897 | + | |
| 1898 | + | |
| 1899 | + | |
1894 | 1900 | | |
1895 | 1901 | | |
1896 | 1902 | | |
| |||
1919 | 1925 | | |
1920 | 1926 | | |
1921 | 1927 | | |
| 1928 | + | |
| 1929 | + | |
| 1930 | + | |
| 1931 | + | |
| 1932 | + | |
| 1933 | + | |
| 1934 | + | |
| 1935 | + | |
| 1936 | + | |
| 1937 | + | |
| 1938 | + | |
| 1939 | + | |
| 1940 | + | |
| 1941 | + | |
| 1942 | + | |
| 1943 | + | |
| 1944 | + | |
| 1945 | + | |
| 1946 | + | |
| 1947 | + | |
| 1948 | + | |
| 1949 | + | |
| 1950 | + | |
| 1951 | + | |
| 1952 | + | |
| 1953 | + | |
| 1954 | + | |
| 1955 | + | |
| 1956 | + | |
| 1957 | + | |
| 1958 | + | |
| 1959 | + | |
| 1960 | + | |
| 1961 | + | |
| 1962 | + | |
| 1963 | + | |
| 1964 | + | |
| 1965 | + | |
| 1966 | + | |
| 1967 | + | |
| 1968 | + | |
| 1969 | + | |
| 1970 | + | |
| 1971 | + | |
| 1972 | + | |
| 1973 | + | |
| 1974 | + | |
| 1975 | + | |
| 1976 | + | |
| 1977 | + | |
| 1978 | + | |
| 1979 | + | |
| 1980 | + | |
| 1981 | + | |
| 1982 | + | |
| 1983 | + | |
| 1984 | + | |
| 1985 | + | |
| 1986 | + | |
| 1987 | + | |
| 1988 | + | |
| 1989 | + | |
| 1990 | + | |
| 1991 | + | |
| 1992 | + | |
| 1993 | + | |
| 1994 | + | |
| 1995 | + | |
| 1996 | + | |
| 1997 | + | |
| 1998 | + | |
| 1999 | + | |
| 2000 | + | |
| 2001 | + | |
| 2002 | + | |
| 2003 | + | |
| 2004 | + | |
| 2005 | + | |
| 2006 | + | |
| 2007 | + | |
| 2008 | + | |
| 2009 | + | |
| 2010 | + | |
| 2011 | + | |
| 2012 | + | |
| 2013 | + | |
| 2014 | + | |
| 2015 | + | |
1922 | 2016 | | |
1923 | 2017 | | |
1924 | 2018 | | |
| |||
9168 | 9262 | | |
9169 | 9263 | | |
9170 | 9264 | | |
| 9265 | + | |
9171 | 9266 | | |
9172 | 9267 | | |
9173 | 9268 | | |
| |||
0 commit comments