Skip to content

conformance: one source for what platform this is, and sizes in bits - #961

Open
tannevaled wants to merge 1 commit into
mainfrom
shim-platform-single-source
Open

tannevaled wants to merge 1 commit into
mainfrom
shim-platform-single-source

Conversation

@tannevaled

Copy link
Copy Markdown
Contributor

The shim had two sources for what platform this is

PLATFORMS = [:darwin, :bsd, :unix]   # a literal
class PlatformGuard
  PLATFORM = RUBY_PLATFORM           # derived

…under a comment saying the literal was the single source of truth. On darwin
the two agree, so the split is invisible from the machine the work is done
on
. On the ubuntu lane that enforces the gate, platform_is :linux was false
while PlatformGuard.os?(:linux) was true.

The fix is not to derive the list. mspec has no list — read at the tip of
ruby/mspec, lib/mspec/guards/platform.rb:26-38: every name but :windows
and :wsl is a plain substring of RUBY_PLATFORM. So platform_is and
platform_is_not now call PlatformGuard, PLATFORMS is gone, and nothing is
typed twice.

Three defects the issue did not name

Found by reading the reference rather than the issue.

:pointer_size compared against WORDSIZE / 8 bytes against a value the corpus writes in bits (platform.rb:61-66 is SIZEOF * 8). Both the 64 and the 32 branch of every such guard were false, on every machine. Nothing looked wrong, because a shut guard is what a guard does.
platform_is_not rebuilt its own negation by OR-ing the parts mspec is run_unless over the same match? (:116-122). The two differ as soon as a site carries a name AND an option.
the os: option was not read at all

Measured, not argued

Same binary, same corpus, only the shim changed — cmd/shimdelta on darwin:

  +188   core/array/pack/j_spec.rb     (0 -> 188)
  +216   core/string/unpack/j_spec.rb  (0 -> 216)

Both were recorded as 0 in BASELINE, which is what a file contributing
nothing looks like from the outside. Their entire contents sit behind
platform_is pointer_size: 64.

And in the other direction, which is why the two are never summed:
core/file/sticky_spec.rb went pass=4 fail=1 → pass=4 fail=0. The literal's
:bsd matched no RUBY_PLATFORM this project runs on, so a BSD-only
expectation was being asserted on a mac.

Static census over the pinned corpus — 2206 files, which is the gate's own
count, and 420 guard sites, 3 of which the reader refuses rather than
guesses at because they do not close on their line:

machine skipped but should run ran but should not
x86_64-linux 20 guards, ≥29 examples, 19 files 11 guards, ≥11 examples, 10 files
arm64-darwin 2 guards, 2 files 1 guard, ≥1 example, 1 file

Two instruments, because neither axis existed

  • cmd/platguard reads the corpus and says which guards the two answers
    disagree about, for a named machine. It has to be named: the defect is
    invisible on darwin, so a tool that could only answer about its own host would
    have reported a clean corpus from here.
  • cmd/shimdelta runs one interpreter over the same files under two
    spec_helper.rb. cmd/specdelta compares two engines through one shim,
    which is the wrong axis when the engine is fixed and the shim decides which
    examples exist. It refuses two byte-identical shims, counts a missing tally as
    DIDNOTRUN and never as zero, and prints the two directions on separate lines.

The gate

conformance_platform_guard_test.go, and every assertion in it is
platform-independent
: it asserts that the two sources agree, not what they
answer, plus three facts true of every machine. This test runs on ubuntu, macos
and windows; one that spelled out an expected answer would be asserting which
runner it is on.

Verified the way a gate has to be — run against main's shim, where it goes red
six times on darwin alone: :bsd, :unix, the pointer_size pair, the
shut-both-ways absolute, the negation, and the full triple. A second test
refuses a PLATFORMS literal in code at all, because a list that happened to
agree with RUBY_PLATFORM on the runner would satisfy every runtime assertion
while putting the second source back for every other machine.

The census table was checked the same way: reintroducing the bits/bytes
comparison in Go turns two rows red.

Issues

Not done here, on purpose

BASELINE is not regenerated in this commit. It is recorded where it is
enforced — the rubyspec-baseline dispatch on ubuntu-24.04 — and this change
moves the population on that machine in both directions. The ratchet lane on
this PR is the measurement, and the re-record follows it.

⛔ cmd/shimdelta measures passing examples and nothing else. A guard change
that removes a failure is invisible to it — sticky_spec.rb above is the
witness, and the limitation is stated in the command's own doc comment rather
than left to be discovered.

Refs #837, #960, #799, #843 — all four stay open: #837 until BASELINE is
re-recorded on the lane that enforces it, #960 until the citation gate is
widened to all six, and #799 and #843 are named here for context only.

🤖 Generated with Claude Code

The shim had TWO platform sources under a comment saying it had one:

    PLATFORMS = [:darwin, :bsd, :unix]   # a literal
    class PlatformGuard
      PLATFORM = RUBY_PLATFORM           # derived

On darwin they agree, so the split is invisible from the machine the work
is done on. On the ubuntu lane that enforces the gate, `platform_is
:linux` was false while `PlatformGuard.os?(:linux)` was true.

mspec has no list either (ruby/mspec lib/mspec/guards/platform.rb:26-38,
read at the tip): every name but :windows and :wsl is a plain substring
of RUBY_PLATFORM. So platform_is / platform_is_not now call
PlatformGuard, PLATFORMS is gone, and nothing is typed twice.

Three defects the issue did not name, found by reading the reference
rather than the issue:

1. :pointer_size was compared against WORDSIZE / 8 — BYTES against a
   value the corpus writes in BITS (platform.rb:61-66 is SIZEOF * 8).
   So `pointer_size: 64` AND `pointer_size: 32` were both false, on
   every machine, and every guard written that way was shut. Nothing
   looked wrong, because a shut guard is what a guard does.

2. platform_is_not rebuilt its own negation by OR-ing the parts. mspec
   is run_unless over the SAME match? platform_is runs on (:116-122),
   and the two differ as soon as a site carries a name AND an option.

3. The `os:` option was not read at all.

MEASURED, same binary, same corpus, only the shim changed (cmd/shimdelta
on darwin):

    +188   core/array/pack/j_spec.rb     (0 -> 188)
    +216   core/string/unpack/j_spec.rb  (0 -> 216)

Both were recorded as 0 in BASELINE — what a file contributing nothing
looks like from the outside. Their whole contents sit behind
`platform_is pointer_size: 64`.

And in the other direction, which is why the two are never summed:
core/file/sticky_spec.rb went pass=4 fail=1 -> pass=4 fail=0. The
literal's :bsd matched no RUBY_PLATFORM this project runs on, so a
BSD-only expectation was being asserted on a mac.

The static census, over the pinned corpus (2206 files — the gate's own
count — and 420 guard sites, 3 of which the reader REFUSES rather than
guesses at, because they do not close on their line):

    x86_64-linux   skipped but should run  20 guards >=29 ex  19 files
                   ran but should not      11 guards >=11 ex  10 files
    arm64-darwin   skipped but should run   2 guards           2 files
                   ran but should not       1 guard  >=1 ex    1 file

Two instruments, because neither axis existed:

  cmd/platguard   reads the corpus and says which guards the two answers
                  disagree about, for a NAMED machine. It has to be
                  named: the defect is invisible on darwin, so a tool
                  that could only answer about its own host would have
                  reported a clean corpus from here.

  cmd/shimdelta   runs ONE interpreter over the same files under two
                  spec_helper.rb. cmd/specdelta compares two engines
                  through one shim, which is the wrong axis when the
                  engine is fixed and the shim decides which examples
                  exist. It refuses two byte-identical shims, counts a
                  missing tally as DIDNOTRUN and never as zero, and
                  prints the two directions on separate lines.

THE GATE is conformance_platform_guard_test.go, and every assertion in
it is platform-independent: it asserts that the two sources AGREE, not
what they answer, plus three facts true of every machine. Verified by
running it against main's shim, where it goes red six times on darwin
alone — :bsd, :unix, the pointer_size pair, the shut-both-ways
absolute, the negation, and the full triple.

A second test refuses a PLATFORMS literal in code at all, because a list
that happened to agree with RUBY_PLATFORM on the runner would satisfy
every runtime assertion while putting the second source back for every
other machine.

Also corrected: the four README citations my own insertion moved, with
MEASURED values, not computed ones. Three of them are outside the gate
that checks such citations (#960).

NOT DONE HERE: BASELINE. It is recorded where it is enforced, through
the rubyspec-baseline dispatch on ubuntu, and this change moves the
population on that machine in both directions. The ratchet lane on this
PR is the measurement.

Refs #837, #960

Co-Authored-By: Claude Opus 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.

1 participant