Skip to content

Runtime Documentation

Sam Westrick edited this page Oct 12, 2017 · 4 revisions

Differences with MLton as of 10/5/17

  • Main compiler hasn't diverged much
    • We have:
      • read/write barriers
      • limit check
      • enabled polymorphic FFI
    • They have:
      • Quality-of-life updates (better error messages?)
  • Runtime is Linux-only
    • Only support C backend (can't do LLVM, native, ...)
  • Interrupts (for multi threading)

Per-file Documentation

include/c-main.h

Why is main a macro?

  • In generated C code, this file is included.
  • This allows targeting different architectures? (Swapping out different implementations of main)

main

  • pthread_key allows pthread local storage
  • GC_state is a catch-all for all necessary processor-local storage
    • statistics is per-processor
    • global heap is shared
    • Duplicate chooses whether or not to copy (for local vs shared)

MLton_threadFunc

  • s->amOriginal
    • For world saving; is probably broken at the moment.
  • conts are like basic blocks
  • trampoline executes conts (this is the whole program from P0's perspective)
  • Other processors wait until runtime call which starts them up

runtime/gc/garbage-collection.c

GC_collect

  • called every time we're sure if we have enough memory (called by any processor)
  • force = true when, e.g., MLton.GC.collect()
  • getStackCurrent
    • used field is a length (in bytes) of how big the stack is
    • used is not updated during normal stack manipulation, so it needs to be updated before GC stuff
  • beginAtomic
    • is not atomic across pthreads, but atomic within my pthread
    • guards against signal interrupts!
    • signal handlers are also ML code

Misc

  • There is a runtime call, MLton exit, which is called when the SML program terminates
    • Called regardless of nature of exit, e.g., unhandled exceptions (but not segfaults)
  • What is parallel_benchmark directory? We never touched this directory.