]> git.lizzy.rs Git - rust.git/commitdiff
rustc: Don't link in syntax extensions
authorAlex Crichton <alex@alexcrichton.com>
Sun, 13 Apr 2014 18:26:43 +0000 (11:26 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Sun, 13 Apr 2014 18:29:28 +0000 (11:29 -0700)
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

src/librustc/driver/driver.rs
src/librustc/driver/session.rs
src/librustc/metadata/creader.rs
src/librustc/metadata/csearch.rs
src/librustc/metadata/decoder.rs
src/librustc/metadata/encoder.rs
src/libsyntax/ext/registrar.rs
src/test/run-make/lto-syntax-extension/Makefile [new file with mode: 0644]
src/test/run-make/lto-syntax-extension/lib.rs [new file with mode: 0644]
src/test/run-make/lto-syntax-extension/main.rs [new file with mode: 0644]

index 1b3653c6948a699910344b7f12e88c22c2ec1a12..4fc7239e63b186f53bfed4d909977f0be062a0ea 100644 (file)
@@ -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));
@@ -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,
index a412742ab3a3612076dbe9e3d15ffd7bd4dfcc06..5d3069bbf3e2ec9e625b4969d00c4bd2be370673 100644 (file)
@@ -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
index b57ab8d0f2fc84c1aefc409f50a8ec190c995944..e6b7049f4f8fa74ede7dd0e198b5842d847875dd 100644 (file)
@@ -16,7 +16,6 @@
 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;
@@ -397,13 +396,14 @@ pub fn new(sess: &'a Session) -> 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(),
index 16068dd939b1d13edd7ca0ccfac7646a30e24384..f02f9c6158227121ba934e2888d74d5b8650c728 100644 (file)
@@ -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)
 }
index 28968a6001616c7dbcd6045434277ddbda3505c9..5fe59a787737aea37253e839f1c1065e25579bc1 100644 (file)
@@ -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> {
index e2fb4e26e596262154be9a435497cc27babfae3d..d5313eb2578108a521e0aa1266323aa207ad403b 100644 (file)
@@ -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 => {}
     }
 }
index ecd60fc9932d97ac88269b5eecd746e93f7c83cc..b76708147e1b2224337d8dbeba887dcc92062981 100644 (file)
@@ -36,7 +36,7 @@ fn visit_item(&mut self, item: &ast::Item, _: ()) {
 }
 
 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, ());
 
@@ -44,10 +44,7 @@ pub fn find_macro_registrar(diagnostic: &diagnostic::SpanHandler,
         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");
diff --git a/src/test/run-make/lto-syntax-extension/Makefile b/src/test/run-make/lto-syntax-extension/Makefile
new file mode 100644 (file)
index 0000000..4652556
--- /dev/null
@@ -0,0 +1,6 @@
+-include ../tools.mk
+
+all:
+       $(RUSTC) lib.rs
+       $(RUSTC) main.rs -Z lto
+       $(call RUN,main)
diff --git a/src/test/run-make/lto-syntax-extension/lib.rs b/src/test/run-make/lto-syntax-extension/lib.rs
new file mode 100644 (file)
index 0000000..fbe9677
--- /dev/null
@@ -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"];
diff --git a/src/test/run-make/lto-syntax-extension/main.rs b/src/test/run-make/lto-syntax-extension/main.rs
new file mode 100644 (file)
index 0000000..0c55d5f
--- /dev/null
@@ -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");
+}