about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2018-01-19 04:45:22 +0000
committerbors <bors@rust-lang.org>2018-01-19 04:45:22 +0000
commit10333dde82b03c7df2620f742596d3e7714f9e25 (patch)
tree8fb15906cf99a8aa18681c612b5b5a426afbb7c4
parent9af8d42ec79558225043189e429e9d652ff89eab (diff)
parentf0a7d8e2bd5a878ef65b34406637c1032507a675 (diff)
downloadrust-10333dde82b03c7df2620f742596d3e7714f9e25.tar.gz
rust-10333dde82b03c7df2620f742596d3e7714f9e25.zip
Auto merge of #47494 - michaelwoerister:proc-macro-incremental, r=nikomatsakis
Don't include DefIndex in proc-macro registrar function symbol.

There can only ever be one registrar function per plugin or proc-macro crate, so adding the `DefIndex` to the function's symbol name does not serve a real purpose. Remove the `DefIndex` from the symbol name makes it stable across incremental compilation sessions.

This should fix issue #47292.
-rw-r--r--src/bootstrap/check.rs5
-rw-r--r--src/librustc/session/mod.rs16
-rw-r--r--src/librustc_metadata/creader.rs16
-rw-r--r--src/librustc_plugin/load.rs4
-rw-r--r--src/librustc_trans/back/symbol_export.rs3
-rw-r--r--src/librustc_trans/back/symbol_names.rs6
-rw-r--r--src/test/incremental-fulldeps/auxiliary/incremental_proc_macro_aux.rs31
-rw-r--r--src/test/incremental-fulldeps/incremental_proc_macro.rs27
8 files changed, 82 insertions, 26 deletions
diff --git a/src/bootstrap/check.rs b/src/bootstrap/check.rs
index 78ad71172a8..1187376e177 100644
--- a/src/bootstrap/check.rs
+++ b/src/bootstrap/check.rs
@@ -605,6 +605,11 @@ static HOST_COMPILETESTS: &[Test] = &[
         mode: "compile-fail",
         suite: "compile-fail-fulldeps",
     },
+    Test {
+        path: "src/test/incremental-fulldeps",
+        mode: "incremental",
+        suite: "incremental-fulldeps",
+    },
     Test { path: "src/test/run-make", mode: "run-make", suite: "run-make" },
     Test { path: "src/test/rustdoc", mode: "rustdoc", suite: "rustdoc" },
 
diff --git a/src/librustc/session/mod.rs b/src/librustc/session/mod.rs
index 3ae7d01823c..94fcfb7e2aa 100644
--- a/src/librustc/session/mod.rs
+++ b/src/librustc/session/mod.rs
@@ -11,7 +11,7 @@
 pub use self::code_stats::{CodeStats, DataTypeKind, FieldInfo};
 pub use self::code_stats::{SizeKind, TypeSizeInfo, VariantInfo};
 
-use hir::def_id::{CrateNum, DefIndex};
+use hir::def_id::CrateNum;
 use ich::Fingerprint;
 
 use lint;
@@ -558,18 +558,16 @@ impl Session {
 
     /// Returns the symbol name for the registrar function,
     /// given the crate Svh and the function DefIndex.
-    pub fn generate_plugin_registrar_symbol(&self, disambiguator: CrateDisambiguator,
-                                            index: DefIndex)
+    pub fn generate_plugin_registrar_symbol(&self,
+                                            disambiguator: CrateDisambiguator)
                                             -> String {
-        format!("__rustc_plugin_registrar__{}_{}", disambiguator.to_fingerprint().to_hex(),
-                                                   index.to_proc_macro_index())
+        format!("__rustc_plugin_registrar_{}__", disambiguator.to_fingerprint().to_hex())
     }
 
-    pub fn generate_derive_registrar_symbol(&self, disambiguator: CrateDisambiguator,
-                                            index: DefIndex)
+    pub fn generate_derive_registrar_symbol(&self,
+                                            disambiguator: CrateDisambiguator)
                                             -> String {
-        format!("__rustc_derive_registrar__{}_{}", disambiguator.to_fingerprint().to_hex(),
-                                                   index.to_proc_macro_index())
+        format!("__rustc_derive_registrar_{}__", disambiguator.to_fingerprint().to_hex())
     }
 
     pub fn sysroot<'a>(&'a self) -> &'a Path {
diff --git a/src/librustc_metadata/creader.rs b/src/librustc_metadata/creader.rs
index 946eecaa45f..246f5c9255e 100644
--- a/src/librustc_metadata/creader.rs
+++ b/src/librustc_metadata/creader.rs
@@ -15,7 +15,7 @@ use locator::{self, CratePaths};
 use native_libs::relevant_lib;
 use schema::CrateRoot;
 
-use rustc::hir::def_id::{CrateNum, DefIndex, CRATE_DEF_INDEX};
+use rustc::hir::def_id::{CrateNum, CRATE_DEF_INDEX};
 use rustc::hir::svh::Svh;
 use rustc::middle::allocator::AllocatorKind;
 use rustc::middle::cstore::DepKind;
@@ -532,8 +532,7 @@ impl<'a> CrateLoader<'a> {
             Err(err) => self.sess.span_fatal(span, &err),
         };
 
-        let sym = self.sess.generate_derive_registrar_symbol(root.disambiguator,
-                                                             root.macro_derive_registrar.unwrap());
+        let sym = self.sess.generate_derive_registrar_symbol(root.disambiguator);
         let registrar = unsafe {
             let sym = match lib.symbol(&sym) {
                 Ok(f) => f,
@@ -588,7 +587,7 @@ impl<'a> CrateLoader<'a> {
     pub fn find_plugin_registrar(&mut self,
                                  span: Span,
                                  name: &str)
-                                 -> Option<(PathBuf, CrateDisambiguator, DefIndex)> {
+                                 -> Option<(PathBuf, CrateDisambiguator)> {
         let name = Symbol::intern(name);
         let ekrate = self.read_extension_crate(span, name, name);
 
@@ -603,11 +602,11 @@ impl<'a> CrateLoader<'a> {
         }
 
         let root = ekrate.metadata.get_root();
-        match (ekrate.dylib.as_ref(), root.plugin_registrar_fn) {
-            (Some(dylib), Some(reg)) => {
-                Some((dylib.to_path_buf(), root.disambiguator, reg))
+        match ekrate.dylib.as_ref() {
+            Some(dylib) => {
+                Some((dylib.to_path_buf(), root.disambiguator))
             }
-            (None, Some(_)) => {
+            None => {
                 span_err!(self.sess, span, E0457,
                           "plugin `{}` only found in rlib format, but must be available \
                            in dylib format",
@@ -616,7 +615,6 @@ impl<'a> CrateLoader<'a> {
                 // empty dylib.
                 None
             }
-            _ => None,
         }
     }
 
diff --git a/src/librustc_plugin/load.rs b/src/librustc_plugin/load.rs
index 8a4ec03b20e..a46b85d93cb 100644
--- a/src/librustc_plugin/load.rs
+++ b/src/librustc_plugin/load.rs
@@ -100,8 +100,8 @@ impl<'a> PluginLoader<'a> {
     fn load_plugin(&mut self, span: Span, name: &str, args: Vec<ast::NestedMetaItem>) {
         let registrar = self.reader.find_plugin_registrar(span, name);
 
-        if let Some((lib, disambiguator, index)) = registrar {
-            let symbol = self.sess.generate_plugin_registrar_symbol(disambiguator, index);
+        if let Some((lib, disambiguator)) = registrar {
+            let symbol = self.sess.generate_plugin_registrar_symbol(disambiguator);
             let fun = self.dylink_registrar(span, lib, symbol);
             self.plugins.push(PluginRegistrar {
                 fun,
diff --git a/src/librustc_trans/back/symbol_export.rs b/src/librustc_trans/back/symbol_export.rs
index fa6fe2e9e93..15ff59c7df9 100644
--- a/src/librustc_trans/back/symbol_export.rs
+++ b/src/librustc_trans/back/symbol_export.rs
@@ -115,9 +115,8 @@ pub fn provide(providers: &mut Providers) {
 
         if let Some(id) = tcx.sess.derive_registrar_fn.get() {
             let def_id = tcx.hir.local_def_id(id);
-            let idx = def_id.index;
             let disambiguator = tcx.sess.local_crate_disambiguator();
-            let registrar = tcx.sess.generate_derive_registrar_symbol(disambiguator, idx);
+            let registrar = tcx.sess.generate_derive_registrar_symbol(disambiguator);
             local_crate.push((registrar, Some(def_id), SymbolExportLevel::C));
         }
 
diff --git a/src/librustc_trans/back/symbol_names.rs b/src/librustc_trans/back/symbol_names.rs
index 825f306499a..3ceff659ea9 100644
--- a/src/librustc_trans/back/symbol_names.rs
+++ b/src/librustc_trans/back/symbol_names.rs
@@ -257,14 +257,12 @@ fn compute_symbol_name<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, instance: Instance
 
     if let Some(id) = node_id {
         if tcx.sess.plugin_registrar_fn.get() == Some(id) {
-            let idx = def_id.index;
             let disambiguator = tcx.sess.local_crate_disambiguator();
-            return tcx.sess.generate_plugin_registrar_symbol(disambiguator, idx);
+            return tcx.sess.generate_plugin_registrar_symbol(disambiguator);
         }
         if tcx.sess.derive_registrar_fn.get() == Some(id) {
-            let idx = def_id.index;
             let disambiguator = tcx.sess.local_crate_disambiguator();
-            return tcx.sess.generate_derive_registrar_symbol(disambiguator, idx);
+            return tcx.sess.generate_derive_registrar_symbol(disambiguator);
         }
     }
 
diff --git a/src/test/incremental-fulldeps/auxiliary/incremental_proc_macro_aux.rs b/src/test/incremental-fulldeps/auxiliary/incremental_proc_macro_aux.rs
new file mode 100644
index 00000000000..e9f9ba86f23
--- /dev/null
+++ b/src/test/incremental-fulldeps/auxiliary/incremental_proc_macro_aux.rs
@@ -0,0 +1,31 @@
+// Copyright 2018 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.
+
+// no-prefer-dynamic
+
+#![crate_type = "proc-macro"]
+
+extern crate proc_macro;
+
+use proc_macro::TokenStream;
+
+// Add a function to shift DefIndex of registrar function
+#[cfg(cfail2)]
+fn foo() {}
+
+#[proc_macro_derive(IncrementalMacro)]
+pub fn derive(input: TokenStream) -> TokenStream {
+    #[cfg(cfail2)]
+    {
+        foo();
+    }
+
+    "".parse().unwrap()
+}
diff --git a/src/test/incremental-fulldeps/incremental_proc_macro.rs b/src/test/incremental-fulldeps/incremental_proc_macro.rs
new file mode 100644
index 00000000000..e4345070853
--- /dev/null
+++ b/src/test/incremental-fulldeps/incremental_proc_macro.rs
@@ -0,0 +1,27 @@
+// Copyright 2018 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.
+
+// aux-build:incremental_proc_macro_aux.rs
+// ignore-stage1
+// revisions: cfail1 cfail2
+// must-compile-successfully
+
+// This test makes sure that we still find the proc-macro registrar function
+// when we compile proc-macros incrementally (see #47292).
+
+#![crate_type = "rlib"]
+
+#[macro_use]
+extern crate incremental_proc_macro_aux;
+
+#[derive(IncrementalMacro)]
+pub struct Foo {
+    x: u32
+}