wip(0.S2): a migration makes a declared read-only state mut where it is now changed; net_sync builds --unsafe

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Orkun ÇAKILKAYA 2026-09-25 15:02:45 +03:00
parent e7f8ee6b91
commit d490d4f9f1
7 changed files with 48213 additions and 46785 deletions

View file

@ -358,10 +358,34 @@ function mg_nparams(n: Node) -> int {
}
return k
}
# a state declared read-only (a run before) that the unit, or something it calls, now changes
function mg_mut_upgrades(u: int, n: Node) -> void {
var ps = n.kids
if g_mu_kind[u] != 0 {
ps = new []Node
var body = n.a
if g_mu_kind[u] == 5 { body = n }
var j = 0
while body != null and j < len(body.kids) and body.kids[j].tps != null and (body.kids[j].tps == "state") {
push(ps, body.kids[j])
j += 1
}
}
var i = 0
while i < len(ps) {
let p = ps[i]
if (p.kind == N_PARAM or p.kind == S_LET) and is_state_ty(p.ty) and p.uns == 0 and p.pos2 >= 0 and p.file != null {
let s = mg_state_named(p.ty)
if has_sub(g_mu_mut[u], `,{itoa(s)},`) { mg_emit(`INS {p.file} {itoa(p.pos2)} {mg_esc("mut ")}`, "") }
}
i += 1
}
}
function mg_units() -> void {
var u = 0
while u < len(g_mu_node) {
let n = g_mu_node[u]
mg_mut_upgrades(u, n)
let need = mg_list(g_mu_need[u])
if len(need) > 0 {
var text = ""

View file

@ -76,6 +76,7 @@ function parse_state() -> void {
}
# `name: mut T` in a parameter list: the `mut`, when it is there
function parse_param_mut(p: Node) -> void {
p.pos2 = toks[pi].pos # where `mut ` goes, when a migration adds it
if is_id("mut") and toks[pi + 1].kind == TK_ID {
pi += 1
p.uns = 1
@ -167,6 +168,7 @@ function entry_bind(body: Node, ps: []Node) -> void {
l.ival = 0
l.uns = p.uns # 1: a `mut` state; 0: read-only
l.tps = "state" # an entry point's state: checked to be one
l.pos2 = p.pos2
let id = node(E_ID)
id.s = state_global(p.ty)
id.file = p.file