Repository navigation
File times keep nanoseconds; Process.clock_gettime refuses unknown clocks - #994
Open
tannevaled wants to merge 3 commits into
Open
tannevaled wants to merge 3 commits into
tannevaled wants to merge 3 commits into
Conversation
tannevaled
force-pushed
the
stat-time-precision
branch
from
November 29, 2026 17:36
4304266 to
e1a9d0c
Compare
File::Stat, File.mtime/atime/ctime/birthtime and the new File#mtime & co. carry the stat struct's nanoseconds in the local zone, as MRI's stat_time does; File.atime and File.ctime read st_atime/st_ctime instead of answering the modification time; File.birthtime works where the stat struct has a creation time; each singleton names its own C function in ENOENT and declares arity 1. File.utime and File.lutime write the nanoseconds too: their carrier was int64 seconds. Process.clock_gettime and clock_getres follow process.c v4.0.10: the platform's CLOCK_* constants with the host's clockid_t values (darwin and linux), the real clock_gettime(2) for every id, Errno::EINVAL naming the id for one the host does not have (it used to answer the wall clock), MRI's symbolic emulations with their resolutions, NUM2UINT/NUM2INT range errors, and "unexpected unit". floatToLong is shared with Math.ldexp. Closes #705 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The ubuntu coverage ratchet failed on two functions. Fixing them showed
three divergences from MRI 4.0.10, measured with rubydiff:
- file.c utime_args_init leaves the timespec NULL ("now") only when BOTH
times are nil; otherwise each goes through rb_time_timespec, atime
first. rbgo read each nil as "now" on its own, so File.utime(nil, 5, f)
succeeded where MRI raises "can't convert NilClass into time".
- time.c time_timespec names the argument's class: "can't convert String
into time". rbgo said "no implicit conversion of \"x\" into Time".
- File.utime with fewer than two arguments reported a Go index panic
("utime: runtime error: index out of range") instead of
"wrong number of arguments (given 1, expected 2+)".
numFloat had a single caller, which already handled Integer first, so
its Integer case was dead (85.7% on linux). It is folded into utimeArg.
timeOf's recorded-birthtime branch runs only where the stat struct has
a creation time, never on linux; a stub stat now drives it everywhere.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The windows test lane failed TestProcessClockSymbolic with a nil pointer dereference: Process.clock_gettime(:CLOCK_BASED_CLOCK_PROCESS_ CPUTIME_ID), the one CPU-time emulation process.c compiles with no #ifdef guard, reads procRusage, and spawn_windows.go and spawn_wasm.go declared that seam without ever assigning it. Windows now reads GetProcessTimes, where MRI's win32 clock() and Process.times read the process's CPU time; a FILETIME duration counts 100 ns ticks. wasm has no getrusage and reports zero, as Plan 9 does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
tannevaled
force-pushed
the
stat-time-precision
branch
from
November 30, 2026 20:21
e1a9d0c to
556f8b5
Compare
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.
Closes #705.
What was wrong (measured on main against MRI 4.0.10, arm64-darwin)
File.stat(f).mtime.nsec0(int64-seconds carrier)File.atime(f)/File.ctime(f)File.birthtime(f)on darwinFile#mtime/#atime/#ctime/#birthtimeFile.method(:mtime).arity1-1File.utime(Time.at(1, 5, :nsec), …)then.nsec50Process::CLOCK_PROCESS_CPUTIME_ID& 3 more12,16,4,8Process.clock_gettime(999)Errno::EINVAL … clock_gettime(999)Process.clock_gettime(:GETTIMEOFDAY_BASED_CLOCK_REALTIME)Process.clock_getres(Process::CLOCK_MONOTONIC_RAW, :nanosecond)421000Process.clock_gettime(0, :foo)ArgumentError: unexpected unit: fooProcess.clock_gettime(2**40)RangeError … to 'unsigned int'File.utime(nil, 5, f)TypeError: can't convert NilClass into timeFile.utime("x", nil, f)TypeError: can't convert String into timeno implicit conversion of "x" into TimeFile.utime(1)ArgumentError: wrong number of arguments (given 1, expected 2+)ArgumentError: utime: runtime error: index out of range [1]The third row of #705 (
clock_gettime(999)) is the one the issue ranks first: an instrument that answers a plausible number instead of failing.The change
filestat.go: the timestamps aretime.TimewithNsec, rendered in the local zone (stat_time→rb_time_nano_new). OnetimeOfservesFile::Stat#…,File.…and the newFile#…(IOError "closed stream" when closed).file.go:File.mtime/atime/ctime/birthtimeread the stat (rb_file_s_<name>in ENOENT, arity 1).File.utime/lutimetake atime.Timethrough the seam on every platform (unix, plan9, windows, wasm).process_clock.go:rb_clock_gettime/rb_clock_getres/make_clock_result/clock_failed, read from process.c at v4.0.10. The platform half is inprocess_clock_{darwin,linux,other}.go: constants fromgolang.org/x/sys/unixinInitVM_processorder,NUM2CLOCKID's C type (darwinunsigned int, measured; linuxint), and darwin'sclock_getrestable (x/sys does not wrap it there, so it was measured on MRI). CLOCK_REALTIME and CLOCK_MONOTONIC still read through theprocessMonoNowseam the tests and Benchmark rely on.math.go:floatToLong(rb_num2long's Float stage) is extracted frommathFloatToIntand shared.File.utime/lutimefollowutime_args_init: only a nil pair means "now". Otherwise both go throughrb_time_timespec, atime first, andtime_timespec's message names the class.numFloat, whose Integer case had become dead, is folded intoutimeArg.The first CI run failed on the ubuntu coverage ratchet:
numFloat(that dead case) andtimeOf(the recorded-birthtime branch, which a Linux stat never takes). A stub stat with a creation time now drives that branch on every host.Measured
Filetimes, constants, symbolic clocks, utime nanoseconds, conversion edges) agree with MRI 4.0.10 byte for byte throughrubydiff.gotest -run 'Process|File|Time|Stat|Clock|Utime|Lutime|Bench' ./internal/vm/: 313 tests pass.mutsweep -sites alloverprocess_clock.goandprocess_clock_darwin.go: 18 mutations, 18 caught. The first sweep left 2 survivors, the float-range and darwin id-range guards. They were rewritten to MRI's measured NUM2UINT/NUM2INT messages and are now caught.Tests changed, and why
TestFileLevelPredicatesassertedFile.birthtime(existing)raises NotImplementedError. On darwin MRI 4.0.10 answers a Time. It now asserts thatFile.birthtimeagrees withFile::Stat#birthtimeon the host.TestProcessStdlibassertedCLOCK_MONOTONIC == 6, the darwin value. On Linux the host's id is 1.TestProcessResidualsasserted 1000 ns for the numeric clocks. Linux'sclock_getressays 1 ns, so the portable bound is asserted instead. The Float#inspect witness moved to a symbolic clock.Not done here
File.birthtimeuses statx. rbgo readssyscall.Stat_t, which has no birth time, so it still raises NotImplementedError there. That is a separate defect.🤖 Generated with Claude Code