From 3ee7b895ccecf95319c839fea4e2c4038495e5e9 Mon Sep 17 00:00:00 2001 From: Nitjsefnie Date: Sun, 2 Aug 2026 14:18:06 +0200 Subject: [PATCH] chore(core): drop two dead ext includes and 29 stale externs (#744) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Takes the two cheapest items of the #744 modularity review, verified independently of the issue's claims: 1. `eigenscript.c` included `ext_db_internal.h` and `model_internal.h` and used nothing from either. Confirmed by set-difference: of the 511 identifiers those two headers add to the TU's preprocessed token set over `eigenscript.h` + `vm.h`, the 18 that also appear in `eigenscript.c` are all parameter/member names inside declarations (`buf`, `query`, `from`, ...) — zero declared entities are referenced. This was the only core->ext include edge in the tree, and it forced libpq's headers onto the core TU: before this change, `eigenscript.c` compiled in the `full` configuration without `-I/usr/include/postgresql` fails with `fatal error: libpq-fe.h: No such file or directory`; after, it compiles clean. 2. `vm.c` carried 32 `extern` re-declarations of symbols already declared in `eigenscript.h`, free to drift from it. 29 are removed. Three are NOT redundant — `builtin_free_val`, `env_hash_find_dict` and `env_get_assign_count` have no declaration in any header and are called by `vm.c`, so they stay with a comment saying why. Of the 29, `val_incref`/`val_decref`/`num_guard` were inert (`static inline` in `eigenscript.h`) and `observer_ensure_fresh` still carried a comment pointing at `eval.c`, the TU the bytecode VM replaced. Behavior-neutral by construction, and measured: `build/{release,full, http,gfx}/{eigenscript,vm}.o` are byte-for-byte identical to the same objects built from the parent commit, and the release suite log diffs to zero lines against its baseline. Explicitly out of scope: items 3-5 of #744 (the per-layer header split, the `eigenscript.h` umbrella, moving `read_file_util` out of the builtins leaf, and the `vm.c` / `builtins.c` splits). Nothing in this commit touches a header, a test, or the build config. Co-Authored-By: Claude Opus 5 --- src/eigenscript.c | 6 ------ src/vm.c | 47 +++++++++++------------------------------------ 2 files changed, 11 insertions(+), 42 deletions(-) diff --git a/src/eigenscript.c b/src/eigenscript.c index 6912e669..25c352b3 100644 --- a/src/eigenscript.c +++ b/src/eigenscript.c @@ -9,12 +9,6 @@ #include "vm.h" /* EigsChunk layout: the cycle collector traverses * fn -> chunk -> env_cache / functions[] edges */ #include -#if EIGENSCRIPT_EXT_DB -#include "ext_db_internal.h" -#endif -#if EIGENSCRIPT_EXT_MODEL -#include "model_internal.h" -#endif /* #298 follow-up: surface use-after-recycle on the per-thread Value/Env * freelists to Valgrind. A num/env whose refcount hits 0 is recycled onto a diff --git a/src/vm.c b/src/vm.c index c3e9ae90..ca669b46 100644 --- a/src/vm.c +++ b/src/vm.c @@ -297,42 +297,17 @@ static int vm_slot_value_opaque(Env *e, int idx) { * fields; the g_* identifiers are macros in eigenscript.h. No extern * decls needed here. */ -/* ---- Helpers from eigenscript.c ---- */ -extern void val_incref(Value *v); -extern void val_decref(Value *v); -extern Value* make_num(double n); -extern Value* make_str(const char *s); -extern Value* make_null(void); -extern Value* make_list(int cap); -extern Value* make_dict(int cap); -extern Value* make_fn(const char *name, char **params, int param_count, - Env *closure); -extern Value* make_builtin(Value* (*fn)(Value*)); -extern void list_append(Value *list, Value *item); -extern void dict_set(Value *dict, const char *key, Value *val); -extern Value* dict_get(Value *dict, const char *key); -extern Env* env_new(Env *parent); -extern void env_incref(Env *env); -extern void env_decref(Env *env); -extern void env_mark_captured(Env *env); -extern void env_reserve_slots(Env *env, int total); -extern void env_set_local(Env *env, const char *name, Value *val); -extern void env_set_hashed(Env *env, const char *name, uint32_t h, Value *val); -extern void env_set_local_hashed(Env *env, const char *name, uint32_t h, Value *val); -extern Value* env_get_hashed(Env *env, const char *name, uint32_t h); -extern Value* env_get(Env *env, const char *name); -extern double num_guard(double x); -extern Value* promote_if_arena(Value *v); -/* Observer helper — declared in eval.c, needs to be exposed for VM. - * For now, call the eval.c version via a non-static wrapper. */ -extern void observer_ensure_fresh(Value *v); -extern Value* builtin_free_val(Value *arg); -extern const char* val_type_name(ValType t); -extern Value* dict_get_hashed(Value *dict, const char *key, uint32_t h); -extern void dict_set_hashed(Value *dict, const char *key, uint32_t h, Value *val); -extern int env_hash_find_dict(Value *dict, const char *key, uint32_t h); -extern int env_get_assign_count(Env *env, const char *name, uint32_t h); -extern void env_hash_insert(EnvHash *ht, uint32_t h, int idx); +/* ---- Cross-TU helpers that no header declares (#744) ---- + * The value/env/dict constructors and accessors this file calls are all + * declared in eigenscript.h — the re-declarations that used to sit here + * were redundant copies free to drift from it (one still claimed + * `observer_ensure_fresh` came from eval.c, a TU the bytecode VM replaced, + * and `val_incref`/`val_decref`/`num_guard` are `static inline` in the + * header, so the extern was inert). These three are the ones with no + * header declaration to defer to; they stay until they get a home. */ +extern Value* builtin_free_val(Value *arg); /* builtins.c */ +extern int env_hash_find_dict(Value *dict, const char *key, uint32_t h); /* eigenscript.c */ +extern int env_get_assign_count(Env *env, const char *name, uint32_t h); /* eigenscript.c */ /* Inline fast-path for binding a single param into a fresh call env. * Caller guarantees `env->count == slot_idx` and `env->capacity > slot_idx`