Skip to content

conformance: a guard used as an expression yields its block's value, as mspec does (#962) - #965

Merged
tannevaled merged 1 commit into
mainfrom
guard-run-returns-block-value
Nov 21, 2026
Merged

tannevaled merged 1 commit into
mainfrom
guard-run-returns-block-value

Conversation

@tannevaled

Copy link
Copy Markdown
Contributor

A guard used as an expression now yields its block's value, as mspec does

mspec's SpecGuard#run_if is yield if yield?(false) (guard.rb:80). With a block, a guard therefore evaluates to the block's value when it holds, and to nil when it does not. The shim's _guard_run ended in a hardcoded nil, so the open case returned nothing as well:

def _guard_run(match)
  return match unless block_given?
  yield if match
end

Where it cost

core/file/stat/birthtime_spec.rb:3-5 splats exactly that value into a platform list:

platform_is(:windows, :darwin, :freebsd, :netbsd,
            *ruby_version_is("4.0") { :linux },
           ) do

*nil added nothing, so the file was guarded by a list that never contained :linux. It was skipped on the gate's own ubuntu runner, at a Ruby version where upstream runs it. It used to run there only because the old literal PLATFORMS matched :darwin on every machine (#837). Two defects cancelled each other, and #961 removing one of them is what made this one measurable. #961's re-recorded BASELINE absorbed the file's −1 for that reason, so expect the ratchet lane to report this file moving.

The gate has a witness on each side

conformance_guard_value_test.go, 10 rows, each platform-independent ("0.0" / "999" / RUBY_PLATFORM):

run against result
the old helper the 4 open rows go red (block value lost)
yield without if match the 4 shut rows go red (block value returned where mspec returns nil)
this helper green; the no-block form is asserted unchanged

A helper that returned the block's value unconditionally would also turn birthtime_spec green, and would add :linux on a Ruby where the corpus says not to. Only the shut rows tell the two fixes apart.

Measured

The corpus uses a guard-with-block as a value in exactly two places in language/ + core/:

  • core/file/stat/birthtime_spec.rb:4: the value is splatted, which is this defect
  • core/tracepoint/inspect_spec.rb:70: statement form, the value is discarded

cmd/shimdelta on darwin over both, same binary, only the shim changed: 0 gained, 0 lost, 0 unmeasured. That was the prediction, since :darwin is in that list either way. The ubuntu effect is for the ratchet lane to report.

Rebased onto main after #961 was squash-merged; the change itself is unchanged.

Citations

The 19-line comment moved three citations; they are updated to measured values: two in the conformance README (gated) and one in the root README (not gated, #960). Nine more citations into this file live in cmd/specdelta's Go source. On main they are already off by a uniform +48. That drift predates this PR (they were written 2026-11-02 and never touched since). It is recorded on #960 rather than fixed by hand here, because hand-fixed values would hold only until the next insertion; the remedy is the gate that issue asks for.

Closes #962
Refs #837, #960, #961

🤖 Generated with Claude Code

…962)

mspec's SpecGuard#run_if is `yield if yield?(false)` (guard.rb:80), so
with a block the guard's value is the block's value when it holds and nil
when it does not. The shim's `_guard_run` ended in a hardcoded `nil`, so
the open case returned nothing too.

It is the same defect the comment above `_guard_run` already records
fixing for the NO-block form, one form over: a guard used as an
expression contributed nothing.

Where it cost: core/file/stat/birthtime_spec.rb:3-5 splats exactly that
value into a platform list,

    platform_is(:windows, :darwin, :freebsd, :netbsd,
                *ruby_version_is("4.0") { :linux },
               ) do

so `*nil` added nothing and the file was guarded for a list that never
contained :linux -- skipped on the gate's own ubuntu runner, at a version
where upstream runs it. It ran there only because the old literal
PLATFORMS matched :darwin on every machine (#837): two defects
cancelling, and #961 removing one is what made this one measurable.

THE GATE, conformance_guard_value_test.go, has a witness on each side,
because one side alone is a weaker rule that also passes:

  against the old helper     the 4 OPEN rows go red (block value lost)
  against `yield` with no    the 4 SHUT rows go red (block value returned
    `if match`                  where mspec returns nil)

A helper returning the block's value unconditionally would ALSO turn
birthtime_spec green, and would add :linux on a Ruby where the corpus
says not to; only the shut rows tell the two fixes apart. Every row is
platform-independent ("0.0" / "999" / RUBY_PLATFORM), and the no-block
form is asserted unchanged.

MEASURED. The corpus uses a guard with a block as a value in exactly two
places in language/ + core/:

  core/file/stat/birthtime_spec.rb:4    value splatted -- THIS defect
  core/tracepoint/inspect_spec.rb:70    statement form, value discarded

cmd/shimdelta on darwin over both, same binary, only the shim changed:
0 gained, 0 lost, 0 unmeasured -- as predicted, since :darwin is in that
list either way. The ubuntu effect is the ratchet lane's to report.

Citations moved by the 19-line comment, with measured values: two in the
conformance README (gated) and one in the root README (not gated, #960).
Nine more citations into this file live in cmd/specdelta's Go source,
and on main they are ALREADY wrong by a uniform +48 -- pre-existing,
written 2026-11-02 and never touched since. Recorded on #960 rather than
hand-fixed here: they would be right until the next insertion, and the
remedy is the gate that issue asks for.

Refs #962, #837, #960

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@tannevaled

Copy link
Copy Markdown
Contributor Author

Ratchet: the red was noise at identical code; the effect is birthtime +1

Same SHA 868e42e, run 44816548538, two attempts:

file baseline attempt 1 attempt 2
core/file/stat/birthtime_spec.rb 0 1 1
core/kernel/require_spec.rb 69 68 (REGRESSED → red) 69
core/random/bytes_spec.rb 8 8 9
  • birthtime_spec +1 in both attempts. That is this PR's effect, predicted in its body: :linux now reaches the platform list on the ubuntu runner.
  • require_spec moved 69 → 68 → 69 without any code change, so the shim cannot be the cause. As a second control, cmd/shimdelta on darwin, with the same binary run under main's shim and under this one, gives 0 gained / 0 lost for both files. And none of the 8 guard sites in require_spec.rb / shared/require.rb uses a guard's value, which is the only thing this change alters.
  • The rerun painted the run green, so attempt 1 is the only record of the require_spec flake. Counting red runs would never find it.

Not locked into BASELINE, on purpose. There is no floor mechanism: bytes_spec's 8 is a floor set by hand. A re-record on this attempt would write 9 and turn that file's known variance into future reds. It would also move the total to 24,107, which re-reddens the figure gates of the README, the docs and the landing for a single example. Better to fold the +1 into the next re-record, together with whatever else that one gains.

🤖 Generated with Claude Code

@tannevaled
tannevaled merged commit d244fd0 into main Nov 21, 2026
26 of 27 checks passed
@tannevaled
tannevaled deleted the guard-run-returns-block-value branch November 21, 2026 06:24
tannevaled added a commit that referenced this pull request Nov 21, 2026
…); sum unchanged (#967)

core/kernel/require_spec.rb read 68 in 2 of 4 ratchet attempts since
BASELINE recorded 69, at code that cannot affect it:

  #965  868e42e  attempt 1  68  red
  #965  868e42e  attempt 2  69  green     <- same SHA, both values
  #966  d66943c  attempt 1  69  green
  #966  6f88f65  attempt 1  68  red       <- a test-only change

Pinned to its floor, as #885 pinned core/random/bytes_spec.rb -- the
remedy #887 describes for a file with no honest single row. Which example
flips is not measured: the ratchet keeps a count per file (#887).

core/file/stat/birthtime_spec.rb 0 -> 1: what #965 made it on the gate's
runner, read 1 in all 3 attempts whose logs were read. The 0 was
absorbed for #961; leaving it unbanked meant a regression to 0 would pass.

The two moves cancel: the sum stays 24106, so the figure gates of the
README, docs and landing are untouched. The header records both edits.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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.

conformance shim: _guard_run returns nil where mspec returns the block's value, so a guard used as an expression contributes nothing

1 participant