Skip to content

Commit 168b2d1

Browse files
committed
auto merge of #13496 : alexcrichton/rust/issue-13495, r=sfackler
This bug was introduced in #13384 by accident, and this commit continues the work of #13384 by finishing support for loading a syntax extension crate without registering it with the local cstore. Closes #13495
2 parents 246ebd2 + e163ab2 commit 168b2d1

File tree

10 files changed

+53
-25
lines changed

10 files changed

+53
-25
lines changed

src/librustc/driver/driver.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -310,10 +310,10 @@ pub fn phase_3_run_analysis_passes(sess: Session,
310310
time(time_passes, "looking for entry point", (),
311311
|_| middle::entry::find_entry_point(&sess, krate, &ast_map));
312312

313-
*sess.macro_registrar_fn.borrow_mut() =
313+
sess.macro_registrar_fn.set(
314314
time(time_passes, "looking for macro registrar", (), |_|
315315
syntax::ext::registrar::find_macro_registrar(
316-
sess.diagnostic(), krate));
316+
sess.diagnostic(), krate)));
317317

318318
let freevars = time(time_passes, "freevar finding", (), |_|
319319
freevars::annotate_freevars(def_map, krate));
@@ -1054,7 +1054,7 @@ pub fn build_session_(sopts: session::Options,
10541054
// For a library crate, this is always none
10551055
entry_fn: RefCell::new(None),
10561056
entry_type: Cell::new(None),
1057-
macro_registrar_fn: RefCell::new(None),
1057+
macro_registrar_fn: Cell::new(None),
10581058
default_sysroot: default_sysroot,
10591059
building_library: Cell::new(false),
10601060
local_crate_source_file: local_crate_source_file,

src/librustc/driver/session.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ pub struct Session {
181181
// For a library crate, this is always none
182182
pub entry_fn: RefCell<Option<(NodeId, codemap::Span)>>,
183183
pub entry_type: Cell<Option<EntryFnType>>,
184-
pub macro_registrar_fn: RefCell<Option<ast::DefId>>,
184+
pub macro_registrar_fn: Cell<Option<ast::NodeId>>,
185185
pub default_sysroot: Option<Path>,
186186
pub building_library: Cell<bool>,
187187
// The name of the root source file of the crate, in the local file system. The path is always

src/librustc/metadata/creader.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ use back::link;
1616
use back::svh::Svh;
1717
use driver::{driver, session};
1818
use driver::session::Session;
19-
use metadata::csearch;
2019
use metadata::cstore;
2120
use metadata::cstore::CStore;
2221
use metadata::decoder;
@@ -397,13 +396,14 @@ impl<'a> Loader<'a> {
397396
impl<'a> CrateLoader for Loader<'a> {
398397
fn load_crate(&mut self, krate: &ast::ViewItem) -> MacroCrate {
399398
let info = extract_crate_info(&self.env, krate).unwrap();
400-
let (cnum, data, library) = resolve_crate(&mut self.env, &None,
401-
info.ident, &info.crate_id,
402-
None, true, krate.span);
399+
let (_, data, library) = resolve_crate(&mut self.env, &None,
400+
info.ident, &info.crate_id,
401+
None, info.should_link,
402+
krate.span);
403403
let macros = decoder::get_exported_macros(data);
404-
let cstore = &self.env.sess.cstore;
405-
let registrar = csearch::get_macro_registrar_fn(cstore, cnum)
406-
.map(|did| csearch::get_symbol(cstore, did));
404+
let registrar = decoder::get_macro_registrar_fn(data).map(|id| {
405+
decoder::get_symbol(data.data.as_slice(), id)
406+
});
407407
MacroCrate {
408408
lib: library.dylib,
409409
macros: macros.move_iter().collect(),

src/librustc/metadata/csearch.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ pub fn get_trait_of_method(cstore: &cstore::CStore,
279279

280280
pub fn get_macro_registrar_fn(cstore: &cstore::CStore,
281281
crate_num: ast::CrateNum)
282-
-> Option<ast::DefId> {
282+
-> Option<ast::NodeId> {
283283
let cdata = cstore.get_crate_data(crate_num);
284284
decoder::get_macro_registrar_fn(cdata)
285285
}

src/librustc/metadata/decoder.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1235,9 +1235,9 @@ pub fn get_native_libraries(cdata: Cmd) -> Vec<(cstore::NativeLibaryKind, ~str)>
12351235
return result;
12361236
}
12371237

1238-
pub fn get_macro_registrar_fn(cdata: Cmd) -> Option<ast::DefId> {
1238+
pub fn get_macro_registrar_fn(cdata: Cmd) -> Option<ast::NodeId> {
12391239
reader::maybe_get_doc(reader::Doc(cdata.data()), tag_macro_registrar_fn)
1240-
.map(|doc| item_def_id(doc, cdata))
1240+
.map(|doc| FromPrimitive::from_u32(reader::doc_as_u32(doc)).unwrap())
12411241
}
12421242

12431243
pub fn get_exported_macros(cdata: Cmd) -> Vec<~str> {

src/librustc/metadata/encoder.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -1565,12 +1565,8 @@ fn encode_native_libraries(ecx: &EncodeContext, ebml_w: &mut Encoder) {
15651565
}
15661566

15671567
fn encode_macro_registrar_fn(ecx: &EncodeContext, ebml_w: &mut Encoder) {
1568-
match *ecx.tcx.sess.macro_registrar_fn.borrow() {
1569-
Some(did) => {
1570-
ebml_w.start_tag(tag_macro_registrar_fn);
1571-
encode_def_id(ebml_w, did);
1572-
ebml_w.end_tag();
1573-
}
1568+
match ecx.tcx.sess.macro_registrar_fn.get() {
1569+
Some(id) => { ebml_w.wr_tagged_u32(tag_macro_registrar_fn, id); }
15741570
None => {}
15751571
}
15761572
}

src/libsyntax/ext/registrar.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,15 @@ impl Visitor<()> for MacroRegistrarContext {
3636
}
3737

3838
pub fn find_macro_registrar(diagnostic: &diagnostic::SpanHandler,
39-
krate: &ast::Crate) -> Option<ast::DefId> {
39+
krate: &ast::Crate) -> Option<ast::NodeId> {
4040
let mut ctx = MacroRegistrarContext { registrars: Vec::new() };
4141
visit::walk_crate(&mut ctx, krate, ());
4242

4343
match ctx.registrars.len() {
4444
0 => None,
4545
1 => {
4646
let (node_id, _) = ctx.registrars.pop().unwrap();
47-
Some(ast::DefId {
48-
krate: ast::LOCAL_CRATE,
49-
node: node_id
50-
})
47+
Some(node_id)
5148
},
5249
_ => {
5350
diagnostic.handler().err("multiple macro registration functions found");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
-include ../tools.mk
2+
3+
all:
4+
$(RUSTC) lib.rs
5+
$(RUSTC) main.rs -Z lto
6+
$(call RUN,main)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#[crate_type = "rlib"];
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![feature(phase)]
12+
13+
extern crate lib;
14+
#[phase(syntax)] extern crate fourcc;
15+
16+
fn main() {
17+
fourcc!("1234");
18+
}

0 commit comments

Comments
 (0)