checker: a function named like a built-in a call always takes is refused at its declaration - function words(st, k) compiled and every call became words(n) with a pointer for n (invalid IR, far from the cause); the table is selfhost/check/check_builtins.ludic, emit_call's built-ins no find_fn guard lets a declared function take, and ludic-dev syntax --check holds it to emit_call both ways; every other built-in (buffer, floats, double, ...) yields to a declared function in the checker as it already did in codegen. string_temps' keep and cross_heap_test's keep renamed (hand, keep_cell); rejected/builtin_call_name and functions/builtin_yield with their cases (added, not run); reseeded, bootstrap-cfree fixpoint holds

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Orkun ÇAKILKAYA 2026-09-30 01:10:24 +03:00
parent 26b986de5b
commit d4df925b8f
13 changed files with 14830 additions and 13043 deletions

9
changes/builtin-names.md Normal file
View file

@ -0,0 +1,9 @@
bump: patch
type: fix
**A function named like a built-in a call always takes is refused.** `function words(st, k)` compiled,
and every call to it became the built-in `words(n)` - n zeroed ints, with a pointer for n - and LLVM
refused the IR far from the cause. A top-level function whose name a call always takes as the
compiler's own (`words`, `keep`, `print`, `save`, `load`, `key`, ...; the table is
`selfhost/check/check_builtins.ludic`, held to `emit_call` by `ludic-dev syntax --check`) is now an
error at its declaration, as `run` already was. Every other built-in (`buffer`, `floats`, `double`,
...) yields to a function the program declares, in the checker as it already did in codegen.

View file

@ -0,0 +1,11 @@
# builtin_yield.ludic - a built-in that a declared function may take (buffer, floats, double, ...)
# yields to it in the checker as in codegen: this `buffer` is the program's own, returning text.
#
# Prints: ab 4
program BuiltinYield {
function buffer(a: string, b: string) -> string { return a + b }
entry {
let s = buffer("a", "b")
print(`{s} {len(floats(4))}`)
}
}

View file

@ -3,7 +3,7 @@
# has been used, and one that IS held - in a variable, handed to a function, a function's result - # has been used, and one that IS held - in a variable, handed to a function, a function's result -
# is not. Prints 1 2 3 4 5 6 7 and `grew 0` (the heap is read on the Mac; 0 elsewhere). # is not. Prints 1 2 3 4 5 6 7 and `grew 0` (the heap is read on the Mac; 0 elsewhere).
program StringTemps { program StringTemps {
function keep(s: string) -> string { return s } function hand(s: string) -> string { return s }
function tag(i: int) -> string { return `t{i}` } function tag(i: int) -> string { return `t{i}` }
# every shape of throwaway text, compared against itself built another way: nothing survives # every shape of throwaway text, compared against itself built another way: nothing survives
@ -29,7 +29,7 @@ program StringTemps {
let n = string(-42) let n = string(-42)
let t = n + "!" + n let t = n + "!" + n
if n == "-42" and t == "-42!-42" { print(2) } if n == "-42" and t == "-42!-42" { print(2) }
let k = keep(a + "+" + b) let k = hand(a + "+" + b)
let k2 = k + "=" + k let k2 = k + "=" + k
if k == "dir+file" and k2 == "dir+file=dir+file" { print(3) } if k == "dir+file" and k2 == "dir+file=dir+file" { print(3) }
var acc = "" var acc = ""
@ -37,7 +37,7 @@ program StringTemps {
if acc == "0,1,2,3," { print(4) } if acc == "0,1,2,3," { print(4) }
if string(0) == "0" and string(2147483647) == "2147483647" and `{long(9000000000)}` == "9000000000" { print(5) } if string(0) == "0" and string(2147483647) == "2147483647" and `{long(9000000000)}` == "9000000000" { print(5) }
let nested = `a{`b{1 + 1}c`}d` let nested = `a{`b{1 + 1}c`}d`
# a function's result is its caller's to keep (keep() hands back its own argument), so only # a function's result is its caller's to keep (hand() hands back its own argument), so only
# the text built round it goes # the text built round it goes
if nested == "ab2cd" and "[" + tag(3) + "]" == "[t3]" { print(6) } if nested == "ab2cd" and "[" + tag(3) + "]" == "[t3]" { print(6) }
var bad = 0 var bad = 0

View file

@ -0,0 +1,8 @@
# builtin_call_name.ludic - a function named like a built-in a call always takes is refused at its
# declaration: every call to `words` is words(n), n zeroed ints, so this helper would never run (a
# pointer became its size). (Rejected on purpose: tools/ludic-cli/test.ludic.)
program BuiltinCallName {
function words(n: int, k: string) -> string { return k }
function keep(s: string) -> string { return s }
entry { print(words(1, keep("x"))) }
}

View file

@ -44,7 +44,7 @@ program CrossHeapTest {
cs.on[c] = false cs.on[c] = false
} }
# the ring kept round chunk (px, pz): those past it out, those in it in, and the broad phase rebuilt # the ring kept round chunk (px, pz): those past it out, those in it in, and the broad phase rebuilt
function keep(physics_st: mut PhysicsState, cs: mut CrossState, px: int, pz: int) -> void { function keep_cell(physics_st: mut PhysicsState, cs: mut CrossState, px: int, pz: int) -> void {
for c in 0 .. N * N { for c in 0 .. N * N {
let near = Math.abs(c % N - px) <= RING and Math.abs(c / N - pz) <= RING let near = Math.abs(c % N - px) <= RING and Math.abs(c / N - pz) <= RING
if cs.on[c] and not near { chunk_out(physics_st, cs, c) } if cs.on[c] and not near { chunk_out(physics_st, cs, c) }
@ -54,8 +54,8 @@ program CrossHeapTest {
phys_step(physics_st) phys_step(physics_st)
} }
function crossing(physics_st: mut PhysicsState, cs: mut CrossState) -> void { function crossing(physics_st: mut PhysicsState, cs: mut CrossState) -> void {
for k in 0 .. N { keep(physics_st, cs, k, k) } for k in 0 .. N { keep_cell(physics_st, cs, k, k) }
for k in 0 .. N { keep(physics_st, cs, N - 1 - k, N - 1 - k) } for k in 0 .. N { keep_cell(physics_st, cs, N - 1 - k, N - 1 - k) }
} }
test "crossing the map and back six times holds the bodies, the shapes and Jolt's bytes of the first crossing" (physics_st: mut PhysicsState, cross_st: mut CrossState) { test "crossing the map and back six times holds the bodies, the shapes and Jolt's bytes of the first crossing" (physics_st: mut PhysicsState, cross_st: mut CrossState) {

View file

@ -0,0 +1,23 @@
# check_builtins.ludic — the names a call always takes as the compiler's own, whatever the program
# declares: emit_call's built-ins that no `find_fn` guard lets a declared function take. A function
# so named is refused (ck_runtime_shadows) - a call would never reach it: a `words(st, k)` helper
# once compiled as words(n) with a pointer for its size. Every other built-in yields to a declared
# function, in the checker as in codegen; `ludic-dev syntax --check` holds this table to emit_call.
function is_call_builtin(name: pointer) -> bool {
if (name == "apply") or (name == "assert") or (name == "bytes") or (name == "data_of") { return true }
if (name == "expect") or (name == "expect_eq") or (name == "expect_near") or (name == "fixed") { return true }
if (name == "floor") or (name == "intern") or (name == "is_owner") or (name == "is_server") { return true }
if (name == "keep") or (name == "key") or (name == "len") or (name == "load") { return true }
if (name == "local_id") or (name == "net_poll") or (name == "net_pump") or (name == "net_send") { return true }
if (name == "owner") or (name == "panic") or (name == "print") or (name == "push") { return true }
if (name == "quit") or (name == "save") or (name == "self") or (name == "serialize") { return true }
if (name == "set_local_id") or (name == "set_owner") or (name == "set_role") or (name == "string") { return true }
if (name == "sync_size") or (name == "tick_fixed") or (name == "tick_render") or (name == "view") { return true }
if (name == "words") or (name == "world_attach_dyn") or (name == "world_count") or (name == "world_detach_dyn") { return true }
if (name == "world_field_count") or (name == "world_field_id") or (name == "world_field_name") or (name == "world_field_type") { return true }
if (name == "world_get") or (name == "world_has") or (name == "world_kind") or (name == "world_load") { return true }
if (name == "world_model_id") or (name == "world_prop_count") or (name == "world_prop_id") or (name == "world_prop_name") { return true }
if (name == "world_query_next") or (name == "world_register_prop") or (name == "world_save") or (name == "world_set") { return true }
if (name == "world_size") or (name == "world_spawn") { return true }
return false
}

View file

@ -231,6 +231,15 @@ function ck_call_named(e: Node, name: pointer) -> pointer {
return "?" return "?"
} }
if ck_raw_builtin(name) { ck_raw(e, `{name}()`) } if ck_raw_builtin(name) { ck_raw(e, `{name}()`) }
# a built-in no call always takes (not is_call_builtin) yields to a function the program declares,
# as codegen's does: the checker once typed a `buffer` helper as buffer(n) while codegen called it
if not is_call_builtin(name) {
let uf = ck_fn(name)
if uf != null {
ck_vis(uf, name, e)
return ck_call_fn(e, name, uf)
}
}
let bt = ck_builtin(e, name) let bt = ck_builtin(e, name)
if bt != null { return bt } if bt != null { return bt }
let f = ck_fn(name) let f = ck_fn(name)

View file

@ -212,7 +212,7 @@ function ck_runtime_shadows() -> void {
var u = 0 var u = 0
while u < g_prog_user_end { while u < g_prog_user_end {
let d = prog[u] let d = prog[u]
if d.kind == N_FN and (is_intrinsic(d.s) or is_intrinsic2(d.s)) { ck_err("shadow", d, `{d.s} is a built-in of the compiler, and a call to it would never reach this function; choose another name`) } if d.kind == N_FN and (is_intrinsic(d.s) or is_intrinsic2(d.s) or is_call_builtin(d.s)) { ck_err("shadow", d, `{d.s} is a built-in of the compiler, and a call to it would never reach this function; choose another name`) }
u += 1 u += 1
} }
var r = g_prog_user_end var r = g_prog_user_end

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load diff

View file

@ -112,6 +112,7 @@ function selfhost_frags() -> []pointer {
push(f, "selfhost/check/check_ops.ludic") push(f, "selfhost/check/check_ops.ludic")
push(f, "selfhost/check/check_call.ludic") push(f, "selfhost/check/check_call.ludic")
push(f, "selfhost/check/check_stmt.ludic") push(f, "selfhost/check/check_stmt.ludic")
push(f, "selfhost/check/check_builtins.ludic")
push(f, "selfhost/check/check_gen.ludic") push(f, "selfhost/check/check_gen.ludic")
push(f, "selfhost/check/check_gen_call.ludic") push(f, "selfhost/check/check_gen_call.ludic")
push(f, "selfhost/check/check_tynames.ludic") push(f, "selfhost/check/check_tynames.ludic")

View file

@ -422,6 +422,53 @@ function sx_parser() -> int {
return n return n
} }
# ---- the built-ins a call always takes, held to emit_call ----
# every `name == "x"` on one of a function's top-level `if` lines (after head, to the next function);
# guarded skips the lines a declared function can take (`find_fn(`)
function sx_name_tests(text: pointer, head: pointer, guarded: bool) -> []pointer {
let out = new []pointer
let n = slen(text)
var inside = false
var i = 0
while i < n {
let line = line_at(text, i)
i = i + slen(line) + 1
if s_starts(line, "function ") { inside = s_starts(line, head) }
else if inside and s_starts(line, " if (") and not (guarded and s_contains(line, "find_fn(")) {
var at = s_index(line, "name == \"", 0)
while at >= 0 {
let a = at + 9
var b = a
while b < slen(line) and line[b] != '"' { b += 1 }
let w = line[a .. b]
if not set_has(out, w) { push(out, w) }
at = s_index(line, "name == \"", b)
}
}
}
return out
}
# selfhost/check/check_builtins.ludic's table against emit_call's unguarded built-ins, both ways
function sx_builtins() -> int {
let ec = read_file("selfhost/backend/emit_call.ludic")
let tb = read_file("selfhost/check/check_builtins.ludic")
if ec == null or tb == null { push(g_sx_prob, "cannot read emit_call.ludic or check_builtins.ludic"); return 1 }
let want = sx_name_tests(ec, "function emit_call(", true)
let have = sx_name_tests(tb, "function is_call_builtin(", false)
var n = 0
var i = 0
while i < len(want) {
if not set_has(have, want[i]) { push(g_sx_prob, `emit_call always takes {want[i]}(...), and check_builtins.ludic does not refuse a function of that name - add it`); n += 1 }
i += 1
}
i = 0
while i < len(have) {
if not set_has(want, have[i]) { push(g_sx_prob, `check_builtins.ludic refuses {have[i]}, which emit_call no longer always takes - drop it`); n += 1 }
i += 1
}
return n
}
# ---- the command ---- # ---- the command ----
function sx_report(what: pointer) -> int { function sx_report(what: pointer) -> int {
if len(g_sx_prob) == 0 { return 0 } if len(g_sx_prob) == 0 { return 0 }
@ -457,6 +504,7 @@ function cmd_syntax_gen() -> int {
while i < len(ts) { sx_carries(ts[i]); i += 1 } while i < len(ts) { sx_carries(ts[i]); i += 1 }
sx_docs() sx_docs()
sx_parser() sx_parser()
sx_builtins()
return sx_report("the vocabulary and what is written from it disagree") return sx_report("the vocabulary and what is written from it disagree")
} }
if changed == 0 { print(" every grammar already says what ludicc --emit-syntax does") } if changed == 0 { print(" every grammar already says what ludicc --emit-syntax does") }

View file

@ -1375,6 +1375,8 @@ function cmd_dev_test() -> int {
schema_case("lang/scenes", "\"scene\": \"Play\", \"layer\": \"Hud\"", "--emit-schema: code.handlers - a scene's handler, its scene and layer") schema_case("lang/scenes", "\"scene\": \"Play\", \"layer\": \"Hud\"", "--emit-schema: code.handlers - a scene's handler, its scene and layer")
schema_case("state/write_reach", "{\"fn\": \"log_note\", \"module\": null, \"at\": \"examples/state/write_reach.ludic:21:37\", \"slot_kind\": \"registry\", \"slot\": \"Kinds.note\", \"entry\": \"box\"}", "--emit-schema: code.fn_refs - a fn in a registry row, the field and row it fills") schema_case("state/write_reach", "{\"fn\": \"log_note\", \"module\": null, \"at\": \"examples/state/write_reach.ludic:21:37\", \"slot_kind\": \"registry\", \"slot\": \"Kinds.note\", \"entry\": \"box\"}", "--emit-schema: code.fn_refs - a fn in a registry row, the field and row it fills")
schema_case("modules/ports", "\"slot_kind\": \"port_default\", \"slot\": \"Clock.day\"", "--emit-schema: code.fn_refs - a port member's default") schema_case("modules/ports", "\"slot_kind\": \"port_default\", \"slot\": \"Clock.day\"", "--emit-schema: code.fn_refs - a port member's default")
diag_json_case("rejected/builtin_call_name", 2, "words is a built-in of the compiler, and a call to it would never reach this function; choose another name", "a function named like a built-in a call always takes (words, keep) is refused at its declaration")
feat_case("functions/builtin_yield", "", "ab 4", "builtin_yield.ludic (a built-in a declared function may take - buffer - yields to it in the checker as in codegen)")
diag_json_case("rejected/i18n_keys/key_missing", 2, "the key pause.gone is not in examples/rejected/i18n_keys/lang/en.po", "a key literal en.po does not have is refused, at its line and column") diag_json_case("rejected/i18n_keys/key_missing", 2, "the key pause.gone is not in examples/rejected/i18n_keys/lang/en.po", "a key literal en.po does not have is refused, at its line and column")
diag_json_case("rejected/i18n_keys/key_missing", 2, "is a plural key, and examples/rejected/i18n_keys/lang/en.po:7 gives pause.resume no msgid_plural", "kn\"...\" is a plural key: en.po's entry has a msgid_plural") diag_json_case("rejected/i18n_keys/key_missing", 2, "is a plural key, and examples/rejected/i18n_keys/lang/en.po:7 gives pause.resume no msgid_plural", "kn\"...\" is a plural key: en.po's entry has a msgid_plural")
diag_json_case("rejected/i18n_keys/key_missing", 2, "trf: hud.day is given 2 value(s), and its English in examples/rejected/i18n_keys/lang/en.po has 1 hole(s)", "trf given more values than the key's English has holes: a warning") diag_json_case("rejected/i18n_keys/key_missing", 2, "trf: hud.day is given 2 value(s), and its English in examples/rejected/i18n_keys/lang/en.po has 1 hole(s)", "trf given more values than the key's English has holes: a warning")