aboutsummaryrefslogtreecommitdiff
path: root/new-luxc/test
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--new-luxc/test/test/luxc/lang/synthesis/common.lux37
-rw-r--r--new-luxc/test/test/luxc/lang/synthesis/function.lux151
-rw-r--r--new-luxc/test/test/luxc/lang/synthesis/primitive.lux46
-rw-r--r--new-luxc/test/test/luxc/lang/synthesis/structure.lux50
-rw-r--r--stdlib/test/test/lux/lang/synthesis/case.lux (renamed from new-luxc/test/test/luxc/lang/synthesis/case/special.lux)14
5 files changed, 7 insertions, 291 deletions
diff --git a/new-luxc/test/test/luxc/lang/synthesis/common.lux b/new-luxc/test/test/luxc/lang/synthesis/common.lux
deleted file mode 100644
index 3379fe7fd..000000000
--- a/new-luxc/test/test/luxc/lang/synthesis/common.lux
+++ /dev/null
@@ -1,37 +0,0 @@
-(.module:
- lux
- (lux (data [bool "bool/" Eq<Bool>]
- [text "text/" Eq<Text>])
- (macro [code])
- ["r" math/random "r/" Monad<Random>])
- (luxc (lang ["la" analysis]
- ["ls" synthesis])))
-
-(def: #export gen-primitive
- (r.Random la.Analysis)
- (r.either (r.either (r.either (r/wrap (' []))
- (r/map code.bool r.bool))
- (r.either (r/map code.nat r.nat)
- (r/map code.int r.int)))
- (r.either (r.either (r/map code.deg r.deg)
- (r/map code.frac r.frac))
- (r/map code.text (r.text +5)))))
-
-(def: #export (corresponds? analysis synthesis)
- (-> la.Analysis ls.Synthesis Bool)
- (case [analysis synthesis]
- (^ [(^code []) (^code [])])
- true
-
- (^template [<tag> <test>]
- [[_ (<tag> valueA)] [_ (<tag> valueS)]]
- (<test> valueA valueS))
- ([#.Bool bool/=]
- [#.Nat n/=]
- [#.Int i/=]
- [#.Deg d/=]
- [#.Frac f/=]
- [#.Text text/=])
-
- _
- false))
diff --git a/new-luxc/test/test/luxc/lang/synthesis/function.lux b/new-luxc/test/test/luxc/lang/synthesis/function.lux
deleted file mode 100644
index fa29b4284..000000000
--- a/new-luxc/test/test/luxc/lang/synthesis/function.lux
+++ /dev/null
@@ -1,151 +0,0 @@
-(.module:
- lux
- (lux [io]
- (control [monad #+ do]
- pipe)
- (data [product]
- [maybe]
- [number]
- text/format
- (coll [list "list/" Functor<List> Fold<List>]
- (dictionary ["dict" unordered #+ Dict])
- (set ["set" unordered])))
- (macro [code])
- ["r" math/random "r/" Monad<Random>]
- test)
- (luxc (lang ["la" analysis]
- ["ls" synthesis]
- (synthesis [".S" expression])
- [".L" extension]
- [".L" variable #+ Variable]))
- (// common))
-
-(def: gen-function//constant
- (r.Random [Nat la.Analysis la.Analysis])
- (r.rec
- (function (_ gen-function//constant)
- (do r.Monad<Random>
- [function? r.bool]
- (if function?
- (do @
- [[num-args outputA subA] gen-function//constant]
- (wrap [(n/inc num-args)
- outputA
- (` ("lux function" [] (~ subA)))]))
- (do @
- [outputA gen-primitive]
- (wrap [+0 outputA outputA])))))))
-
-(def: (pick scope-size)
- (-> Nat (r.Random Nat))
- (|> r.nat (:: r.Monad<Random> map (n/% scope-size))))
-
-(def: gen-function//captured
- (r.Random [Nat Int la.Analysis])
- (do r.Monad<Random>
- [num-locals (|> r.nat (:: @ map (|>> (n/% +100) (n/max +10))))
- #let [indices (list.n/range +0 (n/dec num-locals))
- absolute-env (list/map variableL.local indices)
- relative-env (list/map variableL.captured indices)]
- [total-args prediction bodyA] (: (r.Random [Nat Int la.Analysis])
- (loop [num-args +1
- global-env relative-env]
- (let [env-size (list.size global-env)
- resolver (list/fold (function (_ [idx var] resolver)
- (dict.put idx var resolver))
- (: (Dict Nat Int)
- (dict.new number.Hash<Nat>))
- (list.zip2 (list.n/range +0 (n/dec env-size))
- global-env))]
- (do @
- [nest? r.bool]
- (if nest?
- (do @
- [num-picks (:: @ map (n/max +1) (pick (n/inc env-size)))
- picks (|> (r.set number.Hash<Nat> num-picks (pick env-size))
- (:: @ map set.to-list))
- [total-args prediction bodyA] (recur (n/inc num-args)
- (list/map (function (_ pick) (maybe.assume (list.nth pick global-env)))
- picks))]
- (wrap [total-args prediction (` ("lux function" [(~+ (list/map (|>> variableL.captured code.int) picks))]
- (~ bodyA)))]))
- (do @
- [chosen (pick (list.size global-env))]
- (wrap [num-args
- (maybe.assume (dict.get chosen resolver))
- (la.var (variableL.captured chosen))])))))))]
- (wrap [total-args prediction (` ("lux function"
- [(~+ (list/map code.int absolute-env))]
- (~ bodyA)))])
- ))
-
-(def: gen-function//local
- (r.Random [Nat Int la.Analysis])
- (loop [num-args +0
- nest? true]
- (if nest?
- (do r.Monad<Random>
- [nest?' r.bool
- [total-args prediction bodyA] (recur (n/inc num-args) nest?')]
- (wrap [total-args prediction (` ("lux function" [] (~ bodyA)))]))
- (do r.Monad<Random>
- [chosen (|> r.nat (:: @ map (|>> (n/% +100) (n/max +2))))]
- (wrap [num-args
- (|> chosen (n/+ (n/dec num-args)) nat-to-int)
- (la.var (variableL.local chosen))])))))
-
-(context: "Function definition."
- (<| (times +100)
- (do @
- [[args1 prediction1 function1] gen-function//constant
- [args2 prediction2 function2] gen-function//captured
- [args3 prediction3 function3] gen-function//local]
- ($_ seq
- (test "Nested functions will get folded together."
- (|> (expressionS.synthesize extensionL.no-syntheses function1)
- (case> (^ [_ (#.Form (list [_ (#.Text "lux function")] [_ (#.Nat args)] [_ (#.Tuple captured)] output))])
- (and (n/= args1 args)
- (corresponds? prediction1 output))
-
- _
- (n/= +0 args1))))
- (test "Folded functions provide direct access to captured variables."
- (|> (expressionS.synthesize extensionL.no-syntheses function2)
- (case> (^ [_ (#.Form (list [_ (#.Text "lux function")] [_ (#.Nat args)] [_ (#.Tuple captured)]
- [_ (#.Form (list [_ (#.Int output)]))]))])
- (and (n/= args2 args)
- (i/= prediction2 output))
-
- _
- false)))
- (test "Folded functions properly offset local variables."
- (|> (expressionS.synthesize extensionL.no-syntheses function3)
- (case> (^ [_ (#.Form (list [_ (#.Text "lux function")] [_ (#.Nat args)] [_ (#.Tuple captured)]
- [_ (#.Form (list [_ (#.Int output)]))]))])
- (and (n/= args3 args)
- (i/= prediction3 output))
-
- _
- false)))
- ))))
-
-(context: "Function application."
- (<| (times +100)
- (do @
- [num-args (|> r.nat (:: @ map (|>> (n/% +10) (n/max +1))))
- funcA gen-primitive
- argsA (r.list num-args gen-primitive)]
- ($_ seq
- (test "Can synthesize function application."
- (|> (expressionS.synthesize extensionL.no-syntheses (la.apply argsA funcA))
- (case> (^ [_ (#.Form (list& [_ (#.Text "lux call")] funcS argsS))])
- (and (corresponds? funcA funcS)
- (list.every? (product.uncurry corresponds?)
- (list.zip2 argsA argsS)))
-
- _
- false)))
- (test "Function application on no arguments just synthesizes to the function itself."
- (|> (expressionS.synthesize extensionL.no-syntheses (la.apply (list) funcA))
- (corresponds? funcA)))
- ))))
diff --git a/new-luxc/test/test/luxc/lang/synthesis/primitive.lux b/new-luxc/test/test/luxc/lang/synthesis/primitive.lux
deleted file mode 100644
index d2298193f..000000000
--- a/new-luxc/test/test/luxc/lang/synthesis/primitive.lux
+++ /dev/null
@@ -1,46 +0,0 @@
-(.module:
- lux
- (lux [io]
- (control [monad #+ do]
- pipe)
- (data text/format)
- (macro [code])
- ["r" math/random]
- test)
- (luxc (lang ["la" analysis]
- ["ls" synthesis]
- [".L" extension]
- (synthesis [".S" expression]))))
-
-(context: "Primitives"
- (<| (times +100)
- (do @
- [%bool% r.bool
- %nat% r.nat
- %int% r.int
- %deg% r.deg
- %frac% r.frac
- %text% (r.text +5)]
- (`` ($_ seq
- (test (format "Can synthesize unit.")
- (|> (expressionS.synthesize extensionL.no-syntheses (' []))
- (case> (^code [])
- true
-
- _
- false)))
- (~~ (do-template [<desc> <analysis> <synthesis> <sample>]
- [(test (format "Can synthesize " <desc> ".")
- (|> (expressionS.synthesize extensionL.no-syntheses (<analysis> <sample>))
- (case> [_ (<synthesis> value)]
- (is? <sample> value)
-
- _
- false)))]
-
- ["bool" code.bool #.Bool %bool%]
- ["nat" code.nat #.Nat %nat%]
- ["int" code.int #.Int %int%]
- ["deg" code.deg #.Deg %deg%]
- ["frac" code.frac #.Frac %frac%]
- ["text" code.text #.Text %text%])))))))
diff --git a/new-luxc/test/test/luxc/lang/synthesis/structure.lux b/new-luxc/test/test/luxc/lang/synthesis/structure.lux
deleted file mode 100644
index 46c9bf2a1..000000000
--- a/new-luxc/test/test/luxc/lang/synthesis/structure.lux
+++ /dev/null
@@ -1,50 +0,0 @@
-(.module:
- lux
- (lux [io]
- (control [monad #+ do]
- pipe)
- (data [bool "B/" Eq<Bool>]
- [product]
- (coll [list]))
- ["r" math/random "r/" Monad<Random>]
- test)
- (luxc (lang ["la" analysis]
- ["ls" synthesis]
- (synthesis [".S" expression])
- [".L" extension]))
- (// common))
-
-(context: "Variants"
- (<| (times +100)
- (do @
- [size (|> r.nat (:: @ map (|>> (n/% +10) (n/max +2))))
- tagA (|> r.nat (:: @ map (n/% size)))
- memberA gen-primitive]
- ($_ seq
- (test "Can synthesize variants."
- (|> (expressionS.synthesize extensionL.no-syntheses (la.sum tagA size +0 memberA))
- (case> (^ [_ (#.Form (list [_ (#.Nat tagS)] [_ (#.Bool last?S)] memberS))])
- (and (n/= tagA tagS)
- (B/= (n/= (n/dec size) tagA)
- last?S)
- (corresponds? memberA memberS))
-
- _
- false)))
- ))))
-
-(context: "Tuples"
- (<| (times +100)
- (do @
- [size (|> r.nat (:: @ map (|>> (n/% +10) (n/max +2))))
- membersA (r.list size gen-primitive)]
- ($_ seq
- (test "Can synthesize tuple."
- (|> (expressionS.synthesize extensionL.no-syntheses (la.product membersA))
- (case> [_ (#.Tuple membersS)]
- (and (n/= size (list.size membersS))
- (list.every? (product.uncurry corresponds?) (list.zip2 membersA membersS)))
-
- _
- false)))
- ))))
diff --git a/new-luxc/test/test/luxc/lang/synthesis/case/special.lux b/stdlib/test/test/lux/lang/synthesis/case.lux
index 398f98a57..3ae62badc 100644
--- a/new-luxc/test/test/luxc/lang/synthesis/case/special.lux
+++ b/stdlib/test/test/lux/lang/synthesis/case.lux
@@ -7,7 +7,7 @@
["r" math/random "r/" Monad<Random>]
test)
(luxc (lang ["la" analysis]
- ["ls" synthesis]
+ ["//" synthesis #+ Synthesis]
(synthesis [".S" expression])
[".L" extension]
[".L" variable #+ Variable]))
@@ -22,8 +22,8 @@
{("lux case bind" (~ (code.nat temp)))
(~ (la.var (variableL.local temp)))}))]]
(test "Dummy variables created to mask expressions get eliminated during synthesis."
- (|> (expressionS.synthesize extensionL.no-syntheses
- maskA)
+ (|> (//.run (expressionS.synthesizer extensionL.no-syntheses
+ maskA))
(corresponds? maskedA))))))
(context: "Let expressions."
@@ -36,8 +36,8 @@
{("lux case bind" (~ (code.nat registerA)))
(~ outputA)}))]]
(test "Can detect and reify simple 'let' expressions."
- (|> (expressionS.synthesize extensionL.no-syntheses
- letA)
+ (|> (//.run (expressionS.synthesizer extensionL.no-syntheses
+ letA))
(case> (^ [_ (#.Form (list [_ (#.Text "lux let")] [_ (#.Nat registerS)] inputS outputS))])
(and (n/= registerA registerS)
(corresponds? inputA inputS)
@@ -61,8 +61,8 @@
{false (~ elseA)
true (~ thenA)})))]]
(test "Can detect and reify simple 'if' expressions."
- (|> (expressionS.synthesize extensionL.no-syntheses
- ifA)
+ (|> (//.run (expressionS.synthesizer extensionL.no-syntheses
+ ifA))
(case> (^ [_ (#.Form (list [_ (#.Text "lux if")] inputS thenS elseS))])
(and (corresponds? inputA inputS)
(corresponds? thenA thenS)