Skip to content

Commit

Permalink
Rollup merge of #66027 - Mark-Simulacrum:panic-handler-query, r=alexc…
Browse files Browse the repository at this point in the history
…richton

Move has_panic_handler to query

Moves us off of a global Once instead re-querying the lang item each time. The conditions on when we set it to true change a little (previously we'd make sure a few more lang items were `Some`) but I think they in practice don't matter, we won't compile later on if we don't have them.
  • Loading branch information
Centril authored Nov 6, 2019
2 parents f746d99 + 692ae3d commit 5c4a595
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 11 deletions.
4 changes: 0 additions & 4 deletions src/librustc/session/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,6 @@ pub struct Session {
/// Metadata about the allocators for the current crate being compiled.
pub has_global_allocator: Once<bool>,

/// Metadata about the panic handlers for the current crate being compiled.
pub has_panic_handler: Once<bool>,

/// Cap lint level specified by a driver specifically.
pub driver_lint_caps: FxHashMap<lint::LintId, lint::Level>,

Expand Down Expand Up @@ -1211,7 +1208,6 @@ fn build_session_(
print_fuel,
jobserver: jobserver::client(),
has_global_allocator: Once::new(),
has_panic_handler: Once::new(),
driver_lint_caps,
trait_methods_not_found: Lock::new(Default::default()),
confused_type_with_std_module: Lock::new(Default::default()),
Expand Down
5 changes: 5 additions & 0 deletions src/librustc/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3045,4 +3045,9 @@ pub fn provide(providers: &mut ty::query::Providers<'_>) {
assert_eq!(cnum, LOCAL_CRATE);
attr::contains_name(tcx.hir().krate_attrs(), sym::compiler_builtins)
};
providers.has_panic_handler = |tcx, cnum| {
assert_eq!(cnum, LOCAL_CRATE);
// We want to check if the panic handler was defined in this crate
tcx.lang_items().panic_impl().map_or(false, |did| did.is_local())
};
}
3 changes: 1 addition & 2 deletions src/librustc_metadata/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,6 @@ impl<'tcx> EncodeContext<'tcx> {
let attrs = tcx.hir().krate_attrs();
let has_default_lib_allocator = attr::contains_name(&attrs, sym::default_lib_allocator);
let has_global_allocator = *tcx.sess.has_global_allocator.get();
let has_panic_handler = *tcx.sess.has_panic_handler.try_get().unwrap_or(&false);

let root = self.lazy(CrateRoot {
name: tcx.crate_name(LOCAL_CRATE),
Expand All @@ -553,7 +552,7 @@ impl<'tcx> EncodeContext<'tcx> {
panic_strategy: tcx.sess.panic_strategy(),
edition: tcx.sess.edition(),
has_global_allocator: has_global_allocator,
has_panic_handler: has_panic_handler,
has_panic_handler: tcx.has_panic_handler(LOCAL_CRATE),
has_default_lib_allocator: has_default_lib_allocator,
plugin_registrar_fn: tcx.plugin_registrar_fn(LOCAL_CRATE).map(|id| id.index),
proc_macro_decls_static: if is_proc_macro {
Expand Down
5 changes: 0 additions & 5 deletions src/librustc_typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1267,11 +1267,6 @@ fn check_fn<'a, 'tcx>(
if let Some(panic_impl_did) = fcx.tcx.lang_items().panic_impl() {
if panic_impl_did == fcx.tcx.hir().local_def_id(fn_id) {
if let Some(panic_info_did) = fcx.tcx.lang_items().panic_info() {
// at this point we don't care if there are duplicate handlers or if the handler has
// the wrong signature as this value we'll be used when writing metadata and that
// only happens if compilation succeeded
fcx.tcx.sess.has_panic_handler.try_set_same(true);

if declared_ret_ty.kind != ty::Never {
fcx.tcx.sess.span_err(
decl.output.span(),
Expand Down

0 comments on commit 5c4a595

Please sign in to comment.