From 42e2c68d8e2311119926de4cd6fb005b8a104655 Mon Sep 17 00:00:00 2001 From: hallgren Date: Tue, 30 Aug 2011 20:20:45 +0000 Subject: [PATCH] GF.Infra.Modules: restore module dependency order invariant It is needed by greatestResource (and similar functions, presumably). So keep both the list and the finite map of modules. This slows down some things, but the compilation of PhrasebookFin.pgf benefits from it. To be continued... --- src/compiler/GF/Infra/Modules.hs | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/compiler/GF/Infra/Modules.hs b/src/compiler/GF/Infra/Modules.hs index 8c54ddf30..05d18a33e 100644 --- a/src/compiler/GF/Infra/Modules.hs +++ b/src/compiler/GF/Infra/Modules.hs @@ -23,13 +23,13 @@ module GF.Infra.Modules ( mGrammar,modules, extends, isInherited,inheritAll, updateMGrammar, updateModule, replaceJudgements, addFlag, - addOpenQualif, flagsModule, allFlags, mapModules, + addOpenQualif, flagsModule, allFlags, OpenSpec(..), ModuleStatus(..), openedModule, depPathModule, allDepsModule, partOfGrammar, allExtends, allExtendSpecs, allExtendsPlus, allExtensions, searchPathModule, - -- addModule, + -- addModule, mapModules, emptyMGrammar, emptyModInfo, abstractOfConcrete, abstractModOfConcrete, lookupModule, lookupModuleType, lookupInfo, @@ -51,16 +51,15 @@ import Text.PrettyPrint -- The same structure will be used in both source code and canonical. -- The parameters tell what kind of data is involved. --- No longer maintained invariant (TH 2011-08-30): --- modules are stored in dependency order +-- Invariant: modules are stored in dependency order --mGrammar = MGrammar --newtype MGrammar a = MGrammar {modules :: [(Ident,ModInfo a)]} -newtype MGrammar a = MGrammar {moduleMap :: Map.Map Ident (ModInfo a)} +data MGrammar a = MGrammar {moduleMap :: Map.Map Ident (ModInfo a), + modules :: [(Ident,ModInfo a)] } deriving Show -modules = Map.toList . moduleMap -mGrammar = MGrammar . Map.fromList +mGrammar ms = MGrammar (Map.fromList ms) ms data ModInfo a = ModInfo { mtype :: ModuleType, @@ -126,11 +125,10 @@ flagsModule (_,mi) = flags mi allFlags :: MGrammar a -> Options allFlags gr = concatOptions [flags m | (_,m) <- modules gr] - +{- mapModules :: (ModInfo a -> ModInfo a) -> MGrammar a -> MGrammar a ---mapModules f (MGrammar ms) = MGrammar (map (onSnd f) ms) -mapModules f (MGrammar ms) = MGrammar (fmap f ms) - +mapModules f = mGrammar . map (onSnd f) . modules +-} data OpenSpec = OSimple Ident | OQualif Ident Ident