]> git.lizzy.rs Git - rust.git/commitdiff
auto merge of #14554 : kmcallister/rust/plugin_registrar, r=cmr
authorbors <bors@rust-lang.org>
Mon, 9 Jun 2014 22:52:07 +0000 (15:52 -0700)
committerbors <bors@rust-lang.org>
Mon, 9 Jun 2014 22:52:07 +0000 (15:52 -0700)
This implements the design in rust-lang/rfcs#86.  It shouldn't be merged until that RFC is accepted, but it would be great if somebody has time to review the code before then.

96 files changed:
mk/crates.mk
src/compiletest/compiletest.rs
src/doc/rust.md
src/liballoc/lib.rs
src/libcollections/lib.rs
src/libflate/lib.rs
src/libfourcc/lib.rs
src/libgetopts/lib.rs
src/libgreen/lib.rs
src/libhexfloat/lib.rs
src/liblog/lib.rs
src/liblog/macros.rs
src/librand/lib.rs
src/libregex/lib.rs
src/libregex/re.rs
src/libregex/test/mod.rs
src/libregex_macros/lib.rs
src/librustc/driver/driver.rs
src/librustc/driver/session.rs
src/librustc/front/feature_gate.rs
src/librustc/front/std_inject.rs
src/librustc/front/test.rs
src/librustc/lib.rs
src/librustc/metadata/common.rs
src/librustc/metadata/creader.rs
src/librustc/metadata/cstore.rs
src/librustc/metadata/decoder.rs
src/librustc/metadata/encoder.rs
src/librustc/plugin/build.rs [new file with mode: 0644]
src/librustc/plugin/load.rs [new file with mode: 0644]
src/librustc/plugin/mod.rs [new file with mode: 0644]
src/librustc/plugin/registry.rs [new file with mode: 0644]
src/librustdoc/core.rs
src/librustdoc/lib.rs
src/librustdoc/test.rs
src/librustrt/lib.rs
src/libserialize/lib.rs
src/libstd/lib.rs
src/libsync/lib.rs
src/libsyntax/ext/base.rs
src/libsyntax/ext/expand.rs
src/libsyntax/ext/registrar.rs [deleted file]
src/libsyntax/lib.rs
src/libterm/lib.rs
src/libtime/lib.rs
src/test/auxiliary/issue-13560-3.rs
src/test/auxiliary/logging_right_crate.rs
src/test/auxiliary/macro_crate_outlive_expansion_phase.rs [deleted file]
src/test/auxiliary/macro_crate_test.rs
src/test/auxiliary/plugin_crate_outlive_expansion_phase.rs [new file with mode: 0644]
src/test/auxiliary/syntax-extension-with-dll-deps-2.rs
src/test/auxiliary/weak-lang-items.rs
src/test/bench/shootout-chameneos-redux.rs
src/test/bench/shootout-meteor.rs
src/test/bench/shootout-regex-dna.rs
src/test/bench/shootout-spectralnorm.rs
src/test/bench/shootout-threadring.rs
src/test/compile-fail-fulldeps/gated-phase.rs
src/test/compile-fail-fulldeps/macro-crate-unexported-macro.rs
src/test/compile-fail-fulldeps/macro-crate-unknown-crate.rs
src/test/compile-fail-fulldeps/phase-syntax-doesnt-resolve.rs
src/test/compile-fail-fulldeps/syntax-extension-fourcc-bad-len.rs
src/test/compile-fail-fulldeps/syntax-extension-fourcc-invalid-endian.rs
src/test/compile-fail-fulldeps/syntax-extension-fourcc-non-ascii-str.rs
src/test/compile-fail-fulldeps/syntax-extension-fourcc-non-literal.rs
src/test/compile-fail-fulldeps/syntax-extension-fourcc-unsupported-literal.rs
src/test/compile-fail-fulldeps/syntax-extension-hexfloat-bad-lits.rs
src/test/compile-fail-fulldeps/syntax-extension-hexfloat-bad-types.rs
src/test/compile-fail-fulldeps/syntax-extension-regex-invalid.rs
src/test/compile-fail-fulldeps/syntax-extension-regex-unused-static.rs
src/test/compile-fail-fulldeps/syntax-extension-regex-unused.rs
src/test/compile-fail/gated-macro_registrar.rs [deleted file]
src/test/compile-fail/gated-plugin_registrar.rs [new file with mode: 0644]
src/test/compile-fail/multiple-macro-registrars.rs [deleted file]
src/test/compile-fail/multiple-plugin-registrars.rs [new file with mode: 0644]
src/test/run-fail/rt-set-exit-status-fail.rs
src/test/run-fail/rt-set-exit-status-fail2.rs
src/test/run-fail/rt-set-exit-status.rs
src/test/run-make/lto-syntax-extension/main.rs
src/test/run-pass-fulldeps/macro-crate-outlive-expansion-phase.rs
src/test/run-pass-fulldeps/macro-crate.rs
src/test/run-pass-fulldeps/phase-syntax-link-does-resolve.rs
src/test/run-pass-fulldeps/syntax-extension-fourcc.rs
src/test/run-pass-fulldeps/syntax-extension-hexfloat.rs
src/test/run-pass-fulldeps/syntax-extension-with-dll-deps.rs
src/test/run-pass/capturing-logging.rs
src/test/run-pass/conditional-debug-macro-off.rs
src/test/run-pass/deprecated-phase-syntax.rs [new file with mode: 0644]
src/test/run-pass/issue-14456.rs
src/test/run-pass/logging-enabled-debug.rs
src/test/run-pass/logging-enabled.rs
src/test/run-pass/logging-separate-lines.rs
src/test/run-pass/macro-crate-def-only.rs
src/test/run-pass/macro-export-inner-module.rs
src/test/run-pass/phase-use-ignored.rs
src/test/run-pass/tcp-stress.rs

index 433490f6f5dbfd4985b52b7d53c2bb0ab794c477..cc6532945efad7fc2a7c65a43a9b7326f5e43eb7 100644 (file)
@@ -83,8 +83,8 @@ DEPS_uuid := std serialize
 DEPS_sync := std alloc
 DEPS_getopts := std
 DEPS_collections := core alloc
-DEPS_fourcc := syntax std
-DEPS_hexfloat := syntax std
+DEPS_fourcc := rustc syntax std
+DEPS_hexfloat := rustc syntax std
 DEPS_num := std
 DEPS_test := std getopts serialize term time regex native:rust_test_helpers
 DEPS_time := std serialize sync
@@ -92,7 +92,7 @@ DEPS_rand := core
 DEPS_url := std
 DEPS_log := std sync
 DEPS_regex := std
-DEPS_regex_macros = syntax std regex
+DEPS_regex_macros = rustc syntax std regex
 DEPS_fmt_macros = std
 
 TOOL_DEPS_compiletest := test green rustuv getopts
index 8fcad94ee1cfc7cff997f61b143426c9c50b7105..de0ca4971f5c2ba085bd1185dcfa5ed6f3f3d38f 100644 (file)
 
 extern crate test;
 extern crate getopts;
-#[phase(link, syntax)]
-extern crate log;
 extern crate green;
 extern crate rustuv;
 
+#[cfg(stage0)]
+#[phase(syntax, link)]
+extern crate log;
+
+#[cfg(not(stage0))]
+#[phase(plugin, link)]
+extern crate log;
+
 extern crate regex;
 
 use std::os;
index 619e24af36063b65a7c908dab0623d612f2d8702..35d356bb1b56cd8e4935a627d0a20b1f1134b072 100644 (file)
@@ -1819,9 +1819,8 @@ type int8_t = i8;
 
 ### Function-only attributes
 
-- `macro_registrar` - when using loadable syntax extensions, mark this
-  function as the registration point for the current crate's syntax
-  extensions.
+- `plugin_registrar` - mark this function as the registration point for
+  compiler plugins, such as loadable syntax extensions.
 - `main` - indicates that this function should be passed to the entry point,
   rather than the function in the crate root named `main`.
 - `start` - indicates that this function should be used as the entry point,
@@ -4098,7 +4097,7 @@ that demonstrates all four of them:
 
 ~~~~
 #![feature(phase)]
-#[phase(syntax, link)] extern crate log;
+#[phase(plugin, link)] extern crate log;
 
 fn main() {
     error!("This is an error log")
index ca7ed6f4ba05bda7329cc0139c0138d92de67330..7e2c9a75fad0d3eee0b23ecb3bb5de6dcc776302 100644 (file)
 #![no_std]
 #![feature(phase)]
 
+#[cfg(stage0)]
 #[phase(syntax, link)]
 extern crate core;
+
+#[cfg(not(stage0))]
+#[phase(plugin, link)]
+extern crate core;
+
 extern crate libc;
 
 
 #[cfg(test)] extern crate debug;
 #[cfg(test)] extern crate sync;
 #[cfg(test)] extern crate native;
-#[cfg(test)] #[phase(syntax, link)] extern crate std;
-#[cfg(test)] #[phase(syntax, link)] extern crate log;
+#[cfg(test, stage0)] #[phase(syntax, link)] extern crate std;
+#[cfg(test, stage0)] #[phase(syntax, link)] extern crate log;
+#[cfg(test, not(stage0))] #[phase(plugin, link)] extern crate std;
+#[cfg(test, not(stage0))] #[phase(plugin, link)] extern crate log;
 
 // Heaps provided for low-level allocation strategies
 
index 602ecf39a836c837374bbe167826a9b4895e0b09..a114755a0ed91a3ac011fd8b6cc8020e8ef3b89c 100644 (file)
 #![feature(macro_rules, managed_boxes, default_type_params, phase, globs)]
 #![no_std]
 
-#[phase(syntax, link)] extern crate core;
 extern crate alloc;
 
+#[cfg(stage0)]
+#[phase(syntax, link)]
+extern crate core;
+
+#[cfg(not(stage0))]
+#[phase(plugin, link)]
+extern crate core;
+
 #[cfg(test)] extern crate native;
 #[cfg(test)] extern crate test;
 #[cfg(test)] extern crate debug;
-#[cfg(test)] #[phase(syntax, link)] extern crate std;
-#[cfg(test)] #[phase(syntax, link)] extern crate log;
+
+#[cfg(test, stage0)] #[phase(syntax, link)] extern crate std;
+#[cfg(test, stage0)] #[phase(syntax, link)] extern crate log;
+#[cfg(test, not(stage0))] #[phase(plugin, link)] extern crate std;
+#[cfg(test, not(stage0))] #[phase(plugin, link)] extern crate log;
 
 use core::prelude::*;
 
index 8bfd2d867c130ad749497202ef0d56b40b62d1c4..8d8fe8ffe8cfe404c10aa577d9cd0f4207bc3cc3 100644 (file)
@@ -28,7 +28,8 @@
 #![feature(phase)]
 #![deny(deprecated_owned_vector)]
 
-#[cfg(test)] #[phase(syntax, link)] extern crate log;
+#[cfg(test, stage0)] #[phase(syntax, link)] extern crate log;
+#[cfg(test, not(stage0))] #[phase(plugin, link)] extern crate log;
 
 extern crate libc;
 
index 194de7b2f4aee5a944950a6ae0a3daa411f5a56f..694fe7d0f48b08fa3e3fb9097f443c67e2379b50 100644 (file)
@@ -22,7 +22,7 @@
 To load the extension and use it:
 
 ```rust,ignore
-#[phase(syntax)]
+#[phase(plugin)]
 extern crate fourcc;
 
 fn main() {
@@ -48,29 +48,25 @@ fn main() {
        html_root_url = "http://doc.rust-lang.org/")]
 
 #![deny(deprecated_owned_vector)]
-#![feature(macro_registrar, managed_boxes)]
+#![feature(plugin_registrar, managed_boxes)]
 
 extern crate syntax;
+extern crate rustc;
 
 use syntax::ast;
-use syntax::ast::Name;
 use syntax::attr::contains;
 use syntax::codemap::{Span, mk_sp};
 use syntax::ext::base;
-use syntax::ext::base::{SyntaxExtension, BasicMacroExpander, NormalTT, ExtCtxt, MacExpr};
+use syntax::ext::base::{ExtCtxt, MacExpr};
 use syntax::ext::build::AstBuilder;
 use syntax::parse;
 use syntax::parse::token;
 use syntax::parse::token::InternedString;
+use rustc::plugin::Registry;
 
-#[macro_registrar]
-pub fn macro_registrar(register: |Name, SyntaxExtension|) {
-    register(token::intern("fourcc"),
-        NormalTT(box BasicMacroExpander {
-            expander: expand_syntax_ext,
-            span: None,
-        },
-        None));
+#[plugin_registrar]
+pub fn plugin_registrar(reg: &mut Registry) {
+    reg.register_macro("fourcc", expand_syntax_ext);
 }
 
 pub fn expand_syntax_ext(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
index 10584223486c00a8dd9a495104727817d5383dc3..dec62265516fdb5da21e4285641a8b105300b9e8 100644 (file)
@@ -91,7 +91,8 @@
 #![deny(deprecated_owned_vector)]
 
 #[cfg(test)] extern crate debug;
-#[cfg(test)] #[phase(syntax, link)] extern crate log;
+#[cfg(test, stage0)] #[phase(syntax, link)] extern crate log;
+#[cfg(test, not(stage0))] #[phase(plugin, link)] extern crate log;
 
 use std::cmp::PartialEq;
 use std::result::{Err, Ok};
index 333ac80907f6a9012a2ea6e5040674e0fddc4983..9748dfbae33f0dc8f744797f43e695cea15f4068 100644 (file)
 //!
 //! ```
 //! #![feature(phase)]
-//! #[phase(syntax)] extern crate green;
+//! #[phase(plugin)] extern crate green;
 //!
 //! green_start!(main)
 //!
 #![allow(visible_private_types)]
 #![deny(deprecated_owned_vector)]
 
-#[cfg(test)] #[phase(syntax, link)] extern crate log;
+#[cfg(test)] #[phase(plugin, link)] extern crate log;
 #[cfg(test)] extern crate rustuv;
 extern crate libc;
 extern crate alloc;
 ///
 /// ```
 /// #![feature(phase)]
-/// #[phase(syntax)] extern crate green;
+/// #[phase(plugin)] extern crate green;
 ///
 /// green_start!(main)
 ///
index ee14f1aaea9a2a97fd0b2d28eb8dbc56cf2bd291..54bc2802b09ac364cb92ab2b6f42d3dcc44abf62 100644 (file)
@@ -21,7 +21,7 @@
 To load the extension and use it:
 
 ```rust,ignore
-#[phase(syntax)]
+#[phase(plugin)]
 extern crate hexfloat;
 
 fn main() {
@@ -45,27 +45,23 @@ fn main() {
        html_root_url = "http://doc.rust-lang.org/")]
 
 #![deny(deprecated_owned_vector)]
-#![feature(macro_registrar, managed_boxes)]
+#![feature(plugin_registrar, managed_boxes)]
 
 extern crate syntax;
+extern crate rustc;
 
 use syntax::ast;
-use syntax::ast::Name;
 use syntax::codemap::{Span, mk_sp};
 use syntax::ext::base;
-use syntax::ext::base::{SyntaxExtension, BasicMacroExpander, NormalTT, ExtCtxt, MacExpr};
+use syntax::ext::base::{ExtCtxt, MacExpr};
 use syntax::ext::build::AstBuilder;
 use syntax::parse;
 use syntax::parse::token;
+use rustc::plugin::Registry;
 
-#[macro_registrar]
-pub fn macro_registrar(register: |Name, SyntaxExtension|) {
-    register(token::intern("hexfloat"),
-        NormalTT(box BasicMacroExpander {
-            expander: expand_syntax_ext,
-            span: None,
-        },
-        None));
+#[plugin_registrar]
+pub fn plugin_registrar(reg: &mut Registry) {
+    reg.register_macro("hexfloat", expand_syntax_ext);
 }
 
 //Check if the literal is valid (as LLVM expects),
index daacf8b3c47610ff6294905ce7cbce2256eb83f1..254f9aaf55e4399a9ff06816d6e512494caed3cd 100644 (file)
@@ -16,7 +16,7 @@
 
 ```
 #![feature(phase)]
-#[phase(syntax, link)] extern crate log;
+#[phase(plugin, link)] extern crate log;
 
 fn main() {
     debug!("this is a debug {}", "message");
index 3bb49c237f14686651e21ca731aa0156bd81fc42..dba34c42a7e15997a7f9afa039a30be880b2f217 100644 (file)
@@ -22,7 +22,7 @@
 ///
 /// ```
 /// #![feature(phase)]
-/// #[phase(syntax, link)] extern crate log;
+/// #[phase(plugin, link)] extern crate log;
 ///
 /// # fn main() {
 /// log!(log::DEBUG, "this is a debug message");
@@ -51,7 +51,7 @@ macro_rules! log(
 ///
 /// ```
 /// #![feature(phase)]
-/// #[phase(syntax, link)] extern crate log;
+/// #[phase(plugin, link)] extern crate log;
 ///
 /// # fn main() {
 /// # let error = 3;
@@ -69,7 +69,7 @@ macro_rules! error(
 ///
 /// ```
 /// #![feature(phase)]
-/// #[phase(syntax, link)] extern crate log;
+/// #[phase(plugin, link)] extern crate log;
 ///
 /// # fn main() {
 /// # let code = 3;
@@ -87,7 +87,7 @@ macro_rules! warn(
 ///
 /// ```
 /// #![feature(phase)]
-/// #[phase(syntax, link)] extern crate log;
+/// #[phase(plugin, link)] extern crate log;
 ///
 /// # fn main() {
 /// # let ret = 3;
@@ -107,7 +107,7 @@ macro_rules! info(
 ///
 /// ```
 /// #![feature(phase)]
-/// #[phase(syntax, link)] extern crate log;
+/// #[phase(plugin, link)] extern crate log;
 ///
 /// # fn main() {
 /// debug!("x = {x}, y = {y}", x=10, y=20);
@@ -124,7 +124,7 @@ macro_rules! debug(
 ///
 /// ```
 /// #![feature(phase)]
-/// #[phase(syntax, link)] extern crate log;
+/// #[phase(plugin, link)] extern crate log;
 ///
 /// # fn main() {
 /// # struct Point { x: int, y: int }
index 7a12dcf9f7f319ffcf32b049c5b94c352dea6a37..1f7216fc1a37d9e05b6270cf121703edc3e1af3f 100644 (file)
 #![no_std]
 #![experimental]
 
+#[cfg(stage0)]
 #[phase(syntax, link)]
 extern crate core;
 
+#[cfg(not(stage0))]
+#[phase(plugin, link)]
+extern crate core;
+
+#[cfg(test, stage0)]
+#[phase(syntax, link)] extern crate std;
+
+#[cfg(test, stage0)]
+#[phase(syntax, link)] extern crate log;
+
+#[cfg(test, not(stage0))]
+#[phase(plugin, link)] extern crate std;
+
+#[cfg(test, not(stage0))]
+#[phase(plugin, link)] extern crate log;
+
 #[cfg(test)] extern crate native;
 #[cfg(test)] extern crate debug;
-#[cfg(test)] #[phase(syntax, link)] extern crate std;
-#[cfg(test)] #[phase(syntax, link)] extern crate log;
 
 use core::prelude::*;
 
index 44c206162ab25f24cadc0d35fecc4b8a7edc301b..61e62a0d1053e960bd905310144fb9fbfe8bbe7c 100644 (file)
@@ -65,7 +65,7 @@
 //!
 //! ```rust
 //! #![feature(phase)]
-//! #[phase(syntax)]
+//! #[phase(plugin)]
 //! extern crate regex_macros;
 //! extern crate regex;
 //!
@@ -95,7 +95,7 @@
 //!
 //! ```rust
 //! # #![feature(phase)]
-//! # extern crate regex; #[phase(syntax)] extern crate regex_macros;
+//! # extern crate regex; #[phase(plugin)] extern crate regex_macros;
 //! # fn main() {
 //! let re = regex!(r"(\d{4})-(\d{2})-(\d{2})");
 //! let text = "2012-03-14, 2013-01-01 and 2014-07-05";
 //!
 //! ```rust
 //! # #![feature(phase)]
-//! # extern crate regex; #[phase(syntax)] extern crate regex_macros;
+//! # extern crate regex; #[phase(plugin)] extern crate regex_macros;
 //! # fn main() {
 //! let re = regex!(r"(?P<y>\d{4})-(?P<m>\d{2})-(?P<d>\d{2})");
 //! let before = "2012-03-14, 2013-01-01 and 2014-07-05";
 //!
 //! ```rust
 //! # #![feature(phase)]
-//! # extern crate regex; #[phase(syntax)] extern crate regex_macros;
+//! # extern crate regex; #[phase(plugin)] extern crate regex_macros;
 //! # fn main() {
 //! let re = regex!(r"(?i)Δ+");
 //! assert_eq!(re.find("ΔδΔ"), Some((0, 6)));
 //!
 //! ```rust
 //! # #![feature(phase)]
-//! # extern crate regex; #[phase(syntax)] extern crate regex_macros;
+//! # extern crate regex; #[phase(plugin)] extern crate regex_macros;
 //! # fn main() {
 //! let re = regex!(r"[\pN\p{Greek}\p{Cherokee}]+");
 //! assert_eq!(re.find("abcΔᎠβⅠᏴγδⅡxyz"), Some((3, 23)));
 //!
 //! ```rust
 //! # #![feature(phase)]
-//! # extern crate regex; #[phase(syntax)] extern crate regex_macros;
+//! # extern crate regex; #[phase(plugin)] extern crate regex_macros;
 //! # fn main() {
 //! let re = regex!(r"(?i)a+(?-i)b+");
 //! let cap = re.captures("AaAaAbbBBBb").unwrap();
index a499c1e125dede9e2ec300e2caa962a87b2a3189..054cbb0fcd63dfa2c518f793bdeb3fd80f4599aa 100644 (file)
@@ -87,7 +87,7 @@ pub fn is_match(regex: &str, text: &str) -> Result<bool, parse::Error> {
 /// ```rust
 /// #![feature(phase)]
 /// extern crate regex;
-/// #[phase(syntax)] extern crate regex_macros;
+/// #[phase(plugin)] extern crate regex_macros;
 ///
 /// fn main() {
 ///     let re = regex!(r"\d+");
@@ -172,7 +172,7 @@ pub fn new(re: &str) -> Result<Regex, parse::Error> {
     ///
     /// ```rust
     /// # #![feature(phase)]
-    /// # extern crate regex; #[phase(syntax)] extern crate regex_macros;
+    /// # extern crate regex; #[phase(plugin)] extern crate regex_macros;
     /// # fn main() {
     /// let text = "I categorically deny having triskaidekaphobia.";
     /// let matched = regex!(r"\b\w{13}\b").is_match(text);
@@ -197,7 +197,7 @@ pub fn is_match(&self, text: &str) -> bool {
     ///
     /// ```rust
     /// # #![feature(phase)]
-    /// # extern crate regex; #[phase(syntax)] extern crate regex_macros;
+    /// # extern crate regex; #[phase(plugin)] extern crate regex_macros;
     /// # fn main() {
     /// let text = "I categorically deny having triskaidekaphobia.";
     /// let pos = regex!(r"\b\w{13}\b").find(text);
@@ -224,7 +224,7 @@ pub fn find(&self, text: &str) -> Option<(uint, uint)> {
     ///
     /// ```rust
     /// # #![feature(phase)]
-    /// # extern crate regex; #[phase(syntax)] extern crate regex_macros;
+    /// # extern crate regex; #[phase(plugin)] extern crate regex_macros;
     /// # fn main() {
     /// let text = "Retroactively relinquishing remunerations is reprehensible.";
     /// for pos in regex!(r"\b\w{13}\b").find_iter(text) {
@@ -263,7 +263,7 @@ pub fn find_iter<'r, 't>(&'r self, text: &'t str) -> FindMatches<'r, 't> {
     ///
     /// ```rust
     /// # #![feature(phase)]
-    /// # extern crate regex; #[phase(syntax)] extern crate regex_macros;
+    /// # extern crate regex; #[phase(plugin)] extern crate regex_macros;
     /// # fn main() {
     /// let re = regex!(r"'([^']+)'\s+\((\d{4})\)");
     /// let text = "Not my favorite movie: 'Citizen Kane' (1941).";
@@ -281,7 +281,7 @@ pub fn find_iter<'r, 't>(&'r self, text: &'t str) -> FindMatches<'r, 't> {
     ///
     /// ```rust
     /// # #![feature(phase)]
-    /// # extern crate regex; #[phase(syntax)] extern crate regex_macros;
+    /// # extern crate regex; #[phase(plugin)] extern crate regex_macros;
     /// # fn main() {
     /// let re = regex!(r"'(?P<title>[^']+)'\s+\((?P<year>\d{4})\)");
     /// let text = "Not my favorite movie: 'Citizen Kane' (1941).";
@@ -314,7 +314,7 @@ pub fn captures<'t>(&self, text: &'t str) -> Option<Captures<'t>> {
     ///
     /// ```rust
     /// # #![feature(phase)]
-    /// # extern crate regex; #[phase(syntax)] extern crate regex_macros;
+    /// # extern crate regex; #[phase(plugin)] extern crate regex_macros;
     /// # fn main() {
     /// let re = regex!(r"'(?P<title>[^']+)'\s+\((?P<year>\d{4})\)");
     /// let text = "'Citizen Kane' (1941), 'The Wizard of Oz' (1939), 'M' (1931).";
@@ -350,7 +350,7 @@ pub fn captures_iter<'r, 't>(&'r self, text: &'t str)
     ///
     /// ```rust
     /// # #![feature(phase)]
-    /// # extern crate regex; #[phase(syntax)] extern crate regex_macros;
+    /// # extern crate regex; #[phase(plugin)] extern crate regex_macros;
     /// # fn main() {
     /// let re = regex!(r"[ \t]+");
     /// let fields: Vec<&str> = re.split("a b \t  c\td    e").collect();
@@ -380,7 +380,7 @@ pub fn split<'r, 't>(&'r self, text: &'t str) -> RegexSplits<'r, 't> {
     ///
     /// ```rust
     /// # #![feature(phase)]
-    /// # extern crate regex; #[phase(syntax)] extern crate regex_macros;
+    /// # extern crate regex; #[phase(plugin)] extern crate regex_macros;
     /// # fn main() {
     /// let re = regex!(r"\W+");
     /// let fields: Vec<&str> = re.splitn("Hey! How are you?", 3).collect();
@@ -410,7 +410,7 @@ pub fn splitn<'r, 't>(&'r self, text: &'t str, limit: uint)
     ///
     /// ```rust
     /// # #![feature(phase)]
-    /// # extern crate regex; #[phase(syntax)] extern crate regex_macros;
+    /// # extern crate regex; #[phase(plugin)] extern crate regex_macros;
     /// # fn main() {
     /// let re = regex!("[^01]+");
     /// assert_eq!(re.replace("1078910", "").as_slice(), "1010");
@@ -424,7 +424,7 @@ pub fn splitn<'r, 't>(&'r self, text: &'t str, limit: uint)
     ///
     /// ```rust
     /// # #![feature(phase)]
-    /// # extern crate regex; #[phase(syntax)] extern crate regex_macros;
+    /// # extern crate regex; #[phase(plugin)] extern crate regex_macros;
     /// # use regex::Captures; fn main() {
     /// let re = regex!(r"([^,\s]+),\s+(\S+)");
     /// let result = re.replace("Springsteen, Bruce", |caps: &Captures| {
@@ -441,7 +441,7 @@ pub fn splitn<'r, 't>(&'r self, text: &'t str, limit: uint)
     ///
     /// ```rust
     /// # #![feature(phase)]
-    /// # extern crate regex; #[phase(syntax)] extern crate regex_macros;
+    /// # extern crate regex; #[phase(plugin)] extern crate regex_macros;
     /// # fn main() {
     /// let re = regex!(r"(?P<last>[^,\s]+),\s+(?P<first>\S+)");
     /// let result = re.replace("Springsteen, Bruce", "$first $last");
@@ -458,7 +458,7 @@ pub fn splitn<'r, 't>(&'r self, text: &'t str, limit: uint)
     ///
     /// ```rust
     /// # #![feature(phase)]
-    /// # extern crate regex; #[phase(syntax)] extern crate regex_macros;
+    /// # extern crate regex; #[phase(plugin)] extern crate regex_macros;
     /// # fn main() {
     /// use regex::NoExpand;
     ///
index c563c84fc34ed351971353ffadb6336f77efcc31..96c600b0fda3a4a50f0a5dc04345b1b604d322c1 100644 (file)
@@ -9,7 +9,7 @@
 // except according to those terms.
 
 #[cfg(not(stage1))]
-#[phase(syntax)]
+#[phase(plugin)]
 extern crate regex_macros;
 
 #[cfg(not(stage1))]
index fb7e4211d494c74e1d751cd7594fda9e11b22f91..bbee09d0f38b37512ca502e9e2bdf95d0d0e47e4 100644 (file)
        html_favicon_url = "http://www.rust-lang.org/favicon.ico",
        html_root_url = "http://doc.rust-lang.org/")]
 
-#![feature(macro_registrar, managed_boxes, quote)]
+#![feature(plugin_registrar, managed_boxes, quote)]
 
 extern crate regex;
 extern crate syntax;
+extern crate rustc;
 
 use std::rc::Rc;
 
 use syntax::ast;
 use syntax::codemap;
 use syntax::ext::build::AstBuilder;
-use syntax::ext::base::{
-    SyntaxExtension, ExtCtxt, MacResult, MacExpr, DummyResult,
-    NormalTT, BasicMacroExpander,
-};
+use syntax::ext::base::{ExtCtxt, MacResult, MacExpr, DummyResult};
 use syntax::parse;
 use syntax::parse::token;
 use syntax::print::pprust;
 
+use rustc::plugin::Registry;
+
 use regex::Regex;
 use regex::native::{
     OneChar, CharClass, Any, Save, Jump, Split,
 };
 
 /// For the `regex!` syntax extension. Do not use.
-#[macro_registrar]
+#[plugin_registrar]
 #[doc(hidden)]
-pub fn macro_registrar(register: |ast::Name, SyntaxExtension|) {
-    let expander = box BasicMacroExpander { expander: native, span: None };
-    register(token::intern("regex"), NormalTT(expander, None))
+pub fn plugin_registrar(reg: &mut Registry) {
+    reg.register_macro("regex", native);
 }
 
 /// Generates specialized code for the Pike VM for a particular regular
index 89c0a381cf9f295afa4e38ab1b797eba50de5978..45e9c7b562d0f1631b36f976bc0cd115bcfb12d1 100644 (file)
 use lib::llvm::{ContextRef, ModuleRef};
 use metadata::common::LinkMeta;
 use metadata::creader;
-use metadata::creader::Loader;
 use middle::cfg;
 use middle::cfg::graphviz::LabelledCFG;
 use middle::{trans, freevars, kind, ty, typeck, lint, reachable};
 use middle::dependency_format;
 use middle;
+use plugin::load::Plugins;
+use plugin::registry::Registry;
+use plugin;
 use util::common::time;
 use util::ppaux;
 use util::nodemap::{NodeSet};
@@ -39,7 +41,6 @@
 use syntax::attr;
 use syntax::attr::{AttrMetaMethods};
 use syntax::crateid::CrateId;
-use syntax::ext::base::CrateLoader;
 use syntax::parse;
 use syntax::parse::token;
 use syntax::print::{pp, pprust};
@@ -75,11 +76,10 @@ pub fn compile_input(sess: Session,
                                                  output,
                                                  krate.attrs.as_slice(),
                                                  &sess);
-            let loader = &mut Loader::new(&sess);
             let id = link::find_crate_id(krate.attrs.as_slice(),
                                          outputs.out_filestem.as_slice());
             let (expanded_crate, ast_map) =
-                phase_2_configure_and_expand(&sess, loader, krate, &id);
+                phase_2_configure_and_expand(&sess, krate, &id);
             (outputs, expanded_crate, ast_map)
         };
         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)
 /// harness if one is to be provided and injection of a dependency on the
 /// standard library and prelude.
 pub fn phase_2_configure_and_expand(sess: &Session,
-                                    loader: &mut CrateLoader,
                                     mut krate: ast::Crate,
                                     crate_id: &CrateId)
                                     -> (ast::Crate, syntax::ast_map::Map) {
@@ -197,25 +196,42 @@ pub fn phase_2_configure_and_expand(sess: &Session,
     krate = time(time_passes, "configuration 1", krate, |krate|
                  front::config::strip_unconfigured_items(krate));
 
-    krate = time(time_passes, "expansion", krate, |krate| {
-        // Windows dlls do not have rpaths, so they don't know how to find their
-        // dependencies. It's up to us to tell the system where to find all the
-        // dependent dlls. Note that this uses cfg!(windows) as opposed to
-        // targ_cfg because syntax extensions are always loaded for the host
-        // compiler, not for the target.
-        if cfg!(windows) {
-            sess.host_filesearch().add_dylib_search_paths();
+    let Plugins { macros, registrars }
+        = time(time_passes, "plugin loading", (), |_|
+               plugin::load::load_plugins(sess, &krate));
+
+    let mut registry = Registry::new(&krate);
+
+    time(time_passes, "plugin registration", (), |_| {
+        for &registrar in registrars.iter() {
+            registrar(&mut registry);
         }
-        let cfg = syntax::ext::expand::ExpansionConfig {
-            loader: loader,
-            deriving_hash_type_parameter: sess.features.default_type_params.get(),
-            crate_id: crate_id.clone(),
-        };
-        syntax::ext::expand::expand_crate(&sess.parse_sess,
-                                          cfg,
-                                          krate)
     });
 
+    let Registry { syntax_exts, .. } = registry;
+
+    krate = time(time_passes, "expansion", (krate, macros, syntax_exts),
+        |(krate, macros, syntax_exts)| {
+            // Windows dlls do not have rpaths, so they don't know how to find their
+            // dependencies. It's up to us to tell the system where to find all the
+            // dependent dlls. Note that this uses cfg!(windows) as opposed to
+            // targ_cfg because syntax extensions are always loaded for the host
+            // compiler, not for the target.
+            if cfg!(windows) {
+                sess.host_filesearch().add_dylib_search_paths();
+            }
+            let cfg = syntax::ext::expand::ExpansionConfig {
+                deriving_hash_type_parameter: sess.features.default_type_params.get(),
+                crate_id: crate_id.clone(),
+            };
+            syntax::ext::expand::expand_crate(&sess.parse_sess,
+                                              cfg,
+                                              macros,
+                                              syntax_exts,
+                                              krate)
+        }
+    );
+
     // strip again, in case expansion added anything with a #[cfg].
     krate = time(time_passes, "configuration 2", krate, |krate|
                  front::config::strip_unconfigured_items(krate));
@@ -281,9 +297,9 @@ pub fn phase_3_run_analysis_passes(sess: Session,
     time(time_passes, "looking for entry point", (),
          |_| middle::entry::find_entry_point(&sess, krate, &ast_map));
 
-    sess.macro_registrar_fn.set(
-        time(time_passes, "looking for macro registrar", (), |_|
-            syntax::ext::registrar::find_macro_registrar(
+    sess.plugin_registrar_fn.set(
+        time(time_passes, "looking for plugin registrar", (), |_|
+            plugin::build::find_plugin_registrar(
                 sess.diagnostic(), krate)));
 
     let freevars = time(time_passes, "freevar finding", (), |_|
@@ -596,9 +612,7 @@ pub fn pretty_print_input(sess: Session,
 
     let (krate, ast_map, is_expanded) = match ppm {
         PpmExpanded | PpmExpandedIdentified | PpmTyped | PpmFlowGraph(_) => {
-            let loader = &mut Loader::new(&sess);
             let (krate, ast_map) = phase_2_configure_and_expand(&sess,
-                                                                loader,
                                                                 krate,
                                                                 &id);
             (krate, Some(ast_map), true)
index 109622b66277a3c86077059b28cc3092cf3dfc03..773b9e6e0aac4022055e64b6cfea8afa95b38009 100644 (file)
@@ -36,7 +36,7 @@ pub struct Session {
     // For a library crate, this is always none
     pub entry_fn: RefCell<Option<(NodeId, codemap::Span)>>,
     pub entry_type: Cell<Option<config::EntryFnType>>,
-    pub macro_registrar_fn: Cell<Option<ast::NodeId>>,
+    pub plugin_registrar_fn: Cell<Option<ast::NodeId>>,
     pub default_sysroot: Option<Path>,
     // The name of the root source file of the crate, in the local file system. The path is always
     // expected to be absolute. `None` means that there is no source file.
@@ -232,7 +232,7 @@ pub fn build_session_(sopts: config::Options,
         // For a library crate, this is always none
         entry_fn: RefCell::new(None),
         entry_type: Cell::new(None),
-        macro_registrar_fn: Cell::new(None),
+        plugin_registrar_fn: Cell::new(None),
         default_sysroot: default_sysroot,
         local_crate_source_file: local_crate_source_file,
         working_dir: os::getcwd(),
index 25f0dc808c849f62ca1da0391bef7f2e78a04c29..11dd6a86cd811df749a1f9fdbd6538d6f4e113ac 100644 (file)
@@ -46,7 +46,7 @@
     ("thread_local", Active),
     ("link_args", Active),
     ("phase", Active),
-    ("macro_registrar", Active),
+    ("plugin_registrar", Active),
     ("log_syntax", Active),
     ("trace_macros", Active),
     ("concat_idents", Active),
@@ -192,10 +192,9 @@ fn visit_item(&mut self, i: &ast::Item, _:()) {
             }
 
             ast::ItemFn(..) => {
-                if attr::contains_name(i.attrs.as_slice(), "macro_registrar") {
-                    self.gate_feature("macro_registrar", i.span,
-                                      "cross-crate macro exports are \
-                                       experimental and possibly buggy");
+                if attr::contains_name(i.attrs.as_slice(), "plugin_registrar") {
+                    self.gate_feature("plugin_registrar", i.span,
+                                      "compiler plugins are experimental and possibly buggy");
                 }
             }
 
index fe636f7b686a018f839e37229238214752c671c0..0514f7de505ef59b6baedfc161a0c171f0b3255a 100644 (file)
@@ -81,7 +81,7 @@ fn fold_crate(&mut self, mut krate: ast::Crate) -> ast::Crate {
                 attr::mk_attr_outer(attr::mk_attr_id(), attr::mk_list_item(
                         InternedString::new("phase"),
                         vec!(
-                            attr::mk_word_item(InternedString::new("syntax")),
+                            attr::mk_word_item(InternedString::new("plugin")),
                             attr::mk_word_item(InternedString::new("link")
                         ))))),
             vis: ast::Inherited,
index b21f3c2a019322ea5d74265b9bc720ae0e1ec052..174bcc86d263a4f0f9c82fe18a0dcdc452e7a941 100644 (file)
@@ -16,7 +16,6 @@
 use driver::session::Session;
 use front::config;
 use front::std_inject::with_version;
-use metadata::creader::Loader;
 
 use std::cell::RefCell;
 use std::slice;
@@ -150,12 +149,10 @@ fn nomain(item: @ast::Item) -> @ast::Item {
 
 fn generate_test_harness(sess: &Session, krate: ast::Crate)
                          -> ast::Crate {
-    let loader = &mut Loader::new(sess);
     let mut cx: TestCtxt = TestCtxt {
         sess: sess,
         ext_cx: ExtCtxt::new(&sess.parse_sess, sess.opts.cfg.clone(),
                              ExpansionConfig {
-                                 loader: loader,
                                  deriving_hash_type_parameter: false,
                                  crate_id: from_str("test").unwrap(),
                              }),
index 1b17cfb1bae01dd8b038ea644fb8a82812330e1c..4ac4e3a5a9ffbd547f2dffcf4a3c60aba6781916 100644 (file)
 extern crate syntax;
 extern crate time;
 
+#[cfg(stage0)]
 #[phase(syntax, link)]
 extern crate log;
 
+#[cfg(not(stage0))]
+#[phase(plugin, link)]
+extern crate log;
+
 pub mod middle {
     pub mod def;
     pub mod trans;
@@ -109,6 +114,8 @@ pub mod back {
 
 pub mod driver;
 
+pub mod plugin;
+
 pub mod util {
     pub mod common;
     pub mod ppaux;
index 6287683c1a1416313d15822ed2085d2b40ec3fc3..2ff656853c3bdbffb9617dbc56ef6bb320642452 100644 (file)
@@ -198,7 +198,7 @@ pub fn from_uint(value : uint) -> Option<astencode_tag> {
 pub static tag_native_libraries_name: uint = 0x89;
 pub static tag_native_libraries_kind: uint = 0x8a;
 
-pub static tag_macro_registrar_fn: uint = 0x8b;
+pub static tag_plugin_registrar_fn: uint = 0x8b;
 pub static tag_exported_macros: uint = 0x8c;
 pub static tag_macro_def: uint = 0x8d;
 
index 38d2b7a67a0e17e5afd36228de48822e630d7a32..4df21fbc974be7f20f78d5d57eab24c1ff7d19e6 100644 (file)
@@ -21,6 +21,7 @@
 use metadata::decoder;
 use metadata::loader;
 use metadata::loader::CratePaths;
+use plugin::load::PluginMetadata;
 
 use std::rc::Rc;
 use std::collections::HashMap;
@@ -30,7 +31,6 @@
 use syntax::attr::AttrMetaMethods;
 use syntax::codemap::{Span};
 use syntax::diagnostic::SpanHandler;
-use syntax::ext::base::{CrateLoader, MacroCrate};
 use syntax::parse::token::InternedString;
 use syntax::parse::token;
 use syntax::crateid::CrateId;
@@ -379,23 +379,21 @@ fn resolve_crate_deps(e: &mut Env,
     }).collect()
 }
 
-pub struct Loader<'a> {
+pub struct PluginMetadataReader<'a> {
     env: Env<'a>,
 }
 
-impl<'a> Loader<'a> {
-    pub fn new(sess: &'a Session) -> Loader<'a> {
-        Loader {
+impl<'a> PluginMetadataReader<'a> {
+    pub fn new(sess: &'a Session) -> PluginMetadataReader<'a> {
+        PluginMetadataReader {
             env: Env {
                 sess: sess,
                 next_crate_num: sess.cstore.next_crate_num(),
             }
         }
     }
-}
 
-impl<'a> CrateLoader for Loader<'a> {
-    fn load_crate(&mut self, krate: &ast::ViewItem) -> MacroCrate {
+    pub fn read_plugin_metadata(&mut self, krate: &ast::ViewItem) -> PluginMetadata {
         let info = extract_crate_info(&self.env, krate).unwrap();
         let target_triple = self.env.sess.targ_cfg.target_strs.target_triple.as_slice();
         let is_cross = target_triple != driver::host_triple();
@@ -425,8 +423,8 @@ fn load_crate(&mut self, krate: &ast::ViewItem) -> MacroCrate {
                 load_ctxt.os = config::cfg_os_to_meta_os(self.env.sess.targ_cfg.os);
                 load_ctxt.filesearch = self.env.sess.target_filesearch();
                 let lib = load_ctxt.load_library_crate();
-                if decoder::get_macro_registrar_fn(lib.metadata.as_slice()).is_some() {
-                    let message = format!("crate `{}` contains a macro_registrar fn but \
+                if decoder::get_plugin_registrar_fn(lib.metadata.as_slice()).is_some() {
+                    let message = format!("crate `{}` contains a plugin_registrar fn but \
                                   only a version for triple `{}` could be found (need {})",
                                   info.ident, target_triple, driver::host_triple());
                     self.env.sess.span_err(krate.span, message.as_slice());
@@ -441,10 +439,10 @@ fn load_crate(&mut self, krate: &ast::ViewItem) -> MacroCrate {
             None => { load_ctxt.report_load_errs(); unreachable!() },
         };
         let macros = decoder::get_exported_macros(library.metadata.as_slice());
-        let registrar = decoder::get_macro_registrar_fn(library.metadata.as_slice()).map(|id| {
+        let registrar = decoder::get_plugin_registrar_fn(library.metadata.as_slice()).map(|id| {
             decoder::get_symbol(library.metadata.as_slice(), id).to_string()
         });
-        let mc = MacroCrate {
+        let pc = PluginMetadata {
             lib: library.dylib.clone(),
             macros: macros.move_iter().map(|x| x.to_string()).collect(),
             registrar_symbol: registrar,
@@ -454,6 +452,6 @@ fn load_crate(&mut self, krate: &ast::ViewItem) -> MacroCrate {
             register_crate(&mut self.env, &None, info.ident.as_slice(),
                            &info.crate_id, krate.span, library);
         }
-        mc
+        pc
     }
 }
index aa8d695465a117628ae29c0566200128a29c0a68..846f879104f64f7ba559e62815d7b025d65b024e 100644 (file)
@@ -139,9 +139,6 @@ pub fn get_used_crate_source(&self, cnum: ast::CrateNum)
             .map(|source| source.clone())
     }
 
-    pub fn dump_phase_syntax_crates(&self) {
-    }
-
     pub fn reset(&self) {
         self.metas.borrow_mut().clear();
         self.extern_mod_crate_map.borrow_mut().clear();
index c67b5bf1a60076363268a27db47f53d0e7a2df31..8a2c3c08d419ae8b1c319366173901758b1332d7 100644 (file)
@@ -1255,8 +1255,8 @@ pub fn get_native_libraries(cdata: Cmd)
     return result;
 }
 
-pub fn get_macro_registrar_fn(data: &[u8]) -> Option<ast::NodeId> {
-    reader::maybe_get_doc(ebml::Doc::new(data), tag_macro_registrar_fn)
+pub fn get_plugin_registrar_fn(data: &[u8]) -> Option<ast::NodeId> {
+    reader::maybe_get_doc(ebml::Doc::new(data), tag_plugin_registrar_fn)
         .map(|doc| FromPrimitive::from_u32(reader::doc_as_u32(doc)).unwrap())
 }
 
index 37cb75e4697b30cff2dc253d672077d074ff6302..1846c9c881bc570fd3611dc83bf8c33629d3fd93 100644 (file)
@@ -1582,9 +1582,9 @@ fn encode_native_libraries(ecx: &EncodeContext, ebml_w: &mut Encoder) {
     ebml_w.end_tag();
 }
 
-fn encode_macro_registrar_fn(ecx: &EncodeContext, ebml_w: &mut Encoder) {
-    match ecx.tcx.sess.macro_registrar_fn.get() {
-        Some(id) => { ebml_w.wr_tagged_u32(tag_macro_registrar_fn, id); }
+fn encode_plugin_registrar_fn(ecx: &EncodeContext, ebml_w: &mut Encoder) {
+    match ecx.tcx.sess.plugin_registrar_fn.get() {
+        Some(id) => { ebml_w.wr_tagged_u32(tag_plugin_registrar_fn, id); }
         None => {}
     }
 }
@@ -1791,7 +1791,7 @@ struct Stats {
         dep_bytes: u64,
         lang_item_bytes: u64,
         native_lib_bytes: u64,
-        macro_registrar_fn_bytes: u64,
+        plugin_registrar_fn_bytes: u64,
         macro_defs_bytes: u64,
         impl_bytes: u64,
         misc_bytes: u64,
@@ -1805,7 +1805,7 @@ struct Stats {
         dep_bytes: 0,
         lang_item_bytes: 0,
         native_lib_bytes: 0,
-        macro_registrar_fn_bytes: 0,
+        plugin_registrar_fn_bytes: 0,
         macro_defs_bytes: 0,
         impl_bytes: 0,
         misc_bytes: 0,
@@ -1870,10 +1870,10 @@ struct Stats {
     encode_native_libraries(&ecx, &mut ebml_w);
     stats.native_lib_bytes = ebml_w.writer.tell().unwrap() - i;
 
-    // Encode the macro registrar function
+    // Encode the plugin registrar function
     i = ebml_w.writer.tell().unwrap();
-    encode_macro_registrar_fn(&ecx, &mut ebml_w);
-    stats.macro_registrar_fn_bytes = ebml_w.writer.tell().unwrap() - i;
+    encode_plugin_registrar_fn(&ecx, &mut ebml_w);
+    stats.plugin_registrar_fn_bytes = ebml_w.writer.tell().unwrap() - i;
 
     // Encode macro definitions
     i = ebml_w.writer.tell().unwrap();
@@ -1912,18 +1912,18 @@ struct Stats {
         }
 
         println!("metadata stats:");
-        println!("      attribute bytes: {}", stats.attr_bytes);
-        println!("            dep bytes: {}", stats.dep_bytes);
-        println!("      lang item bytes: {}", stats.lang_item_bytes);
-        println!("         native bytes: {}", stats.native_lib_bytes);
-        println!("macro registrar bytes: {}", stats.macro_registrar_fn_bytes);
-        println!("      macro def bytes: {}", stats.macro_defs_bytes);
-        println!("           impl bytes: {}", stats.impl_bytes);
-        println!("           misc bytes: {}", stats.misc_bytes);
-        println!("           item bytes: {}", stats.item_bytes);
-        println!("          index bytes: {}", stats.index_bytes);
-        println!("           zero bytes: {}", stats.zero_bytes);
-        println!("          total bytes: {}", stats.total_bytes);
+        println!("       attribute bytes: {}", stats.attr_bytes);
+        println!("             dep bytes: {}", stats.dep_bytes);
+        println!("       lang item bytes: {}", stats.lang_item_bytes);
+        println!("          native bytes: {}", stats.native_lib_bytes);
+        println!("plugin registrar bytes: {}", stats.plugin_registrar_fn_bytes);
+        println!("       macro def bytes: {}", stats.macro_defs_bytes);
+        println!("            impl bytes: {}", stats.impl_bytes);
+        println!("            misc bytes: {}", stats.misc_bytes);
+        println!("            item bytes: {}", stats.item_bytes);
+        println!("           index bytes: {}", stats.index_bytes);
+        println!("            zero bytes: {}", stats.zero_bytes);
+        println!("           total bytes: {}", stats.total_bytes);
     }
 }
 
diff --git a/src/librustc/plugin/build.rs b/src/librustc/plugin/build.rs
new file mode 100644 (file)
index 0000000..ad35c4e
--- /dev/null
@@ -0,0 +1,61 @@
+// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+//! Used by `rustc` when compiling a plugin crate.
+
+use syntax::ast;
+use syntax::attr;
+use syntax::codemap::Span;
+use syntax::diagnostic;
+use syntax::visit;
+use syntax::visit::Visitor;
+
+struct RegistrarFinder {
+    registrars: Vec<(ast::NodeId, Span)> ,
+}
+
+impl Visitor<()> for RegistrarFinder {
+    fn visit_item(&mut self, item: &ast::Item, _: ()) {
+        match item.node {
+            ast::ItemFn(..) => {
+                if attr::contains_name(item.attrs.as_slice(),
+                                       "plugin_registrar") {
+                    self.registrars.push((item.id, item.span));
+                }
+            }
+            _ => {}
+        }
+
+        visit::walk_item(self, item, ());
+    }
+}
+
+/// Find the function marked with `#[plugin_registrar]`, if any.
+pub fn find_plugin_registrar(diagnostic: &diagnostic::SpanHandler,
+                             krate: &ast::Crate) -> Option<ast::NodeId> {
+    let mut finder = RegistrarFinder { registrars: Vec::new() };
+    visit::walk_crate(&mut finder, krate, ());
+
+    match finder.registrars.len() {
+        0 => None,
+        1 => {
+            let (node_id, _) = finder.registrars.pop().unwrap();
+            Some(node_id)
+        },
+        _ => {
+            diagnostic.handler().err("multiple plugin registration functions found");
+            for &(_, span) in finder.registrars.iter() {
+                diagnostic.span_note(span, "one is here");
+            }
+            diagnostic.handler().abort_if_errors();
+            unreachable!();
+        }
+    }
+}
diff --git a/src/librustc/plugin/load.rs b/src/librustc/plugin/load.rs
new file mode 100644 (file)
index 0000000..ba50a15
--- /dev/null
@@ -0,0 +1,145 @@
+// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+//! Used by `rustc` when loading a plugin.
+
+use driver::session::Session;
+use metadata::creader::PluginMetadataReader;
+use plugin::registry::Registry;
+
+use std::mem;
+use std::os;
+use std::unstable::dynamic_lib::DynamicLibrary;
+use syntax::ast;
+use syntax::attr;
+use syntax::visit;
+use syntax::visit::Visitor;
+use syntax::ext::expand::ExportedMacros;
+use syntax::attr::AttrMetaMethods;
+
+/// Plugin-related crate metadata.
+pub struct PluginMetadata {
+    /// Source code of macros exported by the crate.
+    pub macros: Vec<String>,
+    /// Path to the shared library file.
+    pub lib: Option<Path>,
+    /// Symbol name of the plugin registrar function.
+    pub registrar_symbol: Option<String>,
+}
+
+/// Pointer to a registrar function.
+pub type PluginRegistrarFun =
+    fn(&mut Registry);
+
+/// Information about loaded plugins.
+pub struct Plugins {
+    /// Source code of exported macros.
+    pub macros: Vec<ExportedMacros>,
+    /// Registrars, as function pointers.
+    pub registrars: Vec<PluginRegistrarFun>,
+}
+
+struct PluginLoader<'a> {
+    sess: &'a Session,
+    reader: PluginMetadataReader<'a>,
+    plugins: Plugins,
+}
+
+impl<'a> PluginLoader<'a> {
+    fn new(sess: &'a Session) -> PluginLoader<'a> {
+        PluginLoader {
+            sess: sess,
+            reader: PluginMetadataReader::new(sess),
+            plugins: Plugins {
+                macros: vec!(),
+                registrars: vec!(),
+            },
+        }
+    }
+}
+
+/// Read plugin metadata and dynamically load registrar functions.
+pub fn load_plugins(sess: &Session, krate: &ast::Crate) -> Plugins {
+    let mut loader = PluginLoader::new(sess);
+    visit::walk_crate(&mut loader, krate, ());
+    loader.plugins
+}
+
+impl<'a> Visitor<()> for PluginLoader<'a> {
+    fn visit_view_item(&mut self, vi: &ast::ViewItem, _: ()) {
+        match vi.node {
+            ast::ViewItemExternCrate(name, _, _) => {
+                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)");
+                    }
+                }
+
+                if !plugin_phase { return; }
+
+                let PluginMetadata { macros, lib, registrar_symbol } =
+                    self.reader.read_plugin_metadata(vi);
+
+                self.plugins.macros.push(ExportedMacros {
+                    crate_name: name,
+                    macros: macros,
+                });
+
+                match (lib, registrar_symbol) {
+                    (Some(lib), Some(symbol))
+                        => self.dylink_registrar(vi, lib, symbol),
+                    _ => (),
+                }
+            }
+            _ => (),
+        }
+    }
+}
+
+impl<'a> PluginLoader<'a> {
+    // Dynamically link a registrar function into the compiler process.
+    fn dylink_registrar(&mut self, vi: &ast::ViewItem, path: Path, symbol: String) {
+        // Make sure the path contains a / or the linker will search for it.
+        let path = os::make_absolute(&path);
+
+        let lib = match DynamicLibrary::open(Some(&path)) {
+            Ok(lib) => lib,
+            // this is fatal: there are almost certainly macros we need
+            // inside this crate, so continue would spew "macro undefined"
+            // errors
+            Err(err) => self.sess.span_fatal(vi.span, err.as_slice())
+        };
+
+        unsafe {
+            let registrar: PluginRegistrarFun =
+                match lib.symbol(symbol.as_slice()) {
+                    Ok(registrar) => registrar,
+                    // again fatal if we can't register macros
+                    Err(err) => self.sess.span_fatal(vi.span, err.as_slice())
+                };
+
+            self.plugins.registrars.push(registrar);
+
+            // Intentionally leak the dynamic library. We can't ever unload it
+            // since the library can make things that will live arbitrarily long
+            // (e.g. an @-box cycle or a task).
+            mem::forget(lib);
+
+        }
+    }
+}
diff --git a/src/librustc/plugin/mod.rs b/src/librustc/plugin/mod.rs
new file mode 100644 (file)
index 0000000..fa70ffc
--- /dev/null
@@ -0,0 +1,64 @@
+// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+/*!
+ * Infrastructure for compiler plugins.
+ *
+ * Plugins are Rust libraries which extend the behavior of `rustc`
+ * in various ways.
+ *
+ * Plugin authors will use the `Registry` type re-exported by
+ * this module, along with its methods.  The rest of the module
+ * is for use by `rustc` itself.
+ *
+ * To define a plugin, build a dylib crate with a
+ * `#[plugin_registrar]` function:
+ *
+ * ```rust,ignore
+ * #![crate_id = "myplugin"]
+ * #![crate_type = "dylib"]
+ * #![feature(plugin_registrar)]
+ *
+ * extern crate rustc;
+ *
+ * use rustc::plugin::Registry;
+ *
+ * #[plugin_registrar]
+ * pub fn plugin_registrar(reg: &mut Registry) {
+ *     reg.register_macro("mymacro", expand_mymacro);
+ * }
+ *
+ * fn expand_mymacro(...) {  // details elided
+ * ```
+ *
+ * WARNING: We currently don't check that the registrar function
+ * has the appropriate type!
+ *
+ * To use a plugin while compiling another crate:
+ *
+ * ```rust
+ * #![feature(phase)]
+ *
+ * #[phase(plugin)]
+ * extern crate myplugin;
+ * ```
+ *
+ * If you also need the plugin crate available at runtime, use
+ * `phase(plugin, link)`.
+ *
+ * See `src/test/auxiliary/macro_crate_test.rs` and `src/libfourcc`
+ * for examples of syntax extension plugins.
+ */
+
+pub use self::registry::Registry;
+
+pub mod registry;
+pub mod load;
+pub mod build;
diff --git a/src/librustc/plugin/registry.rs b/src/librustc/plugin/registry.rs
new file mode 100644 (file)
index 0000000..f6e3782
--- /dev/null
@@ -0,0 +1,70 @@
+// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+//! Used by plugin crates to tell `rustc` about the plugins they provide.
+
+use syntax::ext::base::{SyntaxExtension, NamedSyntaxExtension, NormalTT};
+use syntax::ext::base::{IdentTT, ItemDecorator, ItemModifier, BasicMacroExpander};
+use syntax::ext::base::{MacroExpanderFn};
+use syntax::codemap::Span;
+use syntax::parse::token;
+use syntax::ast;
+
+/// Structure used to register plugins.
+///
+/// A plugin registrar function takes an `&mut Registry` and should call
+/// methods to register its plugins.
+///
+/// This struct has public fields and other methods for use by `rustc`
+/// itself. They are not documented here, and plugin authors should
+/// not use them.
+pub struct Registry {
+    #[doc(hidden)]
+    pub krate_span: Span,
+
+    #[doc(hidden)]
+    pub syntax_exts: Vec<NamedSyntaxExtension>,
+}
+
+impl Registry {
+    #[doc(hidden)]
+    pub fn new(krate: &ast::Crate) -> Registry {
+        Registry {
+            krate_span: krate.span,
+            syntax_exts: vec!(),
+        }
+    }
+
+    /// Register a syntax extension of any kind.
+    ///
+    /// This is the most general hook into `libsyntax`'s expansion behavior.
+    pub fn register_syntax_extension(&mut self, name: ast::Name, extension: SyntaxExtension) {
+        self.syntax_exts.push((name, match extension {
+            NormalTT(ext, _) => NormalTT(ext, Some(self.krate_span)),
+            IdentTT(ext, _) => IdentTT(ext, Some(self.krate_span)),
+            ItemDecorator(ext) => ItemDecorator(ext),
+            ItemModifier(ext) => ItemModifier(ext),
+        }));
+    }
+
+    /// Register a macro of the usual kind.
+    ///
+    /// This is a convenience wrapper for `register_syntax_extension`.
+    /// It builds for you a `NormalTT` with a `BasicMacroExpander`,
+    /// and also takes care of interning the macro's name.
+    pub fn register_macro(&mut self, name: &str, expander: MacroExpanderFn) {
+        self.register_syntax_extension(
+            token::intern(name),
+            NormalTT(box BasicMacroExpander {
+                expander: expander,
+                span: None,
+            }, None));
+    }
+}
index 1786e5b3fd24998471b5b1fb8f71e0b47a64e8d6..f848c5224b7c8318552fb1f404e3d0000709ac6a 100644 (file)
@@ -10,7 +10,6 @@
 
 use rustc;
 use rustc::{driver, middle};
-use rustc::metadata::creader::Loader;
 use rustc::middle::privacy;
 use rustc::middle::lint;
 
@@ -100,8 +99,8 @@ fn get_ast_and_resolve(cpath: &Path, libs: HashSet<Path>, cfgs: Vec<String>)
     }
 
     let krate = phase_1_parse_input(&sess, cfg, &input);
-    let (krate, ast_map) = phase_2_configure_and_expand(&sess, &mut Loader::new(&sess),
-                                                        krate, &from_str("rustdoc").unwrap());
+    let (krate, ast_map) = phase_2_configure_and_expand(&sess, krate,
+                                                        &from_str("rustdoc").unwrap());
     let driver::driver::CrateAnalysis {
         exported_items, public_items, ty_cx, ..
     } = phase_3_run_analysis_passes(sess, &krate, ast_map);
index e623d54675c25c820cddfe898067f9ebca0fe2fb..05875f59fbe1852bb4da502a1cdba1f47aceeb71 100644 (file)
@@ -19,8 +19,6 @@
 extern crate debug;
 extern crate getopts;
 extern crate libc;
-#[phase(syntax, link)]
-extern crate log;
 extern crate rustc;
 extern crate serialize;
 extern crate sync;
 extern crate testing = "test";
 extern crate time;
 
+#[cfg(stage0)]
+#[phase(syntax, link)]
+extern crate log;
+
+#[cfg(not(stage0))]
+#[phase(plugin, link)]
+extern crate log;
+
 use std::io;
 use std::io::{File, MemWriter};
 use std::str;
index 745e29508d218a3554996d5078513db04f45a51d..3436305829791456662c98b6cc355ced2f88b37d 100644 (file)
@@ -23,7 +23,6 @@
 use rustc::driver::config;
 use rustc::driver::driver;
 use rustc::driver::session;
-use rustc::metadata::creader::Loader;
 use syntax::ast;
 use syntax::codemap::{CodeMap, dummy_spanned};
 use syntax::diagnostic;
@@ -68,7 +67,7 @@ pub fn run(input: &str,
         @dummy_spanned(ast::MetaWord(cfg_))
     }));
     let krate = driver::phase_1_parse_input(&sess, cfg, &input);
-    let (krate, _) = driver::phase_2_configure_and_expand(&sess, &mut Loader::new(&sess), krate,
+    let (krate, _) = driver::phase_2_configure_and_expand(&sess, krate,
                                                           &from_str("rustdoc-test").unwrap());
 
     let ctx = @core::DocContext {
index 3158687c6ab937e04be0b278f4a2252e17eba01f..bb57f5c038c0323c4f111c814f37d427f4dd2f3c 100644 (file)
 #![no_std]
 #![experimental]
 
+#[cfg(stage0)]
 #[phase(syntax, link)]
 extern crate core;
+
+#[cfg(not(stage0))]
+#[phase(plugin, link)]
+extern crate core;
+
 extern crate alloc;
 extern crate libc;
 extern crate collections;
@@ -28,7 +34,9 @@
 #[cfg(test)] extern crate realrustrt = "rustrt";
 #[cfg(test)] extern crate test;
 #[cfg(test)] extern crate native;
-#[cfg(test)] #[phase(syntax, link)] extern crate std;
+
+#[cfg(test, stage0)] #[phase(syntax, link)] extern crate std;
+#[cfg(test, not(stage0))] #[phase(plugin, link)] extern crate std;
 
 pub use self::util::{Stdio, Stdout, Stderr};
 pub use self::unwind::{begin_unwind, begin_unwind_fmt};
index 08348c963338265c0812094ac2054a8d6e3ca0be..33d20ed7bcd0fe35313719066df22d713da674e1 100644 (file)
 // test harness access
 #[cfg(test)]
 extern crate test;
+
+#[cfg(stage0)]
 #[phase(syntax, link)]
 extern crate log;
 
+#[cfg(not(stage0))]
+#[phase(plugin, link)]
+extern crate log;
+
 pub use self::serialize::{Decoder, Encoder, Decodable, Encodable,
                           DecoderHelpers, EncoderHelpers};
 
index fbdbc13e1b430ed1ea95462c2e802e970c6a3a90..85813c02d5535be8c25e49515123caf37260e805 100644 (file)
 #[cfg(test)] extern crate native;
 #[cfg(test)] extern crate green;
 #[cfg(test)] extern crate debug;
-#[cfg(test)] #[phase(syntax, link)] extern crate log;
+#[cfg(test, stage0)] #[phase(syntax, link)] extern crate log;
+#[cfg(test, not(stage0))] #[phase(plugin, link)] extern crate log;
 
 extern crate alloc;
 extern crate core;
index fc4d5fec5f52a06e861232dce288da04ee610a2a..44d17e6fb95ce13bb7d446aa8f3e8e7b556f7119 100644 (file)
 
 #![deny(missing_doc)]
 
-#[cfg(test)]
+#[cfg(test, stage0)]
 #[phase(syntax, link)] extern crate log;
 
+#[cfg(test, not(stage0))]
+#[phase(plugin, link)] extern crate log;
+
 extern crate alloc;
 
 pub use comm::{DuplexStream, duplex};
index 521b7ee00631c6cb369d8b410506a0ee7cf5b993..e81421cff043deb894c9bf60bba926c1473565ae 100644 (file)
@@ -95,9 +95,6 @@ fn expand(&self,
 pub type IdentMacroExpanderFn =
     fn(&mut ExtCtxt, Span, ast::Ident, Vec<ast::TokenTree>) -> Box<MacResult>;
 
-pub type MacroCrateRegistrationFun =
-    fn(|ast::Name, SyntaxExtension|);
-
 /// The result of a macro expansion. The return values of the various
 /// methods are spliced into the AST at the callsite of the macro (or
 /// just into the compiler's internal macro table, for `make_def`).
@@ -268,6 +265,8 @@ pub enum SyntaxExtension {
     IdentTT(Box<IdentMacroExpander:'static>, Option<Span>),
 }
 
+pub type NamedSyntaxExtension = (Name, SyntaxExtension);
+
 pub struct BlockInfo {
     // should macros escape from this scope?
     pub macros_escape: bool,
@@ -392,16 +391,6 @@ fn builtin_normal_expander(f: MacroExpanderFn) -> SyntaxExtension {
     syntax_expanders
 }
 
-pub struct MacroCrate {
-    pub lib: Option<Path>,
-    pub macros: Vec<String>,
-    pub registrar_symbol: Option<String>,
-}
-
-pub trait CrateLoader {
-    fn load_crate(&mut self, krate: &ast::ViewItem) -> MacroCrate;
-}
-
 // One of these is made during expansion and incrementally updated as we go;
 // when a macro expansion occurs, the resulting nodes have the backtrace()
 // -> expn_info of their expansion context stored into their span.
@@ -409,7 +398,7 @@ pub struct ExtCtxt<'a> {
     pub parse_sess: &'a parse::ParseSess,
     pub cfg: ast::CrateConfig,
     pub backtrace: Option<@ExpnInfo>,
-    pub ecfg: expand::ExpansionConfig<'a>,
+    pub ecfg: expand::ExpansionConfig,
 
     pub mod_path: Vec<ast::Ident> ,
     pub trace_mac: bool,
@@ -417,7 +406,7 @@ pub struct ExtCtxt<'a> {
 
 impl<'a> ExtCtxt<'a> {
     pub fn new<'a>(parse_sess: &'a parse::ParseSess, cfg: ast::CrateConfig,
-                   ecfg: expand::ExpansionConfig<'a>) -> ExtCtxt<'a> {
+                   ecfg: expand::ExpansionConfig) -> ExtCtxt<'a> {
         ExtCtxt {
             parse_sess: parse_sess,
             cfg: cfg,
index 03001acc5d04d47e6914d640bce40c29691f67f0..bb335e7bed0cf9bf8b9dd91fbc470c59899bb113 100644 (file)
 use visit::Visitor;
 use util::small_vector::SmallVector;
 
-use std::mem;
-use std::os;
-use std::unstable::dynamic_lib::DynamicLibrary;
-
 pub fn expand_expr(e: @ast::Expr, fld: &mut MacroExpander) -> @ast::Expr {
     match e.node {
         // expr_mac should really be expr_ext or something; it's the
@@ -497,96 +493,6 @@ pub fn expand_item_mac(it: @ast::Item, fld: &mut MacroExpander)
     return items;
 }
 
-// load macros from syntax-phase crates
-pub fn expand_view_item(vi: &ast::ViewItem,
-                        fld: &mut MacroExpander)
-                        -> ast::ViewItem {
-    match vi.node {
-        ast::ViewItemExternCrate(..) => {
-            let should_load = vi.attrs.iter().any(|attr| {
-                attr.check_name("phase") &&
-                    attr.meta_item_list().map_or(false, |phases| {
-                        attr::contains_name(phases, "syntax")
-                    })
-            });
-
-            if should_load {
-                load_extern_macros(vi, fld);
-            }
-        }
-        ast::ViewItemUse(_) => {}
-    }
-
-    noop_fold_view_item(vi, fld)
-}
-
-fn load_extern_macros(krate: &ast::ViewItem, fld: &mut MacroExpander) {
-    let MacroCrate { lib, macros, registrar_symbol } =
-        fld.cx.ecfg.loader.load_crate(krate);
-
-    let crate_name = match krate.node {
-        ast::ViewItemExternCrate(name, _, _) => name,
-        _ => unreachable!()
-    };
-    let name = format!("<{} macros>", token::get_ident(crate_name));
-    let name = name.to_string();
-
-    for source in macros.iter() {
-        let item = parse::parse_item_from_source_str(name.clone(),
-                                                     (*source).clone(),
-                                                     fld.cx.cfg(),
-                                                     fld.cx.parse_sess())
-                .expect("expected a serialized item");
-        expand_item_mac(item, fld);
-    }
-
-    let path = match lib {
-        Some(path) => path,
-        None => return
-    };
-    // Make sure the path contains a / or the linker will search for it.
-    let path = os::make_absolute(&path);
-
-    let registrar = match registrar_symbol {
-        Some(registrar) => registrar,
-        None => return
-    };
-
-    debug!("load_extern_macros: mapped crate {} to path {} and registrar {:s}",
-           crate_name, path.display(), registrar);
-
-    let lib = match DynamicLibrary::open(Some(&path)) {
-        Ok(lib) => lib,
-        // this is fatal: there are almost certainly macros we need
-        // inside this crate, so continue would spew "macro undefined"
-        // errors
-        Err(err) => fld.cx.span_fatal(krate.span, err.as_slice())
-    };
-
-    unsafe {
-        let registrar: MacroCrateRegistrationFun =
-            match lib.symbol(registrar.as_slice()) {
-                Ok(registrar) => registrar,
-                // again fatal if we can't register macros
-                Err(err) => fld.cx.span_fatal(krate.span, err.as_slice())
-            };
-        registrar(|name, extension| {
-            let extension = match extension {
-                NormalTT(ext, _) => NormalTT(ext, Some(krate.span)),
-                IdentTT(ext, _) => IdentTT(ext, Some(krate.span)),
-                ItemDecorator(ext) => ItemDecorator(ext),
-                ItemModifier(ext) => ItemModifier(ext),
-            };
-            fld.extsbox.insert(name, extension);
-        });
-
-        // Intentionally leak the dynamic library. We can't ever unload it
-        // since the library can do things that will outlive the expansion
-        // phase (e.g. make an @-box cycle or launch a task).
-        mem::forget(lib);
-    }
-}
-
 // expand a stmt
 pub fn expand_stmt(s: &Stmt, fld: &mut MacroExpander) -> SmallVector<@Stmt> {
     // why the copying here and not in expand_expr?
@@ -969,10 +875,6 @@ fn fold_item(&mut self, item: @ast::Item) -> SmallVector<@ast::Item> {
         expand_item(item, self)
     }
 
-    fn fold_view_item(&mut self, vi: &ast::ViewItem) -> ast::ViewItem {
-        expand_view_item(vi, self)
-    }
-
     fn fold_stmt(&mut self, stmt: &ast::Stmt) -> SmallVector<@ast::Stmt> {
         expand_stmt(stmt, self)
     }
@@ -986,14 +888,20 @@ fn new_span(&mut self, span: Span) -> Span {
     }
 }
 
-pub struct ExpansionConfig<'a> {
-    pub loader: &'a mut CrateLoader,
+pub struct ExpansionConfig {
     pub deriving_hash_type_parameter: bool,
     pub crate_id: CrateId,
 }
 
+pub struct ExportedMacros {
+    pub crate_name: Ident,
+    pub macros: Vec<String>,
+}
+
 pub fn expand_crate(parse_sess: &parse::ParseSess,
                     cfg: ExpansionConfig,
+                    macros: Vec<ExportedMacros>,
+                    user_exts: Vec<NamedSyntaxExtension>,
                     c: Crate) -> Crate {
     let mut cx = ExtCtxt::new(parse_sess, c.config.clone(), cfg);
     let mut expander = MacroExpander {
@@ -1001,6 +909,24 @@ pub fn expand_crate(parse_sess: &parse::ParseSess,
         cx: &mut cx,
     };
 
+    for ExportedMacros { crate_name, macros } in macros.move_iter() {
+        let name = format!("<{} macros>", token::get_ident(crate_name))
+            .into_string();
+
+        for source in macros.move_iter() {
+            let item = parse::parse_item_from_source_str(name.clone(),
+                                                         source,
+                                                         expander.cx.cfg(),
+                                                         expander.cx.parse_sess())
+                    .expect("expected a serialized item");
+            expand_item_mac(item, &mut expander);
+        }
+    }
+
+    for (name, extension) in user_exts.move_iter() {
+        expander.extsbox.insert(name, extension);
+    }
+
     let ret = expander.fold_crate(c);
     parse_sess.span_diagnostic.handler().abort_if_errors();
     return ret;
@@ -1093,7 +1019,6 @@ mod test {
     use attr;
     use codemap;
     use codemap::Spanned;
-    use ext::base::{CrateLoader, MacroCrate};
     use ext::mtwt;
     use parse;
     use parse::token;
@@ -1137,14 +1062,6 @@ pub fn new_path_finder(paths: Vec<ast::Path> ) -> NewPathExprFinderContext {
         }
     }
 
-    struct ErrLoader;
-
-    impl CrateLoader for ErrLoader {
-        fn load_crate(&mut self, _: &ast::ViewItem) -> MacroCrate {
-            fail!("lolwut")
-        }
-    }
-
     // these following tests are quite fragile, in that they don't test what
     // *kind* of failure occurs.
 
@@ -1159,13 +1076,11 @@ fn load_crate(&mut self, _: &ast::ViewItem) -> MacroCrate {
             src,
             Vec::new(), &sess);
         // should fail:
-        let mut loader = ErrLoader;
         let cfg = ::syntax::ext::expand::ExpansionConfig {
-            loader: &mut loader,
             deriving_hash_type_parameter: false,
             crate_id: from_str("test").unwrap(),
         };
-        expand_crate(&sess,cfg,crate_ast);
+        expand_crate(&sess,cfg,vec!(),vec!(),crate_ast);
     }
 
     // make sure that macros can leave scope for modules
@@ -1178,14 +1093,11 @@ fn load_crate(&mut self, _: &ast::ViewItem) -> MacroCrate {
             "<test>".to_string(),
             src,
             Vec::new(), &sess);
-        // should fail:
-        let mut loader = ErrLoader;
         let cfg = ::syntax::ext::expand::ExpansionConfig {
-            loader: &mut loader,
             deriving_hash_type_parameter: false,
             crate_id: from_str("test").unwrap(),
         };
-        expand_crate(&sess,cfg,crate_ast);
+        expand_crate(&sess,cfg,vec!(),vec!(),crate_ast);
     }
 
     // macro_escape modules shouldn't cause macros to leave scope
@@ -1198,13 +1110,11 @@ fn load_crate(&mut self, _: &ast::ViewItem) -> MacroCrate {
             src,
             Vec::new(), &sess);
         // should fail:
-        let mut loader = ErrLoader;
         let cfg = ::syntax::ext::expand::ExpansionConfig {
-            loader: &mut loader,
             deriving_hash_type_parameter: false,
             crate_id: from_str("test").unwrap(),
         };
-        expand_crate(&sess, cfg, crate_ast);
+        expand_crate(&sess, cfg, vec!(), vec!(), crate_ast);
     }
 
     #[test] fn test_contains_flatten (){
@@ -1237,13 +1147,11 @@ fn expand_crate_str(crate_str: String) -> ast::Crate {
         let ps = parse::new_parse_sess();
         let crate_ast = string_to_parser(&ps, crate_str).parse_crate_mod();
         // the cfg argument actually does matter, here...
-        let mut loader = ErrLoader;
         let cfg = ::syntax::ext::expand::ExpansionConfig {
-            loader: &mut loader,
             deriving_hash_type_parameter: false,
             crate_id: from_str("test").unwrap(),
         };
-        expand_crate(&ps,cfg,crate_ast)
+        expand_crate(&ps,cfg,vec!(),vec!(),crate_ast)
     }
 
     //fn expand_and_resolve(crate_str: @str) -> ast::crate {
diff --git a/src/libsyntax/ext/registrar.rs b/src/libsyntax/ext/registrar.rs
deleted file mode 100644 (file)
index b767081..0000000
+++ /dev/null
@@ -1,58 +0,0 @@
-// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-use ast;
-use attr;
-use codemap::Span;
-use diagnostic;
-use visit;
-use visit::Visitor;
-
-struct MacroRegistrarContext {
-    registrars: Vec<(ast::NodeId, Span)> ,
-}
-
-impl Visitor<()> for MacroRegistrarContext {
-    fn visit_item(&mut self, item: &ast::Item, _: ()) {
-        match item.node {
-            ast::ItemFn(..) => {
-                if attr::contains_name(item.attrs.as_slice(),
-                                       "macro_registrar") {
-                    self.registrars.push((item.id, item.span));
-                }
-            }
-            _ => {}
-        }
-
-        visit::walk_item(self, item, ());
-    }
-}
-
-pub fn find_macro_registrar(diagnostic: &diagnostic::SpanHandler,
-                            krate: &ast::Crate) -> Option<ast::NodeId> {
-    let mut ctx = MacroRegistrarContext { registrars: Vec::new() };
-    visit::walk_crate(&mut ctx, krate, ());
-
-    match ctx.registrars.len() {
-        0 => None,
-        1 => {
-            let (node_id, _) = ctx.registrars.pop().unwrap();
-            Some(node_id)
-        },
-        _ => {
-            diagnostic.handler().err("multiple macro registration functions found");
-            for &(_, span) in ctx.registrars.iter() {
-                diagnostic.span_note(span, "one is here");
-            }
-            diagnostic.handler().abort_if_errors();
-            unreachable!();
-        }
-    }
-}
index 1ab420eb69be68bce61aa0a4e3f21a804745d481..754518f5fea3192f8cd7239757b63f8f38706a89 100644 (file)
 
 extern crate serialize;
 extern crate term;
+
+#[cfg(stage0)]
 #[phase(syntax, link)]
 extern crate log;
+
+#[cfg(not(stage0))]
+#[phase(plugin, link)]
+extern crate log;
+
 extern crate fmt_macros;
 extern crate debug;
 
@@ -74,7 +81,6 @@ pub mod ext {
     pub mod asm;
     pub mod base;
     pub mod expand;
-    pub mod registrar;
 
     pub mod quote;
 
index cc813262576ad9d7d28493a7198b4c434edd048f..76118f642abe0480722ffed527cd58ac3aeb7640 100644 (file)
@@ -52,7 +52,8 @@
 
 #![deny(missing_doc)]
 
-#[phase(syntax, link)] extern crate log;
+#[cfg(stage0)] #[phase(syntax, link)] extern crate log;
+#[cfg(not(stage0))] #[phase(plugin, link)] extern crate log;
 
 pub use terminfo::TerminfoTerminal;
 #[cfg(windows)]
index f087b9289c3d723432601ad54e92df23f8a34a4f..f2af59433358e44bc1cfeba8f9fa91b0d87aa169 100644 (file)
@@ -23,7 +23,9 @@
 #![deny(deprecated_owned_vector)]
 
 #[cfg(test)] extern crate debug;
-#[cfg(test)] #[phase(syntax, link)] extern crate log;
+
+#[cfg(test, stage0)] #[phase(syntax, link)] extern crate log;
+#[cfg(test, not(stage0))] #[phase(plugin, link)] extern crate log;
 
 extern crate serialize;
 extern crate libc;
index 3b77b244ce879be5262fff90b7ba3393e7bf6d01..dfd13851774ebd150c5c4dd1afb61310077e60b5 100644 (file)
@@ -13,6 +13,6 @@
 #![crate_type = "rlib"]
 #![feature(phase)]
 
-#[phase(syntax)] extern crate t1 = "issue-13560-1";
-#[phase(syntax, link)] extern crate t2 = "issue-13560-2";
+#[phase(plugin)] extern crate t1 = "issue-13560-1";
+#[phase(plugin, link)] extern crate t2 = "issue-13560-2";
 
index 3f0da3e344af2c5def69faf28e16309022414743..0c4af97b4100d9a183e134da2bfcab85a6b624a2 100644 (file)
@@ -9,7 +9,7 @@
 // except according to those terms.
 
 #![feature(phase)]
-#[phase(syntax, link)] extern crate log;
+#[phase(plugin, link)] extern crate log;
 extern crate debug;
 
 pub fn foo<T>() {
diff --git a/src/test/auxiliary/macro_crate_outlive_expansion_phase.rs b/src/test/auxiliary/macro_crate_outlive_expansion_phase.rs
deleted file mode 100644 (file)
index 670673f..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-// force-host
-
-#![feature(macro_registrar)]
-
-extern crate syntax;
-
-use std::any::Any;
-use syntax::ast::Name;
-use syntax::ext::base::SyntaxExtension;
-
-struct Foo {
-    foo: int
-}
-
-impl Drop for Foo {
-    fn drop(&mut self) {}
-}
-
-#[macro_registrar]
-pub fn registrar(_: |Name, SyntaxExtension|) {
-    local_data_key!(foo: Box<Any:Send>);
-    foo.replace(Some(box Foo { foo: 10 } as Box<Any:Send>));
-}
-
index 95f2a8c1ca1522ea9a77c42a95ab9a0839a7740d..805b8a894cb7e24a15a84a7ff341044417e65291 100644 (file)
 
 // force-host
 
-#![feature(globs, macro_registrar, macro_rules, quote, managed_boxes)]
+#![feature(globs, plugin_registrar, macro_rules, quote, managed_boxes)]
 
 extern crate syntax;
+extern crate rustc;
 
-use syntax::ast::{Name, TokenTree, Item, MetaItem};
+use syntax::ast::{TokenTree, Item, MetaItem};
 use syntax::codemap::Span;
 use syntax::ext::base::*;
 use syntax::parse::token;
+use rustc::plugin::Registry;
 
 #[macro_export]
 macro_rules! exported_macro (() => (2))
 
 macro_rules! unexported_macro (() => (3))
 
-#[macro_registrar]
-pub fn macro_registrar(register: |Name, SyntaxExtension|) {
-    register(token::intern("make_a_1"),
-        NormalTT(box BasicMacroExpander {
-            expander: expand_make_a_1,
-            span: None,
-        },
-        None));
-    register(token::intern("into_foo"), ItemModifier(expand_into_foo));
+#[plugin_registrar]
+pub fn plugin_registrar(reg: &mut Registry) {
+    reg.register_macro("make_a_1", expand_make_a_1);
+    reg.register_syntax_extension(
+        token::intern("into_foo"),
+        ItemModifier(expand_into_foo));
 }
 
 fn expand_make_a_1(cx: &mut ExtCtxt, sp: Span, tts: &[TokenTree])
diff --git a/src/test/auxiliary/plugin_crate_outlive_expansion_phase.rs b/src/test/auxiliary/plugin_crate_outlive_expansion_phase.rs
new file mode 100644 (file)
index 0000000..213fdd6
--- /dev/null
@@ -0,0 +1,33 @@
+// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// force-host
+
+#![feature(plugin_registrar)]
+
+extern crate rustc;
+
+use std::any::Any;
+use rustc::plugin::Registry;
+
+struct Foo {
+    foo: int
+}
+
+impl Drop for Foo {
+    fn drop(&mut self) {}
+}
+
+#[plugin_registrar]
+pub fn registrar(_: &mut Registry) {
+    local_data_key!(foo: Box<Any:Send>);
+    foo.replace(Some(box Foo { foo: 10 } as Box<Any:Send>));
+}
+
index 93b56a7600d09936f6859d4a124a24ae88477825..04318fcae2733d2dbf2cbbdd3e56397bd3d6adc2 100644 (file)
 // no-prefer-dynamic
 
 #![crate_type = "dylib"]
-#![feature(macro_registrar, quote, globs)]
+#![feature(plugin_registrar, quote, globs)]
 
 extern crate other = "syntax-extension-with-dll-deps-1";
 extern crate syntax;
+extern crate rustc;
 
-use syntax::ast::{Name, TokenTree, Item, MetaItem};
+use syntax::ast::{TokenTree, Item, MetaItem};
 use syntax::codemap::Span;
 use syntax::ext::base::*;
-use syntax::parse::token;
+use rustc::plugin::Registry;
 
-#[macro_registrar]
-pub fn macro_registrar(register: |Name, SyntaxExtension|) {
-    register(token::intern("foo"),
-        NormalTT(box BasicMacroExpander {
-            expander: expand_foo,
-            span: None,
-        },
-        None));
+#[plugin_registrar]
+pub fn plugin_registrar(reg: &mut Registry) {
+    reg.register_macro("foo", expand_foo);
 }
 
 fn expand_foo(cx: &mut ExtCtxt, sp: Span, tts: &[TokenTree])
index 68a2ae24b8563309fdaf3643a9a4128c0ba04879..c998e362d7e34f96a3a93a3a16da8fd6d8e9e265 100644 (file)
@@ -17,7 +17,7 @@
 #![feature(phase)]
 #![crate_type = "rlib"]
 
-#[phase(syntax, link)]
+#[phase(plugin, link)]
 extern crate core;
 
 struct A;
index baf02feb5b80a827510c6c16725a40976662a25d..28786f1e163d965898cebb37e67aad8b386ada68 100644 (file)
@@ -11,7 +11,7 @@
 // no-pretty-expanded
 
 #![feature(phase)]
-#[phase(syntax)] extern crate green;
+#[phase(plugin)] extern crate green;
 
 use std::string::String;
 use std::fmt;
index 6f4aef27b63d45f59812c68072ff44497df91495..afefaf2b5353c1832728ec1e88d4bf02dd3a41a3 100644 (file)
@@ -39,7 +39,7 @@
 // OF THE POSSIBILITY OF SUCH DAMAGE.
 
 #![feature(phase)]
-#[phase(syntax)] extern crate green;
+#[phase(plugin)] extern crate green;
 extern crate sync;
 
 use sync::Arc;
index c2f0a58a288e5e5c769b8c41f39f7f0272c5e0d7..ca0248bcf5deacbfceed66fb3f6ad8ca62d9a31a 100644 (file)
@@ -46,7 +46,7 @@
 #![feature(macro_rules, phase)]
 
 extern crate regex;
-#[phase(syntax)]extern crate regex_macros;
+#[phase(plugin)]extern crate regex_macros;
 extern crate sync;
 
 use std::io;
index c038a056569b9918f5108b1dd9a2272092cbb536..15b7ff1e81e8a812ba6dace0960edb135a8da3d6 100644 (file)
@@ -10,7 +10,7 @@
 
 #![feature(phase)]
 #![allow(non_snake_case_functions)]
-#[phase(syntax)] extern crate green;
+#[phase(plugin)] extern crate green;
 extern crate sync;
 
 use std::from_str::FromStr;
index 1a6582927caf2bbc7429c0fa25c5fe276b87e233..a001ff78ba0bfb8e1cc5c2fdcf0ff416049aefe8 100644 (file)
@@ -9,7 +9,7 @@
 // except according to those terms.
 
 #![feature(phase)]
-#[phase(syntax)] extern crate green;
+#[phase(plugin)] extern crate green;
 green_start!(main)
 
 fn start(n_tasks: int, token: int) {
index c8763899269ccefbcbbe98e62e9969cd5a5d1a03..1f384b856334c0340b5e5b3156f45d05678635bd 100644 (file)
@@ -11,7 +11,7 @@
 // aux-build:macro_crate_test.rs
 // ignore-stage1
 
-#[phase(syntax)]
+#[phase(plugin)]
 //~^ ERROR compile time crate loading is experimental and possibly buggy
 extern crate macro_crate_test;
 
index f8eb9868a5b69413047261f344dfd11aeb957be9..39c2accaddf3327dd0259ac7b5344720b4ab4ad6 100644 (file)
@@ -14,7 +14,7 @@
 
 #![feature(phase)]
 
-#[phase(syntax)]
+#[phase(plugin)]
 extern crate macro_crate_test;
 
 fn main() {
index 84c915f267ec26fd78c3ccc59f2f804c37a501fe..7a7eac7b709250ab1d991ebb739e9efde6980575 100644 (file)
@@ -10,7 +10,7 @@
 
 #![feature(phase)]
 
-#[phase(syntax)]
+#[phase(plugin)]
 extern crate doesnt_exist; //~ ERROR can't find crate
 
 fn main() {}
index 2053f81683d7a3d50582dc9276c74da5cbd5766d..274fbf797e1ef96c14a337d9c34b07f82a262513 100644 (file)
@@ -14,7 +14,7 @@
 
 #![feature(phase)]
 
-#[phase(syntax)]
+#[phase(plugin)]
 extern crate macro_crate_test;
 
 fn main() {
index fbcdf55f1acbfca0380ef9f9861feaf62fda58e3..3ad17618fc0b31e33830f5ced682c7e7e69ff4e0 100644 (file)
@@ -13,7 +13,7 @@
 
 #![feature(phase)]
 
-#[phase(syntax)]
+#[phase(plugin)]
 extern crate fourcc;
 
 fn main() {
index 569b54b93fb097f346853b3e4839b7efd4dfbfc9..4d425d9a2056a62f8e7cbf3b019d4a3bd7592e73 100644 (file)
@@ -13,7 +13,7 @@
 
 #![feature(phase)]
 
-#[phase(syntax)]
+#[phase(plugin)]
 extern crate fourcc;
 
 fn main() {
index c0e2304354cc478d74260c3a32fb9c5054bbbef5..1a6d747c1e8368ee7c84ddec51a33e154c1ba00f 100644 (file)
@@ -13,7 +13,7 @@
 
 #![feature(phase)]
 
-#[phase(syntax)]
+#[phase(plugin)]
 extern crate fourcc;
 
 fn main() {
index 536594f3063111ce1c0345418322999de5bbd8b6..885d8dd1ec326fcd76ca10634498807e6debb13f 100644 (file)
@@ -13,7 +13,7 @@
 
 #![feature(phase)]
 
-#[phase(syntax)]
+#[phase(plugin)]
 extern crate fourcc;
 
 fn main() {
index 8a0b0856d24de8897e0b03b22d7ffd615c5c41e1..da1c0070715686c13e14238171bd70a9ed047019 100644 (file)
@@ -13,7 +13,7 @@
 
 #![feature(phase)]
 
-#[phase(syntax)]
+#[phase(plugin)]
 extern crate fourcc;
 
 fn main() {
index 1cd4f654d2e37106192cca90b5fd161cabcdcccd..191042f5f5639f6876b2c66e2e2cf664916a6417 100644 (file)
@@ -13,7 +13,7 @@
 
 #![feature(phase)]
 
-#[phase(syntax)]
+#[phase(plugin)]
 extern crate hexfloat;
 
 fn main() {
index 4a6475cea96722b2998d4a7bb4120d1b3952da9b..f0ace43ec9e8d34ad66d8b35c601feca8646d0b0 100644 (file)
@@ -13,7 +13,7 @@
 
 #![feature(phase)]
 
-#[phase(syntax)]
+#[phase(plugin)]
 extern crate hexfloat;
 
 fn main() {
index 0e072dc1c060b512cebddc1545015027409cdb25..bccba74e05c70e5dd20988758f68aaabc47bdc01 100644 (file)
@@ -15,7 +15,7 @@
 #![feature(phase)]
 
 extern crate regex;
-#[phase(syntax)] extern crate regex_macros;
+#[phase(plugin)] extern crate regex_macros;
 
 // Tests to make sure that `regex!` will produce a compile error when given
 // an invalid regular expression.
index 300e7e524df2543fb94d676e042bca0868b5c002..819c9e6b0fe2f9bf103e75c9e81621957175f13d 100644 (file)
@@ -15,7 +15,7 @@
 #![feature(phase)]
 
 extern crate regex;
-#[phase(syntax)] extern crate regex_macros;
+#[phase(plugin)] extern crate regex_macros;
 
 #[deny(unused_variable)]
 #[deny(dead_code)]
index c77bd52d9e56cfa1f94f8ccca901030b1ce527f7..d96b3f6f224cfb35c10c0d6ef99052bdcd875e2e 100644 (file)
@@ -15,7 +15,7 @@
 #![feature(phase)]
 
 extern crate regex;
-#[phase(syntax)] extern crate regex_macros;
+#[phase(plugin)] extern crate regex_macros;
 
 #[deny(unused_variable)]
 #[deny(dead_code)]
diff --git a/src/test/compile-fail/gated-macro_registrar.rs b/src/test/compile-fail/gated-macro_registrar.rs
deleted file mode 100644 (file)
index 54274cc..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-// the registration function isn't typechecked yet
-#[macro_registrar]
-pub fn registrar() {} //~ ERROR cross-crate macro exports are experimental
-
-fn main() {}
diff --git a/src/test/compile-fail/gated-plugin_registrar.rs b/src/test/compile-fail/gated-plugin_registrar.rs
new file mode 100644 (file)
index 0000000..f6e11ff
--- /dev/null
@@ -0,0 +1,15 @@
+// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// the registration function isn't typechecked yet
+#[plugin_registrar]
+pub fn registrar() {} //~ ERROR compiler plugins are experimental
+
+fn main() {}
diff --git a/src/test/compile-fail/multiple-macro-registrars.rs b/src/test/compile-fail/multiple-macro-registrars.rs
deleted file mode 100644 (file)
index 321c0ff..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-// error-pattern: multiple macro registration functions found
-
-#![feature(macro_registrar)]
-
-// the registration function isn't typechecked yet
-#[macro_registrar]
-pub fn one() {}
-
-#[macro_registrar]
-pub fn two() {}
-
-fn main() {}
diff --git a/src/test/compile-fail/multiple-plugin-registrars.rs b/src/test/compile-fail/multiple-plugin-registrars.rs
new file mode 100644 (file)
index 0000000..f5ebf84
--- /dev/null
@@ -0,0 +1,22 @@
+// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// error-pattern: multiple plugin registration functions found
+
+#![feature(plugin_registrar)]
+
+// the registration function isn't typechecked yet
+#[plugin_registrar]
+pub fn one() {}
+
+#[plugin_registrar]
+pub fn two() {}
+
+fn main() {}
index 385bc1452048704772a66b97f6978fa61e08c6ec..c960679a43f1e074e56667b13c7cc1f3ac893cfe 100644 (file)
@@ -11,7 +11,7 @@
 // error-pattern:whatever
 
 #![feature(phase)]
-#[phase(syntax, link)] extern crate log;
+#[phase(plugin, link)] extern crate log;
 use std::os;
 
 fn main() {
index 3b5e27027b43c96b12814faf17299fb909865c88..22985d57936a29a1237b5c898dffc022fa097a1c 100644 (file)
@@ -11,7 +11,7 @@
 // error-pattern:whatever
 
 #![feature(phase)]
-#[phase(syntax, link)] extern crate log;
+#[phase(plugin, link)] extern crate log;
 use std::os;
 use std::task;
 
index b94045e5d124225d42ad181bd4aa17cccdae23d4..d08cb198802ad38892d5fb9c91a3b67659ae3e4e 100644 (file)
@@ -11,7 +11,7 @@
 // error-pattern:whatever
 
 #![feature(phase)]
-#[phase(syntax, link)] extern crate log;
+#[phase(plugin, link)] extern crate log;
 use std::os;
 
 fn main() {
index 0c55d5fd3144d9e4f3a1fb9657cd0e563d6a2edf..ec4fbca48f8de393128045daf59c5ba99adf9980 100644 (file)
@@ -11,7 +11,7 @@
 #![feature(phase)]
 
 extern crate lib;
-#[phase(syntax)] extern crate fourcc;
+#[phase(plugin)] extern crate fourcc;
 
 fn main() {
     fourcc!("1234");
index 58663bb44c7440efac69ba493d6155b520240a29..dd585ea979408ec30e1abd46f9a4960296439bf1 100644 (file)
@@ -8,12 +8,12 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-// aux-build:macro_crate_outlive_expansion_phase.rs
+// aux-build:plugin_crate_outlive_expansion_phase.rs
 // ignore-stage1
 
 #![feature(phase)]
 
-#[phase(syntax)]
-extern crate macro_crate_outlive_expansion_phase;
+#[phase(plugin)]
+extern crate plugin_crate_outlive_expansion_phase;
 
 pub fn main() {}
index 3c620c5e5720935d6b42a24aad289c5a144fcfc7..1e796d9d724c66f1e150752fcdd74d1d56cc33e3 100644 (file)
@@ -13,7 +13,7 @@
 
 #![feature(phase)]
 
-#[phase(syntax)]
+#[phase(plugin)]
 extern crate macro_crate_test;
 
 #[into_foo]
index b8d3ab2383100010a96a9f97a6426885838c74e0..47ff7d31df5f3f2c5744b8a926b6a159033a2b26 100644 (file)
@@ -17,7 +17,7 @@
 
 #![feature(phase)]
 
-#[phase(syntax, link)]
+#[phase(plugin, link)]
 extern crate macro_crate_test;
 
 fn main() {
index 0681ec63b9ed08c7ac61964ef6964ee490919db2..b16975fe6eea7068f74f1ab4b702b1f7123663d5 100644 (file)
@@ -13,7 +13,7 @@
 
 #![feature(phase)]
 
-#[phase(syntax)]
+#[phase(plugin)]
 extern crate fourcc;
 
 static static_val: u32 = fourcc!("foo ");
index 3601b6101159890dd577389652af4372d693fd5b..496b01113638b180e4963f92602e73d8e2bf474b 100644 (file)
@@ -12,7 +12,7 @@
 // ignore-pretty
 
 #![feature(phase)]
-#[phase(syntax)]
+#[phase(plugin)]
 extern crate hexfloat;
 
 pub fn main() {
index efae04ea4fc7a017b951a326500e7b97ad9a4de9..275463f5d7fc4ee6cc3e3d564dc89293a0dc3507 100644 (file)
@@ -14,7 +14,7 @@
 
 #![feature(phase)]
 
-#[phase(syntax)]
+#[phase(plugin)]
 extern crate extension = "syntax-extension-with-dll-deps-2";
 
 fn main() {
index 636e879fe32a8283fa414bacf1f268df7ff4badd..3402db7c355a942ac93127554baa1ccec5665c36 100644 (file)
@@ -13,7 +13,7 @@
 
 #![feature(phase)]
 
-#[phase(syntax, link)]
+#[phase(plugin, link)]
 extern crate log;
 extern crate native;
 
index 56b38033c8327813204848e710cf2bf8556e2d9c..b7c4ccb3c2a360196165b5cd5be80184f92d4064 100644 (file)
@@ -12,7 +12,7 @@
 // exec-env:RUST_LOG=conditional-debug-macro-off=4
 
 #![feature(phase)]
-#[phase(syntax, link)]
+#[phase(plugin, link)]
 extern crate log;
 extern crate debug;
 
diff --git a/src/test/run-pass/deprecated-phase-syntax.rs b/src/test/run-pass/deprecated-phase-syntax.rs
new file mode 100644 (file)
index 0000000..df835da
--- /dev/null
@@ -0,0 +1,19 @@
+// Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![feature(phase)]
+
+//~ WARNING phase(syntax) is a deprecated synonym for phase(plugin)
+#[phase(syntax, link)]
+extern crate log;
+
+fn main() {
+    debug!("foo");
+}
index 79203503373effbb6d668817aee5310285d6260a..96290386ccc11e4911d802513016464eb3362890 100644 (file)
@@ -10,7 +10,7 @@
 
 #![feature(phase)]
 
-#[phase(syntax, link)]
+#[phase(plugin, link)]
 extern crate green;
 extern crate native;
 
index 9320c77a285b43d7285398a75baee7bfa3e8d0e5..7975af434d2846339e1a8f9196ecdd17caf34697 100644 (file)
@@ -12,7 +12,7 @@
 // exec-env:RUST_LOG=logging-enabled-debug=debug
 
 #![feature(phase)]
-#[phase(syntax, link)]
+#[phase(plugin, link)]
 extern crate log;
 
 pub fn main() {
index b1d24e8b9b6df476edd380f50110aa5cc7f59e6c..184ac713c899bfa178e0dd1f5ea2193f7d44344a 100644 (file)
@@ -11,7 +11,7 @@
 // exec-env:RUST_LOG=logging-enabled=info
 
 #![feature(phase)]
-#[phase(syntax, link)]
+#[phase(plugin, link)]
 extern crate log;
 
 pub fn main() {
index 7f9a4593780a5a35ebfe93645fd28b233dad3931..989a8d4bde57aa58bd6473348d8477b24318735b 100644 (file)
@@ -13,7 +13,7 @@
 
 #![feature(phase)]
 
-#[phase(syntax, link)]
+#[phase(plugin, link)]
 extern crate log;
 
 use std::io::Command;
index abf8edc274cf7ecdec9c03d917ccb79450f4a444..25da809babd4391f172cd57ebfec83d77a3a42d4 100644 (file)
@@ -12,7 +12,7 @@
 
 #![feature(phase)]
 
-#[phase(syntax)]
+#[phase(plugin)]
 extern crate macro_crate_def_only;
 
 pub fn main() {
index 179c65cd046b2ecc6c4e292bc4221a4f320d4a0e..c7911a69ce46a8f16df81115284c367cdf2e316b 100644 (file)
@@ -13,7 +13,7 @@
 
 #![feature(phase)]
 
-#[phase(syntax)]
+#[phase(plugin)]
 extern crate macro_export_inner_module;
 
 pub fn main() {
index 60f2619fffd9bb09aa9f0977742d5051aa211f35..5015e43fa3f346b26cb1f0ecf4489425782cc606 100644 (file)
@@ -11,7 +11,7 @@
 
 #![feature(phase)]
 
-#[phase(syntax)]
+#[phase(plugin)]
 use std::mem;
 
 fn main() {}
index a9a6e25adf38b88809efe909b35e9f4eee1f09a8..9c4716e5f4d3805aa28877d4b5d41dfd34fc024e 100644 (file)
@@ -13,7 +13,7 @@
 // exec-env:RUST_LOG=debug
 
 #![feature(phase)]
-#[phase(syntax, link)]
+#[phase(plugin, link)]
 extern crate log;
 extern crate libc;
 extern crate green;