Equations
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
- instMonadEIO = inferInstanceAs (Monad (EStateM ε IO.RealWorld))
Equations
- instMonadFinallyEIO = inferInstanceAs (MonadFinally (EStateM ε IO.RealWorld))
Equations
- instMonadExceptOfEIO = inferInstanceAs (MonadExceptOf ε (EStateM ε IO.RealWorld))
Equations
- instOrElseEIO = { orElse := MonadExcept.orElse }
Equations
- instInhabitedEIO = inferInstanceAs (Inhabited (EStateM ε IO.RealWorld α))
Equations
Equations
Equations
- BaseIO.toEIO act s = match act s with | EStateM.Result.ok a s => EStateM.Result.ok a s
Equations
- EIO.toBaseIO act 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
Equations
- EIO.catchExceptions act h s = match act s with | EStateM.Result.ok a s => EStateM.Result.ok a s | EStateM.Result.error ex s => h ex s
Equations
- BaseIO.toIO act = liftM act
Equations
- unsafeBaseIO fn = match EStateM.run fn () with | EStateM.Result.ok a a_1 => a
Equations
- unsafeEIO fn = unsafeBaseIO (EIO.toBaseIO fn)
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 = BaseIO.mapTasks.go f prio tasks []
Equations
- BaseIO.mapTasks.go f prio (t :: ts) _fun_discr = BaseIO.bindTask t (fun a => BaseIO.mapTasks.go f prio ts (a :: _fun_discr)) prio
- BaseIO.mapTasks.go f prio [] _fun_discr = BaseIO.asTask (f (List.reverse _fun_discr)) prio
Equations
- EIO.asTask act prio = BaseIO.asTask (EIO.toBaseIO act) prio
EIO
specialization of BaseIO.asTask
.
Equations
- EIO.mapTask f t prio = BaseIO.mapTask (fun a => EIO.toBaseIO (f a)) t prio
EIO
specialization of BaseIO.mapTask
.
Equations
- EIO.bindTask t f prio = BaseIO.bindTask t (fun a => EIO.catchExceptions (f a) fun e => pure { get := Except.error e }) prio
EIO
specialization of BaseIO.bindTask
.
Equations
- EIO.mapTasks f tasks prio = BaseIO.mapTasks (fun as => EIO.toBaseIO (f as)) tasks prio
EIO
specialization of BaseIO.mapTasks
.
Equations
- IO.ofExcept e = match e with | Except.ok a => pure a | Except.error e => throw (IO.userError (toString e))
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.
Equations
- IO.asTask act prio = EIO.asTask act prio
IO
specialization of EIO.asTask
.
Equations
- IO.mapTask f t prio = EIO.mapTask f t prio
IO
specialization of EIO.mapTask
.
Equations
- IO.bindTask t f prio = EIO.bindTask t f prio
IO
specialization of EIO.bindTask
.
Equations
- IO.mapTasks f tasks prio = EIO.mapTasks f tasks prio
IO
specialization of EIO.mapTasks
.
Check if the task's cancellation flag has been set by calling IO.cancel
or dropping the last reference to the task.
Wait until any of the tasks in the given list has finished, then return its result.
Helper method for implementing "deterministic" timeouts. It is the number of "small" memory allocations performed by the current execution thread.
- read: IO.FS.Mode
- write: IO.FS.Mode
- readWrite: IO.FS.Mode
- append: IO.FS.Mode
Equations
- IO.FS.instInhabitedStream = { default := { isEof := default, flush := default, read := default, write := default, getLine := default, putStr := 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.
Equations
- IO.FS.Handle.mk fn Mode bin = IO.FS.Handle.mkPrim fn (IO.FS.Handle.fopenFlags Mode bin)
Remove given directory. Fails if not empty; see also IO.FS.removeDirAll
.
Equations
- IO.FS.withFile fn mode f = IO.FS.Handle.mk fn mode true >>= f
Equations
- IO.FS.Handle.putStrLn h s = IO.FS.Handle.putStr h (String.push s (Char.ofNat 10))
Equations
Equations
- IO.FS.readBinFile fname = do let h ← IO.FS.Handle.mk fname IO.FS.Mode.read true IO.FS.Handle.readBinToEnd h
Equations
- IO.FS.readFile fname = do let h ← IO.FS.Handle.mk fname IO.FS.Mode.read false IO.FS.Handle.readToEnd h
Equations
- IO.FS.lines fname = do let h ← IO.FS.Handle.mk fname IO.FS.Mode.read false IO.FS.lines.read h #[]
Equations
- IO.FS.writeBinFile fname content = do let h ← IO.FS.Handle.mk fname IO.FS.Mode.write true IO.FS.Handle.write h content
Equations
- IO.FS.writeFile fname content = do let h ← IO.FS.Handle.mk fname IO.FS.Mode.write false IO.FS.Handle.putStr h content
Equations
- IO.FS.Stream.putStrLn strm s = IO.FS.Stream.putStr strm (String.push s (Char.ofNat 10))
Equations
- IO.FS.instReprDirEntry = { reprPrec := [anonymous] }
Equations
- IO.FS.DirEntry.path entry = entry.root / { toString := entry.fileName }
- dir: IO.FS.FileType
- file: IO.FS.FileType
- symlink: IO.FS.FileType
- other: IO.FS.FileType
Equations
- IO.FS.instReprFileType = { reprPrec := [anonymous] }
Equations
- IO.FS.instBEqFileType = { beq := [anonymous] }
Equations
- IO.FS.instReprSystemTime = { reprPrec := [anonymous] }
Equations
- IO.FS.instBEqSystemTime = { beq := [anonymous] }
Equations
- IO.FS.instOrdSystemTime = { compare := [anonymous] }
Equations
- IO.FS.instInhabitedSystemTime = { default := { sec := default, nsec := default } }
Equations
- IO.FS.instLTSystemTime = ltOfOrd
Equations
- IO.FS.instLESystemTime = leOfOrd
- accessed : IO.FS.SystemTime
- modified : IO.FS.SystemTime
- byteSize : UInt64
- type : IO.FS.FileType
Equations
- IO.FS.instReprMetadata = { reprPrec := [anonymous] }
Equations
- System.FilePath.isDir p = do let a ← EIO.toBaseIO (System.FilePath.metadata p) match a with | Except.ok m => pure (m.type == IO.FS.FileType.dir) | Except.error a => pure false
Equations
- System.FilePath.pathExists p = do let a ← EIO.toBaseIO (System.FilePath.metadata p) pure (Except.toBool a)
Equations
- System.FilePath.walkDir p enter = Prod.snd <$> StateT.run (System.FilePath.walkDir.go enter p) #[]
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
- IO.withStdin h x = do let prev ← liftM (IO.setStdin h) tryFinally x (discard (liftM (IO.setStdin prev)))
Equations
- IO.withStdout h x = do let prev ← liftM (IO.setStdout h) tryFinally x (discard (liftM (IO.setStdout prev)))
Equations
- IO.withStderr h x = do let prev ← liftM (IO.setStderr h) tryFinally x (discard (liftM (IO.setStderr prev)))
Equations
- IO.println s = IO.print (String.push (toString s) (Char.ofNat 10))
Equations
- IO.eprintln s = IO.eprint (String.push (toString s) (Char.ofNat 10))
Equations
- IO.appDir = do let p ← IO.appPath let discr ← pure (System.FilePath.parent p) match discr with | some p => IO.FS.realPath p | x => throw (IO.userError (toString "System.IO.appDir: unexpected filename '" ++ toString p ++ toString "'"))
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.
- piped: IO.Process.Stdio
- inherit: IO.Process.Stdio
- null: IO.Process.Stdio
Equations
- IO.Process.Stdio.toHandleType _fun_discr = match _fun_discr with | IO.Process.Stdio.piped => IO.FS.Handle | IO.Process.Stdio.inherit => Unit | IO.Process.Stdio.null => Unit
- stdin : IO.Process.Stdio
- stdout : IO.Process.Stdio
- stderr : IO.Process.Stdio
- stdin : IO.Process.Stdio.toHandleType cfg.stdin
- stdout : IO.Process.Stdio.toHandleType cfg.stdout
- stderr : IO.Process.Stdio.toHandleType cfg.stderr
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.
Equations
- IO.Process.output args = do let child ← IO.Process.spawn { toStdioConfig := { stdin := args.toStdioConfig.stdin, stdout := IO.Process.Stdio.piped, stderr := IO.Process.Stdio.piped }, cmd := args.cmd, args := args.args, cwd := args.cwd, env := args.env } let stdout ← liftM (IO.asTask (IO.FS.Handle.readToEnd child.stdout) Task.Priority.dedicated) let stderr ← IO.FS.Handle.readToEnd child.stderr let exitCode ← IO.Process.Child.wait child let stdout ← IO.ofExcept stdout.get pure { exitCode := exitCode, stdout := stdout, stderr := stderr }
Run process to completion and capture output.
Equations
- IO.Process.run args = do let out ← IO.Process.output args let _do_jp : PUnit → IO String := fun y => pure out.stdout if (out.exitCode != 0) = true then do let y ← throw (IO.userError ("process '" ++ args.cmd ++ "' exited with code " ++ toString out.exitCode)) _do_jp y else do let y ← pure PUnit.unit _do_jp y
Run process to completion and return stdout on success.
Equations
- IO.AccessRight.flags acc = let r := if acc.read = true then 4 else 0; let w := if acc.write = true then 2 else 0; let x := if acc.execution = true then 1 else 0; UInt32.lor r (UInt32.lor w x)
- user : IO.AccessRight
- group : IO.AccessRight
- other : IO.AccessRight
Equations
- IO.FileRight.flags acc = let u := UInt32.shiftLeft (IO.AccessRight.flags acc.user) 6; let g := UInt32.shiftLeft (IO.AccessRight.flags acc.group) 3; let o := IO.AccessRight.flags acc.other; UInt32.lor u (UInt32.lor g o)
Equations
- IO.setAccessRights filename mode = IO.Prim.setAccessRights filename (IO.FileRight.flags mode)
Equations
- IO.instMonadLiftSTRealWorldBaseIO = { monadLift := fun {α} => id }
Equations
- IO.FS.Stream.ofHandle h = { isEof := liftM (IO.FS.Handle.isEof h), flush := IO.FS.Handle.flush h, read := IO.FS.Handle.read h, write := IO.FS.Handle.write h, getLine := IO.FS.Handle.getLine h, putStr := IO.FS.Handle.putStr h }
Equations
- IO.FS.Stream.ofBuffer r = { isEof := do let b ← ST.Ref.get r pure (decide (b.pos ≥ ByteArray.size b.data)), flush := pure (), read := fun n => ST.Ref.modifyGet r fun b => let data := ByteArray.extract b.data b.pos (b.pos + USize.toNat n); (data, { data := b.data, pos := b.pos + ByteArray.size data }), write := fun data => ST.Ref.modify r fun b => { data := ByteArray.copySlice data 0 b.data b.pos (ByteArray.size data) false, pos := b.pos + ByteArray.size data }, getLine := ST.Ref.modifyGet r fun b => let pos := match ByteArray.findIdx? b.data (fun u => u == 0 || decide (u = Nat.toUInt8 (Char.toNat (Char.ofNat 10)))) b.pos with | some pos => if (ByteArray.get! b.data pos == 0) = true then pos else pos + 1 | none => ByteArray.size b.data; (String.fromUTF8Unchecked (ByteArray.extract b.data b.pos pos), { data := b.data, pos := pos }), putStr := fun s => ST.Ref.modify r fun b => let data := String.toUTF8 s; { data := ByteArray.copySlice data 0 b.data b.pos (ByteArray.size data) false, pos := b.pos + ByteArray.size data } }
Equations
- IO.FS.withIsolatedStreams x isolateStderr = do let bIn ← liftM (IO.mkRef { data := ByteArray.empty, pos := 0 }) let bOut ← liftM (IO.mkRef { data := ByteArray.empty, pos := 0 }) let r ← IO.withStdin (IO.FS.Stream.ofBuffer bIn) (IO.withStdout (IO.FS.Stream.ofBuffer bOut) (ite (m α → m α) (isolateStderr = true) (instDecidableEqBool isolateStderr true) (IO.withStderr (IO.FS.Stream.ofBuffer bOut)) id x)) let bOut ← liftM (ST.Ref.get bOut) let out : String := String.fromUTF8Unchecked bOut.data pure (out, r)
Run action with stdin
emptied and stdout+stderr
captured into a String
.
Typeclass used for presenting the output of an #eval
command.
Equations
- Lean.instEval = { eval := fun a x => IO.println (toString (a ())) }
Equations
- Lean.instEval_1 = { eval := fun a x => IO.println (repr (a ())) }
Equations
- Lean.instEvalUnit = { eval := fun u hideUnit => if hideUnit = true then pure () else IO.println (repr (u ())) }
Equations
- Lean.instEvalIO = { eval := fun x x_1 => do let a ← x () Lean.Eval.eval (fun x => a) true }
Equations
Equations
- termPrintln!__ = Lean.ParserDescr.node `termPrintln!__ 1022 (Lean.ParserDescr.binary `andthen (Lean.ParserDescr.symbol "println! ") (Lean.ParserDescr.binary `orelse (Lean.ParserDescr.unary `interpolatedStr (Lean.ParserDescr.cat `term 0)) (Lean.ParserDescr.cat `term 0)))