Skip to content

Commit

Permalink
add transformation
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszcz committed Oct 30, 2024
1 parent 30750ac commit 18c71b6
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/Juvix/Compiler/Core/Data/TransformationId.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ data TransformationId
| UnrollRecursion
| ComputeTypeInfo
| ComputeCaseANF
| DetectConstantSideConditions
| DetectRedundantPatterns
| MatchToCase
| EtaExpandApps
Expand Down Expand Up @@ -59,10 +60,10 @@ data PipelineId
type TransformationLikeId = TransformationLikeId' TransformationId PipelineId

toTypecheckTransformations :: [TransformationId]
toTypecheckTransformations = [DetectRedundantPatterns, MatchToCase]
toTypecheckTransformations = [DetectConstantSideConditions, DetectRedundantPatterns, MatchToCase]

toStoredTransformations :: [TransformationId]
toStoredTransformations = [EtaExpandApps, DetectRedundantPatterns, MatchToCase, NatToPrimInt, IntToPrimInt, ConvertBuiltinTypes, OptPhaseEval, DisambiguateNames]
toStoredTransformations = [EtaExpandApps, DetectConstantSideConditions, DetectRedundantPatterns, MatchToCase, NatToPrimInt, IntToPrimInt, ConvertBuiltinTypes, OptPhaseEval, DisambiguateNames]

combineInfoTablesTransformations :: [TransformationId]
combineInfoTablesTransformations = [CombineInfoTables, FilterUnreachable]
Expand All @@ -84,6 +85,7 @@ instance TransformationId' TransformationId where
LambdaLetRecLifting -> strLifting
LetRecLifting -> strLetRecLifting
TopEtaExpand -> strTopEtaExpand
DetectConstantSideConditions -> strDetectConstantSideConditions
DetectRedundantPatterns -> strDetectRedundantPatterns
MatchToCase -> strMatchToCase
EtaExpandApps -> strEtaExpandApps
Expand Down
3 changes: 3 additions & 0 deletions src/Juvix/Compiler/Core/Data/TransformationId/Strings.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ strLetRecLifting = "letrec-lifting"
strTopEtaExpand :: Text
strTopEtaExpand = "top-eta-expand"

strDetectConstantSideConditions :: Text
strDetectConstantSideConditions = "detect-constant-side-conditions"

strDetectRedundantPatterns :: Text
strDetectRedundantPatterns = "detect-redundant-patterns"

Expand Down
2 changes: 2 additions & 0 deletions src/Juvix/Compiler/Core/Transformation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import Juvix.Compiler.Core.Transformation.CombineInfoTables (combineInfoTables)
import Juvix.Compiler.Core.Transformation.ComputeCaseANF
import Juvix.Compiler.Core.Transformation.ComputeTypeInfo
import Juvix.Compiler.Core.Transformation.ConvertBuiltinTypes
import Juvix.Compiler.Core.Transformation.DetectConstantSideConditions
import Juvix.Compiler.Core.Transformation.DetectRedundantPatterns
import Juvix.Compiler.Core.Transformation.DisambiguateNames
import Juvix.Compiler.Core.Transformation.Eta
Expand Down Expand Up @@ -76,6 +77,7 @@ applyTransformations ts tbl = foldM (flip appTrans) tbl ts
ComputeTypeInfo -> return . computeTypeInfo
ComputeCaseANF -> return . computeCaseANF
UnrollRecursion -> unrollRecursion
DetectConstantSideConditions -> return . detectConstantSideConditions
DetectRedundantPatterns -> mapError (JuvixError @CoreError) . detectRedundantPatterns
MatchToCase -> mapError (JuvixError @CoreError) . matchToCase
EtaExpandApps -> return . etaExpansionApps
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ goDetectRedundantPatterns md node = case node of
unless (check matrix row) $
throw
CoreError
{ _coreErrorMsg = ppOutput ("Redundant pattern" <> seq <> ": " <> pat),
{ _coreErrorMsg = ppOutput ("Redundant pattern" <> seq <> ": " <> pat <> "\nPerhaps you mistyped a constructor name in an earlier pattern?"),
_coreErrorNode = Nothing,
_coreErrorLoc = fromMaybe defaultLoc (getInfoLocation _matchBranchInfo)
}
Expand Down
1 change: 0 additions & 1 deletion tests/Compilation/negative/test001.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,3 @@ f : List Nat -> List Nat -> Nat
| _ nil := 0;

main : Nat := f (1 :: nil) (2 :: nil);

0 comments on commit 18c71b6

Please sign in to comment.