diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-11-06 03:28:08 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-11-06 03:28:08 +0100 |
| commit | 5c4a595ff09d08c46ee3b23d343da47b0d12243d (patch) | |
| tree | 653ec51e855d5ef2cdf31f41e041b785a0d9b701 | |
| parent | f746d99f683d1475e1150fc4fa5206fd4cfe7e66 (diff) | |
| parent | 692ae3d9fb55c1f19508e5b3c1aadfdd2cd27431 (diff) | |
| download | rust-5c4a595ff09d08c46ee3b23d343da47b0d12243d.tar.gz rust-5c4a595ff09d08c46ee3b23d343da47b0d12243d.zip | |
Rollup merge of #66027 - Mark-Simulacrum:panic-handler-query, r=alexcrichton
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.
| -rw-r--r-- | src/librustc/session/mod.rs | 4 | ||||
| -rw-r--r-- | src/librustc/ty/context.rs | 5 | ||||
| -rw-r--r-- | src/librustc_metadata/encoder.rs | 3 | ||||
| -rw-r--r-- | src/librustc_typeck/check/mod.rs | 5 |
4 files changed, 6 insertions, 11 deletions
diff --git a/src/librustc/session/mod.rs b/src/librustc/session/mod.rs index 13b76b79b3d..403b32df20e 100644 --- a/src/librustc/session/mod.rs +++ b/src/librustc/session/mod.rs @@ -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>, @@ -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()), diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs index 3d28beefb34..0906d9ebd8e 100644 --- a/src/librustc/ty/context.rs +++ b/src/librustc/ty/context.rs @@ -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()) + }; } diff --git a/src/librustc_metadata/encoder.rs b/src/librustc_metadata/encoder.rs index f2b0cfa5305..de00e9920e6 100644 --- a/src/librustc_metadata/encoder.rs +++ b/src/librustc_metadata/encoder.rs @@ -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), @@ -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 { diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index a2af29aef09..ee0fe48cc8b 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -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(), |
