Skip to content

Commit 0c5b13d

Browse files
author
Keegan McAllister
committed
---
yaml --- r: 117663 b: refs/heads/auto c: 6d15c67 h: refs/heads/master i: 117661: dceedd2 117659: a93d529 117655: b054ac6 117647: 2b239fd 117631: 6a4562d v: v3
1 parent 3d632c3 commit 0c5b13d

File tree

21 files changed

+334
-239
lines changed

21 files changed

+334
-239
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0
1313
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1414
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1515
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
16-
refs/heads/auto: b6146e652ae7f6d373d55dd021dc50cb00e0caf8
16+
refs/heads/auto: 6d15c6749c30d9077c6e12af3be64c5f68fafcff
1717
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1818
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1919
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336

branches/auto/src/librustc/driver/driver.rs

Lines changed: 40 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@ use front;
1818
use lib::llvm::{ContextRef, ModuleRef};
1919
use metadata::common::LinkMeta;
2020
use metadata::creader;
21-
use metadata::creader::Loader;
2221
use middle::cfg;
2322
use middle::cfg::graphviz::LabelledCFG;
2423
use middle::{trans, freevars, kind, ty, typeck, lint, reachable};
2524
use middle::dependency_format;
2625
use middle;
26+
use plugin::load::Plugins;
27+
use plugin::registry::Registry;
28+
use plugin;
2729
use util::common::time;
2830
use util::ppaux;
2931
use util::nodemap::{NodeSet};
@@ -39,7 +41,6 @@ use syntax::ast;
3941
use syntax::attr;
4042
use syntax::attr::{AttrMetaMethods};
4143
use syntax::crateid::CrateId;
42-
use syntax::ext::base::CrateLoader;
4344
use syntax::parse;
4445
use syntax::parse::token;
4546
use syntax::print::{pp, pprust};
@@ -75,11 +76,10 @@ pub fn compile_input(sess: Session,
7576
output,
7677
krate.attrs.as_slice(),
7778
&sess);
78-
let loader = &mut Loader::new(&sess);
7979
let id = link::find_crate_id(krate.attrs.as_slice(),
8080
outputs.out_filestem.as_slice());
8181
let (expanded_crate, ast_map) =
82-
phase_2_configure_and_expand(&sess, loader, krate, &id);
82+
phase_2_configure_and_expand(&sess, krate, &id);
8383
(outputs, expanded_crate, ast_map)
8484
};
8585
write_out_deps(&sess, input, &outputs, &expanded_crate);
@@ -172,7 +172,6 @@ pub fn phase_1_parse_input(sess: &Session, cfg: ast::CrateConfig, input: &Input)
172172
/// harness if one is to be provided and injection of a dependency on the
173173
/// standard library and prelude.
174174
pub fn phase_2_configure_and_expand(sess: &Session,
175-
loader: &mut CrateLoader,
176175
mut krate: ast::Crate,
177176
crate_id: &CrateId)
178177
-> (ast::Crate, syntax::ast_map::Map) {
@@ -197,25 +196,42 @@ pub fn phase_2_configure_and_expand(sess: &Session,
197196
krate = time(time_passes, "configuration 1", krate, |krate|
198197
front::config::strip_unconfigured_items(krate));
199198

200-
krate = time(time_passes, "expansion", krate, |krate| {
201-
// Windows dlls do not have rpaths, so they don't know how to find their
202-
// dependencies. It's up to us to tell the system where to find all the
203-
// dependent dlls. Note that this uses cfg!(windows) as opposed to
204-
// targ_cfg because syntax extensions are always loaded for the host
205-
// compiler, not for the target.
206-
if cfg!(windows) {
207-
sess.host_filesearch().add_dylib_search_paths();
199+
let Plugins { macros, registrars }
200+
= time(time_passes, "plugin loading", (), |_|
201+
plugin::load::load_plugins(sess, &krate));
202+
203+
let mut registry = Registry::new(&krate);
204+
205+
time(time_passes, "plugin registration", (), |_| {
206+
for &registrar in registrars.iter() {
207+
registrar(&mut registry);
208208
}
209-
let cfg = syntax::ext::expand::ExpansionConfig {
210-
loader: loader,
211-
deriving_hash_type_parameter: sess.features.default_type_params.get(),
212-
crate_id: crate_id.clone(),
213-
};
214-
syntax::ext::expand::expand_crate(&sess.parse_sess,
215-
cfg,
216-
krate)
217209
});
218210

211+
let Registry { syntax_exts, .. } = registry;
212+
213+
krate = time(time_passes, "expansion", (krate, macros, syntax_exts),
214+
|(krate, macros, syntax_exts)| {
215+
// Windows dlls do not have rpaths, so they don't know how to find their
216+
// dependencies. It's up to us to tell the system where to find all the
217+
// dependent dlls. Note that this uses cfg!(windows) as opposed to
218+
// targ_cfg because syntax extensions are always loaded for the host
219+
// compiler, not for the target.
220+
if cfg!(windows) {
221+
sess.host_filesearch().add_dylib_search_paths();
222+
}
223+
let cfg = syntax::ext::expand::ExpansionConfig {
224+
deriving_hash_type_parameter: sess.features.default_type_params.get(),
225+
crate_id: crate_id.clone(),
226+
};
227+
syntax::ext::expand::expand_crate(&sess.parse_sess,
228+
cfg,
229+
macros,
230+
syntax_exts,
231+
krate)
232+
}
233+
);
234+
219235
// strip again, in case expansion added anything with a #[cfg].
220236
krate = time(time_passes, "configuration 2", krate, |krate|
221237
front::config::strip_unconfigured_items(krate));
@@ -281,9 +297,9 @@ pub fn phase_3_run_analysis_passes(sess: Session,
281297
time(time_passes, "looking for entry point", (),
282298
|_| middle::entry::find_entry_point(&sess, krate, &ast_map));
283299

284-
sess.macro_registrar_fn.set(
285-
time(time_passes, "looking for macro registrar", (), |_|
286-
syntax::ext::registrar::find_macro_registrar(
300+
sess.plugin_registrar_fn.set(
301+
time(time_passes, "looking for plugin registrar", (), |_|
302+
plugin::build::find_plugin_registrar(
287303
sess.diagnostic(), krate)));
288304

289305
let freevars = time(time_passes, "freevar finding", (), |_|
@@ -596,9 +612,7 @@ pub fn pretty_print_input(sess: Session,
596612

597613
let (krate, ast_map, is_expanded) = match ppm {
598614
PpmExpanded | PpmExpandedIdentified | PpmTyped | PpmFlowGraph(_) => {
599-
let loader = &mut Loader::new(&sess);
600615
let (krate, ast_map) = phase_2_configure_and_expand(&sess,
601-
loader,
602616
krate,
603617
&id);
604618
(krate, Some(ast_map), true)

branches/auto/src/librustc/driver/session.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pub struct Session {
3636
// For a library crate, this is always none
3737
pub entry_fn: RefCell<Option<(NodeId, codemap::Span)>>,
3838
pub entry_type: Cell<Option<config::EntryFnType>>,
39-
pub macro_registrar_fn: Cell<Option<ast::NodeId>>,
39+
pub plugin_registrar_fn: Cell<Option<ast::NodeId>>,
4040
pub default_sysroot: Option<Path>,
4141
// The name of the root source file of the crate, in the local file system. The path is always
4242
// expected to be absolute. `None` means that there is no source file.
@@ -232,7 +232,7 @@ pub fn build_session_(sopts: config::Options,
232232
// For a library crate, this is always none
233233
entry_fn: RefCell::new(None),
234234
entry_type: Cell::new(None),
235-
macro_registrar_fn: Cell::new(None),
235+
plugin_registrar_fn: Cell::new(None),
236236
default_sysroot: default_sysroot,
237237
local_crate_source_file: local_crate_source_file,
238238
working_dir: os::getcwd(),

branches/auto/src/librustc/front/feature_gate.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ static KNOWN_FEATURES: &'static [(&'static str, Status)] = &[
4646
("thread_local", Active),
4747
("link_args", Active),
4848
("phase", Active),
49-
("macro_registrar", Active),
49+
("plugin_registrar", Active),
5050
("log_syntax", Active),
5151
("trace_macros", Active),
5252
("concat_idents", Active),
@@ -192,10 +192,9 @@ impl<'a> Visitor<()> for Context<'a> {
192192
}
193193

194194
ast::ItemFn(..) => {
195-
if attr::contains_name(i.attrs.as_slice(), "macro_registrar") {
196-
self.gate_feature("macro_registrar", i.span,
197-
"cross-crate macro exports are \
198-
experimental and possibly buggy");
195+
if attr::contains_name(i.attrs.as_slice(), "plugin_registrar") {
196+
self.gate_feature("plugin_registrar", i.span,
197+
"compiler plugins are experimental and possibly buggy");
199198
}
200199
}
201200

branches/auto/src/librustc/front/std_inject.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ impl<'a> fold::Folder for StandardLibraryInjector<'a> {
8181
attr::mk_attr_outer(attr::mk_attr_id(), attr::mk_list_item(
8282
InternedString::new("phase"),
8383
vec!(
84-
attr::mk_word_item(InternedString::new("syntax")),
84+
attr::mk_word_item(InternedString::new("plugin")),
8585
attr::mk_word_item(InternedString::new("link")
8686
))))),
8787
vis: ast::Inherited,

branches/auto/src/librustc/front/test.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
use driver::session::Session;
1717
use front::config;
1818
use front::std_inject::with_version;
19-
use metadata::creader::Loader;
2019

2120
use std::cell::RefCell;
2221
use std::slice;
@@ -150,12 +149,10 @@ impl<'a> fold::Folder for TestHarnessGenerator<'a> {
150149

151150
fn generate_test_harness(sess: &Session, krate: ast::Crate)
152151
-> ast::Crate {
153-
let loader = &mut Loader::new(sess);
154152
let mut cx: TestCtxt = TestCtxt {
155153
sess: sess,
156154
ext_cx: ExtCtxt::new(&sess.parse_sess, sess.opts.cfg.clone(),
157155
ExpansionConfig {
158-
loader: loader,
159156
deriving_hash_type_parameter: false,
160157
crate_id: from_str("test").unwrap(),
161158
}),

branches/auto/src/librustc/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,14 @@ pub mod metadata;
109109

110110
pub mod driver;
111111

112+
pub mod plugin {
113+
pub use self::registry::Registry;
114+
115+
pub mod registry;
116+
pub mod load;
117+
pub mod build;
118+
}
119+
112120
pub mod util {
113121
pub mod common;
114122
pub mod ppaux;

branches/auto/src/librustc/metadata/common.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ pub static tag_native_libraries_lib: uint = 0x88;
198198
pub static tag_native_libraries_name: uint = 0x89;
199199
pub static tag_native_libraries_kind: uint = 0x8a;
200200

201-
pub static tag_macro_registrar_fn: uint = 0x8b;
201+
pub static tag_plugin_registrar_fn: uint = 0x8b;
202202
pub static tag_exported_macros: uint = 0x8c;
203203
pub static tag_macro_def: uint = 0x8d;
204204

branches/auto/src/librustc/metadata/creader.rs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use metadata::cstore::{CStore, CrateSource};
2121
use metadata::decoder;
2222
use metadata::loader;
2323
use metadata::loader::CratePaths;
24+
use plugin::load::PluginMetadata;
2425

2526
use std::rc::Rc;
2627
use std::collections::HashMap;
@@ -30,7 +31,6 @@ use syntax::attr;
3031
use syntax::attr::AttrMetaMethods;
3132
use syntax::codemap::{Span};
3233
use syntax::diagnostic::SpanHandler;
33-
use syntax::ext::base::{CrateLoader, MacroCrate};
3434
use syntax::parse::token::InternedString;
3535
use syntax::parse::token;
3636
use syntax::crateid::CrateId;
@@ -379,23 +379,21 @@ fn resolve_crate_deps(e: &mut Env,
379379
}).collect()
380380
}
381381

382-
pub struct Loader<'a> {
382+
pub struct PluginMetadataReader<'a> {
383383
env: Env<'a>,
384384
}
385385

386-
impl<'a> Loader<'a> {
387-
pub fn new(sess: &'a Session) -> Loader<'a> {
388-
Loader {
386+
impl<'a> PluginMetadataReader<'a> {
387+
pub fn new(sess: &'a Session) -> PluginMetadataReader<'a> {
388+
PluginMetadataReader {
389389
env: Env {
390390
sess: sess,
391391
next_crate_num: sess.cstore.next_crate_num(),
392392
}
393393
}
394394
}
395-
}
396395

397-
impl<'a> CrateLoader for Loader<'a> {
398-
fn load_crate(&mut self, krate: &ast::ViewItem) -> MacroCrate {
396+
pub fn read_plugin_metadata(&mut self, krate: &ast::ViewItem) -> PluginMetadata {
399397
let info = extract_crate_info(&self.env, krate).unwrap();
400398
let target_triple = self.env.sess.targ_cfg.target_strs.target_triple.as_slice();
401399
let is_cross = target_triple != driver::host_triple();
@@ -425,8 +423,8 @@ impl<'a> CrateLoader for Loader<'a> {
425423
load_ctxt.os = config::cfg_os_to_meta_os(self.env.sess.targ_cfg.os);
426424
load_ctxt.filesearch = self.env.sess.target_filesearch();
427425
let lib = load_ctxt.load_library_crate();
428-
if decoder::get_macro_registrar_fn(lib.metadata.as_slice()).is_some() {
429-
let message = format!("crate `{}` contains a macro_registrar fn but \
426+
if decoder::get_plugin_registrar_fn(lib.metadata.as_slice()).is_some() {
427+
let message = format!("crate `{}` contains a plugin_registrar fn but \
430428
only a version for triple `{}` could be found (need {})",
431429
info.ident, target_triple, driver::host_triple());
432430
self.env.sess.span_err(krate.span, message.as_slice());
@@ -441,10 +439,10 @@ impl<'a> CrateLoader for Loader<'a> {
441439
None => { load_ctxt.report_load_errs(); unreachable!() },
442440
};
443441
let macros = decoder::get_exported_macros(library.metadata.as_slice());
444-
let registrar = decoder::get_macro_registrar_fn(library.metadata.as_slice()).map(|id| {
442+
let registrar = decoder::get_plugin_registrar_fn(library.metadata.as_slice()).map(|id| {
445443
decoder::get_symbol(library.metadata.as_slice(), id).to_string()
446444
});
447-
let mc = MacroCrate {
445+
let pc = PluginMetadata {
448446
lib: library.dylib.clone(),
449447
macros: macros.move_iter().map(|x| x.to_string()).collect(),
450448
registrar_symbol: registrar,
@@ -454,6 +452,6 @@ impl<'a> CrateLoader for Loader<'a> {
454452
register_crate(&mut self.env, &None, info.ident.as_slice(),
455453
&info.crate_id, krate.span, library);
456454
}
457-
mc
455+
pc
458456
}
459457
}

branches/auto/src/librustc/metadata/cstore.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,6 @@ impl CStore {
139139
.map(|source| source.clone())
140140
}
141141

142-
pub fn dump_phase_syntax_crates(&self) {
143-
}
144-
145142
pub fn reset(&self) {
146143
self.metas.borrow_mut().clear();
147144
self.extern_mod_crate_map.borrow_mut().clear();

branches/auto/src/librustc/metadata/decoder.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1255,8 +1255,8 @@ pub fn get_native_libraries(cdata: Cmd)
12551255
return result;
12561256
}
12571257

1258-
pub fn get_macro_registrar_fn(data: &[u8]) -> Option<ast::NodeId> {
1259-
reader::maybe_get_doc(ebml::Doc::new(data), tag_macro_registrar_fn)
1258+
pub fn get_plugin_registrar_fn(data: &[u8]) -> Option<ast::NodeId> {
1259+
reader::maybe_get_doc(ebml::Doc::new(data), tag_plugin_registrar_fn)
12601260
.map(|doc| FromPrimitive::from_u32(reader::doc_as_u32(doc)).unwrap())
12611261
}
12621262

0 commit comments

Comments
 (0)