From a9093a4dd80e617d50b26647ec2adcb727d2dd29 Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Thu, 26 Jul 2018 13:20:47 -0600 Subject: [PATCH] Move share_generics getter onto options directly --- src/librustc/session/config.rs | 18 +++++++++++++++ src/librustc/ty/context.rs | 22 ++----------------- .../back/symbol_export.rs | 2 +- src/librustc_codegen_llvm/callee.rs | 2 +- src/librustc_codegen_utils/symbol_names.rs | 2 +- src/librustc_mir/monomorphize/collector.rs | 2 +- src/librustc_mir/monomorphize/partitioning.rs | 2 +- 7 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs index f5a2b3730d5..3111777f4ad 100644 --- a/src/librustc/session/config.rs +++ b/src/librustc/session/config.rs @@ -653,6 +653,24 @@ pub fn will_create_output_file(&self) -> bool { !self.debugging_opts.parse_only && // The file is just being parsed !self.debugging_opts.ls // The file is just being queried } + + #[inline] + pub fn share_generics(&self) -> bool { + match self.debugging_opts.share_generics { + Some(setting) => setting, + None => { + self.incremental.is_some() || + match self.optimize { + OptLevel::No | + OptLevel::Less | + OptLevel::Size | + OptLevel::SizeMin => true, + OptLevel::Default | + OptLevel::Aggressive => false, + } + } + } + } } // The type of entry function, so diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs index 03a84021a0d..0cfdea68e88 100644 --- a/src/librustc/ty/context.rs +++ b/src/librustc/ty/context.rs @@ -14,7 +14,7 @@ use dep_graph::{DepNode, DepConstructor}; use errors::DiagnosticBuilder; use session::Session; -use session::config::{BorrowckMode, OutputFilenames, OptLevel}; +use session::config::{BorrowckMode, OutputFilenames}; use session::config::CrateType; use middle; use hir::{TraitCandidate, HirId, ItemLocalId}; @@ -1469,27 +1469,9 @@ pub fn emit_end_regions(self) -> bool { self.use_mir_borrowck() } - #[inline] - pub fn share_generics(self) -> bool { - match self.sess.opts.debugging_opts.share_generics { - Some(setting) => setting, - None => { - self.sess.opts.incremental.is_some() || - match self.sess.opts.optimize { - OptLevel::No | - OptLevel::Less | - OptLevel::Size | - OptLevel::SizeMin => true, - OptLevel::Default | - OptLevel::Aggressive => false, - } - } - } - } - #[inline] pub fn local_crate_exports_generics(self) -> bool { - debug_assert!(self.share_generics()); + debug_assert!(self.sess.opts.share_generics()); self.sess.crate_types.borrow().iter().any(|crate_type| { match crate_type { diff --git a/src/librustc_codegen_llvm/back/symbol_export.rs b/src/librustc_codegen_llvm/back/symbol_export.rs index 5ce0d45a9bc..02434b7be0b 100644 --- a/src/librustc_codegen_llvm/back/symbol_export.rs +++ b/src/librustc_codegen_llvm/back/symbol_export.rs @@ -242,7 +242,7 @@ fn exported_symbols_provider_local<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, symbols.push((exported_symbol, SymbolExportLevel::Rust)); } - if tcx.share_generics() && tcx.local_crate_exports_generics() { + if tcx.sess.opts.share_generics() && tcx.local_crate_exports_generics() { use rustc::mir::mono::{Linkage, Visibility, MonoItem}; use rustc::ty::InstanceDef; diff --git a/src/librustc_codegen_llvm/callee.rs b/src/librustc_codegen_llvm/callee.rs index e64dedac55a..3594351802f 100644 --- a/src/librustc_codegen_llvm/callee.rs +++ b/src/librustc_codegen_llvm/callee.rs @@ -133,7 +133,7 @@ pub fn get_fn( // This is a monomorphization. Its expected visibility depends // on whether we are in share-generics mode. - if cx.tcx.share_generics() { + if cx.tcx.sess.opts.share_generics() { // We are in share_generics mode. if instance_def_id.is_local() { diff --git a/src/librustc_codegen_utils/symbol_names.rs b/src/librustc_codegen_utils/symbol_names.rs index ac71ecff964..d834a6502b2 100644 --- a/src/librustc_codegen_utils/symbol_names.rs +++ b/src/librustc_codegen_utils/symbol_names.rs @@ -201,7 +201,7 @@ fn get_symbol_hash<'a, 'tcx>( if avoid_cross_crate_conflicts { let instantiating_crate = if is_generic { - if !def_id.is_local() && tcx.share_generics() { + if !def_id.is_local() && tcx.sess.opts.share_generics() { // If we are re-using a monomorphization from another crate, // we have to compute the symbol hash accordingly. let upstream_monomorphizations = tcx.upstream_monomorphizations_for(def_id); diff --git a/src/librustc_mir/monomorphize/collector.rs b/src/librustc_mir/monomorphize/collector.rs index 7f5851734fe..230d6f0472e 100644 --- a/src/librustc_mir/monomorphize/collector.rs +++ b/src/librustc_mir/monomorphize/collector.rs @@ -770,7 +770,7 @@ fn is_available_upstream_generic<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, // If we are not in share generics mode, we don't link to upstream // monomorphizations but always instantiate our own internal versions // instead. - if !tcx.share_generics() { + if !tcx.sess.opts.share_generics() { return false } diff --git a/src/librustc_mir/monomorphize/partitioning.rs b/src/librustc_mir/monomorphize/partitioning.rs index bd0b2c6c278..8d6d01633a1 100644 --- a/src/librustc_mir/monomorphize/partitioning.rs +++ b/src/librustc_mir/monomorphize/partitioning.rs @@ -304,7 +304,7 @@ fn place_root_mono_items<'a, 'tcx, I>(tcx: TyCtxt<'a, 'tcx, 'tcx>, // available to downstream crates. This depends on whether we are in // share-generics mode and whether the current crate can even have // downstream crates. - let export_generics = tcx.share_generics() && + let export_generics = tcx.sess.opts.share_generics() && tcx.local_crate_exports_generics(); for mono_item in mono_items { -- 2.44.0