From 98b943e7d821aff17fefbf1a094503f9ae172a4a Mon Sep 17 00:00:00 2001 From: Wesley Wiser Date: Sat, 11 Jul 2020 22:32:42 -0400 Subject: [PATCH] Add partitioning -Z option to control which partitioning scheme is used --- src/librustc_mir/monomorphize/partitioning/mod.rs | 14 +++++++++++--- src/librustc_session/options.rs | 2 ++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/librustc_mir/monomorphize/partitioning/mod.rs b/src/librustc_mir/monomorphize/partitioning/mod.rs index 5526382d3a9fe..9dfbd65e1b1a8 100644 --- a/src/librustc_mir/monomorphize/partitioning/mod.rs +++ b/src/librustc_mir/monomorphize/partitioning/mod.rs @@ -135,8 +135,16 @@ trait Partitioner<'tcx> { ); } -fn get_partitioner<'tcx>() -> Box> { - Box::new(default::DefaultPartitioning) +fn get_partitioner<'tcx>(tcx: TyCtxt<'tcx>) -> Box> { + let strategy = match &tcx.sess.opts.debugging_opts.cgu_partitioning_strategy { + None => "default", + Some(s) => &s[..], + }; + + match strategy { + "default" => Box::new(default::DefaultPartitioning), + _ => tcx.sess.fatal("unknown partitioning strategy"), + } } pub fn partition<'tcx>( @@ -147,7 +155,7 @@ pub fn partition<'tcx>( ) -> Vec> { let _prof_timer = tcx.prof.generic_activity("cgu_partitioning"); - let mut partitioner = get_partitioner(); + let mut partitioner = get_partitioner(tcx); // In the first step, we place all regular monomorphizations into their // respective 'home' codegen unit. Regular monomorphizations are all // functions and statics defined in the local crate. diff --git a/src/librustc_session/options.rs b/src/librustc_session/options.rs index 80164840334a2..d05f1a3f34b78 100644 --- a/src/librustc_session/options.rs +++ b/src/librustc_session/options.rs @@ -807,6 +807,8 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options, "select which borrowck is used (`mir` or `migrate`) (default: `migrate`)"), borrowck_stats: bool = (false, parse_bool, [UNTRACKED], "gather borrowck statistics (default: no)"), + cgu_partitioning_strategy: Option = (None, parse_opt_string, [TRACKED], + "the codegen unit partitioning strategy to use"), chalk: bool = (false, parse_bool, [TRACKED], "enable the experimental Chalk-based trait solving engine"), codegen_backend: Option = (None, parse_opt_string, [TRACKED],