Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rustc: Don't link in syntax extensions #13496

Merged
merged 1 commit into from
Apr 14, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/librustc/driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,10 +310,10 @@ 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.borrow_mut() =
sess.macro_registrar_fn.set(
time(time_passes, "looking for macro registrar", (), |_|
syntax::ext::registrar::find_macro_registrar(
sess.diagnostic(), krate));
sess.diagnostic(), krate)));

let freevars = time(time_passes, "freevar finding", (), |_|
freevars::annotate_freevars(def_map, krate));
Expand Down Expand Up @@ -1054,7 +1054,7 @@ pub fn build_session_(sopts: session::Options,
// For a library crate, this is always none
entry_fn: RefCell::new(None),
entry_type: Cell::new(None),
macro_registrar_fn: RefCell::new(None),
macro_registrar_fn: Cell::new(None),
default_sysroot: default_sysroot,
building_library: Cell::new(false),
local_crate_source_file: local_crate_source_file,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/driver/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,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<EntryFnType>>,
pub macro_registrar_fn: RefCell<Option<ast::DefId>>,
pub macro_registrar_fn: Cell<Option<ast::NodeId>>,
pub default_sysroot: Option<Path>,
pub building_library: Cell<bool>,
// The name of the root source file of the crate, in the local file system. The path is always
Expand Down
14 changes: 7 additions & 7 deletions src/librustc/metadata/creader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use back::link;
use back::svh::Svh;
use driver::{driver, session};
use driver::session::Session;
use metadata::csearch;
use metadata::cstore;
use metadata::cstore::CStore;
use metadata::decoder;
Expand Down Expand Up @@ -397,13 +396,14 @@ impl<'a> Loader<'a> {
impl<'a> CrateLoader for Loader<'a> {
fn load_crate(&mut self, krate: &ast::ViewItem) -> MacroCrate {
let info = extract_crate_info(&self.env, krate).unwrap();
let (cnum, data, library) = resolve_crate(&mut self.env, &None,
info.ident, &info.crate_id,
None, true, krate.span);
let (_, data, library) = resolve_crate(&mut self.env, &None,
info.ident, &info.crate_id,
None, info.should_link,
krate.span);
let macros = decoder::get_exported_macros(data);
let cstore = &self.env.sess.cstore;
let registrar = csearch::get_macro_registrar_fn(cstore, cnum)
.map(|did| csearch::get_symbol(cstore, did));
let registrar = decoder::get_macro_registrar_fn(data).map(|id| {
decoder::get_symbol(data.data.as_slice(), id)
});
MacroCrate {
lib: library.dylib,
macros: macros.move_iter().collect(),
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/metadata/csearch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ pub fn get_trait_of_method(cstore: &cstore::CStore,

pub fn get_macro_registrar_fn(cstore: &cstore::CStore,
crate_num: ast::CrateNum)
-> Option<ast::DefId> {
-> Option<ast::NodeId> {
let cdata = cstore.get_crate_data(crate_num);
decoder::get_macro_registrar_fn(cdata)
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/metadata/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1235,9 +1235,9 @@ pub fn get_native_libraries(cdata: Cmd) -> Vec<(cstore::NativeLibaryKind, ~str)>
return result;
}

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

pub fn get_exported_macros(cdata: Cmd) -> Vec<~str> {
Expand Down
8 changes: 2 additions & 6 deletions src/librustc/metadata/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1565,12 +1565,8 @@ fn encode_native_libraries(ecx: &EncodeContext, ebml_w: &mut Encoder) {
}

fn encode_macro_registrar_fn(ecx: &EncodeContext, ebml_w: &mut Encoder) {
match *ecx.tcx.sess.macro_registrar_fn.borrow() {
Some(did) => {
ebml_w.start_tag(tag_macro_registrar_fn);
encode_def_id(ebml_w, did);
ebml_w.end_tag();
}
match ecx.tcx.sess.macro_registrar_fn.get() {
Some(id) => { ebml_w.wr_tagged_u32(tag_macro_registrar_fn, id); }
None => {}
}
}
Expand Down
7 changes: 2 additions & 5 deletions src/libsyntax/ext/registrar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,15 @@ impl Visitor<()> for MacroRegistrarContext {
}

pub fn find_macro_registrar(diagnostic: &diagnostic::SpanHandler,
krate: &ast::Crate) -> Option<ast::DefId> {
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(ast::DefId {
krate: ast::LOCAL_CRATE,
node: node_id
})
Some(node_id)
},
_ => {
diagnostic.handler().err("multiple macro registration functions found");
Expand Down
6 changes: 6 additions & 0 deletions src/test/run-make/lto-syntax-extension/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-include ../tools.mk

all:
$(RUSTC) lib.rs
$(RUSTC) main.rs -Z lto
$(call RUN,main)
11 changes: 11 additions & 0 deletions src/test/run-make/lto-syntax-extension/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// 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.

#[crate_type = "rlib"];
18 changes: 18 additions & 0 deletions src/test/run-make/lto-syntax-extension/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// 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.

#![feature(phase)]

extern crate lib;
#[phase(syntax)] extern crate fourcc;

fn main() {
fourcc!("1234");
}