Skip to content

Commit aba240b

Browse files
committed
doc-links(cs): a scope its run refused is stored as a rejected marker (S8 across runs)
A C# scope blob written in a run that the reader refuses costs only its own file in that run (a8c5708d). The blob itself was stored, though, and the next incremental run read it back as a stored scope the reader refuses, which fails the layer for the whole run. The surface row now stores, in place of such a blob, the C# rejected marker (the tag and one `!` record). Whether the reader takes a blob is decided where the row is made, by the reader's own record checks on an index of the blob's own (what makes a blob refused depends on the blob alone); the doc-link layer asks the language through two new resolver fields, scope_accepted and rejected_scope (cbm_doclinks_storable_scope). A later run that reads the marker back treats the file as the run that wrote it: it declares nothing, its references are graph gaps, it is counted with the rejected files. A stored scope that does not parse for any other reason still fails the run. The scope delta of a file whose blob is the marker on either side is LOCAL only when both are. The test seam that spoils a file's scope now does it where the scope is written (internal/cbm/doclink_cs.c), so what is stored carries it too. Test: cs_rejected_scope_across_runs (a full run with the spoiled file, then a body-only edit elsewhere and one in the spoiled file: each incremental step equals a full run, and the stored scope is the marker). Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
1 parent decc832 commit aba240b

7 files changed

Lines changed: 214 additions & 80 deletions

File tree

‎internal/cbm/doclink.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,12 @@ void cbm_doclink_test_fail_alloc_after(int kind, int nth);
157157
bool cbm_doclink_test_fail_alloc(int kind);
158158
void cbm_doclink_test_reset_alloc(void);
159159

160+
/* The C# scope scan of the file at `rel_path` writes, after its records, one
161+
* the resolver refuses -- as if writer and reader disagreed (NULL or "":
162+
* none). What is stored for the file and what this run resolves both carry
163+
* it. */
164+
void cbm_doclink_cs_test_spoil_scope(const char *rel_path);
165+
160166
/* Actual comment memcpy bytes, input bytes submitted to the C# lexical parser,
161167
* and bytes allocated for cleaned reference values; separate from token output. */
162168
void cbm_doclink_test_doc_work_reset(void);

‎internal/cbm/doclink_cs.c‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3027,6 +3027,14 @@ char *cbm_doclink_cs_portable_scope(const char *scope) {
30273027
return out;
30283028
}
30293029

3030+
#if defined(CBM_ENABLE_TEST_SEAMS) && CBM_ENABLE_TEST_SEAMS
3031+
static char cs_test_spoiled_path[CBM_SZ_512];
3032+
3033+
void cbm_doclink_cs_test_spoil_scope(const char *rel_path) {
3034+
snprintf(cs_test_spoiled_path, sizeof(cs_test_spoiled_path), "%s", rel_path ? rel_path : "");
3035+
}
3036+
#endif
3037+
30303038
const char *cbm_doclink_cs_scan_scope(CBMExtractCtx *ctx) {
30313039
if (ts_node_is_null(ctx->root)) {
30323040
return NULL;
@@ -3056,6 +3064,10 @@ const char *cbm_doclink_cs_scan_scope(CBMExtractCtx *ctx) {
30563064
if (cbm_doclink_test_fail_alloc(CBM_DOCLINK_ALLOC_SCOPE)) {
30573065
s.failed = true;
30583066
}
3067+
if (cs_test_spoiled_path[0] && ctx->rel_path &&
3068+
strcmp(ctx->rel_path, cs_test_spoiled_path) == 0) {
3069+
sb_puts(&s.sb, "Z\tspoiled\n");
3070+
}
30593071
#endif
30603072
if (s.failed || s.sb.failed || !s.sb.buf) {
30613073
/* memory ran out: no scope would read as a file that declares

‎src/pipeline/doc_links.c‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,18 @@ int cbm_doclinks_scope_delta(const char *stored, const char *fresh, cbm_doclink_
113113
return R->scope_delta(stored, fresh, removed, ud);
114114
}
115115

116+
const char *cbm_doclinks_storable_scope(const char *scope) {
117+
const cbm_doclink_resolver_t *R = resolver_of_scope(scope);
118+
if (!R || !R->scope_accepted || !R->rejected_scope) {
119+
return scope;
120+
}
121+
int accepted = R->scope_accepted(scope);
122+
if (accepted < 0) {
123+
return NULL;
124+
}
125+
return accepted ? scope : R->rejected_scope;
126+
}
127+
116128
/* ── Run state ───────────────────────────────────────────────────── */
117129

118130
typedef struct {

‎src/pipeline/doc_links.h‎

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,15 @@ typedef struct {
212212
bool (*scope_input)(const char *rel_path);
213213
int (*scope_delta)(const char *stored, const char *fresh, cbm_doclink_name_fn removed,
214214
void *ud);
215+
/* Optional, together: whether the reader takes a scope blob written in
216+
* this run (1), refuses it (0), or could not tell for memory (-1); and
217+
* what is stored instead of a refused blob. A run refuses the blob of its
218+
* own file and goes on without the file's declarations; the marker makes
219+
* a later run that reads the file's scope back do the same, where the
220+
* blob itself would be a stored scope the reader refuses, which fails
221+
* the run. */
222+
int (*scope_accepted)(const char *scope);
223+
const char *rejected_scope;
215224
} cbm_doclink_resolver_t;
216225

217226
extern const cbm_doclink_resolver_t cbm_doclink_cs_resolver;
@@ -229,10 +238,8 @@ uint64_t cbm_doclink_cs_test_scratch_work(void);
229238
/* Test seam (doc_links.c): the nth MENTIONS edge insert from now on fails as
230239
* if memory ran out (0: none). */
231240
void cbm_doclinks_test_fail_edge_insert_after(int nth);
232-
/* Test seams (doc_links_cs.c): spoil the scope of the file at `rel_path`
233-
* (every record, then one the reader refuses; NULL or "": none), and ask the
234-
* reader whether it takes a scope blob. */
235-
void cbm_doclink_cs_test_spoil_scope(const char *rel_path);
241+
/* Test seam (doc_links_cs.c): ask the reader whether it takes a scope blob.
242+
* (The scope of one file is spoiled where it is written: doclink.h.) */
236243
bool cbm_doclink_cs_test_scope_parses(const char *scope);
237244
#endif
238245

@@ -246,4 +253,10 @@ bool cbm_doclinks_is_scope_input(const char *rel_path);
246253
int cbm_doclinks_scope_delta(const char *stored, const char *fresh, cbm_doclink_name_fn removed,
247254
void *ud);
248255

256+
/* What is stored for a scope blob written in this run (the surface row's
257+
* `dl`, lsp_surface.c): the blob itself, or its language's rejected-scope
258+
* marker when that language's reader refuses it (scope_accepted). NULL when
259+
* memory ran out deciding. */
260+
const char *cbm_doclinks_storable_scope(const char *scope);
261+
249262
#endif /* CBM_PIPELINE_DOC_LINKS_H */

‎src/pipeline/doc_links_cs.c‎

Lines changed: 48 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -5925,45 +5925,44 @@ static void undo_scope(cs_index_t *ix) {
59255925
u->nmarks = 0;
59265926
}
59275927

5928-
#if defined(CBM_ENABLE_TEST_SEAMS) && CBM_ENABLE_TEST_SEAMS
5929-
/* Test seam: the scope of the file at this path is spoiled -- every record
5930-
* it has, then one this reader refuses -- as if its writer and this reader
5931-
* disagreed after the file's declarations were read. "" or NULL: none. */
5932-
static char cs_test_spoiled_path[CBM_SZ_512];
5933-
5934-
void cbm_doclink_cs_test_spoil_scope(const char *rel_path) {
5935-
snprintf(cs_test_spoiled_path, sizeof(cs_test_spoiled_path), "%s", rel_path ? rel_path : "");
5936-
}
5937-
5938-
static const char *cs_test_spoiled(cs_index_t *ix, const char *rel_path, const char *scope) {
5939-
if (!scope || !cs_test_spoiled_path[0] || strcmp(rel_path, cs_test_spoiled_path) != 0) {
5940-
return scope;
5928+
/* What is stored, in place of its scope blob, for a file whose scope the
5929+
* reader refused in the run that wrote it (cs_scope_accepted, lsp_surface.c):
5930+
* the tag and one `!` record. A later run that reads it back treats the file
5931+
* as that run did -- it declares nothing, its references are graph gaps --
5932+
* where the refused blob itself would fail that run as a stored scope this
5933+
* reader does not take. */
5934+
static const char CS_REJECTED_SCOPE[] = CBM_DOCLINK_CS_SCOPE_TAG "\n!\trejected\n";
5935+
5936+
static bool cs_scope_marked_rejected(const char *scope) {
5937+
return scope && strcmp(scope, CS_REJECTED_SCOPE) == 0;
5938+
}
5939+
5940+
/* Whether this reader takes a scope blob written in this run: its record
5941+
* checks, on an index of the blob's own (what makes a blob refused depends on
5942+
* the blob alone). 1 taken, 0 refused, -1 memory ran out. A project file's
5943+
* blob goes to the MSBuild evaluator, which takes every blob. */
5944+
static int cs_scope_accepted(const char *scope) {
5945+
if (!scope || cbm_msb_is_project_scope(scope) || cs_scope_marked_rejected(scope)) {
5946+
return SKIP_ONE;
59415947
}
5942-
const char *spoiled = cbm_arena_sprintf(&ix->arena, "%sZ\tspoiled\n", scope);
5943-
return spoiled ? spoiled : scope;
5944-
}
5945-
5946-
/* Test seam: true when this reader takes the scope blob `scope` (its record
5947-
* checks, on an index of its own). A test holds every blob the scanner
5948-
* writes against it. */
5949-
bool cbm_doclink_cs_test_scope_parses(const char *scope) {
59505948
cs_index_t *ix = (cs_index_t *)cbm_calloc(CBM_MEM_CLASS_OTHER, sizeof(*ix));
59515949
if (!ix) {
5952-
return false;
5953-
}
5954-
cbm_arena_init(&ix->arena);
5955-
ix->ns_by_key = cbm_ht_create(CBM_SZ_64);
5956-
ix->quarantine = cbm_ht_create(CBM_SZ_64);
5957-
ix->quarantine_test = cbm_ht_create(CBM_SZ_64);
5958-
ix->nss = (cs_ns_t *)ix_zalloc(ix, CBM_SZ_256 * sizeof(cs_ns_t));
5959-
bool ok = ix->ns_by_key && ix->quarantine && ix->quarantine_test && ix->nss;
5960-
if (ok) {
5961-
ix->nscap = CBM_SZ_256;
5950+
return CBM_NOT_FOUND;
5951+
}
5952+
cbm_arena_init_lazy(&ix->arena, CBM_ARENA_APPEND_BLOCK);
5953+
ix->ns_by_key = cbm_ht_create(CBM_SZ_16);
5954+
ix->quarantine = cbm_ht_create(CBM_SZ_16);
5955+
ix->quarantine_test = cbm_ht_create(CBM_SZ_16);
5956+
ix->nss = (cs_ns_t *)ix_zalloc(ix, CBM_SZ_16 * sizeof(cs_ns_t));
5957+
int accepted = CBM_NOT_FOUND;
5958+
if (ix->ns_by_key && ix->quarantine && ix->quarantine_test && ix->nss) {
5959+
ix->nscap = CBM_SZ_16;
59625960
ix->nnss = SKIP_ONE;
59635961
ix->nss[0] = (cs_ns_t){.parent = CS_NONE, .name = ""};
59645962
cs_file_t f = {.rel_path = "Scope.cs"};
59655963
undo_begin(ix);
5966-
ok = parse_scope(ix, &f, scope) && !ix->oom;
5964+
bool parsed = parse_scope(ix, &f, scope);
5965+
accepted = ix->oom ? CBM_NOT_FOUND : (parsed ? SKIP_ONE : 0);
59675966
}
59685967
cbm_ht_free(ix->ns_by_key);
59695968
cbm_ht_free(ix->quarantine);
@@ -5972,7 +5971,14 @@ bool cbm_doclink_cs_test_scope_parses(const char *scope) {
59725971
cbm_free(CBM_MEM_CLASS_OTHER, ix->undo.marks);
59735972
cbm_arena_destroy(&ix->arena);
59745973
cbm_free(CBM_MEM_CLASS_OTHER, ix);
5975-
return ok;
5974+
return accepted;
5975+
}
5976+
5977+
#if defined(CBM_ENABLE_TEST_SEAMS) && CBM_ENABLE_TEST_SEAMS
5978+
/* Test seam: true when this reader takes the scope blob `scope`. A test holds
5979+
* every blob the scanner writes against it. */
5980+
bool cbm_doclink_cs_test_scope_parses(const char *scope) {
5981+
return cs_scope_accepted(scope) == SKIP_ONE;
59765982
}
59775983
#endif
59785984

@@ -5996,13 +6002,12 @@ static const char *build_files(cs_index_t *ix, const cbm_doclink_build_in_t *in)
59966002
f->is_test = cs_is_test_path(src->rel_path);
59976003
/* a project file declares nothing: its blob went to the evaluator */
59986004
const char *scope = cbm_msb_is_project_scope(src->scope) ? NULL : src->scope;
5999-
#if defined(CBM_ENABLE_TEST_SEAMS) && CBM_ENABLE_TEST_SEAMS
6000-
scope = cs_test_spoiled(ix, src->rel_path, scope);
6001-
#endif
6005+
/* a scope its own run refused, stored as the marker: as in that run */
6006+
bool marked = cs_scope_marked_rejected(scope);
60026007
undo_begin(ix);
6003-
if (scope && !parse_scope(ix, f, scope)) {
6008+
if (marked || (scope && !parse_scope(ix, f, scope))) {
60046009
bool fresh = src->run_file >= 0 && src->run_file < in->run_file_count;
6005-
if (ix->oom || !fresh) {
6010+
if (!marked && (ix->oom || !fresh)) {
60066011
bad = ix->oom ? "" : src->rel_path;
60076012
break;
60086013
}
@@ -6354,7 +6359,9 @@ static bool delta_has_bases(const char *scope) {
63546359
* nobody's scope. */
63556360
static int cs_scope_delta(const char *stored, const char *fresh, cbm_doclink_name_fn removed,
63566361
void *ud) {
6357-
if (cbm_msb_is_project_scope(stored) || cbm_msb_is_project_scope(fresh)) {
6362+
/* a rejected file declares nothing: unchanged while it stays rejected */
6363+
if (cbm_msb_is_project_scope(stored) || cbm_msb_is_project_scope(fresh) ||
6364+
cs_scope_marked_rejected(stored) || cs_scope_marked_rejected(fresh)) {
63586365
return strcmp(stored, fresh) == 0 ? CBM_DOCLINK_DELTA_LOCAL : CBM_DOCLINK_DELTA_GLOBAL;
63596366
}
63606367
if (!delta_same_usings(stored, fresh) && (delta_has_bases(stored) || delta_has_bases(fresh))) {
@@ -6400,4 +6407,6 @@ const cbm_doclink_resolver_t cbm_doclink_cs_resolver = {
64006407
.file_end = cs_file_end,
64016408
.resolve = cs_resolve,
64026409
.scope_delta = cs_scope_delta,
6410+
.scope_accepted = cs_scope_accepted,
6411+
.rejected_scope = CS_REJECTED_SCOPE,
64036412
};

‎src/pipeline/lsp_surface.c‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "foundation/log.h"
2929
#include "foundation/mem_core.h"
3030
#include "foundation/sha256.h"
31+
#include "pipeline/doc_links.h" /* cbm_doclinks_storable_scope */
3132
#include "pipeline/worker_pool.h"
3233
#include "yyjson/yyjson.h"
3334

@@ -161,7 +162,11 @@ static char *surface_file_to_json(const CBMFileResult *result, const CBMLSPDef *
161162
* The defs decoder ignores this key; cbm_doclinks_scopes_from_surfaces
162163
* reads it back for the files an incremental run does not re-extract. */
163164
if (result && result->doc_scope) {
164-
char *portable = cbm_doclink_portable_scope(result->doc_scope);
165+
/* a scope this run's reader refuses is stored as its language's
166+
* rejected marker: a later run then treats the file as this one does
167+
* (doc_links.h, scope_accepted) */
168+
const char *kept = cbm_doclinks_storable_scope(result->doc_scope);
169+
char *portable = kept ? cbm_doclink_portable_scope(kept) : NULL;
165170
if (!portable) {
166171
yyjson_mut_doc_free(doc);
167172
return NULL; /* a missing scope would diverge silently: fail the row */

0 commit comments

Comments
 (0)