@@ -36,6 +36,7 @@ structure MatcherInfo where
3636 `discrInfos[i] = { hName? := some h }` if the i-th discriminant was annotated with `h :`.
3737 -/
3838 discrInfos : Array DiscrInfo
39+ deriving Inhabited
3940
4041@[expose] def MatcherInfo.numAlts (info : MatcherInfo) : Nat :=
4142 info.altNumParams.size
@@ -75,21 +76,20 @@ structure Entry where
7576 info : MatcherInfo
7677
7778structure State where
78- map : SMap Name MatcherInfo := {}
79+ map : PHashMap Name MatcherInfo := {}
7980
8081instance : Inhabited State := ⟨{}⟩
8182
8283def State.addEntry (s : State) (e : Entry) : State := { s with map := s.map.insert e.name e.info }
83- def State.switch (s : State) : State := { s with map := s.map.switch }
8484
85- builtin_initialize extension : SimplePersistentEnvExtension Entry State ←
85+ private builtin_initialize extension : SimplePersistentEnvExtension Entry State ←
8686 registerSimplePersistentEnvExtension {
8787 addEntryFn := State.addEntry
88- addImportedFn := fun es => (mkStateFromImportedEntries State.addEntry {} es).switch
88+ addImportedFn := fun _ => {}
8989 asyncMode := .async .mainEnv
9090 exportEntriesFnEx? := some fun env _ entries _ =>
9191 -- Do not export info for private defs
92- entries.filter (env.contains (skipRealize := false ) ·.name) |>.toArray
92+ entries.filter (env.contains (skipRealize := false ) ·.name) |>.toArray.qsort (Name.quickLt ·.name ·.name)
9393 }
9494
9595def addMatcherInfo (env : Environment) (matcherName : Name) (info : MatcherInfo) : Environment :=
@@ -100,7 +100,12 @@ def getMatcherInfo? (env : Environment) (declName : Name) : Option MatcherInfo :
100100 -- avoid blocking on async decls whose names look nothing like matchers
101101 let .str _ s := declName.eraseMacroScopes | none
102102 guard <| s.startsWith "match_"
103- (extension.getState (asyncDecl := declName) env).map.find? declName
103+ match env.getModuleIdxFor? declName with
104+ | some modIdx =>
105+ extension.getModuleEntries env modIdx
106+ |>.binSearch { name := declName, info := default } (Name.quickLt ·.name ·.name)
107+ |>.map (·.info)
108+ | none => (extension.getState (asyncDecl := declName) env).map.find? declName
104109
105110end Extension
106111
0 commit comments