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...
This commit is contained in:
hallgren
2011-08-30 20:20:45 +00:00
parent 0325f7264d
commit 42e2c68d8e

View File

@@ -23,13 +23,13 @@ module GF.Infra.Modules (
mGrammar,modules, mGrammar,modules,
extends, isInherited,inheritAll, extends, isInherited,inheritAll,
updateMGrammar, updateModule, replaceJudgements, addFlag, updateMGrammar, updateModule, replaceJudgements, addFlag,
addOpenQualif, flagsModule, allFlags, mapModules, addOpenQualif, flagsModule, allFlags,
OpenSpec(..), OpenSpec(..),
ModuleStatus(..), ModuleStatus(..),
openedModule, depPathModule, allDepsModule, partOfGrammar, openedModule, depPathModule, allDepsModule, partOfGrammar,
allExtends, allExtendSpecs, allExtendsPlus, allExtensions, allExtends, allExtendSpecs, allExtendsPlus, allExtensions,
searchPathModule, searchPathModule,
-- addModule, -- addModule, mapModules,
emptyMGrammar, emptyModInfo, emptyMGrammar, emptyModInfo,
abstractOfConcrete, abstractModOfConcrete, abstractOfConcrete, abstractModOfConcrete,
lookupModule, lookupModuleType, lookupInfo, lookupModule, lookupModuleType, lookupInfo,
@@ -51,16 +51,15 @@ import Text.PrettyPrint
-- The same structure will be used in both source code and canonical. -- The same structure will be used in both source code and canonical.
-- The parameters tell what kind of data is involved. -- The parameters tell what kind of data is involved.
-- No longer maintained invariant (TH 2011-08-30): -- Invariant: modules are stored in dependency order
-- modules are stored in dependency order
--mGrammar = MGrammar --mGrammar = MGrammar
--newtype MGrammar a = MGrammar {modules :: [(Ident,ModInfo a)]} --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 deriving Show
modules = Map.toList . moduleMap mGrammar ms = MGrammar (Map.fromList ms) ms
mGrammar = MGrammar . Map.fromList
data ModInfo a = ModInfo { data ModInfo a = ModInfo {
mtype :: ModuleType, mtype :: ModuleType,
@@ -126,11 +125,10 @@ flagsModule (_,mi) = flags mi
allFlags :: MGrammar a -> Options allFlags :: MGrammar a -> Options
allFlags gr = concatOptions [flags m | (_,m) <- modules gr] allFlags gr = concatOptions [flags m | (_,m) <- modules gr]
{-
mapModules :: (ModInfo a -> ModInfo a) -> MGrammar a -> MGrammar a mapModules :: (ModInfo a -> ModInfo a) -> MGrammar a -> MGrammar a
--mapModules f (MGrammar ms) = MGrammar (map (onSnd f) ms) mapModules f = mGrammar . map (onSnd f) . modules
mapModules f (MGrammar ms) = MGrammar (fmap f ms) -}
data OpenSpec = data OpenSpec =
OSimple Ident OSimple Ident
| OQualif Ident Ident | OQualif Ident Ident