feat(migrate): 0.R5 - ludic migrate state --tighten takes mut off every state parameter nothing down the chain writes; --root DIR lets the edits reach a directory without running its programs; a write through a local holding part of a mut state counts as a write to it
Maroon Lake: 149 parameters became read-only. What stays mut is a real write - in the packages mostly a lazy start inside a question (things_all, gear__ensure), which is what to take out next. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
40a91f39ed
commit
54f5efb23f
7 changed files with 50934 additions and 50157 deletions
|
|
@ -7,15 +7,19 @@
|
|||
var ck_ro: []int = new []int # parallel to ck_names: 1 for a read-only state
|
||||
var ck_alias: []Node = new []Node # parallel to ck_names: the global a local's reference came from
|
||||
var ck_ro_st: []pointer = new []pointer # parallel to ck_names: the state that makes a local read-only
|
||||
var ck_from_st: []pointer = new []pointer # parallel to ck_names: the state a local's reference came out of, mut or not
|
||||
|
||||
function ck_set_ro(ro: bool) -> void {
|
||||
let k = ck_top - 1
|
||||
while len(ck_ro) < len(ck_names) { push(ck_ro, 0) }
|
||||
while len(ck_alias) < len(ck_names) { push(ck_alias, null) }
|
||||
while len(ck_ro_st) < len(ck_names) { push(ck_ro_st, null) }
|
||||
while len(ck_from_st) < len(ck_names) { push(ck_from_st, null) }
|
||||
if ro { ck_ro[k] = 1 } else { ck_ro[k] = 0 }
|
||||
ck_alias[k] = null
|
||||
ck_ro_st[k] = null
|
||||
ck_from_st[k] = null
|
||||
if is_state_ty(ck_tys[k]) { ck_from_st[k] = ck_tys[k] }
|
||||
if ro { ck_ro_st[k] = ck_tys[k] }
|
||||
}
|
||||
# the local just bound is read-only for the same state as local `li`
|
||||
|
|
@ -42,6 +46,7 @@ function ck_let_from(e: Node, ty: pointer) -> void {
|
|||
if li >= 0 and li < k {
|
||||
if ck_is_ro(li) { ck_ro_like(li) }
|
||||
if li < len(ck_alias) { ck_alias[k] = ck_alias[li] }
|
||||
if li < len(ck_from_st) and k < len(ck_from_st) { ck_from_st[k] = ck_from_st[li] }
|
||||
return
|
||||
}
|
||||
if li >= 0 { return }
|
||||
|
|
@ -75,6 +80,7 @@ function ck_write_check(t: Node, what: pointer) -> void {
|
|||
if li >= 0 {
|
||||
mg_local_write(ck_tys[li]) # 0.S2 --migrate-prune: a state changed here
|
||||
if li < len(ck_ro_st) { mg_local_write(ck_ro_st[li]) }
|
||||
if li < len(ck_from_st) and ck_from_st[li] != null { mg_local_write(ck_from_st[li]) } # through a local holding part of it
|
||||
if li < len(ck_alias) and ck_alias[li] != null {
|
||||
let ag = ck_alias[li]
|
||||
mg_write(t, ag)
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@
|
|||
var g_migrate: bool = false
|
||||
var g_mg_runtime: bool = false # --migrate-runtime: the runtime's own vars too
|
||||
var g_mg_prune: bool = false # --migrate-prune: a declared state nothing uses is taken out
|
||||
var g_mg_tighten: bool = false # --migrate-tighten: and a `mut` state nothing down the chain writes is read-only
|
||||
var g_ma_node: []Node = new []Node # each state argument a call passes (an E_ID), its call, its state
|
||||
var g_ma_call: []int = new []int
|
||||
var g_ma_state: []int = new []int
|
||||
|
|
@ -602,7 +603,7 @@ function mg_norm_line(line: pointer) -> pointer {
|
|||
}
|
||||
if len(w) < 2 { return line }
|
||||
let k = w[0]
|
||||
if (k == "VAR") or (k == "REF") or (k == "INS") or (k == "LET") or (k == "CLOSE") or (k == "DELITEM") { w[1] = mg_norm(w[1]) }
|
||||
if (k == "VAR") or (k == "REF") or (k == "INS") or (k == "LET") or (k == "CLOSE") or (k == "DELITEM") or (k == "DELMUT") { w[1] = mg_norm(w[1]) }
|
||||
if (k == "?") { w[1] = mg_norm(w[1]) }
|
||||
if (k == "VAR") and len(w) > 5 { w[5] = mg_norm_key(w[5]) }
|
||||
if (k == "STATE") and len(w) > 6 {
|
||||
|
|
@ -787,6 +788,7 @@ function mg_prune_unit(u: int, n: Node) -> void {
|
|||
let p = n.kids[i]
|
||||
if p.kind == N_PARAM and is_state_ty(p.ty) and p.pos >= 0 and p.file != null {
|
||||
if not has_sub(g_mu_need[u], `,{itoa(mg_state_named(p.ty))},`) { mg_emit(`DELITEM {p.file} {itoa(p.pos)}`, "") }
|
||||
else if g_mg_tighten and p.uns == 1 and p.pos2 >= 0 and not has_sub(g_mu_mut[u], `,{itoa(mg_state_named(p.ty))},`) { mg_emit(`DELMUT {p.file} {itoa(p.pos2)}`, "") }
|
||||
}
|
||||
i += 1
|
||||
}
|
||||
|
|
|
|||
50527
selfhost/ludicc.seed.ll
50527
selfhost/ludicc.seed.ll
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
|
@ -161,6 +161,10 @@ entry {
|
|||
g_allow_globals = true
|
||||
}
|
||||
else if a == "--migrate-prune" { g_mg_prune = true } # 0.S2: state parameters nothing uses go too
|
||||
else if a == "--migrate-tighten" { # 0.R5: and `mut` goes where nothing down the chain writes
|
||||
g_mg_prune = true
|
||||
g_mg_tighten = true
|
||||
}
|
||||
else if a == "--migrate-runtime" { g_mg_runtime = true } # 0.S: the toolchain's own programs keep module-level vars # parse, type, module and port checks; nothing emitted
|
||||
else if a == "--coverage" { g_coverage = true }
|
||||
else if a == "--target" { ai += 1; if ai < arg_count() { target = arg(ai) } }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue