Add primary marker on codegen unit to take charge of main_wrapper for non-local cases.
This commit is contained in:
parent
49920bc581
commit
89a67051a7
5 changed files with 20 additions and 31 deletions
|
@ -357,20 +357,9 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
|
||||||
if !cx.codegen_unit().contains_item(&MonoItem::Fn(instance)) {
|
if !cx.codegen_unit().contains_item(&MonoItem::Fn(instance)) {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
} else {
|
} else if !cx.codegen_unit().is_primary() {
|
||||||
// FIXME: Add support for non-local main fn codegen
|
// We want to create the wrapper only when the codegen unit is the primary one
|
||||||
let span = cx.tcx().main_def.unwrap().span;
|
return None;
|
||||||
let n = 28937;
|
|
||||||
cx.sess()
|
|
||||||
.struct_span_err(span, "entry symbol `main` from foreign crate is not yet supported.")
|
|
||||||
.note(&format!(
|
|
||||||
"see issue #{} <https://github.com/rust-lang/rust/issues/{}> \
|
|
||||||
for more information",
|
|
||||||
n, n,
|
|
||||||
))
|
|
||||||
.emit();
|
|
||||||
cx.sess().abort_if_errors();
|
|
||||||
bug!();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let main_llfn = cx.get_fn_addr(instance);
|
let main_llfn = cx.get_fn_addr(instance);
|
||||||
|
|
|
@ -229,6 +229,7 @@ pub struct CodegenUnit<'tcx> {
|
||||||
name: Symbol,
|
name: Symbol,
|
||||||
items: FxHashMap<MonoItem<'tcx>, (Linkage, Visibility)>,
|
items: FxHashMap<MonoItem<'tcx>, (Linkage, Visibility)>,
|
||||||
size_estimate: Option<usize>,
|
size_estimate: Option<usize>,
|
||||||
|
primary: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Specifies the linkage type for a `MonoItem`.
|
/// Specifies the linkage type for a `MonoItem`.
|
||||||
|
@ -258,7 +259,7 @@ pub enum Visibility {
|
||||||
|
|
||||||
impl<'tcx> CodegenUnit<'tcx> {
|
impl<'tcx> CodegenUnit<'tcx> {
|
||||||
pub fn new(name: Symbol) -> CodegenUnit<'tcx> {
|
pub fn new(name: Symbol) -> CodegenUnit<'tcx> {
|
||||||
CodegenUnit { name, items: Default::default(), size_estimate: None }
|
CodegenUnit { name, items: Default::default(), size_estimate: None, primary: false }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn name(&self) -> Symbol {
|
pub fn name(&self) -> Symbol {
|
||||||
|
@ -269,6 +270,14 @@ impl<'tcx> CodegenUnit<'tcx> {
|
||||||
self.name = name;
|
self.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn is_primary(&self) -> bool {
|
||||||
|
self.primary
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn make_primary(&mut self) {
|
||||||
|
self.primary = true;
|
||||||
|
}
|
||||||
|
|
||||||
pub fn items(&self) -> &FxHashMap<MonoItem<'tcx>, (Linkage, Visibility)> {
|
pub fn items(&self) -> &FxHashMap<MonoItem<'tcx>, (Linkage, Visibility)> {
|
||||||
&self.items
|
&self.items
|
||||||
}
|
}
|
||||||
|
@ -378,6 +387,7 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for CodegenUnit<'tcx> {
|
||||||
name,
|
name,
|
||||||
// The size estimate is not relevant to the hash
|
// The size estimate is not relevant to the hash
|
||||||
size_estimate: _,
|
size_estimate: _,
|
||||||
|
primary: _,
|
||||||
} = *self;
|
} = *self;
|
||||||
|
|
||||||
name.hash_stable(hcx, hasher);
|
name.hash_stable(hcx, hasher);
|
||||||
|
|
|
@ -350,12 +350,14 @@ fn collect_and_partition_mono_items<'tcx>(
|
||||||
let (codegen_units, _) = tcx.sess.time("partition_and_assert_distinct_symbols", || {
|
let (codegen_units, _) = tcx.sess.time("partition_and_assert_distinct_symbols", || {
|
||||||
sync::join(
|
sync::join(
|
||||||
|| {
|
|| {
|
||||||
&*tcx.arena.alloc_from_iter(partition(
|
let mut codegen_units = partition(
|
||||||
tcx,
|
tcx,
|
||||||
&mut items.iter().cloned(),
|
&mut items.iter().cloned(),
|
||||||
tcx.sess.codegen_units(),
|
tcx.sess.codegen_units(),
|
||||||
&inlining_map,
|
&inlining_map,
|
||||||
))
|
);
|
||||||
|
codegen_units[0].make_primary();
|
||||||
|
&*tcx.arena.alloc_from_iter(codegen_units)
|
||||||
},
|
},
|
||||||
|| assert_symbols_are_distinct(tcx, items.iter()),
|
|| assert_symbols_are_distinct(tcx, items.iter()),
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
// build-fail
|
// run-pass
|
||||||
// aux-build:main_functions.rs
|
// aux-build:main_functions.rs
|
||||||
|
|
||||||
#![feature(imported_main)]
|
#![feature(imported_main)]
|
||||||
|
|
||||||
extern crate main_functions;
|
extern crate main_functions;
|
||||||
pub use main_functions::boilerplate as main; //~ ERROR entry symbol `main` from foreign crate
|
pub use main_functions::boilerplate as main;
|
||||||
|
|
||||||
// FIXME: Should be run-pass
|
|
||||||
|
|
|
@ -1,10 +0,0 @@
|
||||||
error: entry symbol `main` from foreign crate is not yet supported.
|
|
||||||
--> $DIR/imported_main_from_extern_crate.rs:7:9
|
|
||||||
|
|
|
||||||
LL | pub use main_functions::boilerplate as main;
|
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
||||||
|
|
|
||||||
= note: see issue #28937 <https://github.com/rust-lang/rust/issues/28937> for more information
|
|
||||||
|
|
||||||
error: aborting due to previous error
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue