Skip to content

Commit

Permalink
JuvixTree recursors and transformation framework (#2594)
Browse files Browse the repository at this point in the history
* Generalizes JuvixCore map and fold recursors to work also for
JuvixTree.
* Adds a transformation framework to JuvixTree.
* Adds identity trasformation tests for JuvixTree.
* Depends on #2590 
* Depends on #2589 
* Depends on #2587
  • Loading branch information
lukaszcz authored Jan 29, 2024
1 parent 21a5568 commit a5bfba6
Show file tree
Hide file tree
Showing 66 changed files with 1,315 additions and 685 deletions.
2 changes: 1 addition & 1 deletion src/Juvix/Compiler/Asm/Translation/FromTree.hs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ genCode fi =
( Save
CmdSave
{ _cmdSaveInfo = emptyInfo,
_cmdSaveName = _nodeSaveName,
_cmdSaveName = _nodeSaveTempVarInfo ^. Tree.tempVarInfoName,
_cmdSaveIsTail = isTail,
_cmdSaveCode = DL.toList $ go isTail _nodeSaveBody
}
Expand Down
1 change: 0 additions & 1 deletion src/Juvix/Compiler/Backend/Geb/Translation/FromCore.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import Juvix.Compiler.Core.Data.InfoTable qualified as Core
import Juvix.Compiler.Core.Extra qualified as Core
import Juvix.Compiler.Core.Info.TypeInfo qualified as Info
import Juvix.Compiler.Core.Language (Index, Level, Symbol)
import Juvix.Compiler.Core.Language qualified as Core

data Env = Env
{ _envIdentMap :: HashMap Symbol Level,
Expand Down
1 change: 0 additions & 1 deletion src/Juvix/Compiler/Core/Data/IdentDependencyInfo.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import Data.HashSet qualified as HashSet
import Juvix.Compiler.Core.Data.InfoTable
import Juvix.Compiler.Core.Data.Module
import Juvix.Compiler.Core.Extra.Utils
import Juvix.Compiler.Core.Language

-- | Call graph type
type IdentDependencyInfo = DependencyInfo Symbol
Expand Down
85 changes: 61 additions & 24 deletions src/Juvix/Compiler/Core/Data/TransformationId.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module Juvix.Compiler.Core.Data.TransformationId where

import Juvix.Compiler.Core.Data.TransformationId.Base
import Juvix.Compiler.Core.Data.TransformationId.Strings
import Juvix.Prelude

data TransformationId
Expand Down Expand Up @@ -51,23 +53,7 @@ data PipelineId
| PipelineStripped
deriving stock (Data, Bounded, Enum)

data TransformationLikeId
= TransformationId TransformationId
| PipelineId PipelineId
deriving stock (Data)

allTransformationLikeIds :: [TransformationLikeId]
allTransformationLikeIds =
map TransformationId allElements
++ map PipelineId allElements

fromTransformationLike :: TransformationLikeId -> [TransformationId]
fromTransformationLike = \case
TransformationId i -> [i]
PipelineId p -> pipeline p

fromTransformationLikes :: [TransformationLikeId] -> [TransformationId]
fromTransformationLikes = concatMap fromTransformationLike
type TransformationLikeId = TransformationLikeId' TransformationId PipelineId

toTypecheckTransformations :: [TransformationId]
toTypecheckTransformations = [MatchToCase]
Expand All @@ -88,10 +74,61 @@ toStrippedTransformations =
toGebTransformations :: [TransformationId]
toGebTransformations = [CombineInfoTables, FilterUnreachable, CheckGeb, LetRecLifting, OptPhaseGeb, UnrollRecursion, FoldTypeSynonyms, ComputeTypeInfo]

pipeline :: PipelineId -> [TransformationId]
pipeline = \case
PipelineStored -> toStoredTransformations
PipelineNormalize -> toNormalizeTransformations
PipelineGeb -> toGebTransformations
PipelineVampIR -> toVampIRTransformations
PipelineStripped -> toStrippedTransformations
instance TransformationId' TransformationId where
transformationText :: TransformationId -> Text
transformationText = \case
LambdaLetRecLifting -> strLifting
LetRecLifting -> strLetRecLifting
TopEtaExpand -> strTopEtaExpand
MatchToCase -> strMatchToCase
NaiveMatchToCase -> strNaiveMatchToCase
EtaExpandApps -> strEtaExpandApps
Identity -> strIdentity
RemoveTypeArgs -> strRemoveTypeArgs
MoveApps -> strMoveApps
NatToPrimInt -> strNatToPrimInt
IntToPrimInt -> strIntToPrimInt
ConvertBuiltinTypes -> strConvertBuiltinTypes
ComputeTypeInfo -> strComputeTypeInfo
UnrollRecursion -> strUnrollRecursion
DisambiguateNames -> strDisambiguateNames
CombineInfoTables -> strCombineInfoTables
CheckGeb -> strCheckGeb
CheckExec -> strCheckExec
CheckVampIR -> strCheckVampIR
Normalize -> strNormalize
LetFolding -> strLetFolding
LambdaFolding -> strLambdaFolding
LetHoisting -> strLetHoisting
Inlining -> strInlining
MandatoryInlining -> strMandatoryInlining
FoldTypeSynonyms -> strFoldTypeSynonyms
CaseCallLifting -> strCaseCallLifting
SimplifyIfs -> strSimplifyIfs
SimplifyComparisons -> strSimplifyComparisons
SpecializeArgs -> strSpecializeArgs
CaseFolding -> strCaseFolding
CasePermutation -> strCasePermutation
FilterUnreachable -> strFilterUnreachable
OptPhaseEval -> strOptPhaseEval
OptPhaseExec -> strOptPhaseExec
OptPhaseGeb -> strOptPhaseGeb
OptPhaseVampIR -> strOptPhaseVampIR
OptPhaseMain -> strOptPhaseMain

instance PipelineId' TransformationId PipelineId where
pipelineText :: PipelineId -> Text
pipelineText = \case
PipelineStored -> strStoredPipeline
PipelineNormalize -> strNormalizePipeline
PipelineGeb -> strGebPipeline
PipelineVampIR -> strVampIRPipeline
PipelineStripped -> strStrippedPipeline

pipeline :: PipelineId -> [TransformationId]
pipeline = \case
PipelineStored -> toStoredTransformations
PipelineNormalize -> toNormalizeTransformations
PipelineGeb -> toGebTransformations
PipelineVampIR -> toVampIRTransformations
PipelineStripped -> toStrippedTransformations
32 changes: 32 additions & 0 deletions src/Juvix/Compiler/Core/Data/TransformationId/Base.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{-# LANGUAGE FunctionalDependencies #-}

module Juvix.Compiler.Core.Data.TransformationId.Base where

import Juvix.Prelude

class TransformationId' t where
transformationText :: t -> Text

class (Enum p, Enum t, Bounded p, Bounded t, TransformationId' t) => PipelineId' t p | p -> t where
pipelineText :: p -> Text
pipeline :: p -> [t]

data TransformationLikeId' t p
= TransformationId t
| PipelineId p
deriving stock (Data)

allTransformationLikeIds ::
(Bounded t, Bounded p, Enum t, Enum p) =>
[TransformationLikeId' t p]
allTransformationLikeIds =
map TransformationId allElements
++ map PipelineId allElements

fromTransformationLike :: (PipelineId' t p) => TransformationLikeId' t p -> [t]
fromTransformationLike = \case
TransformationId i -> [i]
PipelineId p -> pipeline p

fromTransformationLikes :: (PipelineId' t p) => [TransformationLikeId' t p] -> [t]
fromTransformationLikes = concatMap fromTransformationLike
Loading

0 comments on commit a5bfba6

Please sign in to comment.