diff options
| author | Keegan McAllister <kmcallister@mozilla.com> | 2014-12-31 19:48:39 -0800 |
|---|---|---|
| committer | Keegan McAllister <kmcallister@mozilla.com> | 2015-01-05 18:21:13 -0800 |
| commit | f314e2c4ea48c2027e627fdfca821bb6e0012e59 (patch) | |
| tree | 26d83d97f04f460583535c604b78b4c7515c4105 /src/librustc/plugin | |
| parent | 677b7cad3d0ca1347f65ae9b409078343a5f302e (diff) | |
| download | rust-f314e2c4ea48c2027e627fdfca821bb6e0012e59.tar.gz rust-f314e2c4ea48c2027e627fdfca821bb6e0012e59.zip | |
creader: Load parts of plugin metadata on demand
Diffstat (limited to 'src/librustc/plugin')
| -rw-r--r-- | src/librustc/plugin/load.rs | 59 |
1 files changed, 27 insertions, 32 deletions
diff --git a/src/librustc/plugin/load.rs b/src/librustc/plugin/load.rs index 9aa7d8fe990..78730defc7f 100644 --- a/src/librustc/plugin/load.rs +++ b/src/librustc/plugin/load.rs @@ -23,14 +23,6 @@ use syntax::visit; use syntax::visit::Visitor; use syntax::attr::AttrMetaMethods; -/// Metadata for a single plugin crate. -pub struct PluginMetadata { - /// Macros exported by the crate. - pub macros: Vec<ast::MacroDef>, - /// Path to the shared library file, and registrar function symbol. - pub registrar: Option<(Path, String)>, -} - /// Pointer to a registrar function. pub type PluginRegistrarFun = fn(&mut Registry); @@ -86,37 +78,40 @@ pub fn load_plugins(sess: &Session, krate: &ast::Crate, // note that macros aren't expanded yet, and therefore macros can't add plugins. impl<'a, 'v> Visitor<'v> for PluginLoader<'a> { fn visit_view_item(&mut self, vi: &ast::ViewItem) { + // We're only interested in `extern crate`. match vi.node { - ast::ViewItemExternCrate(_, _, _) => { - let mut plugin_phase = false; - - for attr in vi.attrs.iter().filter(|a| a.check_name("phase")) { - let phases = attr.meta_item_list().unwrap_or(&[]); - if attr::contains_name(phases, "plugin") { - plugin_phase = true; - } - if attr::contains_name(phases, "syntax") { - plugin_phase = true; - self.sess.span_warn(attr.span, - "phase(syntax) is a deprecated synonym for phase(plugin)"); - } - } + ast::ViewItemExternCrate(..) => (), + _ => return, + } - if !plugin_phase { return; } + let mut plugin_phase = false; + for attr in vi.attrs.iter().filter(|a| a.check_name("phase")) { + let phases = attr.meta_item_list().unwrap_or(&[]); + if attr::contains_name(phases, "plugin") { + plugin_phase = true; + } + if attr::contains_name(phases, "syntax") { + plugin_phase = true; + self.sess.span_warn(attr.span, + "phase(syntax) is a deprecated synonym for phase(plugin)"); + } + } - let PluginMetadata { macros, registrar } = - self.reader.read_plugin_metadata(vi); + let mut macros = vec![]; + let mut registrar = None; - self.plugins.macros.extend(macros.into_iter()); + if plugin_phase { + let pmd = self.reader.read_plugin_metadata(vi); + macros = pmd.exported_macros(); + registrar = pmd.plugin_registrar(); + } - match registrar { - Some((lib, symbol)) => self.dylink_registrar(vi, lib, symbol), - _ => (), - } - } - _ => (), + self.plugins.macros.extend(macros.into_iter()); + if let Some((lib, symbol)) = registrar { + self.dylink_registrar(vi, lib, symbol); } } + fn visit_mac(&mut self, _: &ast::Mac) { // bummer... can't see plugins inside macros. // do nothing. |
