Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changes/internal/1665-core-slot-api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Internal: the core runtime (eigenscript.c/.h, trace.c) reads containers, walks values and traces GC edges through the slot API, ahead of NaN-boxed container storage (#1665 arm D B1).
9 changes: 9 additions & 0 deletions src/container.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,18 @@ static inline Value *dict_value_get_return(const Value *dict, int i) {
return v->type == VAL_NUM ? make_num(VAL_NUM_RAW(v)) : v;
}

/* Compatibility reads for files not yet migrated in later batches. */
static inline Value *dict_get(Value *dict, const char *key) {
return dict_get_ref_legacy(dict, key);
}
static inline Value *dict_get_hashed(Value *dict, const char *key, uint32_t h) {
return dict_get_hashed_ref_legacy(dict, key, h);
}

/* Low-level compatibility accessors retain their pre-flip meaning. */
static inline Value *list_get_borrow(const Value *list, int i) { return list->data.list.items[i]; }
static inline Value *dict_value_get_borrow(const Value *dict, int i) { return dict->data.dict.vals[i]; }
static inline Value *dict_value_compat_ref(const Value *dict, int i) { return dict->data.dict.vals[i]; }
static inline void list_set_owned(Value *list, int i, Value *v) { list->data.list.items[i] = v; }
static inline void dict_value_set_owned(Value *dict, int i, Value *v) { dict->data.dict.vals[i] = v; }
static inline void list_set_borrow(Value *list, int i, Value *v) { val_incref(v); list_set_owned(list, i, v); }
Expand Down
164 changes: 93 additions & 71 deletions src/eigenscript.c

Large diffs are not rendered by default.

34 changes: 17 additions & 17 deletions src/eigenscript.h
Original file line number Diff line number Diff line change
Expand Up @@ -1412,21 +1412,6 @@ int eigs_opt_num(const Value *v, double *out, const char *who);
#define EIGS_BOOL_GATE_SCAN 8
int eigs_bool_gate_slow(BuiltinFn fn, const Value *arg);
void eigs_bool_gate_exempt(BuiltinFn fn); /* a host function: never gated */
static inline int eigs_bool_gate(BuiltinFn fn, const Value *arg) {
if (!arg) return 0;
if (arg->type == VAL_BOOL) return eigs_bool_gate_slow(fn, arg);
if (arg->type != VAL_LIST) return 0;
int n = arg->data.list.count < EIGS_BOOL_GATE_SCAN ? arg->data.list.count
: EIGS_BOOL_GATE_SCAN;
for (int i = 0; i < n; i++) {
const Value *e = arg->data.list.items[i];
if (e && e->type == VAL_BOOL) return eigs_bool_gate_slow(fn, arg);
}
return 0;
}
static inline Value *eigs_call_builtin(BuiltinFn fn, Value *arg) {
return eigs_bool_gate(fn, arg) ? NULL : fn(arg);
}
/* #1637: for a builtin that reads a number without a typed guard (its other
* wrong types answer null): a bool there raises in every strict mode. */
#define BOOL_REFUSE(v, who) \
Expand Down Expand Up @@ -1814,7 +1799,8 @@ void dict_set_owned(Value *dict, const char *key, Value *val);
* keys into a process-global intern table so they survive the sender thread's
* detach. Returns a heap value (refcount 1). */
Value *val_clone_for_send(Value *v);
Value* dict_get(Value *dict, const char *key);
Value* dict_get_ref_legacy(Value *dict, const char *key);
Value* dict_get_hashed_ref_legacy(Value *dict, const char *key, uint32_t h);
void list_append(Value *list, Value *item);
void list_append_owned(Value *list, Value *item);

Expand Down Expand Up @@ -1993,6 +1979,21 @@ static inline void val_decref(Value *v) {
#include "value_slot.h"
#include "container.h"

static inline int eigs_bool_gate(BuiltinFn fn, const Value *arg) {
if (!arg) return 0;
if (arg->type == VAL_BOOL) return eigs_bool_gate_slow(fn, arg);
if (arg->type != VAL_LIST) return 0;
int n = arg->data.list.count < EIGS_BOOL_GATE_SCAN ? arg->data.list.count
: EIGS_BOOL_GATE_SCAN;
for (int i = 0; i < n; i++)
if (list_elem_type(arg, i) == VAL_BOOL)
return eigs_bool_gate_slow(fn, arg);
return 0;
}
static inline Value *eigs_call_builtin(BuiltinFn fn, Value *arg) {
return eigs_bool_gate(fn, arg) ? NULL : fn(arg);
}

/* ---- Environment ---- */

/* #607: post-resolve array access for an env the MAIN thread may grow
Expand Down Expand Up @@ -2127,7 +2128,6 @@ void env_store_slot(Env *env, int idx, EigsSlot s);
Env *env_resolve_chain(Env *start, const char *name, uint32_t h,
int *out_slot, int *out_depth);
void dict_set_hashed(Value *dict, const char *key, uint32_t h, Value *val);
Value* dict_get_hashed(Value *dict, const char *key, uint32_t h);
/* #1057 module namespaces. `import M` binds a dict that is a LIVE VIEW of the
* module's top-level Env: `M.x` reads the module's CURRENT binding and
* `M.x is v` writes it. attach flags the dict and takes an OWNING ref on the
Expand Down
6 changes: 4 additions & 2 deletions src/trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -2960,7 +2960,8 @@ static void write_value_ptr_full(Value *v, int *budget) {
int n = v->data.list.count;
for (int i = 0; i < n && *budget > 0; i++) {
if (i) wf_puts(", ", budget);
write_value_ptr_full(list_get_borrow(v, i), budget);
EIGS_VIEW(item_view);
write_value_ptr_full(list_get_view(v, i, &item_view), budget);
}
wf_putc(']', budget);
break;
Expand All @@ -2972,7 +2973,8 @@ static void write_value_ptr_full(Value *v, int *budget) {
if (i) wf_puts(", ", budget);
write_string_full(v->data.dict.keys[i], budget);
wf_puts(": ", budget);
write_value_ptr_full(dict_value_get_borrow(v, i), budget);
EIGS_VIEW(item_view);
write_value_ptr_full(dict_value_get_view(v, i, &item_view), budget);
}
wf_putc('}', budget);
break;
Expand Down
4 changes: 0 additions & 4 deletions tools/container_access_check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ while IFS= read -r hit; do
src/jit.c:*'offsetof(Value, data.dict.vals)'*)
# Emitted machine code needs the representation offset (step-2 site).
allowed=$((allowed + 1)); continue ;;
src/eigenscript.h:*'arg->data.list.items[i]'*)
# eigs_bool_gate scans arg lists before container.h is included
# (step-2 site: it must test the slot tag, not a Value*).
allowed=$((allowed + 1)); continue ;;
esac
printf 'raw Value container access: %s:%s:%s\n' "$file" "$line" "$text" >&2
violations=$((violations + 1))
Expand Down
5 changes: 4 additions & 1 deletion tools/container_migrated_files.txt
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
# B0 has no migrated production call sites. Add one src-relative path per line.
# Whole-file migrations completed after the B0 API introduction.
src/eigenscript.h
src/eigenscript.c
src/trace.c
5 changes: 2 additions & 3 deletions tools/num_read_allowlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,14 @@ chunk.c|const_equal|2|constant-pool dedup compares two constants after testing b
chunk.c|const_hash_value|1|constant-pool hash of a constant inside its type == VAL_NUM branch
eigenscript.c|chan_clone_rec|1|channel deep-copy, switch case VAL_NUM
eigenscript.c|compute_entropy_impl|1|observer entropy, switch case VAL_NUM
eigenscript.c|eigs_elem_num|1|checking accessor itself: reads only after type == VAL_NUM
eigenscript.c|ent_child_slot|1|observer entropy reads an immediate only after slot_is_num
eigenscript.c|eigs_num_arg_slow|1|checking accessor itself: reads only after type == VAL_NUM, raises otherwise
eigenscript.c|eigs_opt_num|1|checking accessor itself: reads only after type == VAL_NUM, raises on non-null non-numbers
eigenscript.c|is_truthy|1|truthiness, switch case VAL_NUM (a bool has its own case)
eigenscript.c|make_num|1|constructor: writes the number of a Value it just typed VAL_NUM
eigenscript.c|make_num_permanent|1|constructor: writes the number of a Value it just typed VAL_NUM
eigenscript.c|module_ns_project|2|mirror refresh: reads a slot after slot_is_num and writes a VAL_NUM mirror it owns exclusively
eigenscript.c|observer_entropy_now|1|observer entropy of a slot after slot_is_num
eigenscript.c|observer_slot_from_trajectory|9|trajectory snapshot fields each read right after its own type != VAL_NUM refusal
eigenscript.c|observer_slot_from_trajectory|6|trajectory snapshot fields each read right after its own type != VAL_NUM refusal
eigenscript.c|observer_slot_sample_gated|1|observer sample after newval->type == VAL_NUM
eigenscript.c|observer_slot_update|1|observer update after newval->type == VAL_NUM
eigenscript.c|slot_from_value|1|NaN-boxing boundary, inside its VAL_NUM branch
Expand Down
14 changes: 7 additions & 7 deletions tools/strict_shape_contracts.json
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@
"0f2463d9f7d4223393269796d4688a5d8fa708244de3f974f0e2f62c8cb0b540"
],
"eigs_list_num": [
"7411c7e0c55633135b58755125bdfb3363fcf5ef2ab7efb450526d9a2f4c684d"
"25755c9b1f519fb0447e2d648dc0272419914db805f9249954cd2e146b48a3bc"
]
}
},
Expand Down Expand Up @@ -779,7 +779,7 @@
"268d0eea61701a8101ef750b078302f77890f8baf08b211aebb51c75ce87293d"
],
"eigs_list_num": [
"7411c7e0c55633135b58755125bdfb3363fcf5ef2ab7efb450526d9a2f4c684d"
"25755c9b1f519fb0447e2d648dc0272419914db805f9249954cd2e146b48a3bc"
]
}
},
Expand Down Expand Up @@ -1046,7 +1046,7 @@
"038cedc73097976fcb26f43537ffd5fa8d598b2da404e2c05439106ac636bc3e"
],
"eigs_opt_num": [
"5bd33573efec2133743c045bc9827a72a8c9ea73f15a185468495764b5c37ecd"
"a59259f1f1c8f200ce3f1c7e6f668b797fbfa1219686fb8f9078719cdc9d129e"
]
}
},
Expand Down Expand Up @@ -1687,7 +1687,7 @@
"bcb3999873c5e085e20e6370e6ae81ddaf01a610069729a2a12dd5d402df301c"
],
"value_to_string": [
"0162dd03ddc58d709c0752df0b991eebc305c3b058f78838f8f5ecdb0a1143dc"
"c5f081c068f1ae84bec75b29c9954f194376fbaa26f557bd596eb2bf889db46f"
]
}
},
Expand Down Expand Up @@ -2130,7 +2130,7 @@
"54d7497ad4bc951a7f8b8e0e690f901fcab06ed74c92050e4e68be8c36921372"
],
"value_to_string": [
"0162dd03ddc58d709c0752df0b991eebc305c3b058f78838f8f5ecdb0a1143dc"
"c5f081c068f1ae84bec75b29c9954f194376fbaa26f557bd596eb2bf889db46f"
]
}
},
Expand Down Expand Up @@ -2752,7 +2752,7 @@
"dce6eda1020469efb73a67c34f60fa7cc66c03c617d1fb4bc96aaea536346ae3"
],
"value_to_string": [
"0162dd03ddc58d709c0752df0b991eebc305c3b058f78838f8f5ecdb0a1143dc"
"c5f081c068f1ae84bec75b29c9954f194376fbaa26f557bd596eb2bf889db46f"
]
}
},
Expand Down Expand Up @@ -2844,7 +2844,7 @@
"5556903dd96019edcff890e180e1e8f04ffc7101fe80b5fcf93520968ea3c180"
],
"value_to_string": [
"0162dd03ddc58d709c0752df0b991eebc305c3b058f78838f8f5ecdb0a1143dc"
"c5f081c068f1ae84bec75b29c9954f194376fbaa26f557bd596eb2bf889db46f"
]
}
},
Expand Down
Loading