@@ -15,7 +15,7 @@ Author: Leonardo de Moura
1515namespace lean {
1616struct documentation_ext : public environment_extension {
1717 /* * Doc string for the current module being processed. It does not include imported doc strings. */
18- list<doc_entry> m_module_doc;
18+ optional<std::string> m_module_doc;
1919 /* * Doc strings for declarations (including imported ones). We store doc_strings for declarations in the .olean files. */
2020 name_map<std::string> m_doc_string_map;
2121};
@@ -36,25 +36,16 @@ static environment update(environment const & env, documentation_ext const & ext
3636struct doc_modification : public modification {
3737 LEAN_MODIFICATION (" doc" )
3838
39- /* * If non-empty, this is a doc on a declaration. Otherwise,
40- * it's a doc on the whole module. */
4139 name m_decl;
4240 std::string m_doc;
4341
4442 doc_modification () {}
45- /* * A docstring for the entire module. */
46- doc_modification (std::string const & doc) : m_decl(" " ), m_doc(doc) {}
4743 /* * A docstring for a declaration in the module. */
4844 doc_modification (name const & decl, std::string const & doc) : m_decl(decl), m_doc(doc) {}
4945
5046 void perform (environment & env) const override {
5147 auto ext = get_extension (env);
52- if (m_decl != " " ) {
53- ext.m_doc_string_map .insert (m_decl, m_doc);
54- }
55- // Note that we do NOT add anything to `m_module_doc` here, because `perform` is called
56- // when applying modifications from imported .olean modules whose doc strings are NOT
57- // part of the current module's documentation.
48+ ext.m_doc_string_map .insert (m_decl, m_doc);
5849 env = update (env, ext);
5950 }
6051
@@ -179,9 +170,13 @@ static std::string process_doc(std::string s) {
179170environment add_module_doc_string (environment const & env, std::string doc) {
180171 doc = process_doc (doc);
181172 auto ext = get_extension (env);
182- ext.m_module_doc = cons (doc_entry (doc), ext.m_module_doc );
173+ if (ext.m_module_doc ) {
174+ *ext.m_module_doc += " \n " + doc;
175+ } else {
176+ ext.m_module_doc = doc;
177+ }
183178 auto new_env = update (env, ext);
184- return module::add (new_env, std::make_shared<doc_modification>( doc) );
179+ return module::add_doc_string (new_env, doc);
185180}
186181
187182environment add_doc_string (environment const & env, name const & n, std::string doc) {
@@ -191,7 +186,6 @@ environment add_doc_string(environment const & env, name const & n, std::string
191186 throw exception (sstream () << " environment already contains a doc string for '" << n << " '" );
192187 }
193188 ext.m_doc_string_map .insert (n, doc);
194- ext.m_module_doc = cons (doc_entry (n, doc), ext.m_module_doc );
195189 auto new_env = update (env, ext);
196190 return module::add (new_env, std::make_shared<doc_modification>(n, doc));
197191}
@@ -204,10 +198,15 @@ optional<std::string> get_doc_string(environment const & env, name const & n) {
204198 return optional<std::string>();
205199}
206200
207- void get_module_doc_strings (environment const & env, buffer<doc_entry > & result) {
201+ void get_module_doc_strings (environment const & env, buffer<mod_doc_entry > & result) {
208202 auto ext = get_extension (env);
209- to_buffer (ext.m_module_doc , result);
210- std::reverse (result.begin (), result.end ());
203+ auto const & mod_docs = module::get_doc_strings (env);
204+ for (auto const & pr : mod_docs) {
205+ result.push_back ({ optional<std::string>{ pr.first }, pr.second });
206+ }
207+ if (ext.m_module_doc ) {
208+ result.push_back ({ {}, *ext.m_module_doc });
209+ }
211210}
212211
213212void initialize_documentation () {
0 commit comments