Like https://hackage.haskell.org/package/ghc-Prim-0.5.2.0/docs/GHC-Prim.html#t:RealWorld.
Makes sure we never reorder IO
operations.
TODO: mark opaque
Equations
Instances For
Equations
- instMonadEIO = inferInstanceAs (Monad (EStateM ε IO.RealWorld))
Equations
- instMonadFinallyEIO = inferInstanceAs (MonadFinally (EStateM ε IO.RealWorld))
Equations
- instMonadExceptOfEIO = inferInstanceAs (MonadExceptOf ε (EStateM ε IO.RealWorld))
Equations
- instInhabitedEIO = inferInstanceAs (Inhabited (EStateM ε IO.RealWorld α))
Equations
Equations
Equations
- act.toEIO s = match act s with | EStateM.Result.ok a s => EStateM.Result.ok a s
Instances For
Equations
- act.toBaseIO s = match act s with | EStateM.Result.ok a s => EStateM.Result.ok (Except.ok a) s | EStateM.Result.error ex s => EStateM.Result.ok (Except.error ex) s
Instances For
Equations
- act.catchExceptions h s = match act s with | EStateM.Result.ok a s => EStateM.Result.ok a s | EStateM.Result.error ex s => h ex s
Instances For
Equations
- unsafeBaseIO fn = match EStateM.run fn () with | EStateM.Result.ok a a_1 => a
Instances For
Programs can execute IO actions during initialization that occurs before
the main
function is executed. The attribute [init <action>]
specifies
which IO action is executed to set the value of an opaque constant.
The action initializing
returns true
iff it is invoked during initialization.
Run act
in a separate Task
.
This is similar to Haskell's unsafeInterleaveIO
,
except that the Task
is started eagerly as usual. Thus pure accesses to the Task
do not influence the impure act
computation.
Unlike with pure tasks created by Task.spawn
, tasks created by this function will be run even if the last reference
to the task is dropped. The act
should manually check for cancellation via IO.checkCanceled
if it wants to react
to that.
See BaseIO.asTask
.
See BaseIO.asTask
.
Equations
- BaseIO.mapTasks f tasks prio sync = BaseIO.mapTasks.go f prio sync tasks []
Instances For
Equations
- BaseIO.mapTasks.go f prio sync (t :: ts) x✝ = BaseIO.bindTask t (fun (a : α) => BaseIO.mapTasks.go f prio sync ts (a :: x✝)) prio sync
- BaseIO.mapTasks.go f prio sync [] x✝ = (f x✝.reverse).asTask prio
Instances For
EIO
specialization of BaseIO.asTask
.
Equations
- act.asTask prio = act.toBaseIO.asTask prio
Instances For
EIO
specialization of BaseIO.mapTask
.
Equations
- EIO.mapTask f t prio sync = BaseIO.mapTask (fun (a : α) => (f a).toBaseIO) t prio sync
Instances For
EIO
specialization of BaseIO.bindTask
.
Equations
- EIO.bindTask t f prio sync = BaseIO.bindTask t (fun (a : α) => (f a).catchExceptions fun (e : ε) => pure { get := Except.error e }) prio sync
Instances For
EIO
specialization of BaseIO.mapTasks
.
Equations
- EIO.mapTasks f tasks prio sync = BaseIO.mapTasks (fun (as : List α) => (f as).toBaseIO) tasks prio sync
Instances For
Equations
- IO.ofExcept (Except.ok a) = pure a
- IO.ofExcept (Except.error e_2) = throw (IO.userError (toString e_2))
Instances For
Equations
- IO.lazyPure fn = pure (fn ())
Instances For
Monotonically increasing time since an unspecified past point in milliseconds. No relation to wall clock time.
Monotonically increasing time since an unspecified past point in nanoseconds. No relation to wall clock time.
Read bytes from a system entropy source. Not guaranteed to be cryptographically secure.
If nBytes = 0
, return immediately with an empty buffer.
IO
specialization of EIO.asTask
.
Equations
- act.asTask prio = EIO.asTask act prio
Instances For
IO
specialization of EIO.mapTask
.
Equations
- IO.mapTask f t prio sync = EIO.mapTask f t prio sync
Instances For
IO
specialization of EIO.bindTask
.
Equations
- IO.bindTask t f prio sync = EIO.bindTask t f prio sync
Instances For
IO
specialization of EIO.mapTasks
.
Equations
- IO.mapTasks f tasks prio sync = EIO.mapTasks f tasks prio sync
Instances For
Check if the task's cancellation flag has been set by calling IO.cancel
or dropping the last reference to the task.
The current state of a Task
in the Lean runtime's task manager.
- waiting : IO.TaskState
The
Task
is waiting to be run. It can be waiting for dependencies to complete or sitting in the task manager queue waiting for a thread to run on. - running : IO.TaskState
The
Task
is actively running on a thread or, in the case of aPromise
, waiting for a call toIO.Promise.resolve
. - finished : IO.TaskState
Instances For
Equations
- IO.instInhabitedTaskState = { default := IO.TaskState.waiting }
Equations
- IO.instReprTaskState = { reprPrec := IO.reprTaskState✝ }
Equations
- IO.instDecidableEqTaskState x✝ y✝ = if h : x✝.toCtorIdx = y✝.toCtorIdx then isTrue ⋯ else isFalse ⋯
Equations
- IO.instOrdTaskState = { compare := IO.ordTaskState✝ }
Equations
- IO.TaskState.waiting.toString = "waiting"
- IO.TaskState.running.toString = "running"
- IO.TaskState.finished.toString = "finished"
Instances For
Equations
- IO.instToStringTaskState = { toString := IO.TaskState.toString }
Returns current state of the Task
in the Lean runtime's task manager.
Check if the task has finished execution, at which point calling Task.get
will return immediately.
Equations
- IO.hasFinished task = do let __do_lift ← IO.getTaskState task pure (match __do_lift with | IO.TaskState.finished => true | x => false)
Instances For
Helper method for implementing "deterministic" timeouts. It is the number of "small" memory allocations performed by the current execution thread.
Adjusts the heartbeat counter of the current thread by the given amount. This can be useful to give allocation-avoiding code additional "weight" and is also used to adjust the counter after resuming from a snapshot.
The mode of a file handle (i.e., a set of open
flags and an fdopen
mode).
All modes do not translate line endings (i.e., O_BINARY
on Windows) and
are not inherited across process creation (i.e., O_NOINHERIT
on Windows,
O_CLOEXEC
elsewhere).
References:
- read : IO.FS.Mode
File opened for reading. On open, the stream is positioned at the beginning of the file. Errors if the file does not exist.
open
flags:O_RDONLY
fdopen
mode:r
- write : IO.FS.Mode
File opened for writing. On open, truncate an existing file to zero length or create a new file. The stream is positioned at the beginning of the file.
open
flags:O_WRONLY | O_CREAT | O_TRUNC
fdopen
mode:w
- writeNew : IO.FS.Mode
New file opened for writing. On open, create a new file with the stream positioned at the start. Errors if the file already exists.
open
flags:O_WRONLY | O_CREAT | O_TRUNC | O_EXCL
fdopen
mode:w
- readWrite : IO.FS.Mode
File opened for reading and writing. On open, the stream is positioned at the beginning of the file. Errors if the file does not exist.
open
flags:O_RDWR
fdopen
mode:r+
- append : IO.FS.Mode
File opened for writing. On open, create a new file if it does not exist. The stream is positioned at the end of the file.
open
flags:O_WRONLY | O_CREAT | O_APPEND
fdopen
mode:a
Instances For
A pure-Lean abstraction of POSIX streams. We use Stream
s for the standard streams stdin/stdout/stderr so we can
capture output of #eval
commands into memory.
Read up to the given number of bytes from the stream. If the returned array is empty, an end-of-file marker has been reached. Note that EOF does not actually close a stream, so further reads may block and return more data.
Read text up to (including) the next line break from the stream. If the returned string is empty, an end-of-file marker has been reached. Note that EOF does not actually close a stream, so further reads may block and return more data.
Returns true if a stream refers to a Windows console or Unix terminal.
Instances For
Equations
- IO.FS.instInhabitedStream = { default := { flush := default, read := default, write := default, getLine := default, putStr := default, isTty := default } }
Replaces the stdin stream of the current thread and returns its previous value.
Replaces the stdout stream of the current thread and returns its previous value.
Replaces the stderr stream of the current thread and returns its previous value.
Acquires an exclusive or shared lock on the handle. Will block to wait for the lock if necessary.
NOTE: Acquiring a exclusive lock while already possessing a shared lock will NOT reliably succeed (i.e., it works on Unix but not on Windows).
Tries to acquire an exclusive or shared lock on the handle.
Will NOT block for the lock, but instead return false
.
NOTE: Acquiring a exclusive lock while already possessing a shared lock will NOT reliably succeed (i.e., it works on Unix but not on Windows).
Releases any previously acquired lock on the handle. Will succeed even if no lock has been acquired.
Returns true if a handle refers to a Windows console or Unix terminal.
Rewinds the read/write cursor to the beginning of the handle.
Truncates the handle to the read/write cursor.
Does not automatically flush. Usually this is fine because the read/write
cursor includes buffered writes. However, the combination of buffered writes,
then rewind
, then truncate
, then close may lead to a file with content.
If unsure, flush before truncating.
Read up to the given number of bytes from the handle. If the returned array is empty, an end-of-file marker has been reached. Note that EOF does not actually close a handle, so further reads may block and return more data.
Read text up to (including) the next line break from the handle. If the returned string is empty, an end-of-file marker has been reached. Note that EOF does not actually close a handle, so further reads may block and return more data.
Resolves a pathname to an absolute pathname with no '.', '..', or symbolic links.
This function coincides with the POSIX realpath
function,
see there for more information.
Remove given directory. Fails if not empty; see also IO.FS.removeDirAll
.
Moves a file or directory old
to the new location new
.
This function coincides with the POSIX rename
function,
see there for more information.
Creates a temporary file in the most secure manner possible. There are no race conditions in the
file’s creation. The file is readable and writable only by the creating user ID. Additionally
on UNIX style platforms the file is executable by nobody. The function returns both a Handle
to the already opened file as well as its FilePath
.
Note that it is the caller's job to remove the file after use.
Creates a temporary directory in the most secure manner possible. There are no race conditions in the directory’s creation. The directory is readable and writable only by the creating user ID.
Returns the new directory's path.
It is the caller's job to remove the directory after use.
Equations
- IO.FS.withFile fn mode f = IO.FS.Handle.mk fn mode >>= f
Instances For
Equations
- h.putStrLn s = h.putStr (s.push '\n')
Instances For
Equations
- h.readBinToEndInto buf = IO.FS.Handle.readBinToEndInto.loop h buf
Instances For
Equations
- h.readBinToEnd = h.readBinToEndInto ByteArray.empty
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- IO.FS.lines fname = do let h ← IO.FS.Handle.mk fname IO.FS.Mode.read IO.FS.lines.read h #[]
Instances For
Equations
- IO.FS.writeBinFile fname content = do let h ← IO.FS.Handle.mk fname IO.FS.Mode.write h.write content
Instances For
Equations
- IO.FS.writeFile fname content = do let h ← IO.FS.Handle.mk fname IO.FS.Mode.write h.putStr content
Instances For
Equations
- strm.putStrLn s = strm.putStr (s.push '\n')
Instances For
Equations
- IO.FS.instReprDirEntry = { reprPrec := IO.FS.reprDirEntry✝ }
Instances For
- dir : IO.FS.FileType
- file : IO.FS.FileType
- symlink : IO.FS.FileType
- other : IO.FS.FileType
Instances For
Equations
- IO.FS.instReprFileType = { reprPrec := IO.FS.reprFileType✝ }
Equations
- IO.FS.instBEqFileType = { beq := IO.FS.beqFileType✝ }
Equations
- IO.FS.instReprSystemTime = { reprPrec := IO.FS.reprSystemTime✝ }
Equations
- IO.FS.instBEqSystemTime = { beq := IO.FS.beqSystemTime✝ }
Equations
- IO.FS.instOrdSystemTime = { compare := IO.FS.ordSystemTime✝ }
Equations
- IO.FS.instInhabitedSystemTime = { default := { sec := default, nsec := default } }
- accessed : IO.FS.SystemTime
- modified : IO.FS.SystemTime
- byteSize : UInt64
- type : IO.FS.FileType
Instances For
Equations
- IO.FS.instReprMetadata = { reprPrec := IO.FS.reprMetadata✝ }
Equations
- p.isDir = do let __do_lift ← EIO.toBaseIO p.metadata match __do_lift with | Except.ok m => pure (m.type == IO.FS.FileType.dir) | Except.error a => pure false
Instances For
Equations
- p.pathExists = do let __do_lift ← EIO.toBaseIO p.metadata pure __do_lift.toBool
Instances For
Return all filesystem entries of a preorder traversal of all directories satisfying enter
, starting at p
.
Symbolic links are visited as well by default.
Equations
- p.walkDir enter = Prod.snd <$> (System.FilePath.walkDir.go enter p).run #[]
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- IO.withStdin h x = do let prev ← liftM (IO.setStdin h) tryFinally x (discard (liftM (IO.setStdin prev)))
Instances For
Equations
- IO.withStdout h x = do let prev ← liftM (IO.setStdout h) tryFinally x (discard (liftM (IO.setStdout prev)))
Instances For
Equations
- IO.withStderr h x = do let prev ← liftM (IO.setStderr h) tryFinally x (discard (liftM (IO.setStderr prev)))
Instances For
Equations
- IO.println s = IO.print ((toString s).push '\n')
Instances For
Equations
- IO.eprintln s = IO.eprint ((toString s).push '\n')
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Create given path and all missing parents as directories.
Fully remove given directory by deleting all contained files and directories in an unspecified order. Fails if any contained entry cannot be deleted or was newly created during execution.
Like createTempFile
, but also takes care of removing the file after usage.
Equations
- IO.FS.withTempFile f = do let __discr ← liftM IO.FS.createTempFile match __discr with | (handle, path) => tryFinally (f handle path) (liftM (IO.FS.removeFile path))
Instances For
Like createTempDir
, but also takes care of removing the directory after usage.
All files in the directory are recursively deleted, regardless of how or when they were created.
Equations
- IO.FS.withTempDir f = do let path ← liftM IO.FS.createTempDir tryFinally (f path) (liftM (IO.FS.removeDirAll path))
Instances For
Returns the current working directory of the calling process.
Sets the current working directory of the calling process.
Returns the process ID of the calling process.
- piped : IO.Process.Stdio
- inherit : IO.Process.Stdio
- null : IO.Process.Stdio
Instances For
Equations
- IO.Process.Stdio.piped.toHandleType = IO.FS.Handle
- IO.Process.Stdio.inherit.toHandleType = Unit
- IO.Process.Stdio.null.toHandleType = Unit
Instances For
- stdin : IO.Process.Stdio
Configuration for the process' stdin handle.
- stdout : IO.Process.Stdio
Configuration for the process' stdout handle.
- stderr : IO.Process.Stdio
Configuration for the process' stderr handle.
Instances For
- cmd : String
Command name.
Arguments for the process
- cwd : Option System.FilePath
Working directory for the process. Inherit from current process if
none
. Add or remove environment variables for the process.
- setsid : Bool
Start process in new session and process group using
setsid
. Currently a no-op on non-POSIX platforms.
Instances For
- stdin : cfg.stdin.toHandleType
- stdout : cfg.stdout.toHandleType
- stderr : cfg.stderr.toHandleType
Instances For
Block until the child process has exited and return its exit code.
Check whether the child has exited yet. If it hasn't return none, otherwise its exit code.
Terminates the child process using the SIGTERM signal or a platform analogue.
If the process was started using SpawnArgs.setsid
, terminates the entire process group instead.
Extract the stdin
field from a Child
object, allowing them to be freed independently.
This operation is necessary for closing the child process' stdin while still holding on to a process handle,
e.g. for Child.wait
. A file handle is closed when all references to it are dropped, which without this
operation includes the Child
object.
Run process to completion and capture output. The process does not inherit the standard input of the caller.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Run process to completion and return stdout on success.
Equations
- One or more equations did not get rendered due to their size.
Instances For
- user : IO.AccessRight
- group : IO.AccessRight
- other : IO.AccessRight
Instances For
Equations
- acc.flags = (acc.user.flags.shiftLeft 6).lor ((acc.group.flags.shiftLeft 3).lor acc.other.flags)
Instances For
Equations
- IO.setAccessRights filename mode = IO.Prim.setAccessRights filename mode.flags
Instances For
Equations
- IO.instMonadLiftSTRealWorldBaseIO = { monadLift := fun {α : Type} => id }
Mutable cell that can be passed around for purposes of cooperative task cancellation: request
cancellation with CancelToken.set
and check for it with CancelToken.isSet
.
This is a more flexible alternative to Task.cancel
as the token can be shared between multiple
tasks.
Instances For
Creates a new cancellation token.
Equations
Instances For
Activates a cancellation token. Idempotent.
Equations
- tk.set = ST.Ref.set (IO.CancelToken.ref✝ tk) true
Instances For
Checks whether the cancellation token has been activated.
Equations
- tk.isSet = ST.Ref.get (IO.CancelToken.ref✝ tk)
Instances For
Equations
- IO.FS.Stream.ofHandle h = { flush := h.flush, read := h.read, write := h.write, getLine := h.getLine, putStr := h.putStr, isTty := h.isTty }
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Run action with stdin
emptied and stdout+stderr
captured into a String
.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Marks given value and its object graph closure as multi-threaded if currently marked single-threaded. This will make reference counter updates atomic and thus more costly. It can still be useful to do eagerly when the value will be shared between threads later anyway and there is available time budget to mark it now.
Equations
Instances For
Marks given value and its object graph closure as persistent. This will remove reference counter updates but prevent the closure from being deallocated until the end of the process! It can still be useful to do eagerly when the value will be marked persistent later anyway and there is available time budget to mark it now or it would be unnecessarily marked multi-threaded in between.
This function is only safe to use on objects (in the full closure) which are not used concurrently or which are already persistent.