Skip to content

Commit 033be76

Browse files
committed
fix(doc-links): a Go method claims no flat doc-link node name
#1913 makes Go method nodes receiver-qualified (<dir>.<Recv>.<Method>). The Go doc-link model still let every method claim the flat node <dir>.<name>: - doclink_go.c go_scan_method pushed a claim record; - doc_links_go.c go_add_claim put it in the flat table. So a type, function or value that shares its name with a method in its directory became a graph_gap ("lost its node to the method"), although the graph now gives it that node. Base reports the same graph_gap for this shape, because there the method really did take the node. So this completes #1913's QN scheme for one of its consumers; it is not a regression #1913 causes. - A method record now carries w `-`: it claims no flat name. - The resolver no longer enters methods into the flat table. Methods are found through their receiver (the member table), which was already the first lookup. - The flat fallback in go_method_node is now unreachable. It stays, with a comment saying so. Corpus, before = this branch's tree, par x2, r1 == r2: - terraform: graph_gap rows 9 -> 0, doc-link MENTIONS 528 -> 536 (+8, -0). All 8 new edges were judged correct: e.g. [AbsProviderConfig] now lands on the type, not on the method RootProviderConfig.AbsProviderConfig. - vault, prometheus: unchanged. - prometheus incremental == full for MENTIONS. - The 3 -> 4 index-format bump already forces a full rebuild, so no stored scope blob mixes the two meanings. Signed-off-by: Martin Vogel <[email protected]>
1 parent ee2a4d6 commit 033be76

2 files changed

Lines changed: 22 additions & 17 deletions

File tree

‎internal/cbm/doclink_go.c‎

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@
4343
* drops these lines and so carries no line number
4444
* at all.
4545
* G path go.mod: the module path
46-
* w says who keeps the node. A Go method node has a FLAT qualified name
47-
* (<dir>.<Method>), so a function, the methods of every receiver, a type and
48-
* a value of one name all claim the node <dir>.<name>, and within a file the
49-
* declaration on the LAST line keeps it (cbm_gbuf_upsert_node). w is 1 for
46+
* w says who keeps the node <dir>.<name>. A function, a type and a value of
47+
* one name all claim it, and within a file the declaration on the LAST line
48+
* keeps it (cbm_gbuf_upsert_node). A method claims nothing: its node is
49+
* receiver-qualified (<dir>.<Recv>.<Method>, #1913), and its w is `-`. w is 1 for
5050
* that declaration, 0 for the others of that name, x when two of them start
5151
* on that last line, and - for a value the extractor gives no node at all
5252
* (it gives one to the first name of a constant spec and of a parenthesis-
@@ -1511,9 +1511,11 @@ static void go_scan_method(go_scan_t *s, TSNode m) {
15111511
recv = "?";
15121512
recv_len = SKIP_ONE;
15131513
}
1514-
go_push_claim(s,
1515-
cbm_arena_sprintf(s->tmp, "M\t%.*s\t%.*s", (int)recv_len, recv, (int)len, name),
1516-
name, len, m);
1514+
/* #1913: a Go method node is receiver-qualified (<dir>.<Recv>.<Method>),
1515+
* so a method claims no flat name: w is `-`, and the method is found
1516+
* through its receiver (the member table), never through <dir>.<name>. */
1517+
(void)go_push_rec(
1518+
s, cbm_arena_sprintf(s->tmp, "M\t%.*s\t%.*s\t-", (int)recv_len, recv, (int)len, name));
15171519
}
15181520

15191521
/* The implied name of an embedded field: the type's own name, without

‎src/pipeline/doc_links_go.c‎

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,11 @@
3232
* fields of its own struct declaration and the methods of its own interface
3333
* declaration: nothing promoted through embedding.
3434
*
35-
* Binding. The graph keeps one node per qualified name, Go method nodes have
36-
* a FLAT name (<dir>.<Method>), and <dir> is the directory, not the package
37-
* clause: functions, methods of every receiver, types and values of one name,
38-
* in every file of the directory, share one node, and the node is ONE of those
35+
* Binding. The graph keeps one node per qualified name, and <dir> is the
36+
* directory, not the package clause. Go method nodes are receiver-qualified
37+
* (<dir>.<Recv>.<Method>, #1913) and are found through their receiver only.
38+
* Functions, types and values of one name, in every file of the directory,
39+
* share one node <dir>.<name>, and the node is ONE of those
3940
* declarations (cbm_gbuf_upsert_node keeps the smallest file path, then the
4041
* last line). So a reference binds only when the node IS the entity it names:
4142
* the node's file is a file of the named package, the declaration that keeps
@@ -59,7 +60,7 @@
5960
* not), missing (a repository package that does not declare the name; an
6061
* import path inside a module without a package there), graph_gap (declared,
6162
* but the node is another declaration's or absent: block variables, later
62-
* names of a declaration, embedded fields, methods that lost the flat name;
63+
* names of a declaration, embedded fields;
6364
* also an undeclared name in a package with a parse error), test_only_target
6465
* (product code naming a declaration that only test files have), ambiguous
6566
* (several modules or packages fit; a name declared as two kinds; a name two
@@ -1063,7 +1064,7 @@ static void go_record_decl(go_index_t *ix, go_file_t *file, char **f, int nf) {
10631064
FIELD_FIELDS = 4,
10641065
IM_FIELDS = 3
10651066
};
1066-
enum { F_OWNER = 2, T_ALIAS = 3, T_OWNER = 4, V_OWNER = 2, M_OWNER = 3, FIELD_NODE = 3 };
1067+
enum { F_OWNER = 2, T_ALIAS = 3, T_OWNER = 4, V_OWNER = 2, FIELD_NODE = 3 };
10671068
char kind = f[0][0];
10681069
if (nf < IM_FIELDS || !go_name_ok(f[SKIP_ONE])) {
10691070
return;
@@ -1078,10 +1079,12 @@ static void go_record_decl(go_index_t *ix, go_file_t *file, char **f, int nf) {
10781079
go_add_sym(ix, file, GO_KIND_VALUE, f[SKIP_ONE], NULL);
10791080
go_add_claim(ix, file, GO_KIND_VALUE, f[SKIP_ONE], NULL, f[V_OWNER]);
10801081
} else if (kind == 'M' && nf == M_FIELDS && go_name_ok(f[PAIR_LEN])) {
1082+
/* #1913: a method is found through its receiver only; it claims no
1083+
* flat <dir>.<name> (its record says w `-`), so a type, function or
1084+
* value of the same name keeps that node. */
10811085
if (strcmp(f[SKIP_ONE], "?") != 0) {
10821086
go_add_member(ix, file, GO_MEM_METHOD, f[SKIP_ONE], f[PAIR_LEN], true);
10831087
}
1084-
go_add_claim(ix, file, GO_KIND_METHOD, f[PAIR_LEN], f[SKIP_ONE], f[M_OWNER]);
10851088
} else if (kind == 'f' && nf == FIELD_FIELDS && go_name_ok(f[PAIR_LEN])) {
10861089
go_add_member(ix, file, GO_MEM_FIELD, f[SKIP_ONE], f[PAIR_LEN], f[FIELD_NODE][0] == '1');
10871090
} else if (kind == 'm' && nf == IM_FIELDS && go_name_ok(f[PAIR_LEN])) {
@@ -1342,9 +1345,9 @@ static const cbm_gbuf_node_t *go_member_node(const go_ctx_t *c, const go_pkg_t *
13421345
return (fm && (fm->node_kinds & kind)) ? n : NULL;
13431346
}
13441347

1345-
/* The node of the method `recv.name`: its receiver-qualified node, else the
1346-
* flat node <dir>.<name> when the method is the one that kept it (the last
1347-
* declaration of that name in the node's file). */
1348+
/* The node of the method `recv.name`: its receiver-qualified node. The flat
1349+
* fallback below (the method that kept <dir>.<name>) is unreachable since
1350+
* #1913: no method record claims a flat name any more. */
13481351
static const cbm_gbuf_node_t *go_method_node(const go_ctx_t *c, const go_pkg_t *pkg, go_str_t recv,
13491352
go_str_t name) {
13501353
const cbm_gbuf_node_t *qualified = go_member_node(c, pkg, GO_MEM_METHOD, recv, name);

0 commit comments

Comments
 (0)