From 8b071ebe4c7cc1e986f15e5dca00c3ee7e31db3a Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Mon, 20 Feb 2012 22:24:59 -0800 Subject: [PATCH] rustdoc: Make it easy to switch between parallel and sequential folds --- src/rustdoc/attr_pass.rs | 2 +- src/rustdoc/desc_pass.rs | 2 +- src/rustdoc/desc_to_brief_pass.rs | 2 +- src/rustdoc/fold.rs | 15 +++++++++++++++ src/rustdoc/path_pass.rs | 4 ++-- src/rustdoc/prune_undoc_details_pass.rs | 2 +- src/rustdoc/prune_undoc_items_pass.rs | 4 ++-- src/rustdoc/prune_unexported_pass.rs | 4 ++-- src/rustdoc/sort_pass.rs | 4 ++-- src/rustdoc/tystr_pass.rs | 2 +- 10 files changed, 28 insertions(+), 13 deletions(-) diff --git a/src/rustdoc/attr_pass.rs b/src/rustdoc/attr_pass.rs index 8d77dc6b055..474189f3619 100644 --- a/src/rustdoc/attr_pass.rs +++ b/src/rustdoc/attr_pass.rs @@ -27,7 +27,7 @@ fn run( fold_res: fold_res, fold_iface: fold_iface, fold_impl: fold_impl - with *fold::default_par_fold(srv) + with *fold::default_any_fold(srv) }); fold.fold_crate(fold, doc) } diff --git a/src/rustdoc/desc_pass.rs b/src/rustdoc/desc_pass.rs index be6bc708e67..9dbda071ba4 100644 --- a/src/rustdoc/desc_pass.rs +++ b/src/rustdoc/desc_pass.rs @@ -22,7 +22,7 @@ fn run( fold_res: fold_res, fold_iface: fold_iface, fold_impl: fold_impl - with *fold::default_par_fold(op) + with *fold::default_any_fold(op) }); fold.fold_crate(fold, doc) } diff --git a/src/rustdoc/desc_to_brief_pass.rs b/src/rustdoc/desc_to_brief_pass.rs index 0ea14c3bff2..b506f502933 100644 --- a/src/rustdoc/desc_to_brief_pass.rs +++ b/src/rustdoc/desc_to_brief_pass.rs @@ -21,7 +21,7 @@ fn run( fold_item: fold_item, fold_iface: fold_iface, fold_impl: fold_impl - with *fold::default_par_fold(()) + with *fold::default_any_fold(()) }); fold.fold_crate(fold, doc) } diff --git a/src/rustdoc/fold.rs b/src/rustdoc/fold.rs index 777dc0f83e9..61a28150825 100644 --- a/src/rustdoc/fold.rs +++ b/src/rustdoc/fold.rs @@ -13,6 +13,8 @@ export default_seq_fold_impl; export default_seq_fold_type; export default_par_fold; export default_par_fold_mod; +export default_any_fold; +export default_any_fold_mod; enum fold = t; @@ -104,6 +106,12 @@ fn default_par_fold(ctxt: T) -> fold { ) } +// Just a convenient wrapper to convert back and forth between +// parallel and sequential folds for perf testing +fn default_any_fold(ctxt: T) -> fold { + default_par_fold(ctxt) +} + fn default_seq_fold_crate( fold: fold, doc: doc::cratedoc @@ -146,6 +154,13 @@ fn default_par_fold_mod( } } +fn default_any_fold_mod( + fold: fold, + doc: doc::moddoc +) -> doc::moddoc { + default_par_fold_mod(fold, doc) +} + fn fold_itemtag(fold: fold, doc: doc::itemtag) -> doc::itemtag { alt doc { doc::modtag(moddoc) { diff --git a/src/rustdoc/path_pass.rs b/src/rustdoc/path_pass.rs index bdd7709a3c4..66b6d10f9fa 100644 --- a/src/rustdoc/path_pass.rs +++ b/src/rustdoc/path_pass.rs @@ -17,7 +17,7 @@ fn run(srv: astsrv::srv, doc: doc::cratedoc) -> doc::cratedoc { let fold = fold::fold({ fold_item: fold_item, fold_mod: fold_mod - with *fold::default_par_fold(ctxt) + with *fold::default_any_fold(ctxt) }); fold.fold_crate(fold, doc) } @@ -33,7 +33,7 @@ fn fold_mod(fold: fold::fold, doc: doc::moddoc) -> doc::moddoc { let is_topmod = doc.id() == rustc::syntax::ast::crate_node_id; if !is_topmod { vec::push(fold.ctxt.path, doc.name()); } - let doc = fold::default_par_fold_mod(fold, doc); + let doc = fold::default_any_fold_mod(fold, doc); if !is_topmod { vec::pop(fold.ctxt.path); } { diff --git a/src/rustdoc/prune_undoc_details_pass.rs b/src/rustdoc/prune_undoc_details_pass.rs index e6dcc45c454..6e8865dbd03 100644 --- a/src/rustdoc/prune_undoc_details_pass.rs +++ b/src/rustdoc/prune_undoc_details_pass.rs @@ -16,7 +16,7 @@ fn run( fold_res: fold_res, fold_iface: fold_iface, fold_impl: fold_impl - with *fold::default_par_fold(()) + with *fold::default_any_fold(()) }); fold.fold_crate(fold, doc) } diff --git a/src/rustdoc/prune_undoc_items_pass.rs b/src/rustdoc/prune_undoc_items_pass.rs index 341527c540a..d8a75a8334b 100644 --- a/src/rustdoc/prune_undoc_items_pass.rs +++ b/src/rustdoc/prune_undoc_items_pass.rs @@ -26,7 +26,7 @@ fn run( fold_iface: fold_iface, fold_impl: fold_impl, fold_type: fold_type - with *fold::default_par_fold(ctxt) + with *fold::default_any_fold(ctxt) }); fold.fold_crate(fold, doc) } @@ -105,7 +105,7 @@ fn fold_mod( _ { some(itemtag) } } } - with fold::default_par_fold_mod(fold, doc) + with fold::default_any_fold_mod(fold, doc) }; fold.ctxt.have_docs = doc.brief() != none diff --git a/src/rustdoc/prune_unexported_pass.rs b/src/rustdoc/prune_unexported_pass.rs index 577f44e464d..dc7b240a155 100644 --- a/src/rustdoc/prune_unexported_pass.rs +++ b/src/rustdoc/prune_unexported_pass.rs @@ -13,13 +13,13 @@ fn mk_pass() -> pass { fn run(srv: astsrv::srv, doc: doc::cratedoc) -> doc::cratedoc { let fold = fold::fold({ fold_mod: fold_mod - with *fold::default_par_fold(srv) + with *fold::default_any_fold(srv) }); fold.fold_crate(fold, doc) } fn fold_mod(fold: fold::fold, doc: doc::moddoc) -> doc::moddoc { - let doc = fold::default_par_fold_mod(fold, doc); + let doc = fold::default_any_fold_mod(fold, doc); { items: ~exported_items(fold.ctxt, doc) with doc diff --git a/src/rustdoc/sort_pass.rs b/src/rustdoc/sort_pass.rs index 28b97191c41..32dee0d095d 100644 --- a/src/rustdoc/sort_pass.rs +++ b/src/rustdoc/sort_pass.rs @@ -19,7 +19,7 @@ fn run( ) -> doc::cratedoc { let fold = fold::fold({ fold_mod: fold_mod - with *fold::default_par_fold(lteq) + with *fold::default_any_fold(lteq) }); fold.fold_crate(fold, doc) } @@ -28,7 +28,7 @@ fn fold_mod( fold: fold::fold, doc: doc::moddoc ) -> doc::moddoc { - let doc = fold::default_par_fold_mod(fold, doc); + let doc = fold::default_any_fold_mod(fold, doc); { items: ~sort::merge_sort(fold.ctxt, *doc.items) with doc diff --git a/src/rustdoc/tystr_pass.rs b/src/rustdoc/tystr_pass.rs index f2e531fd285..c4a2a042313 100644 --- a/src/rustdoc/tystr_pass.rs +++ b/src/rustdoc/tystr_pass.rs @@ -23,7 +23,7 @@ fn run( fold_iface: fold_iface, fold_impl: fold_impl, fold_type: fold_type - with *fold::default_par_fold(srv) + with *fold::default_any_fold(srv) }); fold.fold_crate(fold, doc) }