Verified Commit 56b15eb7 authored by Camil Staps's avatar Camil Staps

Use {#Index} instead of [Index] (depends on clean-and-itasks/clean-platform!234)

parent b5525a59
......@@ -32,19 +32,19 @@ NGRAMS_CI :== True
*/
:: *CloogleDB =
{ db :: !*NativeDB CloogleEntry Annotation //* Core data
, name_ngrams :: !NGramIndex Index //* Name ngrams
, name_map :: !Map Name [Index] //* For exact name search
, types :: !TypeTree Index //* Types, map to FunctionEntries
, core :: ![Index] //* Entries in core modules
, apps :: ![Index] //* Entries in app modules
, builtins :: ![Index] //* Entries in Clean core
, syntax :: ![Index] //* SyntaxEntries
, abc_instrs :: ![Index] //* ABCInstructionEntries
, library_map :: !Map Name [Index] //* Entries by library name
, module_map :: !Map Name [Index] //* Entries by module name
, derive_map :: !Map Name [Index] //* DeriveEntries by generic name
, instance_map :: !Map Name [Index] //* InstanceEntries by class name
, always_unique :: !Map Name () //* Types that are always unique, like World
, name_ngrams :: !NGramIndex Index //* Name ngrams
, name_map :: !Map Name {#Index} //* For exact name search
, types :: !TypeTree Index //* Types, map to FunctionEntries
, core :: !{#Index} //* Entries in core modules
, apps :: !{#Index} //* Entries in app modules
, builtins :: !{#Index} //* Entries in Clean core
, syntax :: !{#Index} //* SyntaxEntries
, abc_instrs :: !{#Index} //* ABCInstructionEntries
, library_map :: !Map Name {#Index} //* Entries by library name
, module_map :: !Map Name {#Index} //* Entries by module name
, derive_map :: !Map Name {#Index} //* DeriveEntries by generic name
, instance_map :: !Map Name {#Index} //* InstanceEntries by class name
, always_unique :: !Map Name () //* Types that are always unique, like World
}
/**
......@@ -119,8 +119,8 @@ location :: !Library !String !FilePath !LineNr !LineNr !Name -> Location
, fe_documentation :: !Maybe FunctionDoc //* Documentation on this entry
, fe_typedef :: !Maybe Index //* The TypeDefEntry for constructors/record fields
, fe_class :: !Maybe Index //* The class, for class members
, fe_derivations :: !Maybe [Index] //* The DerivaionEntries
, fe_usages :: ![Index] //* FunctionEntries where the implementation uses this function
, fe_derivations :: !Maybe {#Index} //* The DerivaionEntries
, fe_usages :: !{#Index} //* FunctionEntries where the implementation uses this function
}
/**
......@@ -130,9 +130,9 @@ location :: !Library !String !FilePath !LineNr !LineNr !Name -> Location
= { tde_loc :: !Location //* The location
, tde_typedef :: !TypeDef //* The TypeDef
, tde_doc :: !Maybe TypeDoc //* Documentation on the TypeDef
, tde_instances :: ![Index] //* Instances of this type
, tde_derivations :: ![Index] //* Derivations of this type
, tde_usages :: ![Index] //* FunctionEntries using the type
, tde_instances :: !{#Index} //* Instances of this type
, tde_derivations :: !{#Index} //* Derivations of this type
, tde_usages :: !{#Index} //* FunctionEntries using the type
}
/**
......@@ -143,7 +143,7 @@ location :: !Library !String !FilePath !LineNr !LineNr !Name -> Location
, me_is_core :: !Bool //* Whether this is a core module (e.g. the os* modules in ObjectIO and TCPIP)
, me_is_app :: !Bool //* Whether this module is not actually a library but an app
, me_documentation :: !Maybe ModuleDoc //* Documentation on this module
, me_usages :: ![Index] //* Modules importing this module
, me_usages :: !{#Index} //* Modules importing this module
}
/**
......@@ -156,10 +156,10 @@ location :: !Library !String !FilePath !LineNr !LineNr !Name -> Location
, ce_is_meta :: !Bool //* Whether this is a meta class (no non-macro members and not TC)
, ce_context :: !TypeContext //* A class context
, ce_documentation :: !Maybe ClassDoc //* Documentation on this class
, ce_members :: [Index] //* Class members (FunctionEntries; must be lazy for CloogleDBFactory to work)
, ce_instances :: ![Index] //* All instances of the class
, ce_derivations :: ![Index] //* Derivations of generic meta-classes like iTask
, ce_usages :: ![Index] //* FunctionEntries, TypeDefEntries and ClassEntries using this class
, ce_members :: !{#Index} //* Class members (FunctionEntries; must be lazy for CloogleDBFactory to work)
, ce_instances :: !{#Index} //* All instances of the class
, ce_derivations :: !{#Index} //* Derivations of generic meta-classes like iTask
, ce_usages :: !{#Index} //* FunctionEntries, TypeDefEntries and ClassEntries using this class
}
/**
......
......@@ -49,6 +49,12 @@ import Clean.Doc
import Cloogle.API
:: IndexArray :== {#Index}
JSONEncode{|IndexArray|} infield xs = JSONEncode{|*|} infield [x \\ x <-: xs]
JSONDecode{|IndexArray|} infield json = case JSONDecode{|*|} infield json of
(Just xs,json) -> (Just {#x \\ x <- xs},json)
(Nothing,json) -> (Nothing,json)
derive JSONEncode ClassDoc, ClassEntry, ClassMemberDoc, CloogleEntry,
Constructor, ConstructorDoc, DeriveEntry, FunctionDoc, FunctionEntry,
InstanceEntry, Location, ModuleDoc, ModuleEntry, Priority, RecordField,
......@@ -92,7 +98,7 @@ where
, fe_typedef = Nothing
, fe_class = Nothing
, fe_derivations = Nothing
, fe_usages = []
, fe_usages = {}
}
instance zero ModuleEntry
......@@ -102,7 +108,7 @@ where
, me_is_core=False
, me_is_app=False
, me_documentation=Nothing
, me_usages=[]
, me_usages={}
}
instance print (!Name, !FunctionEntry)
......@@ -180,9 +186,9 @@ toTypeDefEntry loc td doc =
{ tde_loc=loc
, tde_typedef=td
, tde_doc=doc
, tde_instances=[]
, tde_derivations=[]
, tde_usages=[]
, tde_instances={}
, tde_derivations={}
, tde_usages={}
}
getTypeDef :: !TypeDefEntry -> TypeDef
......@@ -204,10 +210,10 @@ toClass loc vs meta cc doc =
, ce_is_meta = meta
, ce_context = cc
, ce_documentation = doc
, ce_members = []
, ce_instances = []
, ce_derivations = []
, ce_usages = []
, ce_members = {}
, ce_instances = {}
, ce_derivations = {}
, ce_usages = {}
}
classContext :: !ClassEntry -> [TypeRestriction]
......@@ -346,44 +352,44 @@ filterDB f db = {db & db = 'Database.Native'.search Intersect (\v -> (f v, []))
excludeCore :: !*CloogleDB -> *CloogleDB
excludeCore wrap=:{db,core}
# db = 'Database.Native'.unsearchIndices core db
# db = 'Database.Native'.unsearchIndices` core db
= {wrap & db=db}
excludeApps :: !*CloogleDB -> *CloogleDB
excludeApps wrap=:{db,apps}
# db = 'Database.Native'.unsearchIndices apps db
# db = 'Database.Native'.unsearchIndices` apps db
= {wrap & db=db}
excludeBuiltins :: !*CloogleDB -> *CloogleDB
excludeBuiltins wrap=:{db,builtins}
# db = 'Database.Native'.unsearchIndices builtins db
# db = 'Database.Native'.unsearchIndices` builtins db
= {wrap & db=db}
includeBuiltins :: !*CloogleDB -> *CloogleDB
includeBuiltins wrap=:{db,builtins}
# db = 'Database.Native'.searchIndices AddExcluded (map (flip tuple []) builtins) db
# db = 'Database.Native'.searchIndices AddExcluded [(b,[]) \\ b <-: builtins] db
= {wrap & db=db}
filterLibraries :: ![Name] !*CloogleDB -> *CloogleDB
filterLibraries ss wrap=:{db,library_map}
# db = 'Database.Native'.searchIndices Intersect (map (flip tuple []) idxs) db
# db = 'Database.Native'.searchIndices Intersect [(i,[]) \\ i <- idxs] db
= {wrap & db=db}
where
idxs = foldr merge [] $ catMaybes $ map (flip get library_map) ss
idxs = foldr merge [] $ map (\xs->[x\\x<-:xs]) $ catMaybes $ map (flip get library_map) ss
filterModules :: ![Name] !*CloogleDB -> *CloogleDB
filterModules ss wrap=:{db,module_map}
# db = 'Database.Native'.searchIndices Intersect (map (flip tuple []) idxs) db
= {wrap & db=db}
where
idxs = foldr merge [] $ catMaybes $ map (flip get module_map) ss
idxs = foldr merge [] $ map (\xs->[x\\x<-:xs]) $ catMaybes $ map (flip get module_map) ss
filterName :: !String !*CloogleDB -> *CloogleDB
filterName s wrap=:{db,name_ngrams,syntax,abc_instrs}
# (indices,db) = mapSt (uncurry getIndexWithDistance) ('Data.NGramIndex'.search s name_ngrams) db
# db = 'Database.Native'.searchIndices Intersect indices db
# db = 'Database.Native'.searchWithIndices syntaxSearch syntax db
# db = 'Database.Native'.searchWithIndices abcSearch abc_instrs db
# db = 'Database.Native'.searchWithIndices` syntaxSearch syntax db
# db = 'Database.Native'.searchWithIndices` abcSearch abc_instrs db
= {wrap & db=db}
where
getIndexWithDistance :: !Index !Int !*(NativeDB CloogleEntry Annotation)
......@@ -414,7 +420,7 @@ filterExactName n wrap=:{db,name_map}
# db = 'Database.Native'.searchIndices Intersect [(i,[ExactResult]) \\ i <- idxs] db
= {wrap & db=db}
where
idxs = fromMaybe [] $ get n name_map
idxs = fromMaybe [] $ fmap (\xs->[x\\x<-:xs]) $ get n name_map
filterUnifying :: !Type !*CloogleDB -> *CloogleDB
filterUnifying t wrap=:{db,types}
......@@ -426,15 +432,15 @@ where
filterUsages :: !(*CloogleDB -> *CloogleDB) ![String] !*CloogleDB -> *CloogleDB
filterUsages filter names wrap=:{name_map}
// For each name, the corresponding entries
# idxss = map (fromMaybe [] o flip get name_map) names
# nameidxs = [(i,[ExactResult]) \\ i <- sort [i \\ is <- idxss, i <- is]]
# idxss = map (fromMaybe {#} o flip get name_map) names
# nameidxs = [(i,[ExactResult]) \\ i <- sort [i \\ is <- idxss, i <-: is]]
# wrap=:{db} = filter wrap
# db = 'Database.Native'.searchIndices Intersect nameidxs db
// For all lists of entries, the corresponding usages
# (entriess,db) = mapSt 'Database.Native'.getIndices idxss db
# (entriess,db) = mapSt 'Database.Native'.getIndices` idxss db
# wrap & db = db
# wrap=:{db} = filter $ resetDB wrap
# usagess = map (foldr mergeUnion [] o map \e -> getUsages e.value) entriess
# usagess = map (foldr mergeUnion [] o map \e -> [u \\ u <-: getUsages e.value]) entriess
// AND all usages together
# usages = case usagess of
[] -> []
......@@ -447,12 +453,12 @@ filterUsages filter names wrap=:{name_map}
# db = 'Database.Native'.searchIndices Intersect (mergeUnionWithAnnots nameidxs [(u,[]) \\ u <- usages]) db
= {wrap & db=db}
where
getUsages :: !CloogleEntry -> [Index]
getUsages :: !CloogleEntry -> {#Index}
getUsages (TypeDefEntry tde) = tde.tde_usages
getUsages (ClassEntry ce) = ce.ce_usages
getUsages (ModuleEntry me) = me.me_usages
getUsages (FunctionEntry fe) = fe.fe_usages
getUsages _ = []
getUsages _ = {}
// Efficient union on sorted lists
mergeUnion :: !['Database.Native'.Index] !['Database.Native'.Index] -> ['Database.Native'.Index]
......@@ -497,7 +503,7 @@ alwaysUniquePredicate wrap=:{always_unique} = (isJust o flip get always_unique,
getInstances :: !Name !*CloogleDB -> *([InstanceEntry], *CloogleDB)
getInstances c wrap=:{db,instance_map}
| isNothing idxs = ([], wrap)
# (es,db) = 'Database.Native'.getIndices (fromJust idxs) db
# (es,db) = 'Database.Native'.getIndices` (fromJust idxs) db
= ([ie \\ {value=InstanceEntry ie} <- es], {wrap & db=db})
where
idxs = get c instance_map
......@@ -505,7 +511,7 @@ where
getDerivations :: !Name !*CloogleDB -> *([DeriveEntry], *CloogleDB)
getDerivations c wrap=:{db,derive_map}
| isNothing idxs = ([], wrap)
# (es,db) = 'Database.Native'.getIndices (fromJust idxs) db
# (es,db) = 'Database.Native'.getIndices` (fromJust idxs) db
= ([de \\ {value=DeriveEntry de} <- es], {wrap & db=db})
where
idxs = get c derive_map
......
......@@ -41,7 +41,7 @@ from Data.Func import $, mapSt, on, `on`, instance Functor ((->) a)
import Data.Functor
import Data.GenDefault
import Data.List
from Data.Map import :: Map
from Data.Map import :: Map, instance Functor (Map k)
import qualified Data.Map
import Data.Maybe
from Data.NGramIndex import :: NGramIndex, newNGramIndex, index
......@@ -165,7 +165,7 @@ finaliseDB extra tdb =
{ db = 'Database.Native'.mapInPlace link $ newDB entries
, name_ngrams = foldr (uncurry index) (newNGramIndex NGRAMS_N NGRAMS_CI)
[('Cloogle.DB'.getName loc, i) \\ (i,e) <- entridxs, Just loc <- ['Cloogle.DB'.getLocation e]]
, name_map = foldr (\(name,i) -> flip 'Data.Map'.alter name \is -> case is of
, name_map = (\is->{i\\i<-is}) <$> foldr (\(name,i) -> flip 'Data.Map'.alter name \is -> case is of
Nothing -> Just [i]
Just is -> Just [i:is]) 'Data.Map'.newMap
[('Cloogle.DB'.getName loc, i) \\ (i,e) <- entridxs, Just loc <- ['Cloogle.DB'.getLocation e]]
......@@ -174,17 +174,17 @@ finaliseDB extra tdb =
\\ (i,FunctionEntry fe) <- entridxs, Just t <- [fe.fe_type <|> (docType =<< fe.fe_documentation)]]
, core = coreidxs
, apps = appidxs
, builtins = idxfilter \e -> fromMaybe False ('Cloogle.DB'.isBuiltin <$> 'Cloogle.DB'.getLocation e)
, syntax = idxfilter \e -> e=:(SyntaxEntry _)
, abc_instrs = idxfilter \e -> e=:(ABCInstructionEntry _)
, builtins = idxarr \e -> fromMaybe False ('Cloogle.DB'.isBuiltin <$> 'Cloogle.DB'.getLocation e)
, syntax = idxarr \e -> e=:(SyntaxEntry _)
, abc_instrs = idxarr \e -> e=:(ABCInstructionEntry _)
, library_map = libmap
, module_map = modmap
, derive_map = 'Data.Map'.fromList
$ map (\ds=:[(g,_):_] -> (g,map snd ds))
$ map (\ds=:[(g,_):_] -> (g,{i \\ (_,i) <- ds}))
$ groupBy ((==) `on` fst) $ sort
[(de.de_generic, i) \\ (i,DeriveEntry de) <- entridxs]
, instance_map = 'Data.Map'.fromList
$ map (\is=:[(c,_):_] -> (c,map snd is))
$ map (\is=:[(c,_):_] -> (c,{i \\ (_,i) <- is}))
$ groupBy ((==) `on` fst) $ sort
[(ie.ie_class, i) \\ (i,InstanceEntry ie) <- entridxs]
, always_unique = always_unique
......@@ -194,43 +194,43 @@ where
link i e = case e of
TypeDefEntry tde -> TypeDefEntry
{ tde
& tde_instances=idxfilter \e -> case e of
& tde_instances=idxarr \e -> case e of
InstanceEntry ie -> case name of
"(->)" -> any (\t -> t=:('Clean.Types'.Func _ _ _) || t=:('Clean.Types'.Arrow _)) $ concatMap ('Clean.Types'.subtypes o fst) ie.ie_types
_ -> or [t == name \\ 'Clean.Types'.Type t _ <- concatMap ('Clean.Types'.subtypes o fst) ie.ie_types]
_ -> False
, tde_derivations=idxfilter \e -> case e of
, tde_derivations=idxarr \e -> case e of
DeriveEntry {de_type='Clean.Types'.Type t _} -> t == name
DeriveEntry {de_type='Clean.Types'.Arrow _} -> name == "(->)"
DeriveEntry {de_type='Clean.Types'.Func _ _ _} -> name == "(->)"
_ -> False
, tde_usages=fromMaybe [] ('Data.Map'.get name type_usages_map)
, tde_usages={u \\ u <- fromMaybe [] ('Data.Map'.get name type_usages_map)}
}
with name = 'Clean.Types'.td_name $ 'Cloogle.DB'.getTypeDef tde
ClassEntry ce -> ClassEntry
{ ce
& ce_instances=idxfilter \e -> case e of
& ce_instances=idxarr \e -> case e of
InstanceEntry ie -> ie.ie_class == name
_ -> False
, ce_members=idxfilter \e -> case e of
, ce_members=idxarr \e -> case e of
FunctionEntry fe -> fe.fe_class == Just (Index i)
_ -> False
, ce_usages=fromMaybe [] ('Data.Map'.get name class_usages_map)
, ce_usages={u \\ u <- fromMaybe [] ('Data.Map'.get name class_usages_map)}
}
with name = 'Cloogle.DB'.getName ce.ce_loc
FunctionEntry fe -> FunctionEntry
{ fe
& fe_derivations=case fe.fe_derivations of
Nothing -> Nothing
Just _ -> Just $ idxfilter \e -> case e of
Just _ -> Just $ idxarr \e -> case e of
DeriveEntry de -> de.de_generic == name
_ -> False
, fe_usages=fromMaybe [] ('Data.Map'.get name function_usages_map)
, fe_usages={u \\ u <- fromMaybe [] ('Data.Map'.get name function_usages_map)}
}
with name = 'Cloogle.DB'.getName fe.fe_loc
ModuleEntry me -> ModuleEntry
{ me
& me_usages=fromMaybe [] ('Data.Map'.get name module_usages_map)
& me_usages={u \\ u <- fromMaybe [] ('Data.Map'.get name module_usages_map)}
}
with name = 'Cloogle.DB'.getName me.me_loc
e -> e
......@@ -335,16 +335,17 @@ where
entridxs = zip2 [Index i \\ i <- [0..]] entries
idxfilter f = [idx \\ (idx,e) <- entridxs | f e]
idxarr f = {idx \\ idx <- idxfilter f}
idxhd = hd o idxfilter
coreidxs = idxfilter \e -> case 'Cloogle.DB'.getLocation e of
coreidxs = idxarr \e -> case 'Cloogle.DB'.getLocation e of
Nothing -> False
Just l -> case ('Cloogle.DB'.getLibrary l, 'Cloogle.DB'.getModule l) of
(Just l, Just m) -> isMember (l,m) coremods
_ -> False
where
coremods = [(fromJust $ 'Cloogle.DB'.getLibrary me.me_loc, fromJust $ 'Cloogle.DB'.getModule me.me_loc) \\ (me,_) <- tdb.temp_modules | me.me_is_core]
appidxs = idxfilter \e -> case 'Cloogle.DB'.getLocation e of
appidxs = idxarr \e -> case 'Cloogle.DB'.getLocation e of
Nothing -> False
Just l -> case ('Cloogle.DB'.getLibrary l, 'Cloogle.DB'.getModule l) of
(Just l, Just m) -> isMember (l,m) appmods
......@@ -353,12 +354,12 @@ where
appmods = [(fromJust $ 'Cloogle.DB'.getLibrary me.me_loc, fromJust $ 'Cloogle.DB'.getModule me.me_loc) \\ (me,_) <- tdb.temp_modules | me.me_is_app]
libmap = 'Data.Map'.fromList
[(l,idxfilter \e -> case 'Cloogle.DB'.getLocation e >>= 'Cloogle.DB'.getLibrary of
[(l,idxarr \e -> case 'Cloogle.DB'.getLocation e >>= 'Cloogle.DB'.getLibrary of
Nothing -> False
Just l` -> l == l`) \\ l <- libs]
where libs = removeDup [fromJust ('Cloogle.DB'.getLibrary me.me_loc) \\ (me,_) <- tdb.temp_modules]
modmap = 'Data.Map'.fromList
[(m,idxfilter \e -> case 'Cloogle.DB'.getLocation e >>= 'Cloogle.DB'.getModule of
[(m,idxarr \e -> case 'Cloogle.DB'.getLocation e >>= 'Cloogle.DB'.getModule of
Nothing -> False
Just m` -> m == m`) \\ m <- mods]
where mods = removeDup [fromJust ('Cloogle.DB'.getModule me.me_loc) \\ (me,_) <- tdb.temp_modules]
......@@ -400,7 +401,7 @@ where
, me_is_core = match item.pattern_core (path </?> fn)
, me_is_app = match item.pattern_app (path </?> fn)
, me_documentation = Nothing
, me_usages = []
, me_usages = {}
}
where
modname = basedot +++ fn % (0, size fn - 5)
......@@ -621,7 +622,7 @@ where
, fe_generic_vars=Just $ map 'Clean.Types'.toTypeVar gen_vars
, fe_representation=Just $ cpp gen
, fe_documentation=findDoc hideIsUsedReturn gen comments
, fe_derivations=Just []
, fe_derivations=Just {}
}
, 'Data.Set'.newSet
) \\ gen=:(PD_Generic {gen_ident=id=:{id_name},gen_pos,gen_type,gen_vars}) <- defs]
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment