Repository navigation
Conversation
Contributor
Author
|
Iterate tier on 1958e43 (pinned seed driving): |
added 3 commits
October 3, 2026 04:02
…ge is evaluated only on failure Sema records each call of the std.builtins / std.testing forms (precondition_form_calls) and checks the operands after the condition as an if-arm that does not return: what they move or invalidate is untouched after the form. MirLower branches on the condition and lowers the message, location and the declaration's call only on the failing path, ending it unreachable. The comptime evaluator does the same. The forms are refused as values.
…path is a lazy arm; a diverging ?? default keeps what it would move `c |> require(msg)` lowers as the form with `c` as its condition (the pipeline path also dropped the location default: #2024 is the general case). The failing path uses ??'s lazy-arm frame. Sema: a ?? fallback that does not return leaves the move state at the join untouched, as a diverging if arm does; D86 names ??'s right operand as the model.
The default path dropped the subject whatever its type. For a Copy subject that drop is a no-op, but it made the local owned storage to the ownership validator, which reported it Init at return (a leak) on the success path whenever the default diverges: `o ?? panic(..)` failed --validate-all. Found by D86's ?? fixture (#1864).
…ype is its address (#1864 exposed) D86 made assert a branch on its condition, so two values that were poison or undef on main became UB the optimizer folded to `brk #1` in main (behav_rotate, behav_int_to_pointer_cast_sign_extends exit 133): - CodegenDispatch.w, ROTATE_LEFT/RIGHT lowered `(x << n) | (x >> (W - n))`; n of 0 or W shifts by W, poison (`shl i32 x, 32` in the IR). It is now llvm.fshl/fshr(x, x, n), the count modulo the width as comptime_rotate_bits takes it. - CodegenDispatch.w mir_const_value, CK_INT_EXACT at a pointer Sema type (the module const `-1 as extern "C" fn(...)` folded by MirLower) returned `undef` silently (`icmp eq i64 undef, -1`); CK_INT at a pointer type was an i32. Both are the address now (const_int_address), and an exact constant with no lowering is a reported BUG, not an undef. - CodegenTraits.w, a module binding of function-pointer type with value 0 was emitted `@STATIC = internal constant i32 0` and read as eight bytes; every binding whose type lowers to a pointer gets its address constant.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements D86 (spec §18.2, #1864): "
assert,require,checkand theirstd.testingforms are compiler-known forms, not functions. Each evaluates its message operand only when its condition is false. The message operand follows the rules of the right operand of??: its effects do not run when the condition holds, and a move inside it is a conditional move."Design
check_callrecords each call whose resolved callee isassert/require/checkdeclared instd/builtins.worstd/testing.winSema.precondition_form_calls(call node → form). A user's ownfn checkis an ordinary function.ifarm that does not return: the scope and field-move/poison state is saved after the condition and restored after the call. A move inside the message is a conditional move on a path that does not return, so the value is still owned after a passing form.let f = require,run(check),testing.assert) is refused. A function value would evaluate the message before the call.MirLower.w lower_precondition_form). Lower the condition, then switch on it. The failing path is a??-style lazy arm: it lowers the message and the location default (still the call site'ssrc()), calls the declaration withfalse, flushes its pending resets, and endsunreachable. The passing path continues.c |> require(msg)lowers the same way with the piped value as the condition. Emit-C reads the same MIR.eval_precondition_form): same order. Note: comptime fns cannot call the forms today ("comptime can only call comptime functions"), so this path only matters where the evaluator runs ordinary code.Two adjacent fixes, found by the fixtures:
??with a diverging default (§18.2 names??'s right operand as the model). Sema now restores move state when the default isNever, as it does for a divergingifarm. Before,o ?? panic(f"{consume(r)}")followed by a use ofrwas refused.??on a Copy subject dropped the subject on the default path. When the default diverges,--validate-allthen reported a leak (o ?? panic("x")). The default path no longer drops a Copy subject.Filed rather than fixed: #2024, a pipeline stage call omits the callee's default arguments (invalid LLVM).
Tests (each new test failed on the base compiler first)
test/behavior/precondition_lazy.w://! known-issue: #1864dropped; covers all three builtins forms.test/behavior/precondition_lazy_std_testing.w:testing.assert/require/checkand an importedrequire.test/behavior/precondition_lazy_pipeline.w: the piped condition. The message would index out of range if evaluated. The base compiler produced invalid LLVM here.test/behavior/precondition_message_runs_on_failure{,_check,_assert,_std_testing}.w: on failure the message runs once, after the condition, and the form panics with it (exit 134, stderr).test/behavior/precondition_message_conditional_move.w: a message that consumes a Drop value, in every form. The value is usable afterwards and dropped once. Also an ownedstrpassed totesting.check.test/debug_alloc/da_precondition_message_conditional_move.w: the same moves under the debug allocator,leak count=0.test/emit_c/precondition_lazy.w: the C backend. The emitted C calls the message only in the failing block, which ends in the unreachable panic.test/compile_errors/err_1864_{require_as_value,check_passed_as_fn,testing_assert_as_value}.w: the refusals.test/behavior/coalesce_diverging_default_conditional_move.wandtest/phase/validate_coalesce_diverging_default_copy.w: the two??fixes.--validate-all: okandanalyze audit:all: violations=0on the precondition fixtures.Gate:
src/main build :gategreen;:deep-debug-tool-testsgreen;:drop-audit254 cells, 0 regressions (see comment).