]> git.lizzy.rs Git - rust.git/commitdiff
Add -Z maximal-hir-to-mir-coverage flag
authorWill Crichton <wcrichto@cs.stanford.edu>
Mon, 5 Dec 2022 05:07:55 +0000 (21:07 -0800)
committerWill Crichton <wcrichto@cs.stanford.edu>
Mon, 5 Dec 2022 07:58:20 +0000 (23:58 -0800)
compiler/rustc_interface/src/tests.rs
compiler/rustc_middle/src/lint.rs
compiler/rustc_session/src/options.rs
src/test/rustdoc-ui/z-help.stdout
src/test/ui/maximal_mir_to_hir_coverage.rs [new file with mode: 0644]

index a6205f4d3a531dd1a519d62ea281fb2ea9876495..2b8f6557c829b32042879be2c525ed09e4fbef8f 100644 (file)
@@ -747,6 +747,7 @@ macro_rules! tracked {
     tracked!(link_only, true);
     tracked!(llvm_plugins, vec![String::from("plugin_name")]);
     tracked!(location_detail, LocationDetail { file: true, line: false, column: false });
+    tracked!(maximal_hir_to_mir_coverage, true);
     tracked!(merge_functions, Some(MergeFunctions::Disabled));
     tracked!(mir_emit_retag, true);
     tracked!(mir_enable_passes, vec![("DestProp".to_string(), false)]);
index 51df42f6d14e06a3ddfff7346d82fa3f14a85e06..bde3e28c1345d0c29003e918aabc9d59f37b9ddf 100644 (file)
@@ -173,6 +173,16 @@ pub fn lint_level_at_node(self, lint: &'static Lint, id: HirId) -> (Level, LintL
     /// Walks upwards from `id` to find a node which might change lint levels with attributes.
     /// It stops at `bound` and just returns it if reached.
     pub fn maybe_lint_level_root_bounded(self, mut id: HirId, bound: HirId) -> HirId {
+        // Some consumers of rustc need to map MIR locations back to HIR nodes. Currently the
+        // the only part of rustc that tracks MIR -> HIR is the `SourceScopeLocalData::lint_root`
+        // field that tracks lint levels for MIR locations.  Normally the number of source scopes
+        // is limited to the set of nodes with lint  annotations. The -Zmaximal-hir-to-mir-coverage
+        // flag changes this behavior to maximize the number of source scopes, increasing the
+        // granularity of the MIR->HIR mapping.
+        if self.sess.opts.unstable_opts.maximal_hir_to_mir_coverage {
+            return id;
+        }
+
         let hir = self.hir();
         loop {
             if id == bound {
index 01a9361e7867663f200ec7938cccc2da6352a5fa..8e9198b79dff7cb39284333ad0f1fe6f53e27d78 100644 (file)
@@ -1382,6 +1382,9 @@ pub(crate) fn parse_proc_macro_execution_strategy(
         "list the symbols defined by a library crate (default: no)"),
     macro_backtrace: bool = (false, parse_bool, [UNTRACKED],
         "show macro backtraces (default: no)"),
+    maximal_hir_to_mir_coverage: bool = (false, parse_bool, [TRACKED],
+        "save as much information as possible about the correspondence between MIR and HIR \
+        as source scopes (default: no)"),
     merge_functions: Option<MergeFunctions> = (None, parse_merge_functions, [TRACKED],
         "control the operation of the MergeFunctions LLVM pass, taking \
         the same values as the target option of the same name"),
index 55154803098675fdacff687709d0b8ab9c475cec..94cf7b94241df8d79144969b852f538de8ccfa88 100644 (file)
@@ -77,6 +77,7 @@
     -Z                         location-detail=val -- what location details should be tracked when using caller_location, either `none`, or a comma separated list of location details, for which valid options are `file`, `line`, and `column` (default: `file,line,column`)
     -Z                                      ls=val -- list the symbols defined by a library crate (default: no)
     -Z                         macro-backtrace=val -- show macro backtraces (default: no)
+    -Z             maximal-hir-to-mir-coverage=val -- save as much information as possible about the correspondence between MIR and HIR as source scopes (default: no)
     -Z                         merge-functions=val -- control the operation of the MergeFunctions LLVM pass, taking the same values as the target option of the same name
     -Z                              meta-stats=val -- gather metadata statistics (default: no)
     -Z                          mir-emit-retag=val -- emit Retagging MIR statements, interpreted e.g., by miri; implies -Zmir-opt-level=0 (default: no)
diff --git a/src/test/ui/maximal_mir_to_hir_coverage.rs b/src/test/ui/maximal_mir_to_hir_coverage.rs
new file mode 100644 (file)
index 0000000..5ca5463
--- /dev/null
@@ -0,0 +1,10 @@
+// compile-flags: -Zmaximal-hir-to-mir-coverage
+// run-pass
+
+// Just making sure this flag is accepted and doesn't crash the compiler
+
+fn main() {
+  let x = 1;
+  let y = x + 1;
+  println!("{y}");
+}