Warnings for big copies: a struct with 256+ bytes of plain data as a parameter or in for x in list

- on stderr (finch ir stays the IR), as yellow warnings in editors (@W in the index), once per place
- str, arrays and maps inside a struct don't count: passing it copies only their handles
- none in the compiler, the examples or the tests other than the new one
- docs: the warning instead of "not planned"; what was and wasn't checked for Android

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016GzNP6r8dg6WDxUVZy8wjL
This commit is contained in:
Nexoniarz 2026-10-29 12:15:22 +01:00
commit d557b5505e
15 changed files with 210 additions and 18 deletions

52
tests/new/big_copies.fch Normal file
View file

@ -0,0 +1,52 @@
// a struct of 256 bytes or more copied without the code saying so: a warning (the program still builds)
struct M4 {
float a0
float a1
float a2
float a3
float b0
float b1
float b2
float b3
float c0
float c1
float c2
float c3
float d0
float d1
float d2
float d3
}
struct Body {
M4 world
M4 local
int id
}
fn weight(Body b) -> float { // warned: 264 bytes copied on every call
return b.world.a0 + float(b.id)
}
fn nudge(ptr[Body] b) { // shared: no warning
b.world.a0 += 1.0
}
fn small(M4 m) -> float { // 128 bytes: no warning
return m.a0
}
fn main() {
b := Body(id: 2)
nudge(b)
print(weight(b), small(b.world))
bodies := [b, b]
total := 0.0
for x in bodies { // warned: each element copied into x
total += x.world.a0
}
for i in 0..bodies.len { // in place: no warning
total += bodies[i].world.a0
}
print(total)
}

4
tests/new/big_copies.out Normal file
View file

@ -0,0 +1,4 @@
new/big_copies.fch:27:11: warning: 'b' is a Body (264 bytes), copied on every call to weight; take ptr[Body] to share it instead (callers can still pass the variable as it is)
new/big_copies.fch:45:5: warning: each Body (264 bytes) is copied into 'x'; for i in 0..bodies.len with bodies[i] works on it in place
3 1
4