You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
gen_perceptron.t27: the reference passes a weight update Zig never analyzes (assignment through a by-value parameter) #7741
Part of #6063 (t27b coverage). Found while landing #7740.
specs/port/trinity/src/tri/gen_perceptron.t27 passes the reference (t27c gen + zig test, 5 of 5) only because Zig never analyzes the body of its weight update.
fn Perceptron_train(perceptron: Perceptron, inputs: []const f64, target: i32) -> void {
...
for i in 0..inputs.len {
if (i < perceptron.weights.len) {
perceptron.weights[i] += perceptron.learning_rate * diff * inputs[i];
}
}
}
perceptron is a by-value parameter, so the assignment writes through a constant. Zig refuses that ("cannot assign to constant").
weights is [0]f64, so the condition is i < 0 on a usize. Zig decides it at compile time from the type's range, and does not analyze the arm.
Measured on the t27c lab with zig 0.16.0: the same generated Zig with [1]f64 instead fails to compile at that line, error: cannot assign to constant.
The only test that reaches the fn, perceptron_training_update, asserts true. So the reference passes a weight update that can never run and would not compile if it could.
After #7740 t27b gets past const diff: f64 = target - guess; and refuses the assignment by name: StmtAssign (assignment through a constant) at line 38. That refusal is right. The ledger records this spec as reference-bug.
The spec fix is the port's, not t27b's: make the update a var copy or a *Perceptron parameter, and give it a test that reads a weight.
Boundary
specs/port/trinity/src/tri/gen_perceptron.t27
User Scenarios
Given the gen_perceptron.t27 spec defines Perceptron_train with a by-value perceptron parameter and zero-length weights, when t27b compiles the spec, then the assignment to perceptron.weights[i] is rejected as an assignment through a constant.
Given the spec is fixed to use a var copy or pointer parameter for the perceptron and gives weights a non-zero length, when the generated Zig code is compiled and tested, then the weight update executes and a test observes the changed weight.
Requirements
FR-001: The Perceptron_train function MUST accept the perceptron by pointer (*Perceptron) or operate on a var copy so that weight updates are not assignments through a constant.
FR-002: The weights field MUST have a non-zero length (e.g., [2]f64) so the loop condition i < perceptron.weights.len is not trivially false and the loop body is analyzed.
FR-003: The spec MUST include a test that calls Perceptron_train and asserts that a weight value has changed after training.
Success Criteria
t27c specs/port/trinity/src/tri/gen_perceptron.t27 compiles without errors and exits 0
zig test zig-out/bin/gen_perceptron_test.zig (or equivalent generated test binary) runs and exits 0 with at least 1 test that reads a weight after training
The spec ledger no longer records gen_perceptron.t27 as reference-bug
Fixed by #8916 (issue #8905), merged as fd20f48. Perceptron_train now takes *Perceptron, and weights is [2]f64, starting at zero. The tests read the weights after training: a wrong guess moves each weight by -0.1, a right guess moves none, and inputs past the last weight are skipped. On the t27c lab, t27c test-report gives 6/6 with 0 vacuous, and t27b test gives 6 passed with 14 runtime asserts. The ledger row is pass.
Activity
t27b: the type mismatch family from a t27 plan -- two integer types c…
gen_perceptron.t27: train updates the caller's perceptron through a p…
gHashTag commentedon Oct 11, 2026
Fixed by #8916 (issue #8905), merged as fd20f48.
Perceptron_trainnow takes*Perceptron, andweightsis[2]f64, starting at zero. The tests read the weights after training: a wrong guess moves each weight by -0.1, a right guess moves none, and inputs past the last weight are skipped. On the t27c lab,t27c test-reportgives 6/6 with 0 vacuous, andt27b testgives 6 passed with 14 runtime asserts. The ledger row ispass.