Fixed the Rain passes so that the order correctly satisfies the pre-requisites

This commit is contained in:
Neil Brown 2008-05-21 12:46:51 +00:00
parent 4537cd205c
commit 9f411bfd45
3 changed files with 20 additions and 11 deletions

View File

@ -31,6 +31,7 @@ import Errors
import Pass
import qualified Properties as Prop
import RainTypes
import SimplifyTypes
import TreeUtils
import Types
@ -38,22 +39,24 @@ import Types
-- | An ordered list of the Rain-specific passes to be run.
rainPasses :: [Pass]
rainPasses = makePassesDep' ((== FrontendRain) . csFrontend)
rainPasses = let f = makePassesDep' ((== FrontendRain) . csFrontend) in f
[ ("AST Validity check, Rain #1", excludeNonRainFeatures, [], []) -- TODO work out some dependencies
,("Dummy Rain pass", return, [], [Prop.retypesChecked])
,("Resolve Int -> Int64", transformInt, [], [Prop.noInt])
,("Uniquify variable declarations, record declared types and resolve variable names",
uniquifyAndResolveVars, [Prop.noInt], Prop.agg_namesDone \\ [Prop.inferredTypesRecorded])
,("Fold all constant expressions", constantFoldPass, [Prop.noInt] ++ Prop.agg_namesDone
++ Prop.agg_typesDone, [Prop.constantsFolded, Prop.constantsChecked])
,("Rain Type Checking", performTypeUnification, [Prop.noInt] ++ Prop.agg_namesDone,
Prop.agg_typesDone)
,("Record inferred name types in dictionary", recordInfNameTypes,
Prop.agg_namesDone \\ [Prop.inferredTypesRecorded], [Prop.inferredTypesRecorded])
,("Find and tag the main function", findMain, Prop.agg_namesDone, [Prop.mainTagged])
,("Rain Type Checking", performTypeUnification, [Prop.noInt] ++ Prop.agg_namesDone,
[Prop.expressionTypesChecked, Prop.functionTypesChecked, Prop.processTypesChecked,
Prop.retypesChecked])
,("Fold all constant expressions", constantFoldPass, [Prop.noInt] ++ Prop.agg_namesDone
++ [Prop.inferredTypesRecorded], [Prop.constantsFolded, Prop.constantsChecked])
] ++ enablePassesWhen ((== FrontendRain) . csFrontend) simplifyTypes ++ f [
("Find and tag the main function", findMain, Prop.agg_namesDone, [Prop.mainTagged])
,("Convert seqeach/pareach loops over ranges into simple replicated SEQ/PAR",
transformEachRange, Prop.agg_typesDone ++ [Prop.constantsFolded], [Prop.eachRangeTransformed])
,("Pull up foreach-expressions", pullUpForEach,

View File

@ -105,6 +105,10 @@ makePassesDep = map (\(s, p, pre, post) -> Pass p s (Set.fromList pre) (Set.from
makePassesDep' :: (CompState -> Bool) -> [(String, A.AST -> PassM A.AST, [Property], [Property])] -> [Pass]
makePassesDep' f = map (\(s, p, pre, post) -> Pass p s (Set.fromList pre) (Set.fromList post) f)
enablePassesWhen :: (CompState -> Bool) -> [Pass] -> [Pass]
enablePassesWhen f = map (\p -> p
{passEnabled = \c -> f c && (passEnabled p c)})
-- | Compose a list of passes into a single pass by running them in the order given.
runPasses :: [Pass] -> (A.AST -> PassM A.AST)
runPasses [] ast = return ast

View File

@ -43,7 +43,8 @@ import Utils
commonPasses :: CompState -> [Pass]
commonPasses opts = concat $
[ simplifyTypes
-- Rain does simplifyTypes separately:
[ enablePassesWhen ((== FrontendOccam) . csFrontend) simplifyTypes
, makePassesDep' csUsageChecking [("Usage checking", runPassR usageCheckPass, Prop.agg_namesDone, [Prop.parUsageChecked])]
-- If usage checking is turned off, the pass list will break unless we insert this dummy item:
, makePassesDep' (not . csUsageChecking) [("Usage checking turned OFF", return, Prop.agg_namesDone, [Prop.parUsageChecked])]
@ -86,8 +87,9 @@ checkList passes = case check [] passes of
check :: [Pass] -> [Pass] -> Either String [Pass]
check prev [] = Right prev
check prev (p:ps)
= case filter givesPrereq ps of
-- Check that our pre-requisites are not supplied by a later pass:
= case filter givesPrereq (p:ps) of
-- Check that our pre-requisites are not supplied by a later pass
-- or supplied by the pass that needs them:
(x:_) ->
Left $ "Pass order not correct; one of the pre-requisites"
++ " for pass: " ++ (passName p) ++ " is supplied in a later"