Skip to content

Commit eb4f6b9

Browse files
committed
fix(pipeline): decline the closure plan through one exit
The Python namespace checks added two more raw free(dep_targets) calls on decline paths, growing pipeline_incremental.c past its memory-core baseline. The first file that declines now stops both the changed and the deleted loop; one exit after the loops skips the dependent query and releases dep_targets and the row index for every reason, including the existing missing-row and added-name declines. closure_python_namespace_decline maps the namespace comparison to its decline reason. Decline order and reasons are unchanged. The file drops to 140 raw sites; the baseline is tightened to match. Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
1 parent c278f4b commit eb4f6b9

2 files changed

Lines changed: 40 additions & 41 deletions

File tree

‎scripts/memory-core-baseline.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ src/pipeline/pass_usages.c 4
7777
src/pipeline/path_alias.c 40
7878
src/pipeline/pipeline.c 134
7979
src/pipeline/pipeline_delta.c 19
80-
src/pipeline/pipeline_incremental.c 142
80+
src/pipeline/pipeline_incremental.c 140
8181
src/pipeline/registry.c 17
8282
src/pipeline/worker_pool.c 2
8383
src/store/store.c 354

‎src/pipeline/pipeline_incremental.c‎

Lines changed: 39 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2500,6 +2500,18 @@ static const char *closure_k8s_decline(cbm_store_t *store, const char *project,
25002500
return NULL;
25012501
}
25022502

2503+
/* A Python file whose namespace metadata changed, or is unreadable, declines
2504+
* the closure before any hash cutoff: its importers' bindings follow the
2505+
* namespace order. A deleted file passes NULL for fresh_json. */
2506+
static const char *closure_python_namespace_decline(const char *stored_json,
2507+
const char *fresh_json) {
2508+
int change = cbm_lsp_surface_python_change(stored_json, fresh_json);
2509+
if (change < 0) {
2510+
return "python_namespace_metadata_invalid";
2511+
}
2512+
return change > 0 ? "python_namespace_changed" : NULL;
2513+
}
2514+
25032515
/* Decide whether this manifest delta is closure-repairable, and if so build
25042516
* the plan. Returns 1 with *plan filled, or 0 (decline → FULL) with the
25052517
* reason logged. Every early exit declines; nothing here mutates state. */
@@ -2708,7 +2720,10 @@ static int closure_try_plan(cbm_pipeline_t *p, cbm_store_t *store, const char *p
27082720
}
27092721
body_targets = dep_targets + n_changed + n_deleted;
27102722
int dep_target_count = 0;
2711-
for (int i = 0; i < n_changed; i++) {
2723+
/* The first file that declines the closure stops both loops; the one exit
2724+
* below releases dep_targets and the row index for every reason. */
2725+
const char *why = NULL;
2726+
for (int i = 0; i < n_changed && !why; i++) {
27122727
const cbm_lsp_surface_row_t *stored_row = cbm_ht_get(rows_by_path, changed_paths[i]);
27132728
const cbm_lsp_surface_row_t *fresh_row = NULL;
27142729
for (int j = 0; j < probe_count; j++) {
@@ -2718,19 +2733,12 @@ static int closure_try_plan(cbm_pipeline_t *p, cbm_store_t *store, const char *p
27182733
}
27192734
}
27202735
if (!stored_row || !fresh_row) {
2721-
free(dep_targets);
2722-
cbm_ht_free(rows_by_path);
2723-
decline = "missing_surface_row";
2724-
goto done;
2736+
why = "missing_surface_row";
2737+
break;
27252738
}
2726-
int python_change =
2727-
cbm_lsp_surface_python_change(stored_row->defs_json, fresh_row->defs_json);
2728-
if (python_change != 0) {
2729-
free(dep_targets);
2730-
cbm_ht_free(rows_by_path);
2731-
decline = python_change < 0 ? "python_namespace_metadata_invalid"
2732-
: "python_namespace_changed";
2733-
goto done;
2739+
why = closure_python_namespace_decline(stored_row->defs_json, fresh_row->defs_json);
2740+
if (why) {
2741+
break;
27342742
}
27352743
if (strcmp(stored_row->surface_sha, fresh_row->surface_sha) == 0) {
27362744
/* body edit: the file re-resolves, and of the others only the
@@ -2739,38 +2747,25 @@ static int closure_try_plan(cbm_pipeline_t *p, cbm_store_t *store, const char *p
27392747
continue;
27402748
}
27412749
bool added = false;
2742-
const char *why = NULL;
27432750
if (surface_added_names(stored_row->defs_json, fresh_row->defs_json, &added) != 0 ||
27442751
added) {
27452752
why = "added_definition_names";
27462753
} else if (!doc_scope_repairable(stored_row->defs_json, fresh_row->defs_json,
27472754
removed_names)) {
27482755
why = "doc_scope_changed";
2756+
} else {
2757+
n_surface_changed++;
2758+
dep_targets[dep_target_count++] = changed_paths[i];
27492759
}
2750-
if (why) {
2751-
free(dep_targets);
2752-
cbm_ht_free(rows_by_path);
2753-
decline = why;
2754-
goto done;
2755-
}
2756-
n_surface_changed++;
2757-
dep_targets[dep_target_count++] = changed_paths[i];
27582760
}
27592761
bool gone_scope_changed = false; /* a deleted file takes its declarations along */
2760-
for (int i = 0; i < n_deleted; i++) {
2761-
const cbm_lsp_surface_row_t *stored_row =
2762-
cbm_ht_get(rows_by_path, changed_paths[n_changed + i]);
2763-
int python_change =
2764-
cbm_lsp_surface_python_change(stored_row ? stored_row->defs_json : NULL, NULL);
2765-
if (python_change != 0) {
2766-
free(dep_targets);
2767-
cbm_ht_free(rows_by_path);
2768-
decline = python_change < 0 ? "python_namespace_metadata_invalid"
2769-
: "python_namespace_changed";
2770-
goto done;
2762+
for (int i = 0; i < n_deleted && !why; i++) {
2763+
const cbm_lsp_surface_row_t *gone = cbm_ht_get(rows_by_path, changed_paths[n_changed + i]);
2764+
why = closure_python_namespace_decline(gone ? gone->defs_json : NULL, NULL);
2765+
if (why) {
2766+
break;
27712767
}
27722768
dep_targets[dep_target_count++] = changed_paths[n_changed + i];
2773-
const cbm_lsp_surface_row_t *gone = cbm_ht_get(rows_by_path, changed_paths[n_changed + i]);
27742769
if (gone && !doc_scope_repairable(gone->defs_json, NULL, removed_names)) {
27752770
gone_scope_changed = true;
27762771
}
@@ -2782,14 +2777,18 @@ static int closure_try_plan(cbm_pipeline_t *p, cbm_store_t *store, const char *p
27822777
* target, so the documents with edges into a body-edited file re-resolve
27832778
* too (added to the closure below). */
27842779
bool dep_failed =
2785-
(dep_target_count > 0 &&
2786-
cbm_store_get_dependent_files(store, project, dep_targets, dep_target_count, &dependents,
2787-
&dependent_count) != CBM_STORE_OK) ||
2788-
(body_target_count > 0 &&
2789-
cbm_store_get_dependent_files(store, project, body_targets, body_target_count, &line_docs,
2790-
&line_doc_count) != CBM_STORE_OK);
2780+
!why && ((dep_target_count > 0 &&
2781+
cbm_store_get_dependent_files(store, project, dep_targets, dep_target_count,
2782+
&dependents, &dependent_count) != CBM_STORE_OK) ||
2783+
(body_target_count > 0 &&
2784+
cbm_store_get_dependent_files(store, project, body_targets, body_target_count,
2785+
&line_docs, &line_doc_count) != CBM_STORE_OK));
27912786
free(dep_targets); /* body_targets with it */
27922787
body_targets = NULL;
2788+
if (why) {
2789+
decline = why;
2790+
goto done;
2791+
}
27932792
if (dep_failed) {
27942793
decline = "dependent_query_failed";
27952794
goto done;

0 commit comments

Comments
 (0)