-
Notifications
You must be signed in to change notification settings - Fork 423
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Revamp file reading and writing #4906
Conversation
Mathlib CI status (docs):
|
tests/lean/3546.lean
Outdated
IO.println cond | ||
IO.FS.removeFile tmpFile | ||
|
||
#eval test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could use #guard_msgs
, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might as well move this to tests/run
now?
!bench |
Here are the benchmark results for commit aaff432. Benchmark Metric Change
======================================================
+ lake build clean task-clock -1.2% (-16.7 σ)
+ stdlib tactic execution -1.5% (-19.1 σ)
+ stdlib wall-clock -1.6% (-31.0 σ) |
!bench |
Here are the benchmark results for commit 1be6f69. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
tests/lean/3546.lean
Outdated
IO.println cond | ||
IO.FS.removeFile tmpFile | ||
|
||
#eval test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might as well move this to tests/run
now?
|
||
def readFile (fname : FilePath) : IO String := do | ||
let data ← readBinFile fname | ||
match String.fromUTF8? data with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this make a copy of the data?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, unfortunately the runtime representation of ByteArray
has the data part inlined instead of as a pointer and the layout of the ByteArray
and String
object are not compatible :/.
Of course windows doesn't have getline and this breaks everything /o\ |
This PR:
readBinFile
andreadFile
to only require two system calls (stat
+read
) instead of oneread
per 1024 byte chunk.Handle.getLine
would get tripped up by a NUL character in the line and cut the string off. This is caused by the fact that the original implementation usesstrlen
andlean_mk_string
which is the backer ofmk_string
does so as well.Handle.putStr
and thus by extensionwriteFile
would get tripped up by a NUL char in the line and cut the string off. Cause here is the use offputs
when a NUL char is possible.Closes: #4891
Closes: #3546
Closes: #3741