Skip to content

Commit 0ea7aa3

Browse files
committed
auto merge of rust-lang#14554 : kmcallister/rust/plugin_registrar, r=cmr
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.
2 parents b6146e6 + deecda6 commit 0ea7aa3

File tree

92 files changed

+669
-403
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+669
-403
lines changed

mk/crates.mk

+3-3
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,16 @@ DEPS_uuid := std serialize
8383
DEPS_sync := std alloc
8484
DEPS_getopts := std
8585
DEPS_collections := core alloc
86-
DEPS_fourcc := syntax std
87-
DEPS_hexfloat := syntax std
86+
DEPS_fourcc := rustc syntax std
87+
DEPS_hexfloat := rustc syntax std
8888
DEPS_num := std
8989
DEPS_test := std getopts serialize term time regex native:rust_test_helpers
9090
DEPS_time := std serialize sync
9191
DEPS_rand := core
9292
DEPS_url := std
9393
DEPS_log := std sync
9494
DEPS_regex := std
95-
DEPS_regex_macros = syntax std regex
95+
DEPS_regex_macros = rustc syntax std regex
9696
DEPS_fmt_macros = std
9797

9898
TOOL_DEPS_compiletest := test green rustuv getopts

src/compiletest/compiletest.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,17 @@
1818

1919
extern crate test;
2020
extern crate getopts;
21-
#[phase(link, syntax)]
22-
extern crate log;
2321
extern crate green;
2422
extern crate rustuv;
2523

24+
#[cfg(stage0)]
25+
#[phase(syntax, link)]
26+
extern crate log;
27+
28+
#[cfg(not(stage0))]
29+
#[phase(plugin, link)]
30+
extern crate log;
31+
2632
extern crate regex;
2733

2834
use std::os;

src/doc/rust.md

+3-4
Original file line numberDiff line numberDiff line change
@@ -1819,9 +1819,8 @@ type int8_t = i8;
18191819

18201820
### Function-only attributes
18211821

1822-
- `macro_registrar` - when using loadable syntax extensions, mark this
1823-
function as the registration point for the current crate's syntax
1824-
extensions.
1822+
- `plugin_registrar` - mark this function as the registration point for
1823+
compiler plugins, such as loadable syntax extensions.
18251824
- `main` - indicates that this function should be passed to the entry point,
18261825
rather than the function in the crate root named `main`.
18271826
- `start` - indicates that this function should be used as the entry point,
@@ -4098,7 +4097,7 @@ that demonstrates all four of them:
40984097

40994098
~~~~
41004099
#![feature(phase)]
4101-
#[phase(syntax, link)] extern crate log;
4100+
#[phase(plugin, link)] extern crate log;
41024101
41034102
fn main() {
41044103
error!("This is an error log")

src/liballoc/lib.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,14 @@
7070
#![no_std]
7171
#![feature(phase)]
7272

73+
#[cfg(stage0)]
7374
#[phase(syntax, link)]
7475
extern crate core;
76+
77+
#[cfg(not(stage0))]
78+
#[phase(plugin, link)]
79+
extern crate core;
80+
7581
extern crate libc;
7682

7783

@@ -80,8 +86,10 @@ extern crate libc;
8086
#[cfg(test)] extern crate debug;
8187
#[cfg(test)] extern crate sync;
8288
#[cfg(test)] extern crate native;
83-
#[cfg(test)] #[phase(syntax, link)] extern crate std;
84-
#[cfg(test)] #[phase(syntax, link)] extern crate log;
89+
#[cfg(test, stage0)] #[phase(syntax, link)] extern crate std;
90+
#[cfg(test, stage0)] #[phase(syntax, link)] extern crate log;
91+
#[cfg(test, not(stage0))] #[phase(plugin, link)] extern crate std;
92+
#[cfg(test, not(stage0))] #[phase(plugin, link)] extern crate log;
8593

8694
// Heaps provided for low-level allocation strategies
8795

src/libcollections/lib.rs

+13-3
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,24 @@
2323
#![feature(macro_rules, managed_boxes, default_type_params, phase, globs)]
2424
#![no_std]
2525

26-
#[phase(syntax, link)] extern crate core;
2726
extern crate alloc;
2827

28+
#[cfg(stage0)]
29+
#[phase(syntax, link)]
30+
extern crate core;
31+
32+
#[cfg(not(stage0))]
33+
#[phase(plugin, link)]
34+
extern crate core;
35+
2936
#[cfg(test)] extern crate native;
3037
#[cfg(test)] extern crate test;
3138
#[cfg(test)] extern crate debug;
32-
#[cfg(test)] #[phase(syntax, link)] extern crate std;
33-
#[cfg(test)] #[phase(syntax, link)] extern crate log;
39+
40+
#[cfg(test, stage0)] #[phase(syntax, link)] extern crate std;
41+
#[cfg(test, stage0)] #[phase(syntax, link)] extern crate log;
42+
#[cfg(test, not(stage0))] #[phase(plugin, link)] extern crate std;
43+
#[cfg(test, not(stage0))] #[phase(plugin, link)] extern crate log;
3444

3545
use core::prelude::*;
3646

src/libflate/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ Simple [DEFLATE][def]-based compression. This is a wrapper around the
2828
#![feature(phase)]
2929
#![deny(deprecated_owned_vector)]
3030

31-
#[cfg(test)] #[phase(syntax, link)] extern crate log;
31+
#[cfg(test, stage0)] #[phase(syntax, link)] extern crate log;
32+
#[cfg(test, not(stage0))] #[phase(plugin, link)] extern crate log;
3233

3334
extern crate libc;
3435

src/libfourcc/lib.rs

+8-12
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ to be `big`, i.e. left-to-right order. It returns a u32.
2222
To load the extension and use it:
2323
2424
```rust,ignore
25-
#[phase(syntax)]
25+
#[phase(plugin)]
2626
extern crate fourcc;
2727
2828
fn main() {
@@ -48,29 +48,25 @@ fn main() {
4848
html_root_url = "http://doc.rust-lang.org/")]
4949

5050
#![deny(deprecated_owned_vector)]
51-
#![feature(macro_registrar, managed_boxes)]
51+
#![feature(plugin_registrar, managed_boxes)]
5252

5353
extern crate syntax;
54+
extern crate rustc;
5455

5556
use syntax::ast;
56-
use syntax::ast::Name;
5757
use syntax::attr::contains;
5858
use syntax::codemap::{Span, mk_sp};
5959
use syntax::ext::base;
60-
use syntax::ext::base::{SyntaxExtension, BasicMacroExpander, NormalTT, ExtCtxt, MacExpr};
60+
use syntax::ext::base::{ExtCtxt, MacExpr};
6161
use syntax::ext::build::AstBuilder;
6262
use syntax::parse;
6363
use syntax::parse::token;
6464
use syntax::parse::token::InternedString;
65+
use rustc::plugin::Registry;
6566

66-
#[macro_registrar]
67-
pub fn macro_registrar(register: |Name, SyntaxExtension|) {
68-
register(token::intern("fourcc"),
69-
NormalTT(box BasicMacroExpander {
70-
expander: expand_syntax_ext,
71-
span: None,
72-
},
73-
None));
67+
#[plugin_registrar]
68+
pub fn plugin_registrar(reg: &mut Registry) {
69+
reg.register_macro("fourcc", expand_syntax_ext);
7470
}
7571

7672
pub fn expand_syntax_ext(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])

src/libgetopts/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@
9191
#![deny(deprecated_owned_vector)]
9292

9393
#[cfg(test)] extern crate debug;
94-
#[cfg(test)] #[phase(syntax, link)] extern crate log;
94+
#[cfg(test, stage0)] #[phase(syntax, link)] extern crate log;
95+
#[cfg(test, not(stage0))] #[phase(plugin, link)] extern crate log;
9596

9697
use std::cmp::PartialEq;
9798
use std::result::{Err, Ok};

src/libgreen/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@
148148
//!
149149
//! ```
150150
//! #![feature(phase)]
151-
//! #[phase(syntax)] extern crate green;
151+
//! #[phase(plugin)] extern crate green;
152152
//!
153153
//! green_start!(main)
154154
//!
@@ -211,7 +211,7 @@
211211
#![allow(visible_private_types)]
212212
#![deny(deprecated_owned_vector)]
213213

214-
#[cfg(test)] #[phase(syntax, link)] extern crate log;
214+
#[cfg(test)] #[phase(plugin, link)] extern crate log;
215215
#[cfg(test)] extern crate rustuv;
216216
extern crate libc;
217217
extern crate alloc;
@@ -249,7 +249,7 @@ pub mod task;
249249
///
250250
/// ```
251251
/// #![feature(phase)]
252-
/// #[phase(syntax)] extern crate green;
252+
/// #[phase(plugin)] extern crate green;
253253
///
254254
/// green_start!(main)
255255
///

src/libhexfloat/lib.rs

+8-12
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ literal.
2121
To load the extension and use it:
2222
2323
```rust,ignore
24-
#[phase(syntax)]
24+
#[phase(plugin)]
2525
extern crate hexfloat;
2626
2727
fn main() {
@@ -45,27 +45,23 @@ fn main() {
4545
html_root_url = "http://doc.rust-lang.org/")]
4646

4747
#![deny(deprecated_owned_vector)]
48-
#![feature(macro_registrar, managed_boxes)]
48+
#![feature(plugin_registrar, managed_boxes)]
4949

5050
extern crate syntax;
51+
extern crate rustc;
5152

5253
use syntax::ast;
53-
use syntax::ast::Name;
5454
use syntax::codemap::{Span, mk_sp};
5555
use syntax::ext::base;
56-
use syntax::ext::base::{SyntaxExtension, BasicMacroExpander, NormalTT, ExtCtxt, MacExpr};
56+
use syntax::ext::base::{ExtCtxt, MacExpr};
5757
use syntax::ext::build::AstBuilder;
5858
use syntax::parse;
5959
use syntax::parse::token;
60+
use rustc::plugin::Registry;
6061

61-
#[macro_registrar]
62-
pub fn macro_registrar(register: |Name, SyntaxExtension|) {
63-
register(token::intern("hexfloat"),
64-
NormalTT(box BasicMacroExpander {
65-
expander: expand_syntax_ext,
66-
span: None,
67-
},
68-
None));
62+
#[plugin_registrar]
63+
pub fn plugin_registrar(reg: &mut Registry) {
64+
reg.register_macro("hexfloat", expand_syntax_ext);
6965
}
7066

7167
//Check if the literal is valid (as LLVM expects),

src/liblog/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Utilities for program-wide and customizable logging
1616
1717
```
1818
#![feature(phase)]
19-
#[phase(syntax, link)] extern crate log;
19+
#[phase(plugin, link)] extern crate log;
2020
2121
fn main() {
2222
debug!("this is a debug {}", "message");

src/liblog/macros.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
///
2323
/// ```
2424
/// #![feature(phase)]
25-
/// #[phase(syntax, link)] extern crate log;
25+
/// #[phase(plugin, link)] extern crate log;
2626
///
2727
/// # fn main() {
2828
/// log!(log::DEBUG, "this is a debug message");
@@ -51,7 +51,7 @@ macro_rules! log(
5151
///
5252
/// ```
5353
/// #![feature(phase)]
54-
/// #[phase(syntax, link)] extern crate log;
54+
/// #[phase(plugin, link)] extern crate log;
5555
///
5656
/// # fn main() {
5757
/// # let error = 3;
@@ -69,7 +69,7 @@ macro_rules! error(
6969
///
7070
/// ```
7171
/// #![feature(phase)]
72-
/// #[phase(syntax, link)] extern crate log;
72+
/// #[phase(plugin, link)] extern crate log;
7373
///
7474
/// # fn main() {
7575
/// # let code = 3;
@@ -87,7 +87,7 @@ macro_rules! warn(
8787
///
8888
/// ```
8989
/// #![feature(phase)]
90-
/// #[phase(syntax, link)] extern crate log;
90+
/// #[phase(plugin, link)] extern crate log;
9191
///
9292
/// # fn main() {
9393
/// # let ret = 3;
@@ -107,7 +107,7 @@ macro_rules! info(
107107
///
108108
/// ```
109109
/// #![feature(phase)]
110-
/// #[phase(syntax, link)] extern crate log;
110+
/// #[phase(plugin, link)] extern crate log;
111111
///
112112
/// # fn main() {
113113
/// debug!("x = {x}, y = {y}", x=10, y=20);
@@ -124,7 +124,7 @@ macro_rules! debug(
124124
///
125125
/// ```
126126
/// #![feature(phase)]
127-
/// #[phase(syntax, link)] extern crate log;
127+
/// #[phase(plugin, link)] extern crate log;
128128
///
129129
/// # fn main() {
130130
/// # struct Point { x: int, y: int }

src/librand/lib.rs

+17-2
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,28 @@
2828
#![no_std]
2929
#![experimental]
3030

31+
#[cfg(stage0)]
3132
#[phase(syntax, link)]
3233
extern crate core;
3334

35+
#[cfg(not(stage0))]
36+
#[phase(plugin, link)]
37+
extern crate core;
38+
39+
#[cfg(test, stage0)]
40+
#[phase(syntax, link)] extern crate std;
41+
42+
#[cfg(test, stage0)]
43+
#[phase(syntax, link)] extern crate log;
44+
45+
#[cfg(test, not(stage0))]
46+
#[phase(plugin, link)] extern crate std;
47+
48+
#[cfg(test, not(stage0))]
49+
#[phase(plugin, link)] extern crate log;
50+
3451
#[cfg(test)] extern crate native;
3552
#[cfg(test)] extern crate debug;
36-
#[cfg(test)] #[phase(syntax, link)] extern crate std;
37-
#[cfg(test)] #[phase(syntax, link)] extern crate log;
3853

3954
use core::prelude::*;
4055

0 commit comments

Comments
 (0)