Skip to content

Commit

Permalink
Simplify prims with named types
Browse files Browse the repository at this point in the history
  • Loading branch information
V-FEXrt committed Aug 30, 2024
1 parent 4a1162f commit 3d4da14
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 61 deletions.
8 changes: 2 additions & 6 deletions share/wake/lib/system/io.wake
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,8 @@ target writeImp inputs mode path content =
(\_ \_ \_ prim "write") mode path content

def run (job: Job) ((RunnerInput _ _ vis _ _ _ _ _ predict _): RunnerInput): Result RunnerOutput Error =
def Usage status runtime cputime mem in out = predict

# Insert the <write> job into the database
def _ = primJobVirtual job "" "" status runtime cputime mem in out
def _ = primJobVirtual job "" "" predict

# Wait for the virtual job to complete
require Pass reality = job.getJobReality
Expand Down Expand Up @@ -272,10 +270,8 @@ def mkdirRunner: Runner =
require "<mkdir>", "-m", smode, path, Nil = cmd
else panic "mkdirImp violated command-line contract"

def Usage status runtime cputime mem in out = predict

# Insert the <mkdir> job into the database
def _ = primJobVirtual job "" "" status runtime cputime mem in out
def _ = primJobVirtual job "" "" predict

# Wait for the virtual job to complete
require Pass reality = job.getJobReality
Expand Down
58 changes: 25 additions & 33 deletions share/wake/lib/system/job.wake
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,17 @@

package wake

export tuple JobKey =
export dir: String
export stdin: String
export env: String
export cmd: String
export signature: Integer
export visible: String
export isatty: Integer

# Create/reserve a job handle, parameters aren't necessarily finalized
export def primJobCreate (label: String) (dir: String) (stdin: String) (env: String) (cmd: String) (signature: Integer) (visible: String) (keep: Integer) (echo: String) (stdout: String) (stderr: String) (isatty: Integer): Job =
export def primJobCreate (label: String) ((JobKey dir stdin env cmd signature visible isatty): JobKey) (keep: Integer) (echo: String) (stdout: String) (stderr: String): Job =
(\_ \_ \_ \_ \_ \_ \_ \_ \_ \_ \_ \_ prim "job_create")
label
dir
Expand All @@ -32,7 +41,7 @@ export def primJobCreate (label: String) (dir: String) (stdin: String) (env: Str
isatty

# Imediatly complete a job with the provided ouputs without launching a process
export def primJobVirtual (job: Job) (stdout: String) (stderr: String) (status: Integer) (runtime: Double) (cputime: Double) (membytes: Integer) (ibytes: Integer) (obytes: Integer): Unit =
export def primJobVirtual (job: Job) (stdout: String) (stderr: String) ((Usage status runtime cputime membytes ibytes obytes): Usage): Unit =
(\_ \_ \_ \_ \_ \_ \_ \_ \_ prim "job_virtual")
job
stdout
Expand All @@ -45,7 +54,7 @@ export def primJobVirtual (job: Job) (stdout: String) (stderr: String) (status:
obytes

# Launch the job via a child process. Values such as command or environment can be freely changed from the initial reservation.
export def primJobLaunch (job: Job) (dir: String) (stdin: String) (env: String) (cmd: String) (status: Integer) (runtime: Double) (cputime: Double) (membytes: Integer) (ibytes: Integer) (obytes: Integer) (isatty: Integer): Unit =
export def primJobLaunch (job: Job) ((JobKey dir stdin env cmd signature visible isatty): JobKey) ((Usage status runtime cputime membytes ibytes obytes): Usage): Unit =
(\_ \_ \_ \_ \_ \_ \_ \_ \_ \_ \_ \_ prim "job_launch")
job
dir
Expand All @@ -69,7 +78,7 @@ export def primJobFailFinish (job: Job) (error: Error): Unit =
(\_ \_ prim "job_fail_finish") job error

# Complete a job successfully by providing to the runtime the inputs/outputs/usage of the job
export def primJobFinish (job: Job) (inputs: String) (outputs: String) (all_outputs: String) (status: Integer) (runtime: Double) (cputime: Double) (membytes: Integer) (ibytes: Integer) (obytes: Integer): Unit =
export def primJobFinish (job: Job) (inputs: String) (outputs: String) (all_outputs: String) ((Usage status runtime cputime membytes ibytes obytes): Usage): Unit =
(\_ \_ \_ \_ \_ \_ \_ \_ \_ \_ prim "job_finish")
job
inputs
Expand All @@ -83,7 +92,7 @@ export def primJobFinish (job: Job) (inputs: String) (outputs: String) (all_outp
obytes

# Look up a job in the local database. Returns a completed Job handle with outputs already resolved if it is already cached
export def primJobCache (dir: String) (stdin: String) (env: String) (cmd: String) (signature: Integer) (visible: String) (isatty: Integer): Pair (List Job) (List (Pair String String)) =
export def primJobCache ((JobKey dir stdin env cmd signature visible isatty): JobKey): Pair (List Job) (List (Pair String String)) =
(\_ \_ \_ \_ \_ \_ \_ prim "job_cache") dir stdin env cmd signature visible isatty

# Creates a hash of 5 elements
Expand All @@ -102,24 +111,15 @@ def jobSignature cmd res fni fno keep =
def runAlways cmd env dir stdin res uusage finputs foutputs vis keep run echo stdout stderr label isatty: Job =
def hash = jobSignature cmd res finputs foutputs keep

def build Unit =
def visStrings = map getPathName vis

def job =
primJobCreate
label
dir
stdin
env.implode
cmd.implode
hash
visStrings.implode
(booleanToInteger keep)
echo
stdout
stderr
(booleanToInteger isatty)
def visKey =
vis
| map getPathName
| implode

def jobKey = JobKey dir stdin env.implode cmd.implode hash visKey isatty.booleanToInteger

def build Unit =
def job = primJobCreate label jobKey keep.booleanToInteger echo stdout stderr
def prefix = str (getJobId job)

def usage =
Expand All @@ -131,7 +131,7 @@ def runAlways cmd env dir stdin res uusage finputs foutputs vis keep run echo st

def final _ = match output
Fail e -> primJobFailLaunch job e
Pass (RunnerOutput inputs outputs (Usage status runtime cputime mem in out)) ->
Pass (RunnerOutput inputs outputs reality) ->
def input =
finputs inputs
| map simplify
Expand All @@ -142,7 +142,7 @@ def runAlways cmd env dir stdin res uusage finputs foutputs vis keep run echo st
| computeHashes prefix
| implode

primJobFinish job input output (implode outputs) status runtime cputime mem in out
primJobFinish job input output (implode outputs) reality

# Make sure we don't hash files before the job has stopped running
def _ = waitJobMerged final job
Expand All @@ -169,15 +169,7 @@ def runAlways cmd env dir stdin res uusage finputs foutputs vis keep run echo st
require True = keep
else build Unit

def cache =
primJobCache
dir
stdin
env.implode
cmd.implode
hash
(map getPathName vis).implode
(booleanToInteger isatty)
def cache = primJobCache jobKey

match cache
Pair (job, _) last -> confirm True last job
Expand Down
2 changes: 1 addition & 1 deletion share/wake/lib/system/job_cache_runner.wake
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ export def mkJobCacheRunner (hashFn: RunnerInput => Result String Error) (wakero

def outputs = output_files ++ output_dirs ++ output_symlinks
def predict = Usage status runtime cputime mem ibytes obytes
def _ = primJobVirtual job stdout stderr status runtime cputime mem ibytes obytes
def _ = primJobVirtual job stdout stderr predict

Pass (RunnerOutput inputs outputs predict)

Expand Down
2 changes: 1 addition & 1 deletion share/wake/lib/system/remote_cache_runner.wake
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ export def mkRemoteCacheRunner (rscApi: RemoteCacheApi) (hashFn: RunnerInput =>
| findFail
| addErrorContext "rsc: Failed to create a symlink"

def _ = primJobVirtual job stdout stderr status runtime cputime mem ibytes obytes
def _ = primJobVirtual job stdout stderr predict

Pass (RunnerOutput inputs outputs predict)

Expand Down
23 changes: 3 additions & 20 deletions share/wake/lib/system/runner.wake
Original file line number Diff line number Diff line change
Expand Up @@ -81,22 +81,8 @@ export def makeRunner (name: String) (run: Job => RunnerInput => Result RunnerOu
# Advanced usage only, proceed with caution
export def localRunner: Runner =
def run (job: Job) ((RunnerInput _ cmd vis env dir stdin _ _ predict isatty): RunnerInput): Result RunnerOutput Error =
def Usage status runtime cputime mem in out = predict

def _ =
primJobLaunch
job
dir
stdin
env.implode
cmd.implode
status
runtime
cputime
mem
in
out
(booleanToInteger isatty)
def jobKey = JobKey dir stdin env.implode cmd.implode 0 "" isatty.booleanToInteger
def _ = primJobLaunch job jobKey predict

job
| getJobReality
Expand All @@ -109,10 +95,7 @@ export def localRunner: Runner =
# This runner is useful for tracking a unit of work that is job like but not launched as a process
export def virtualRunner: Runner =
def run (job: Job) ((RunnerInput _ _ vis _ _ _ _ _ predict _): RunnerInput): Result RunnerOutput Error =
def Usage status runtime cputime mem in out = predict

# sets predict+reality
def _ = primJobVirtual job "" "" status runtime cputime mem in out
def _ = primJobVirtual job "" "" predict

job
| getJobReality
Expand Down

0 comments on commit 3d4da14

Please sign in to comment.