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-builtins-slot-api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Migrate the builtin runtime onto representation-independent container slots.
1 change: 1 addition & 0 deletions changes/internal/1665-builtins-slot-retention.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Fix slot-rehearsal numeric views retained by mutating builtins while completing the #1665 migration audit.
500 changes: 262 additions & 238 deletions src/builtins.c

Large diffs are not rendered by default.

9 changes: 7 additions & 2 deletions src/eigenscript.c
Original file line number Diff line number Diff line change
Expand Up @@ -2607,7 +2607,10 @@ static Value *chan_clone_rec(Value *v, int depth) {
if (!v) return make_null();
/* Cycle / pathological-depth guard: fall back to sharing (the pre-#293
* behavior) rather than overflow the stack. */
if (depth > CHAN_CLONE_MAX_DEPTH) { val_incref(v); return v; }
/* #1665: scalars are copied at any depth: a number may be a stack view,
* which must never be shared out of its frame. */
if (depth > CHAN_CLONE_MAX_DEPTH && v->type != VAL_NUM && v->type != VAL_NULL &&
v->type != VAL_BOOL && v->type != VAL_STR) { val_incref(v); return v; }
switch (v->type) {
case VAL_NUM: return make_num(VAL_NUM_RAW(v));
case VAL_NULL: return make_null();
Expand Down Expand Up @@ -2840,7 +2843,9 @@ static int values_equal_impl(Value *a, Value *b, int depth, const char *op) {
}
return 0;
}
if (depth > 64) return a == b;
/* #1665: the depth cap is for containers only; scalars compare by value
* (a number may be a view, so pointer identity is meaningless). */
if (depth > 64 && (a->type == VAL_LIST || a->type == VAL_DICT)) return a == b;
switch (a->type) {
case VAL_NUM: return VAL_NUM_RAW(a) == VAL_NUM_RAW(b);
case VAL_STR: return strcmp(a->data.str, b->data.str) == 0;
Expand Down
2 changes: 2 additions & 0 deletions src/vm.c
Original file line number Diff line number Diff line change
Expand Up @@ -6508,6 +6508,7 @@ static Value *vm_run_ex(EigsChunk *chunk, Env *env, Task *resume,
if (!fn || fn->type == VAL_NULL || fn->type == VAL_FN) {
slot_decref(arg_s); slot_decref(table_s);
vm_push_slot(slot_null());
eigs_view_check(&fn_view);
DISPATCH();
}

Expand All @@ -6516,6 +6517,7 @@ static Value *vm_run_ex(EigsChunk *chunk, Env *env, Task *resume,
slot_decref(arg_s); slot_decref(table_s);
rt_error(EK_TYPE, current_line, "dispatch: slot %d is not a function", key);
vm_push_slot(slot_null());
eigs_view_check(&fn_view);
DISPATCH();
}

Expand Down
4 changes: 4 additions & 0 deletions tests/sections/0fh-slot-escape-regress.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# #1665 arm D B3 review regressions (get_at owned grandchild, dispatch numeric return).
echo "[0fh] Slot API escape regressions (#1665)"
check_eigs_suite "slot escape regressions" test_slot_escape_regress.eigs "All tests passed"
echo ""
34 changes: 34 additions & 0 deletions tests/test_slot_escape_regress.eigs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# #1665 arm D B3 review regressions: values handed out of builtins must not be
# borrowed views or unowned grandchildren. Each case failed before its fix
# (get_at use-after-free under ASan; dispatch returned a dead stack frame).

load_file of "lib/test.eigs"
# get_at of a REFERENCE element is a grandchild of the argument list, so it must
# be owned: reading it, dropping it, and reading the list again stays intact.
names is ["alpha", "beta"]
x is get_at of [names, 0]
assert_eq of [x, "alpha", "get_at returns the string element"]
x is null
assert_eq of [get_at of [names, 1], "beta", "the list is intact after the element is released"]
grid is [["a", "b"], ["c", "d"]]
c is get_at of [grid, 1, 0]
assert_eq of [c, "c", "2-D get_at returns the string element"]
c is null
assert_eq of [grid, [["a", "b"], ["c", "d"]], "the grid is intact after release"]

# dispatch into a builtin that returns its numeric argument (num) must return a
# real number, not a pointer into dispatch's stack frame.
d is dispatch
r is d of [[num], 0, 5]
assert_eq of [r, 5, "dispatch -> num returns the number"]
r2 is d of [[num], 0, 7.5]
assert_eq of [r + r2, 12.5, "two dispatched numbers are independent values"]

# Equality and channel clone past the depth-64 container cap compare/copy
# scalars by value.
deep is 1
for i in range of 70:
deep is [deep]
assert_eq of [deep == deep, true, "a deep nest equals itself"]

test_summary of null
1 change: 1 addition & 0 deletions tools/container_migrated_files.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ src/eigenscript.h
src/eigenscript.c
src/trace.c
src/vm.c
src/builtins.c
36 changes: 18 additions & 18 deletions tools/strict_shape_contracts.json
Original file line number Diff line number Diff line change
Expand Up @@ -839,11 +839,11 @@
],
"disposition": "exempt",
"body_sha256": [
"f183d591ccd95ae6c658f3167403047669a5b6510b2a9c7c25ecd1464cb8dbac"
"e59c44bc54e46cbb61a478fb1c7431779980708478ff77cb24e40d8296b5f2ea"
],
"source_sha256": {
"builtin_get_at": [
"f183d591ccd95ae6c658f3167403047669a5b6510b2a9c7c25ecd1464cb8dbac"
"e59c44bc54e46cbb61a478fb1c7431779980708478ff77cb24e40d8296b5f2ea"
]
}
},
Expand Down Expand Up @@ -1185,11 +1185,11 @@
],
"disposition": "exempt",
"body_sha256": [
"6f12d49ea07ba5e4549f0047540aa8ba367331b3ec6e4852df9129a4b62fe4e1"
"6be773a899e620154d0984cb8adc99adb8767128437828d17b0db11a5375a590"
],
"source_sha256": {
"builtin_json_build": [
"6f12d49ea07ba5e4549f0047540aa8ba367331b3ec6e4852df9129a4b62fe4e1"
"6be773a899e620154d0984cb8adc99adb8767128437828d17b0db11a5375a590"
]
}
},
Expand All @@ -1212,7 +1212,7 @@
"5815ee115524cd711b01ba1bca89f1e152cd2303c2214447e1482ffde5df1189"
],
"eigs_json_encode_value": [
"b4e507c44e9d19a595a631c662e0805d10fce44fb03ffd496fa8a5f885923fe7"
"3624642731f3daaa091b7fdbe2f5fd8a12649ab1d9012b536e86f91f48a8bc7b"
]
}
},
Expand Down Expand Up @@ -1409,7 +1409,7 @@
"957d6367080150932b0eb91b77222af62118688b594ef3e894134f13c7ea1765"
],
"minmax_reduce": [
"beedf8c488020f3af2d920fb08165ad3cce16db8541ea91ff0840fae0352668f"
"595d20f4e17f76ec9e5f7b1f2ad47dd9a1703501bbb4fb975f889ed464f57066"
]
}
},
Expand All @@ -1432,7 +1432,7 @@
"895d02903f98e67d498faf4410e6d7d4cedc13d14f2d5699c86a24deccbea53c"
],
"minmax_reduce": [
"beedf8c488020f3af2d920fb08165ad3cce16db8541ea91ff0840fae0352668f"
"595d20f4e17f76ec9e5f7b1f2ad47dd9a1703501bbb4fb975f889ed464f57066"
]
}
},
Expand Down Expand Up @@ -1871,11 +1871,11 @@
],
"disposition": "exempt",
"body_sha256": [
"30690a745c7be23bb742c83b13764110cd187d0758ed2a2619b48a1f3c260eb5"
"897aa7a6f7c2d1177ea364e0178045289ae8ca6572f3456cb3b19cd32d2e6d4e"
],
"source_sha256": {
"builtin_set_at": [
"30690a745c7be23bb742c83b13764110cd187d0758ed2a2619b48a1f3c260eb5"
"897aa7a6f7c2d1177ea364e0178045289ae8ca6572f3456cb3b19cd32d2e6d4e"
]
}
},
Expand Down Expand Up @@ -1963,11 +1963,11 @@
],
"disposition": "exempt",
"body_sha256": [
"ec14b9b013b30cb7b269ce2a25984664c969f50b8dde97b84abdc553842aaea4"
"8a22c6ab7d441da0f47dc11ca19e0286132298db87e1402725a2ded6c80a826e"
],
"source_sha256": {
"builtin_sort": [
"ec14b9b013b30cb7b269ce2a25984664c969f50b8dde97b84abdc553842aaea4"
"8a22c6ab7d441da0f47dc11ca19e0286132298db87e1402725a2ded6c80a826e"
]
}
},
Expand Down Expand Up @@ -1995,11 +1995,11 @@
],
"disposition": "exempt",
"body_sha256": [
"d43b7c42b2248b1360cc76f5d998f77ef4350c6f022149d6ec5c1e833e679195"
"a4b876609d41ae093b50297d6aa8ea69fae0fbfbcc4fc9c98a451f1c23f293a2"
],
"source_sha256": {
"builtin_spawn": [
"d43b7c42b2248b1360cc76f5d998f77ef4350c6f022149d6ec5c1e833e679195"
"a4b876609d41ae093b50297d6aa8ea69fae0fbfbcc4fc9c98a451f1c23f293a2"
]
}
},
Expand Down Expand Up @@ -2217,11 +2217,11 @@
],
"disposition": "exempt",
"body_sha256": [
"4098fcc1457eb05e82f34ff4b1524275f67c5d821e52e734c41e89256c4fdaeb"
"428d69ce68b3789b9afdbefc670424a81b49aa64b1c8420eb9e6a3678102465e"
],
"source_sha256": {
"builtin_task_spawn": [
"4098fcc1457eb05e82f34ff4b1524275f67c5d821e52e734c41e89256c4fdaeb"
"428d69ce68b3789b9afdbefc670424a81b49aa64b1c8420eb9e6a3678102465e"
]
}
},
Expand Down Expand Up @@ -2788,11 +2788,11 @@
],
"disposition": "exempt",
"body_sha256": [
"2206aa352dbf84a6e78cc62c7fdd95f7185fc3a71ed3f5573f00eb33ad65083f"
"2083ab19a237e4a13f59634c4ebce02f7e7796de41d8a40254f2bff643229ba6"
],
"source_sha256": {
"builtin_values": [
"2206aa352dbf84a6e78cc62c7fdd95f7185fc3a71ed3f5573f00eb33ad65083f"
"2083ab19a237e4a13f59634c4ebce02f7e7796de41d8a40254f2bff643229ba6"
],
"eigs_module_ns_sync": [
"dd006fbaeca47f68e2df6343ad33e00bcdcf4c41243aae224c6798f0c2fc3a7c"
Expand Down Expand Up @@ -2821,7 +2821,7 @@
"fce8334d124e479de21cd22dfed262a8edcc656341a1f7c272507762481c57fc"
],
"vm_desc_abi_error": [
"cf2662e7782cb1679f191a68392821c334d53d165f776c90919b4cbc16d96c3a"
"d04f5e7fb2d2e37822a432fe90a03208d9de9cfcb1cbcb44774186f730fd1333"
]
}
},
Expand Down
Loading