Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Erase the distinction between terms and types #101

Merged
merged 45 commits into from
Jun 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
10cba45
Merge `Type` with `Atom`.
dougalm May 22, 2020
63c2875
Make a dedicated typeclass for our embedding/builder monad.
dougalm May 22, 2020
8fe4036
Start building a new front-end language, `UExpr`, based around depend…
dougalm May 24, 2020
42bcbc3
Use names instead of de Bruijn indices in UExpr pi binders.
dougalm May 25, 2020
7431e7c
Build out UExpr parser.
dougalm May 25, 2020
1ccda34
Add Idris-like implicit arguments, generalizing and (soon) replacing …
dougalm May 27, 2020
aeaed86
Add Coq-style syntax for function definitions.
dougalm May 27, 2020
07ae3c6
Add source annotations to UExpr to improve error reporting.
dougalm May 27, 2020
6e67271
Check for unbound/shadowed variables in UExpr.
dougalm May 27, 2020
f169361
Evaluate type expressions just enough to handle parametric type aliases.
dougalm May 27, 2020
aa7f57e
Implement UExpr versions of `for`/`get`/`=>`.
dougalm May 28, 2020
77ee8db
Delete FExpr!
dougalm May 28, 2020
dde4ea0
Reorganize core `Expr` IR in line with `UExpr`.
dougalm May 29, 2020
97366b4
Simplify type checker and make internal errors more informative.
dougalm May 29, 2020
abb854a
Use ordinary names instead of de Bruijn indices for pi binders.
dougalm May 30, 2020
1b7f66b
Merge type parameters and term parameters to `PrimOp`, `PrimCon` etc.
dougalm May 31, 2020
bf91c4a
Add a pair type.
dougalm Jun 1, 2020
13d75c5
Start re-adding effects.
dougalm Jun 5, 2020
f38c49b
Small readjustments to arrow parameterization.
dougalm Jun 5, 2020
f4162d3
Fix a couple of bugs blocking effects in loops.
dougalm Jun 5, 2020
a83dc53
Add implicit implicit arguments at the parser level.
dougalm Jun 6, 2020
f4d86c5
Parsing rules for table constructor.
dougalm Jun 6, 2020
d96f3eb
Improve error messages.
dougalm Jun 6, 2020
567261a
Get FFI working again and start UExpr version of prelude.
dougalm Jun 7, 2020
cd82579
Add patterns to UExpr lambda and let.
dougalm Jun 8, 2020
79754af
Remove tuples/records.
dougalm Jun 8, 2020
b970b76
Make more effort to preserve source names in Embed.
dougalm Jun 8, 2020
04bd1e9
Add `(!)` operation for indexing into references.
dougalm Jun 9, 2020
21ad938
Proper effect row unification.
dougalm Jun 11, 2020
5ff8391
Add a check for variables escaping their scopes due to unification.
dougalm Jun 11, 2020
4cba4c2
Avoid unnecessary inlining during type inference.
dougalm Jun 12, 2020
1b16cb0
Simplify inference a bit.
dougalm Jun 12, 2020
68db99e
Port most of prelude over to UExpr.
dougalm Jun 12, 2020
2cb2f76
Various UExpr fixes
dougalm Jun 13, 2020
859a7c6
Add holes to UExpr, whose values are inferred during type inference.
dougalm Jun 13, 2020
80ae79c
Track allowed effects in Embed.
dougalm Jun 14, 2020
27d75de
Start handling AD using new effect system.
dougalm Jun 14, 2020
087e53e
Transposition of loops and indexing.
dougalm Jun 15, 2020
709db40
Start updating tests to UExpr frontend and fix various bugs uncovered.
dougalm Jun 15, 2020
8d7baf5
Handle sum types and case expressions in parser and prelude.
dougalm Jun 16, 2020
5245766
Add index range syntax to UExpr.
dougalm Jun 16, 2020
aee0ec3
Fix table equality comparisons and mutual shadowing in patterns.
dougalm Jun 16, 2020
4433c48
Update most of the remaining tests and examples to UExpr frontend.
dougalm Jun 16, 2020
b92e76c
Merge branch 'main' into dependenter-types
dougalm Jun 17, 2020
e564e62
Make edits suggested by Adam.
dougalm Jun 18, 2020
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
6 changes: 3 additions & 3 deletions dex.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ flag inotify
default: False

library
exposed-modules: Record, Env, Syntax, Type, Inference, JIT, LLVMExec,
exposed-modules: Env, Syntax, Type, Inference, JIT, LLVMExec,
Parser, Util, Imp, PPrint, Array,
Actor, Cat, Flops, Normalize, Embed, Serialize,
RenderHtml, Plot, LiveOutput, Subst, Simplify, TopLevel,
Actor, Cat, Flops, Embed, Serialize,
RenderHtml, Plot, LiveOutput, Simplify, TopLevel,
Autodiff, JAX, Interpreter, Logging, PipeRPC
build-depends: base, containers, mtl, binary, bytestring,
time, tf-random, llvm-hs-pure ==9.*, llvm-hs ==9.*,
Expand Down
71 changes: 7 additions & 64 deletions examples/ad-tests.dx
Original file line number Diff line number Diff line change
@@ -1,78 +1,27 @@
:p
f : Real -> Real
f x = x
jvp f 3.0 2.0
> 2.0

:p
f x = x * x
jvp f 3.0 1.5
> 9.0

:p
f x = x + x
jvp f 3.0 2.0
> 4.0

:p
f x = x * x * x
jvp f 2.0 1.5
> 18.0

:p
f x = x * x * x
f = \x. x * x * x
jvp (\x. jvp f x 1.0) 2.0 1.0
> 12.0

:p
f x = 4.0 * x * x * x
f = \x. 4.0 * x * x * x
deriv (deriv (deriv f)) 1.234
> 24.0

-- TODO: handle pairs and re-enable
:p
f : Real --o Real
f x = x
transposeLinear f 2.0
> 2.0

:p
f : Real --o Real
f x = x + x
transposeLinear f 1.0
> 2.0

:p
f : Real --o Real
f x = x + (x + x) * 2.0
transposeLinear f 1.0
> 5.0

:p
f : Real --o Real
f x = x * 2.0
transposeLinear f 1.0
> 2.0

:p
f : Real --o Real
f x = 2.0 * x
transposeLinear f 1.0
> 2.0

:p
f : Real --o (Real, Real)
f x = (x, 2.0 * x)
f : Real --o (Real & Real) = \x. (x, 2.0 * x)
transposeLinear f (1.0, 3.0)
> 7.0

-- TODO: handle pairs and re-enable
:p
f : (Real, Real) --o Real
f (x,y) = x + 2.0 * y
f : (Real & Real) --o Real = \(x,y). x + 2.0 * y
transposeLinear f 1.0
> (1.0, 2.0)

:p grad (\x. x * x) 1.0
> 2.0
-- TODO: handle user-defined linearity rules an re-enable

:p deriv cos 0.0
> 0.0
Expand Down Expand Up @@ -110,12 +59,6 @@
:p checkDeriv (deriv cos) 1.0
> True

:p deriv (fdiv 3.0) 2.0
> -0.75

:p deriv (\x. x / 2.0) 3.0
> 0.5

badDerivFun : Real -> Real
badDerivFun x = x

Expand Down
54 changes: 0 additions & 54 deletions examples/annot-tests.dx

This file was deleted.

26 changes: 13 additions & 13 deletions examples/brownian_motion.dx
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@


type UnitInterval = Real
UnitInterval = Real

bmIter : (Key, Real, Real, UnitInterval) -> (Key, Real, Real, UnitInterval)
bmIter (key, y, sigma, t) =
(kDraw, kL, kR) = splitKey3 key
t' = abs (t - 0.5)
y' = sigma * randn kDraw * (0.5 - t')
key' = select (t > 0.5) kL kR
(key', y + y', sigma / sqrt 2.0, t' * 2.0)
bmIter : (Key & Real & Real & UnitInterval) -> (Key & Real & Real & UnitInterval) =
\(key, y, sigma, t).
(kDraw, kL, kR) = splitKey3 key
t' = abs (t - 0.5)
y' = sigma * randn kDraw * (0.5 - t')
key' = select (t > 0.5) kL kR
(key', y + y', sigma / sqrt 2.0, t' * 2.0)

sampleBM : Key -> UnitInterval -> Real
sampleBM key t =
(_, y, _, _) = fold (key, 0.0, 1.0, t) \i:10. bmIter
y
sampleBM : Key -> UnitInterval -> Real =
\key t.
(_, y, _, _) = fold (key, 0.0, 1.0, t) \i:(Fin 10). bmIter
y

xs = linspace @1000 0.0 1.0
xs = linspace (Fin 1000) 0.0 1.0
ys = map (sampleBM (newKey 0)) xs

:plot zip xs ys
Expand Down
53 changes: 53 additions & 0 deletions examples/easy-ad-tests.dx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
:p
f : Real -> Real = \x. x
jvp f 3.0 2.0
> 2.0

:p
f = \x. x * x
jvp f 3.0 1.5
> 9.0

:p
f = \x. x + x
jvp f 3.0 2.0
> 4.0

:p
f = \x. x * x * x
jvp f 2.0 1.5
> 18.0

:p
f : Real --o Real = \x. x
transposeLinear f 2.0
> 2.0

:p
f : Real --o Real = \x. x + x
transposeLinear f 1.0
> 2.0

:p
f : Real --o Real = \x. x + (x + x) * 2.0
transposeLinear f 1.0
> 5.0

:p
f : Real --o Real = \x. x * 2.0
transposeLinear f 1.0
> 2.0

:p
f : Real --o Real = \x. 2.0 * x
transposeLinear f 1.0
> 2.0

:p grad (\x. x * x) 1.0
> 2.0

:p deriv (\x. 3.0 / x) 2.0
> -0.75

:p deriv (\x. x / 2.0) 3.0
> 0.5
Loading