Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ s2 is the compiler. It is purely functional (`val` and recursion, no `var` or `w
* **Flags**: `--eval` runs pure defs at compile time, `--hash` prints content hashes, and `--store-check` writes and reads the content-addressed store.
* **Errors** have the shape of Rust's: `error[code]`, then the file and line, the source line, the expected and found types, and a help line.

s1, the first compiler (imperative, written in srs), and s0, its Zig bootstrap, are still in the tree and are being removed. Lean generation (`--lean`) waits until the core is stable. The known rough edges of s2 are tracked before s3.
s1, the first compiler (imperative, written in srs), and s0, its Zig bootstrap, are historic: they stay in the tree, and nothing builds or runs them. Lean generation (`--lean`) waits until the core is stable. The known rough edges of s2 are tracked before s3.

The s2 libraries live in `s2/`: persistent collections, miniKanren with disequality and finite domains, and Datalog with stratified negation. The checker phases also live there, and the driver lives in `s2c/`.

Expand Down Expand Up @@ -314,7 +314,7 @@ The test runner validates every feature across positive and negative cases:
* `tests/s2/neg/`: Programs that s2 must reject. Each one names the error code and the exact file and line it expects.
* `tests/s2/eval/` and `tests/s2/hash/`: the compile-time values and the content hashes they must give.
* `tests/s2/*.srs`: tests of the s2 components themselves.
* `tests/s1/` is the suite of the old compiler, removed with it.
* `tests/s1/` is the historic suite of s1.

---

Expand Down
24 changes: 9 additions & 15 deletions bench/baseline.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
corpus-self wall 0.12775143381818183 0.011372803783640187
corpus-self instr 274041244.1363636 33.912064793051734
corpus-self mem 52900957.09090909 126570.67215362299
corpus-lean wall 0.24611097923076924 0.015624251307958045
corpus-lean instr 494192153.0 83.77549363228684
corpus-lean mem 95700204.3076923 151121.35071269964
corpus-tests wall 0.4935262161000001 0.002177963859206702
corpus-tests instr 1112008029.7 15236.22809877096
corpus-tests mem 10970726.4 70449.0831723325
info-s1-self wall 0.14322669809523808 0.001320767815550332
info-s1-self instr 334215777.8095238 16.101611868440525
info-s1-self mem 62343460.571428575 108467.24186249574
info-s1-lean wall 0.26766985463636367 0.0022573760950091648
info-s1-lean instr 575020362.0909091 9.648363026488436
info-s1-lean mem 111277149.0909091 67877.30514605681
corpus-self wall 3.8078688442 1.1918706563666694
corpus-self instr 3157647545.0 724.000345303785
corpus-self mem 1259725619.2 205074.24837653313
corpus-tests wall 6.646648772400001 1.5940560827021355
corpus-tests instr 7408109693.6 5573.769891195725
corpus-tests mem 143262515.2 77737.72059431637
info-s2c-self wall 2.3844662332000004 0.09882857217685709
info-s2c-self instr 3157645890.6 944.2217959780425
info-s2c-self mem 1259707596.8 220736.02041171258
40 changes: 20 additions & 20 deletions bench/corpus/lib/kanren.srs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
enum Term:
case TVar(n: I64)
case TCon(f: Str, args: Terms)
case TInt(v: I64)
case KInt(v: I64)

enum Terms:
case TNil
Expand All @@ -22,7 +22,7 @@ enum Unified:
def walk(s: Subst, t: Term): Term = t match
case TVar(n) => lookup(s, s, n, t)
case TCon(_, _) => t
case TInt(_) => t
case KInt(_) => t

def lookup(all: Subst, s: Subst, n: I64, t: Term): Term = s match
case SNil => t
Expand All @@ -32,7 +32,7 @@ def lookup(all: Subst, s: Subst, n: I64, t: Term): Term = s match
def occurs(s: Subst, n: I64, t: Term): Bool = walk(s, t) match
case TVar(m) => m == n
case TCon(_, args) => occursIn(s, n, args)
case TInt(_) => false
case KInt(_) => false

def occursIn(s: Subst, n: I64, ts: Terms): Bool = ts match
case TNil => false
Expand All @@ -47,16 +47,16 @@ def unify {r: Region} (s: Subst, a: Term, b: Term): Unified =
case TCon(f, xs) => y match
case TVar(m) => bind(s, m, x)
case TCon(g, ys) => if rt_str_eq(f, g) then unifyAll(s, xs, ys) else Fail
case TInt(_) => Fail
case TInt(v) => y match
case KInt(_) => Fail
case KInt(v) => y match
case TVar(m) => bind(s, m, x)
case TInt(w) => if v == w then Ok(s) else Fail
case KInt(w) => if v == w then Ok(s) else Fail
case TCon(_, _) => Fail

def bind {r: Region} (s: Subst, n: I64, t: Term): Unified = t match
case TVar(m) => if m == n then Ok(s) else Ok(SBind(n, t, s))
case TCon(_, _) => if occurs(s, n, t) then Fail else Ok(SBind(n, t, s))
case TInt(_) => Ok(SBind(n, t, s))
case KInt(_) => Ok(SBind(n, t, s))

def unifyAll {r: Region} (s: Subst, xs: Terms, ys: Terms): Unified = xs match
case TNil => ys match
Expand All @@ -72,7 +72,7 @@ def unifyAll {r: Region} (s: Subst, xs: Terms, ys: Terms): Unified = xs match
def walkAll {r: Region} (s: Subst, t: Term): Term = walk(s, t) match
case TVar(n) => TVar(n)
case TCon(f, args) => TCon(f, walkEach(s, args))
case TInt(v) => TInt(v)
case KInt(v) => KInt(v)

def walkEach {r: Region} (s: Subst, ts: Terms): Terms = ts match
case TNil => TNil
Expand All @@ -90,7 +90,7 @@ def showTerm(t: Term): Unit = t match
rt_print("(")
showTerms(args)
rt_print(")")
case TInt(v) => rt_print_i64(v)
case KInt(v) => rt_print_i64(v)

def showTerms(ts: Terms): Unit = ts match
case TNil => ()
Expand Down Expand Up @@ -202,7 +202,7 @@ enum Run:
def shift {r: Region} (t: Term, k: I64): Term = t match
case TVar(n) => TVar(n + k)
case TCon(f, args) => TCon(f, shiftAll(args, k))
case TInt(v) => TInt(v)
case KInt(v) => KInt(v)

def shiftAll {r: Region} (ts: Terms, k: I64): Terms = ts match
case TNil => TNil
Expand Down Expand Up @@ -309,9 +309,9 @@ def between {r: Region} (xs: Ints, a: I64, b: I64): Ints = xs match
case INil => INil
case ICons(h, t) => if h >= a && h <= b then ICons(h, between(t, a, b)) else between(t, a, b)

def without {r: Region} (xs: Ints, v: I64): Ints = xs match
def kwithout {r: Region} (xs: Ints, v: I64): Ints = xs match
case INil => INil
case ICons(h, t) => if h == v then without(t, v) else ICons(h, without(t, v))
case ICons(h, t) => if h == v then kwithout(t, v) else ICons(h, kwithout(t, v))

def meetInts {r: Region} (xs: Ints, d: Dom): Ints = xs match
case INil => INil
Expand All @@ -334,18 +334,18 @@ def dropDom {r: Region} (ds: Doms, n: I64): Doms = ds match
def domOf {r: Region} (st: State, t: Term): DomOf = st match
case State(s, _, ds, _, _) => walk(s, t) match
case TVar(n) => lookupDom(ds, n)
case TInt(v) => Has(Dom(v, INil))
case KInt(v) => Has(Dom(v, INil))
case TCon(_, _) => NotInt

// t takes a value of xs (ascending): Bad when none is left, bound when one is left
def setDom {r: Region} (st: State, t: Term, xs: Ints): Checked = st match
case State(s, ns, ds, fs, nx) => xs match
case INil => Bad
case ICons(h, rest) => walk(s, t) match
case TInt(v) => if member(v, xs) then Good(st) else Bad
case KInt(v) => if member(v, xs) then Good(st) else Bad
case TCon(_, _) => Bad
case TVar(n) => rest match
case INil => unify(s, TVar(n), TInt(h)) match
case INil => unify(s, TVar(n), KInt(h)) match
case Fail => Bad
case Ok(s2) => Good(State(s2, ns, dropDom(ds, n), fs, nx))
case ICons(_, _) => Good(State(s, ns, DCons(n, Dom(h, rest), dropDom(ds, n)), fs, nx))
Expand All @@ -372,8 +372,8 @@ def leAt {r: Region} (st: State, x: Term, y: Term, dx: Dom, dy: Dom, k: I64): Ch

def neqAt {r: Region} (st: State, x: Term, y: Term, dx: Dom, dy: Dom): Checked =
if domSize(dx) == 1 && domSize(dy) == 1 then (if lo(dx) == lo(dy) then Bad else Good(st))
else if domSize(dx) == 1 then setDom(st, y, without(ints(dy), lo(dx)))
else if domSize(dy) == 1 then setDom(st, x, without(ints(dx), lo(dy)))
else if domSize(dx) == 1 then setDom(st, y, kwithout(ints(dy), lo(dx)))
else if domSize(dy) == 1 then setDom(st, x, kwithout(ints(dx), lo(dy)))
else Good(st)

def binAt {r: Region} (st: State, op: Bin, x: Term, y: Term, dx: Dom, dy: Dom): Checked = op match
Expand Down Expand Up @@ -455,7 +455,7 @@ def smaller(d: Dom, best: Pick): Bool = best match

def labelBranches {r: Region} (st: State, t: Term, vs: Ints, after: Goals): Queue = vs match
case INil => QNil
case ICons(v, more) => QCons(Branch(st, GCons(GEq(t, TInt(v)), after)), labelBranches(st, t, more, after))
case ICons(v, more) => QCons(Branch(st, GCons(GEq(t, KInt(v)), after)), labelBranches(st, t, more, after))

// every two of xs differ
def distinct {r: Region} (xs: Terms): Goal = xs match
Expand Down Expand Up @@ -484,7 +484,7 @@ def picks {r: Region} (rules: Rules, rel: Str, args: Terms, st: State, nx: I64,
Picked(QCons(b, bs), cost + 1)
else Picked(bs, cost)

def step {r: Region} (rules: Rules, b: Branch): Step = b match
def kstep {r: Region} (rules: Rules, b: Branch): Step = b match
case Branch(st, gs) => gs match
case GNil => Done(st)
case GCons(g, rest) => st match
Expand Down Expand Up @@ -525,7 +525,7 @@ def solve {r: Region} (rules: Rules, g: Goal, nvars: I64, fuel: I64, limit: I64)
case QNil => go = false
case QCons(b, t) =>
q = t
step(rules, b) match
kstep(rules, b) match
case Done(st) =>
found = ACons(st, found)
n = n + 1
Expand Down
Loading
Loading