Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Transform.Simplify
Synopsis
- basic ∷ Term Name DefaultUni DefaultFun ()
- nested ∷ Term Name DefaultUni DefaultFun ()
- extraDelays ∷ Term Name DefaultUni DefaultFun ()
- interveningLambda ∷ Term Name DefaultUni DefaultFun ()
- caseOfCase1 ∷ Term Name DefaultUni DefaultFun ()
- caseOfCase2 ∷ Term Name DefaultUni DefaultFun ()
- caseOfCase3 ∷ Term Name DefaultUni DefaultFun ()
- floatDelay1 ∷ Term Name DefaultUni DefaultFun ()
- floatDelay2 ∷ Term Name DefaultUni DefaultFun ()
- floatDelay3 ∷ Term Name DefaultUni DefaultFun ()
- basicInline ∷ Term Name DefaultUni DefaultFun ()
- mkInlinePurityTest ∷ Quote ([Name], Term Name DefaultUni DefaultFun ()) → Term Name DefaultUni DefaultFun ()
- inlinePure1 ∷ Term Name DefaultUni DefaultFun ()
- inlinePure2 ∷ Term Name DefaultUni DefaultFun ()
- inlinePure3 ∷ Term Name DefaultUni DefaultFun ()
- inlinePure4 ∷ Term Name DefaultUni DefaultFun ()
- inlineImpure1 ∷ Term Name DefaultUni DefaultFun ()
- inlineImpure2 ∷ Term Name DefaultUni DefaultFun ()
- inlineImpure3 ∷ Term Name DefaultUni DefaultFun ()
- inlineImpure4 ∷ Term Name DefaultUni DefaultFun ()
- callsiteInline ∷ Term Name DefaultUni DefaultFun ()
- multiApp ∷ Term Name DefaultUni DefaultFun ()
- forceDelayNoApps ∷ Term Name DefaultUni DefaultFun ()
- forceDelayNoAppsLayered ∷ Term Name DefaultUni DefaultFun ()
- forceDelaySimple ∷ Term Name DefaultUni DefaultFun ()
- forceDelayMultiApply ∷ Term Name DefaultUni DefaultFun ()
- forceDelayMultiForce ∷ Term Name DefaultUni DefaultFun ()
- forceDelayComplex ∷ Term Name DefaultUni DefaultFun ()
- cse1 ∷ Term Name DefaultUni DefaultFun ()
- cse2 ∷ Term Name DefaultUni DefaultFun ()
- cse3 ∷ Term Name DefaultUni DefaultFun ()
- cseExpensive ∷ Term Name DefaultUni DefaultFun ()
- testSimplifyInputs ∷ [(String, Term Name DefaultUni DefaultFun ())]
- testCseInputs ∷ [(String, Term Name DefaultUni DefaultFun ())]
- test_simplify ∷ TestTree
Documentation
basic ∷ Term Name DefaultUni DefaultFun () Source #
nested ∷ Term Name DefaultUni DefaultFun () Source #
caseOfCase2 ∷ Term Name DefaultUni DefaultFun () Source #
This should not simplify, because one of the branches of ifThenElse
is not a Constr
.
Unless both branches are known constructors, the case-of-case transformation
may increase the program size.
caseOfCase3 ∷ Term Name DefaultUni DefaultFun () Source #
Similar to caseOfCase1
, but the type of the true
and false
branches is
[Integer]
rather than Bool (note that Constr 0
has two parameters, x
and xs
).
floatDelay1 ∷ Term Name DefaultUni DefaultFun () Source #
The Delay
should be floated into the lambda.
floatDelay2 ∷ Term Name DefaultUni DefaultFun () Source #
The Delay
should not be floated into the lambda, because the argument (1 + 2)
is not work-free.
mkInlinePurityTest ∷ Quote ([Name], Term Name DefaultUni DefaultFun ()) → Term Name DefaultUni DefaultFun () Source #
A helper function to create a term which tests whether the inliner
behaves as expected for a given pure or impure term. It receives
a Quote
that produces a term together with a list of free variables.
The free variables are bound at the top level of the final term in order
to ensure that the produced final term is well-scoped.
inlinePure1 ∷ Term Name DefaultUni DefaultFun () Source #
A single Var
is pure.
inlinePure2 ∷ Term Name DefaultUni DefaultFun () Source #
force (delay a)
is pure.
Note that this relies on forceDelayCancel
to cancel the force
and the delay
,
otherwise the inliner would treat the term as impure.
inlinePure3 ∷ Term Name DefaultUni DefaultFun () Source #
[(x -> y -> [x x]) (con integer 1)]
is pure.
Note that the (con integer 1)
won't get inlined: it isn't pre-inlined because
x
occurs twice, and it isn't post-inlined because costIsAcceptable Constant{} = False
.
However, the entire term will be inlined since it is pure.
inlinePure4 ∷ Term Name DefaultUni DefaultFun () Source #
force ([(x -> delay (y -> [x x])) (delay ([error (con integer 1)]))])
is pure,
but it is very tricky to see so. It requires us to match up a force and a
delay through several steps of intervening computation.
inlineImpure1 ∷ Term Name DefaultUni DefaultFun () Source #
error
is impure.
inlineImpure2 ∷ Term Name DefaultUni DefaultFun () Source #
force (delay error)
is impure.
inlineImpure3 ∷ Term Name DefaultUni DefaultFun () Source #
force (force (force (delay (delay (delay (error))))))
is impure, since it
is the same as error
.
inlineImpure4 ∷ Term Name DefaultUni DefaultFun () Source #
force (force (force (delay (delay a))))
is impure, since a
may expand
to an impure term such as error
.
callsiteInline ∷ Term Name DefaultUni DefaultFun () Source #
(a -> f (a 0 1) (a 2)) (x y -> g x y)
The first occurrence of a
should be inlined because doing so does not increase
the size or the cost.
The second occurrence of a
should be unconditionally inlined in the second simplifier
iteration, but in this test we are only running one iteration.
multiApp ∷ Term Name DefaultUni DefaultFun () Source #
forceDelaySimple ∷ Term Name DefaultUni DefaultFun () Source #
The UPLC term in this test should come from the following TPLC term after erasing its types:
(/\(p :: *) -> \(x : p) -> /\(q :: *) -> \(y : q) -> /\(r :: *) -> \(z : r) -> z) Int 1 Int 2 Int 3
This case is simple in the sense that each type abstraction is followed by a single term abstraction.
forceDelayMultiForce ∷ Term Name DefaultUni DefaultFun () Source #
A test for the case when there are multiple type abstractions over a single term abstraction/application.
forceDelayComplex ∷ Term Name DefaultUni DefaultFun () Source #
The UPLC term in this test should come from the following TPLC term after erasing its types:
(/\(p1 :: *) (p2 :: *) -> \(x : p2) -> /\(q1 :: *) (q2 :: *) (q3 :: *) -> \(y1 : q1) (y2 : q2) (y3 : String) -> /\(r :: *) -> \(z1 : r) -> \(z2 : r) -> /\(t :: *) -> \(f : p1 -> q1 -> q2 -> String -> r -> r -> String) -> f x y1 y2 y3 z1 z2 ) Int Int 1 Int String Int 2 "foo" "bar" Int 3 3 ByteString (funcVar : Int -> Int -> String -> String -> Int -> String)
Note this term has multiple interleaved type and term instantiations/applications.
cse1 ∷ Term Name DefaultUni DefaultFun () Source #
This is the first example in Note [CSE].
cse2 ∷ Term Name DefaultUni DefaultFun () Source #
This is the second example in Note [CSE].
cse3 ∷ Term Name DefaultUni DefaultFun () Source #
This is the third example in Note [CSE].
testSimplifyInputs ∷ [(String, Term Name DefaultUni DefaultFun ())] Source #
testCseInputs ∷ [(String, Term Name DefaultUni DefaultFun ())] Source #