From ba10b5b0ca0c906b1b5c94f64b37b5a34f200f71 Mon Sep 17 00:00:00 2001 From: hallgren Date: Tue, 30 Aug 2011 18:54:50 +0000 Subject: GF.Infra.Modules: keep the modules of a grammar in a finite map instead of a list This speeds up the compilation of PhrasebookFin.pgf by 12%, mosly by speeding up calls to lookupModule in calls from lookupParamValues, in calls from allParamValues. The invariant "modules are stored in dependency order" is no longer respected! But the type MGrammar is now abstract, making it easier to maintain this or other invariants in the future. --- src/compiler/GF/Compile/GrammarToPGF.hs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'src/compiler/GF/Compile/GrammarToPGF.hs') diff --git a/src/compiler/GF/Compile/GrammarToPGF.hs b/src/compiler/GF/Compile/GrammarToPGF.hs index a6c7035d5..ed10697fd 100644 --- a/src/compiler/GF/Compile/GrammarToPGF.hs +++ b/src/compiler/GF/Compile/GrammarToPGF.hs @@ -44,10 +44,13 @@ mkCanon2pgf opts cnc gr = (canon2pgf opts gr . reorder abs) gr -- Generate PGF from grammar. -canon2pgf :: Options -> SourceGrammar -> SourceGrammar -> IO D.PGF -canon2pgf opts gr cgr@(M.MGrammar (am:cms)) = do +type AbsConcsGrammar = (IdModInfo,[IdModInfo]) -- (abstract,concretes) +type IdModInfo = (Ident,SourceModInfo) + +canon2pgf :: Options -> SourceGrammar -> AbsConcsGrammar -> IO D.PGF +canon2pgf opts gr (am,cms) = do if dump opts DumpCanon - then putStrLn (render (vcat (map (ppModule Qualified) (M.modules cgr)))) + then putStrLn (render (vcat (map (ppModule Qualified) (am:cms)))) else return () (an,abs) <- mkAbstr am cncs <- mapM (mkConcr am) cms @@ -148,12 +151,12 @@ compilePatt eqs = whilePP eqs Map.empty -- return just one module per language -reorder :: Ident -> SourceGrammar -> SourceGrammar +reorder :: Ident -> SourceGrammar -> AbsConcsGrammar reorder abs cg = - M.MGrammar $ - (abs, M.ModInfo M.MTAbstract M.MSComplete aflags [] Nothing [] [] adefs): +-- M.MGrammar $ + ((abs, M.ModInfo M.MTAbstract M.MSComplete aflags [] Nothing [] [] adefs), [(cnc, M.ModInfo (M.MTConcrete abs) M.MSComplete cflags [] Nothing [] [] cdefs) - | cnc <- M.allConcretes cg abs, let (cflags,cdefs) = concr cnc] + | cnc <- M.allConcretes cg abs, let (cflags,cdefs) = concr cnc]) where aflags = concatOptions (reverse [M.flags mo | (_,mo) <- M.modules cg, M.isModAbs mo]) -- cgit v1.2.3