Repository navigation
Pathname#empty? asks the filesystem, so an empty file is true and the empty path is false (fixes #91) - #159
Open
jiro-by-nori[bot] wants to merge 1 commit into
Open
jiro-by-nori[bot] wants to merge 1 commit into
jiro-by-nori[bot] wants to merge 1 commit into
Conversation
…he empty path is false (fixes #91) The prelude answered `Pathname#empty?` as `@path.empty?`, a question about the path String. CRuby 4.0 asks the file: FileTest.directory?(@path) ? Dir.empty?(@path) : File.empty?(@path) So the model inverted two shapes: after `File.write(path, "")` it answered `false` where CRuby answers `true`, and `Pathname.new("").empty?` answered `true` where CRuby answers `false` (no such file is `File.zero?`'s `false`, not an error). A non-empty file happened to agree, which is why this went unnoticed. The method is now defined over the step-1 VFS builtins: a path that does not exist is `false`, and a regular file is `File.size(path).zero?`. Directory emptiness is `Dir.empty?`, which the model does not have (VFS step 3), so that shape gates by name - `Pathname#empty?: directory emptiness needs Dir.empty?` - instead of reporting the path's own non-emptiness. The class comment is updated: `empty?` is the one Pathname operation that is not a path-string question. Validated: `make check` (ALL CHECKS PASSED) - conformance ran 1287 programs against CRuby 4.0.5 with agree 1087, sut_unsupported 194, not_compared 6, disagree 0, holding the recorded baseline, and the regressions and tier-3 tiers agree; `make check-not-weakened` (CHECKS NOT WEAKENED). New `difftest/tests/test_pathname_empty.py` (12 cases) pins the three shapes, and fails 5 of them on the previous prelude: the two emptied-file answers, the empty path, and the two directory gates. Its CRuby expectations were taken from CRuby 4.0.5 over a real file tree with the same shapes. Co-authored-by: Jiro <jiro@nori.ai>
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.
What this fixes
Pathname#empty?was@path.empty?in the prelude — a question about the path String. CRuby 4.0 asks the file:So the model inverted two shapes, and answered a wrong value rather than gating:
/tmp/readme.txt="hello\n")File.write("/tmp/readme.txt", ""); Pathname.new("/tmp/readme.txt").empty?falsetruePathname.new("").empty?truefalsePathname.new("/tmp/no-such-path").empty?falsefalsePathname.new("/tmp/readme.txt").empty?falsefalseThe non-empty-file case agrees, which is why the defect went unnoticed.
no such fileisfalse(that isFile.zero?'s answer, not an error), so a missing path is not a gate either.The change
ruby-lean/prelude/prelude.rb,class Pathname:false, as CRuby'sFile.empty?answers.File.size(path).zero?, so an empty file istrue.Dir.empty?, which the model does not have (VFS step 3, issue Proposal: virtual filesystem with symbolic and dynamic modes for the Ruby semantics #7), so it gates by name rather than approximating with the directory's own non-emptiness. This is the option issue Pathname#empty? answers String#empty? instead of asking the filesystem, so it is a wrong answer #91 asks for.Pathnameclass comment now saysempty?is the one operation that is not a path-string question.No other Pathname operation changed:
to_s,basename,dirname,extname,sub,==,inspectare untouched, and themethod_missingguard is unchanged.Tests
New
difftest/tests/test_pathname_empty.py(runs undermake difftest-test, 12 cases):/tmp/vfsdata/nums.txt(boot content"1\n2\n3\n") emptied byFile.writearetrue; a file with content, the empty path, a missing path and a trailing slash on a regular file arefalse. Every expected value was taken from CRuby 4.0.5 run over a real file tree with the same shapes (empty file,missing,"",file/,nonempty dir,empty dir).Pathname.new("/tmp").empty?andPathname.new("/tmp/vfsdata").empty?decline, and the reason names bothPathname#empty?andDir.empty?.to_s,basename.to_sand the empty path'sto_sstill answer.On the previous prelude (
git stashthe prelude, rebuild, rerun) 5 of the 12 fail: both emptied-file answers, the empty path, and both directory gates. So the suite pins the defect, not just the fix.How I validated it
Run locally on the branch, cold toolchain (Lean
v4.32.2, CRuby4.0.5):make lean— model builds from the regenerated prelude.make conformance— CRuby4.0.5over the 1287-program bootstraptest corpus:ran 1287, agree 1087, sut_unsupported 194, not_compared 6, disagree 0, exactly the recorded baseline; theregressionsandtier3tiers agree.make difftest-test— 213 passed (201 before; +12 here); coverage still holds its baseline (line 73.19 / branch 68.61), so no baseline file moved.make books,make metatheory,make soundness,make comparator,make desugar-test,make desugar-coverage,make feature-loading,make book-checks,make gen-check(regeneratedPrelude.lean/PreludeJson.leanare fresh),make lint,make docs— all green undermake check.No recorded result fell; no check, theorem, test skip or lint suppression was added.
Provenance
Authored by Jiro, an autonomous agent, including this description.
Closes #91