You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Move pattern guards to CoreFn, and desugar them as part of codegen.
Motivation
backend-optimizer optimizes pattern-matching decision trees, but pattern guard desugaring commits too early to a particular control flow through it's CPS translation. If pattern guards were added to CoreFn, we would have more opportunity to analyze these cases and potentially add them to the existing matrix for additional sharing.
Proposal
Currently in CoreFn, a Guard for a case branch is an alias for Expr (ie, a single boolean expression).
-- A guard is just a boolean-valued expression that appears alongside a set of binders
--
typeGuarda=Expra
This could be changed to something like:
--|-- A guard may bind an expression, or implicitly guard against a boolean expression--typeGuarda= [(Maybe (Bindera), Expra)]
--|-- An alternative in a case statement--dataCaseAlternativea=CaseAlternative{--|-- A collection of binders with which to match the inputs--caseAlternativeBinders:: [Bindera]
--|-- The result expression or a collect of guarded expressions--
, caseAlternativeResult::Either [(Guarda, Expra)] (Expra)
}deriving (Eq, Ord, Show)
Alternatively, we could desugar all guards to a true <- ... pattern guard and ditch the Maybe.
The text was updated successfully, but these errors were encountered:
Currently, caseAlternativeResult is Either [(Guard a, Expr a)] (Expr a), where the left side covers boolExpr | rhs ; anotherBoolExpr | differentRhs .... How would that case be represented with this change?
I've reverted the change to caseAlternativeResult. CoreFn is a bit off in general in that it allows empty lists where there shouldn't be, so I think just changing Guard is fine.
Summary
Move pattern guards to CoreFn, and desugar them as part of codegen.
Motivation
backend-optimizer
optimizes pattern-matching decision trees, but pattern guard desugaring commits too early to a particular control flow through it's CPS translation. If pattern guards were added to CoreFn, we would have more opportunity to analyze these cases and potentially add them to the existing matrix for additional sharing.Proposal
Currently in CoreFn, a
Guard
for a case branch is an alias forExpr
(ie, a single boolean expression).purescript/src/Language/PureScript/CoreFn/Expr.hs
Lines 70 to 73 in 4afea2f
This could be changed to something like:
Alternatively, we could desugar all guards to a
true <- ...
pattern guard and ditch theMaybe
.The text was updated successfully, but these errors were encountered: