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.
This commit is contained in:
commit
5c4a595ff0
4 changed files with 6 additions and 11 deletions
|
@ -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()),
|
||||
|
|
|
@ -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())
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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(),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue