Skip to content

Commit 10333dd

Browse files
committed
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.
2 parents 9af8d42 + f0a7d8e commit 10333dd

File tree

8 files changed

+82
-26
lines changed

8 files changed

+82
-26
lines changed

src/bootstrap/check.rs

+5
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,11 @@ static HOST_COMPILETESTS: &[Test] = &[
605605
mode: "compile-fail",
606606
suite: "compile-fail-fulldeps",
607607
},
608+
Test {
609+
path: "src/test/incremental-fulldeps",
610+
mode: "incremental",
611+
suite: "incremental-fulldeps",
612+
},
608613
Test { path: "src/test/run-make", mode: "run-make", suite: "run-make" },
609614
Test { path: "src/test/rustdoc", mode: "rustdoc", suite: "rustdoc" },
610615

src/librustc/session/mod.rs

+7-9
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
pub use self::code_stats::{CodeStats, DataTypeKind, FieldInfo};
1212
pub use self::code_stats::{SizeKind, TypeSizeInfo, VariantInfo};
1313

14-
use hir::def_id::{CrateNum, DefIndex};
14+
use hir::def_id::CrateNum;
1515
use ich::Fingerprint;
1616

1717
use lint;
@@ -558,18 +558,16 @@ impl Session {
558558

559559
/// Returns the symbol name for the registrar function,
560560
/// given the crate Svh and the function DefIndex.
561-
pub fn generate_plugin_registrar_symbol(&self, disambiguator: CrateDisambiguator,
562-
index: DefIndex)
561+
pub fn generate_plugin_registrar_symbol(&self,
562+
disambiguator: CrateDisambiguator)
563563
-> String {
564-
format!("__rustc_plugin_registrar__{}_{}", disambiguator.to_fingerprint().to_hex(),
565-
index.to_proc_macro_index())
564+
format!("__rustc_plugin_registrar_{}__", disambiguator.to_fingerprint().to_hex())
566565
}
567566

568-
pub fn generate_derive_registrar_symbol(&self, disambiguator: CrateDisambiguator,
569-
index: DefIndex)
567+
pub fn generate_derive_registrar_symbol(&self,
568+
disambiguator: CrateDisambiguator)
570569
-> String {
571-
format!("__rustc_derive_registrar__{}_{}", disambiguator.to_fingerprint().to_hex(),
572-
index.to_proc_macro_index())
570+
format!("__rustc_derive_registrar_{}__", disambiguator.to_fingerprint().to_hex())
573571
}
574572

575573
pub fn sysroot<'a>(&'a self) -> &'a Path {

src/librustc_metadata/creader.rs

+7-9
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use locator::{self, CratePaths};
1515
use native_libs::relevant_lib;
1616
use schema::CrateRoot;
1717

18-
use rustc::hir::def_id::{CrateNum, DefIndex, CRATE_DEF_INDEX};
18+
use rustc::hir::def_id::{CrateNum, CRATE_DEF_INDEX};
1919
use rustc::hir::svh::Svh;
2020
use rustc::middle::allocator::AllocatorKind;
2121
use rustc::middle::cstore::DepKind;
@@ -532,8 +532,7 @@ impl<'a> CrateLoader<'a> {
532532
Err(err) => self.sess.span_fatal(span, &err),
533533
};
534534

535-
let sym = self.sess.generate_derive_registrar_symbol(root.disambiguator,
536-
root.macro_derive_registrar.unwrap());
535+
let sym = self.sess.generate_derive_registrar_symbol(root.disambiguator);
537536
let registrar = unsafe {
538537
let sym = match lib.symbol(&sym) {
539538
Ok(f) => f,
@@ -588,7 +587,7 @@ impl<'a> CrateLoader<'a> {
588587
pub fn find_plugin_registrar(&mut self,
589588
span: Span,
590589
name: &str)
591-
-> Option<(PathBuf, CrateDisambiguator, DefIndex)> {
590+
-> Option<(PathBuf, CrateDisambiguator)> {
592591
let name = Symbol::intern(name);
593592
let ekrate = self.read_extension_crate(span, name, name);
594593

@@ -603,11 +602,11 @@ impl<'a> CrateLoader<'a> {
603602
}
604603

605604
let root = ekrate.metadata.get_root();
606-
match (ekrate.dylib.as_ref(), root.plugin_registrar_fn) {
607-
(Some(dylib), Some(reg)) => {
608-
Some((dylib.to_path_buf(), root.disambiguator, reg))
605+
match ekrate.dylib.as_ref() {
606+
Some(dylib) => {
607+
Some((dylib.to_path_buf(), root.disambiguator))
609608
}
610-
(None, Some(_)) => {
609+
None => {
611610
span_err!(self.sess, span, E0457,
612611
"plugin `{}` only found in rlib format, but must be available \
613612
in dylib format",
@@ -616,7 +615,6 @@ impl<'a> CrateLoader<'a> {
616615
// empty dylib.
617616
None
618617
}
619-
_ => None,
620618
}
621619
}
622620

src/librustc_plugin/load.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ impl<'a> PluginLoader<'a> {
100100
fn load_plugin(&mut self, span: Span, name: &str, args: Vec<ast::NestedMetaItem>) {
101101
let registrar = self.reader.find_plugin_registrar(span, name);
102102

103-
if let Some((lib, disambiguator, index)) = registrar {
104-
let symbol = self.sess.generate_plugin_registrar_symbol(disambiguator, index);
103+
if let Some((lib, disambiguator)) = registrar {
104+
let symbol = self.sess.generate_plugin_registrar_symbol(disambiguator);
105105
let fun = self.dylink_registrar(span, lib, symbol);
106106
self.plugins.push(PluginRegistrar {
107107
fun,

src/librustc_trans/back/symbol_export.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,8 @@ pub fn provide(providers: &mut Providers) {
115115

116116
if let Some(id) = tcx.sess.derive_registrar_fn.get() {
117117
let def_id = tcx.hir.local_def_id(id);
118-
let idx = def_id.index;
119118
let disambiguator = tcx.sess.local_crate_disambiguator();
120-
let registrar = tcx.sess.generate_derive_registrar_symbol(disambiguator, idx);
119+
let registrar = tcx.sess.generate_derive_registrar_symbol(disambiguator);
121120
local_crate.push((registrar, Some(def_id), SymbolExportLevel::C));
122121
}
123122

src/librustc_trans/back/symbol_names.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -257,14 +257,12 @@ fn compute_symbol_name<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, instance: Instance
257257

258258
if let Some(id) = node_id {
259259
if tcx.sess.plugin_registrar_fn.get() == Some(id) {
260-
let idx = def_id.index;
261260
let disambiguator = tcx.sess.local_crate_disambiguator();
262-
return tcx.sess.generate_plugin_registrar_symbol(disambiguator, idx);
261+
return tcx.sess.generate_plugin_registrar_symbol(disambiguator);
263262
}
264263
if tcx.sess.derive_registrar_fn.get() == Some(id) {
265-
let idx = def_id.index;
266264
let disambiguator = tcx.sess.local_crate_disambiguator();
267-
return tcx.sess.generate_derive_registrar_symbol(disambiguator, idx);
265+
return tcx.sess.generate_derive_registrar_symbol(disambiguator);
268266
}
269267
}
270268

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright 2018 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+
// no-prefer-dynamic
12+
13+
#![crate_type = "proc-macro"]
14+
15+
extern crate proc_macro;
16+
17+
use proc_macro::TokenStream;
18+
19+
// Add a function to shift DefIndex of registrar function
20+
#[cfg(cfail2)]
21+
fn foo() {}
22+
23+
#[proc_macro_derive(IncrementalMacro)]
24+
pub fn derive(input: TokenStream) -> TokenStream {
25+
#[cfg(cfail2)]
26+
{
27+
foo();
28+
}
29+
30+
"".parse().unwrap()
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright 2018 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+
// aux-build:incremental_proc_macro_aux.rs
12+
// ignore-stage1
13+
// revisions: cfail1 cfail2
14+
// must-compile-successfully
15+
16+
// This test makes sure that we still find the proc-macro registrar function
17+
// when we compile proc-macros incrementally (see #47292).
18+
19+
#![crate_type = "rlib"]
20+
21+
#[macro_use]
22+
extern crate incremental_proc_macro_aux;
23+
24+
#[derive(IncrementalMacro)]
25+
pub struct Foo {
26+
x: u32
27+
}

0 commit comments

Comments
 (0)