Skip to content

Batch: merge a transitive module's @externs, faults and actors; tcp.close_reset; discarded-call trailing block; a local lasts to the end of its function (#3872) - #3877

Merged
paul-hammant merged 5 commits into
mainfrom
batch/nov25
Nov 25, 2026
Merged

paul-hammant merged 5 commits into
mainfrom
batch/nov25

Conversation

@paul-hammant

Copy link
Copy Markdown
Collaborator

Five commits, one fix each.

1. codegen: run a trailing block on a discarded call (90f9a4d)

_ = f() { … } ran the call but dropped its trailing block; regression test test_trailing_block_discard.ae

2. merge: one merge path for a direct and a transitive import

A regression in 0.944.0 and 0.945.0; 0.941.0 is fine:

// a.ae
import std.math
sq(x: float) -> float { return math.sqrt(x) }
// mid.ae
import std.math (math_sin)
import a (sq)
ms(x: float) -> float { return math_sin(sq(x)) }
// m.ae
import mid
main() { println(mid.ms(4.0)) }

fails with E0301 Undefined function 'math.sqrt' in a.ae.

A module the program reaches only through other modules' imports is merged by the transitive pass (#243), which kept its own copy of the direct pass's per-declaration merge. That copy had functions, constants and types, but no @extern("sym") name(...) declarations, fault sets, messages, protocols or actors. A bare import anywhere on the path made the #870 synthetic import merge the module directly and hid the gap. #3852 (0.944.0) made std.math's sqrt, floor, ceil, round, abs, min, max and clamp into @externs, which exposed it. The same gap made a fault returned by such a module E0300 (Undefined variable '<ns>_<Fault>') and an actor it spawns Undefined function 'spawn_<Actor>'; both of those fail on 0.941.0 too.

The direct pass's loop is now merge_module_decls, and both passes call it. Bisected to c0c4783 (#3852): the compiler commits in v0.941.0..v0.945.0 don't change this path. Regression test: tests/integration/transitive_selective_import_merge. It fails before the fix with six errors and passes after.

3. std.tcp: close_reset, a close that resets on every platform

tests/integration/http_proxy_reset_is_502 fails on FreeBSD, on main as well. Its upstream closes a connection with the request unread to reset it. Linux, macOS and Windows reset in that case, but FreeBSD closes with a FIN, so the 502 said "the connection closed with no response" instead of naming the reset. The new tcp.close_reset(sock) (tcp_close_reset_raw, SO_LINGER on with a zero timeout) resets on every platform, and the test uses it. README, docs/api and the stdlib index are updated. It cross-builds for x86_64-windows and runs under Wine.

4. tcp_deadline_cancel: echo 256 KiB a chunk at a time

The "256 KiB echoed whole" case wrote all 256 KiB to an echo peer before reading any of it back. Wherever loopback buffers hold less than that, the write stalls until the 20 s deadline. It failed that way in a full FreeBSD sweep and passed when run alone. The case now writes 16 KiB and reads it back before sending the next chunk.

5. checker: a local lasts to the end of its function (0eb0b29)

A local lives to the end of its function: a call to the function it hid, made after the loop or branch that bound it, is E0301, and codegen no longer renames a closure's own local outside the closure.

Closes #3872

Verification (lab lanes)

  • FreeBSD 15.1 native suite, on 0eb0b29: make test 786/786; make test-ae 2381 pass, 0 fail, 34 skip; check-examples, test-install, test-differential, test-release-archive and check-archive-exports-nozlib all pass. Main fails http_proxy_reset_is_502 there.
  • Ubuntu 22.04 x86_64, CC=gcc make ci (compiler built with -Werror), on 0eb0b29: CI passed; make test-ae 2384 pass, 0 fail, 31 skip.
  • macOS arm64 make test-ae on 0eb0b29: 2359 pass, 0 fail.

🤖 Generated with Claude Code

paul-hammant and others added 5 commits November 25, 2026 08:30
`_ = f() { ... }` took the `_` discard path, which emitted `(void)(f())`
and never looked at the call's trailing block, so the block vanished
without a diagnostic. The same call bound to a name runs the block with
the value as its context.

The discard now binds the value to a temporary, pushes it as the
context, runs the block, and throws the value away, freeing a fresh
string. A builder's block already ran ahead of the call and is left as
it was.

tests/regression/test_trailing_block_discard.ae fails on 0.941.0 and
passes here; it covers an int, a fresh string, and a discard nested in
another's block, and is clean under macOS leaks. Mac make test-ae
2357/0; ae-x64 CC=gcc make ci green, 2382/0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With `import std.math (math_sin)` and `import a (sq)` in one module, the
program importing that module failed in `a`'s own `math.sqrt(x)` with
E0301 "Undefined function 'math.sqrt'".

A module the program reaches only through other modules' imports is merged
by the transitive pass (#243), which kept its own copy of the direct
pass's per-declaration merge. The copy had functions, constants and types,
but not `@extern("sym") name(...)` declarations (cloned as `<ns>_<name>`
so a qualified `ns.name(...)` resolves, #234), fault sets, messages,
protocols or actors. So in such a module a qualified call of its own
`@extern` was E0301, a fault it returned was E0300 "Undefined variable
'<ns>_<Fault>'", and an actor it spawned was "Undefined function
'spawn_<Actor>'". A bare import anywhere on the path had the #870
synthetic import merge the module through the direct pass, which hid the
gap; an all-selective path left only the transitive copy. #3852 (0.944.0)
made std.math's sqrt, floor, ceil, round, abs, min, max and clamp
`@extern`s, which exposed it for std.math; the same program built on
0.941.0, where they were bare externs. The fault and actor cases failed on
0.941.0 as well.

The direct pass's loop is now merge_module_decls, and both passes call it.

Regression: tests/integration/transitive_selective_import_merge (a user
module's `@extern`s, std.math's, a fault set, a message and an actor, all
reached through selective imports only), failing before the fix with six
errors.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
tests/integration/http_proxy_reset_is_502 failed on FreeBSD, on main as
well: its upstream closes the proxy's retry connection with the request
unread to reset it, and the 502 it got read "the connection closed with no
response" rather than naming the reset. A close with bytes unread resets
on Linux, macOS and Windows; FreeBSD ends the connection with a FIN, which
the client rightly reports as a bare close.

tcp.close_reset(sock) (tcp_close_reset_raw) sets SO_LINGER on with a zero
timeout and closes, so the peer's next read or write fails with
ECONNRESET on every platform. The test's upstream resets the retry
connection with it. std/tcp/README.md and docs/api regenerated.

Verified on FreeBSD 15.1: both cases of the test fail on main and pass
with this.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
"256 KiB echoed whole under a deadline and a cancel handle" wrote all
256 KiB to the echo peer before reading any of it back. The peer echoes as
it reads, so once the echo fills this side's receive buffer the peer stops
reading, its receive buffer and this side's send buffer fill, and the
write stalls until the 20 s deadline wherever the loopback buffers hold
less than the 256 KiB in flight. It failed so in a full FreeBSD sweep
("write [deadline exceeded], 0 bytes back") and passed alone. The case now
writes 16 KiB and reads it back before the next, so at most 16 KiB is in
flight; what it checks is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A local first bound in a loop or `if` body hid the function of its name
to the end of the function in the generated C (codegen names it
`ae_local_<name>` from its first binding on), but the checker's scope of
it closed with the body, so a call of the function after the body was
accepted and failed in the C compiler on an undeclared
`ae_local_<name>`. As decided on the issue, a local lives to the end of
its function, as the language reference and E0301's hint already say:
the checker now refuses such a call with E0301, as it does one after a
binding in the function's own body. A local that holds a closure is
called through, and is left alone.

A closure's own local is the closure's: codegen renamed a call of the
function after the closure too, the same C failure, on 0.941.0 as well.
The rename now ends with the closure that bound it.

Tests: local_named_after_called_function gains a loop and a branch case
(refused, E0301 twice) and a closure case (runs, "6 5"); it fails on the
compiler before this change. The language reference says the rule
outright. Mac make test-ae 2359/0.

Closes #3872

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@paul-hammant
paul-hammant merged commit c57521d into main Nov 25, 2026
54 checks passed
@paul-hammant
paul-hammant deleted the batch/nov25 branch November 25, 2026 21:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Is a local's scope its block or the rest of its function? The checker and codegen disagree

1 participant