Skip to content

Commit

Permalink
Added special optimizations for pattern matching on I64, Decimal & Text.
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardoejp committed Jan 26, 2024
1 parent 68bccd4 commit f53ef96
Show file tree
Hide file tree
Showing 48 changed files with 1,158 additions and 707 deletions.
4 changes: 2 additions & 2 deletions stdlib/source/library/lux/control/scope.lux
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@
(function (_ env)
(mma env env)))))

(every .public (With ! context of)
(every .public (With context ! of)
(Scope context (! of)))

(the .public (with monad)
(for_any (_ !)
(-> (Monad !)
(for_any (_ context)
(Monad (With ! context)))))
(Monad (With context !)))))
(implementation
(the (functor it)
(|> it
Expand Down
12 changes: 6 additions & 6 deletions stdlib/source/library/lux/control/state.lux
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,14 @@
[_ body]
(while condition body)))

(every .public (With ! state of)
(every .public (With state ! of)
(-> state
(! [state of])))

(the (with//functor functor)
(for_any (_ ! state)
(-> (Functor !)
(Functor (With ! state))))
(Functor (With state !))))
(implementation
(the (each f sfa)
(function (_ state)
Expand All @@ -127,7 +127,7 @@
(the (with//apply monad)
(for_any (_ ! state)
(-> (Monad !)
(Apply (With ! state))))
(Apply (With state !))))
(implementation
(the functor (with//functor (of monad functor)))

Expand All @@ -140,14 +140,14 @@

(the .public (value' state action)
(for_any (_ ! state of)
(-> state (With ! state of)
(-> state (With state ! of)
(! [state of])))
(action state))

(the .public (with monad)
(for_any (_ ! state)
(-> (Monad !)
(Monad (With ! state))))
(Monad (With state !))))
(implementation
(the functor (with//functor (of monad functor)))

Expand All @@ -164,7 +164,7 @@
(the .public (lifted monad ma)
(for_any (_ ! state of)
(-> (Monad !) (! of)
(With ! state of)))
(With state ! of)))
(function (_ state)
(do monad
[a ma]
Expand Down
4 changes: 2 additions & 2 deletions stdlib/source/library/lux/control/writer.lux
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@
(let [[trace0 [trace1 a]] mma]
[(of monoid composite trace0 trace1) a]))))

(every .public (With ! trace of)
(every .public (With trace ! of)
(! (Writer trace of)))

(the .public (with monoid monad)
(for_any (_ ! trace)
(-> (Monoid trace) (Monad !)
(Monad (With ! trace))))
(Monad (With trace !))))
(implementation
(the (functor it)
(|> it
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
[archive (.only Archive)]]])

(every .public (Operation state of)
(state.With Try state of))
(state.With state Try of))

(the .public functor
(for_any (_ state)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,22 +136,27 @@
[synthesis.#Extension]))

(synthesis.when @ it)
(when (synthesis.multi_let it)
{.#Some it}
(//when.multi_let! statement expression archive it)

_
(//when.when! statement expression archive it))
(<| (,, (template.with [,synthesis ,translation]
[(when (,synthesis it)
{.#Some it}
(,translation statement expression archive it)

else)]

[synthesis.if //when.if!]
[synthesis.when_i64 //when.when_i64!]
[synthesis.when_f64 //when.when_f64!]
[synthesis.when_text //when.when_text!]
[synthesis.multi_let //when.multi_let!]
))
(//when.when! statement expression archive it))

(synthesis.exec @ it)
(//when.exec! statement expression archive it)

(synthesis.let @ let)
(//when.let! statement expression archive let)

(synthesis.if @ if)
(//when.if! statement expression archive if)

(synthesis.scope @ scope)
(//loop.scope! statement expression archive scope)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -935,11 +935,6 @@
{synthesis.#Let [(-- register) (without_fake_parameter value)]
(without_fake_parameter body)}

{synthesis.#If when then else}
{synthesis.#If (without_fake_parameter when)
(without_fake_parameter then)
(without_fake_parameter else)}

{synthesis.#Its members record}
{synthesis.#Its members
(without_fake_parameter record)}
Expand Down Expand Up @@ -1080,9 +1075,6 @@
(synthesis.let @ [[register inputS] outputS])
(synthesis.let @ [[register (again inputS)] (again outputS)])

(synthesis.if @ [testS thenS elseS])
(synthesis.if @ [(again testS) (again thenS) (again elseS)])

(synthesis.its @ [path recordS])
(synthesis.its @ [path (again recordS)])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,22 +90,27 @@
[synthesis.#Extension]))

(synthesis.when @ it)
(when (synthesis.multi_let it)
{.#Some it}
(//when.multi_let! statement expression archive it)

_
(//when.when! statement expression archive it))
(<| (,, (template.with [,synthesis ,translation]
[(when (,synthesis it)
{.#Some it}
(,translation statement expression archive it)

else)]

[synthesis.if //when.if!]
[synthesis.when_i64 //when.when_i64!]
[synthesis.when_f64 //when.when_f64!]
[synthesis.when_text //when.when_text!]
[synthesis.multi_let //when.multi_let!]
))
(//when.when! statement expression archive it))

(synthesis.exec @ it)
(//when.exec! statement expression archive it)

(synthesis.let @ let)
(//when.let! statement expression archive let)

(synthesis.if @ if)
(//when.if! statement expression archive if)

(synthesis.scope @ scope)
(do phase.monad
[[inits scope!] (//loop.scope! statement expression archive false scope)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,20 +88,27 @@
[synthesis.#Extension]))

(synthesis.when @ it)
(when (synthesis.multi_let it)
{.#Some it}
(//when.multi_let! statement expression archive it)

_
(//when.when! false statement expression archive it))
(<| (,, (template.with [,synthesis ,translation]
[(when (,synthesis it)
{.#Some it}
(,translation statement expression archive it)

else)]

[synthesis.if //when.if!]
[synthesis.when_i64 //when.when_i64!]
[synthesis.when_f64 //when.when_f64!]
[synthesis.when_text //when.when_text!]
[synthesis.multi_let //when.multi_let!]
))
(//when.when! false statement expression archive it))

(,, (template.with [<tag> <translator>]
[(<tag> @ value)
(<translator> statement expression archive value)]

[synthesis.exec //when.exec!]
[synthesis.let //when.let!]
[synthesis.if //when.if!]
[synthesis.scope //loop.scope!]
[synthesis.again //loop.again!]))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,20 +91,27 @@
[synthesis.#Extension]))

(synthesis.when @ it)
(when (synthesis.multi_let it)
{.#Some it}
(//when.multi_let! statement expression archive it)

_
(//when.when! false statement expression archive it))
(<| (,, (template.with [,synthesis ,translation]
[(when (,synthesis it)
{.#Some it}
(,translation statement expression archive it)

else)]

[synthesis.if //when.if!]
[synthesis.when_i64 //when.when_i64!]
[synthesis.when_f64 //when.when_f64!]
[synthesis.when_text //when.when_text!]
[synthesis.multi_let //when.multi_let!]
))
(//when.when! false statement expression archive it))

(,, (template.with [<tag> <translator>]
[(<tag> @ value)
(<translator> statement expression archive value)]

[synthesis.exec //when.exec!]
[synthesis.let //when.let!]
[synthesis.if //when.if!]
[synthesis.scope //loop.scope!]
[synthesis.again //loop.again!]))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,6 @@
[inputS' (grow environment inputS)
bodyS' (grow environment bodyS)]
(in (/.let @ [[(++ register) inputS'] bodyS'])))

{/.#If [testS thenS elseS]}
(do phase.monad
[testS' (grow environment testS)
thenS' (grow environment thenS)
elseS' (grow environment elseS)]
(in (/.if @ [testS' thenS' elseS'])))

{/.#Its members inputS}
(phase#each (|>> [members] (/.its @))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,6 @@
body' (again return? body)]
(in (/.let @ [[(register_optimization offset register) input'] body'])))

(/.if @ [input then else])
(do maybe.monad
[input' (again false input)
then' (again return? then)
else' (again return? else)]
(in (/.if @ [input' then' else'])))

(/.its @ [path record])
(do maybe.monad
[record (again false record)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,6 @@
(again input)]
(again output)}

{/.#If test then else}
{/.#If (again test) (again then) (again else)}

{/.#Its path record}
{/.#Its path (again record)}

Expand Down Expand Up @@ -404,14 +401,6 @@
{/.#Exec input (..remove_local register output)}
{/.#Let [register input] output})}}]]))

{/.#If test then else}
(do try.monad
[[redundancy test] (optimization' [redundancy test])
[redundancy then] (optimization' [redundancy then])
[redundancy else] (optimization' [redundancy else])]
(in [redundancy
[@ {/.#Control {/.#Branch {/.#If test then else}}}]]))

{/.#Its path record}
(do try.monad
[[redundancy record] (optimization' [redundancy record])]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@
{<to> [(<conversion> test) then] (list)})
thenC)]

[///simple.#Natural /.#I64_Fork .i64]
[///simple.#Integer /.#I64_Fork .i64]
[///simple.#Revolution /.#I64_Fork .i64]
[///simple.#Natural /.#I64_Fork .i64]
[///simple.#Integer /.#I64_Fork .i64]
[///simple.#Revolution /.#I64_Fork .i64]
[///simple.#Decimal /.#F64_Fork |>]
[///simple.#Text /.#Text_Fork |>]))))

Expand Down Expand Up @@ -291,14 +291,6 @@
(phase#in input)
(..synthesize_let synthesize @ archive input @variable [@ {analysis.#Reference (///reference.local @output)}])))

(the .public (synthesize_if synthesize @ archive test then else)
(-> Phase Location Archive /.Term analysis.Term analysis.Term
(Operation /.Term))
(do phase.monad
[then (synthesize archive then)
else (synthesize archive else)]
(in (/.if @ [test then else]))))

(the !get
(template.macro (_ <@> <patterns> <output>)
[[[(///pattern.tuple <patterns>)
Expand Down Expand Up @@ -344,17 +336,6 @@
{.#End}]
(..synthesize_let synthesize^ @ archive inputS @variable body)

(^.or [[(///pattern.bit .true) then]
(list [(///pattern.bit .false) else])]
[[(///pattern.bit .true) then]
(list [(///pattern.unit) else])]

[[(///pattern.bit .false) else]
(list [(///pattern.bit .true) then])]
[[(///pattern.bit .false) else]
(list [(///pattern.unit) then])])
(..synthesize_if synthesize^ @ archive inputS then else)

(!get @ patterns @member)
(..synthesize_the synthesize^ @ archive inputS patterns @member)

Expand Down Expand Up @@ -469,9 +450,6 @@
(its #dependencies)))
(for_synthesis inputS synthesis_storage))

(/.if @ [testS thenS elseS])
(list#mix for_synthesis synthesis_storage (list testS thenS elseS))

(/.its @ [access whole])
(for_synthesis whole synthesis_storage)

Expand Down
Loading

0 comments on commit f53ef96

Please sign in to comment.