about summary refs log tree commit diff
path: root/compiler
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2022-04-26 22:35:40 +0000
committerbors <bors@rust-lang.org>2022-04-26 22:35:40 +0000
commita7197189cd0e3a86d1b661d1dceb8bdff021d0b8 (patch)
treeae44942c8c11f105428b13946bf9607679fa8fab /compiler
parent082e4ca49770ebc9cb0ee616f3726a67471be8cb (diff)
parent3568bdc6cdf04da3bf8f1be02741ea731265a3da (diff)
downloadrust-a7197189cd0e3a86d1b661d1dceb8bdff021d0b8.tar.gz
rust-a7197189cd0e3a86d1b661d1dceb8bdff021d0b8.zip
Auto merge of #96425 - oli-obk:fix_incremental_regression_unsafety_checking, r=compiler-errors
Fix incremental perf regression unsafety checking

Perf regression introduced in #96294

We will simply avoid emitting the name of the unsafe function in MIR unsafeck, since we're moving to THIR unsafeck anyway.
Diffstat (limited to 'compiler')
-rw-r--r--compiler/rustc_middle/src/mir/query.rs68
-rw-r--r--compiler/rustc_mir_transform/src/check_unsafety.rs9
2 files changed, 23 insertions, 54 deletions
diff --git a/compiler/rustc_middle/src/mir/query.rs b/compiler/rustc_middle/src/mir/query.rs
index e1e63dd48ba..4d4eed179ca 100644
--- a/compiler/rustc_middle/src/mir/query.rs
+++ b/compiler/rustc_middle/src/mir/query.rs
@@ -12,7 +12,6 @@ use rustc_index::vec::IndexVec;
 use rustc_span::Span;
 use rustc_target::abi::VariantIdx;
 use smallvec::SmallVec;
-use std::borrow::Cow;
 use std::cell::Cell;
 use std::fmt::{self, Debug};
 
@@ -29,7 +28,7 @@ pub enum UnsafetyViolationKind {
 
 #[derive(Copy, Clone, PartialEq, TyEncodable, TyDecodable, HashStable, Debug)]
 pub enum UnsafetyViolationDetails {
-    CallToUnsafeFunction(Option<DefId>),
+    CallToUnsafeFunction,
     UseOfInlineAssembly,
     InitializingTypeWith,
     CastOfPointerToInt,
@@ -40,95 +39,66 @@ pub enum UnsafetyViolationDetails {
     AccessToUnionField,
     MutationOfLayoutConstrainedField,
     BorrowOfLayoutConstrainedField,
-    CallToFunctionWith(DefId),
+    CallToFunctionWith,
 }
 
 impl UnsafetyViolationDetails {
-    pub fn simple_description(&self) -> &'static str {
-        use UnsafetyViolationDetails::*;
-
-        match self {
-            CallToUnsafeFunction(..) => "call to unsafe function",
-            UseOfInlineAssembly => "use of inline assembly",
-            InitializingTypeWith => "initializing type with `rustc_layout_scalar_valid_range` attr",
-            CastOfPointerToInt => "cast of pointer to int",
-            UseOfMutableStatic => "use of mutable static",
-            UseOfExternStatic => "use of extern static",
-            DerefOfRawPointer => "dereference of raw pointer",
-            AssignToDroppingUnionField => "assignment to union field that might need dropping",
-            AccessToUnionField => "access to union field",
-            MutationOfLayoutConstrainedField => "mutation of layout constrained field",
-            BorrowOfLayoutConstrainedField => {
-                "borrow of layout constrained field with interior mutability"
-            }
-            CallToFunctionWith(..) => "call to function with `#[target_feature]`",
-        }
-    }
-
-    pub fn description_and_note(&self, tcx: TyCtxt<'_>) -> (Cow<'static, str>, &'static str) {
+    pub fn description_and_note(&self) -> (&'static str, &'static str) {
         use UnsafetyViolationDetails::*;
         match self {
-            CallToUnsafeFunction(did) => (
-                if let Some(did) = did {
-                    Cow::from(format!("call to unsafe function `{}`", tcx.def_path_str(*did)))
-                } else {
-                    Cow::Borrowed(self.simple_description())
-                },
+            CallToUnsafeFunction => (
+                "call to unsafe function",
                 "consult the function's documentation for information on how to avoid undefined \
                  behavior",
             ),
             UseOfInlineAssembly => (
-                Cow::Borrowed(self.simple_description()),
+                "use of inline assembly",
                 "inline assembly is entirely unchecked and can cause undefined behavior",
             ),
             InitializingTypeWith => (
-                Cow::Borrowed(self.simple_description()),
+                "initializing type with `rustc_layout_scalar_valid_range` attr",
                 "initializing a layout restricted type's field with a value outside the valid \
                  range is undefined behavior",
             ),
-            CastOfPointerToInt => (
-                Cow::Borrowed(self.simple_description()),
-                "casting pointers to integers in constants",
-            ),
+            CastOfPointerToInt => {
+                ("cast of pointer to int", "casting pointers to integers in constants")
+            }
             UseOfMutableStatic => (
-                Cow::Borrowed(self.simple_description()),
+                "use of mutable static",
                 "mutable statics can be mutated by multiple threads: aliasing violations or data \
                  races will cause undefined behavior",
             ),
             UseOfExternStatic => (
-                Cow::Borrowed(self.simple_description()),
+                "use of extern static",
                 "extern statics are not controlled by the Rust type system: invalid data, \
                  aliasing violations or data races will cause undefined behavior",
             ),
             DerefOfRawPointer => (
-                Cow::Borrowed(self.simple_description()),
+                "dereference of raw pointer",
                 "raw pointers may be null, dangling or unaligned; they can violate aliasing rules \
                  and cause data races: all of these are undefined behavior",
             ),
             AssignToDroppingUnionField => (
-                Cow::Borrowed(self.simple_description()),
+                "assignment to union field that might need dropping",
                 "the previous content of the field will be dropped, which causes undefined \
                  behavior if the field was not properly initialized",
             ),
             AccessToUnionField => (
-                Cow::Borrowed(self.simple_description()),
+                "access to union field",
                 "the field may not be properly initialized: using uninitialized data will cause \
                  undefined behavior",
             ),
             MutationOfLayoutConstrainedField => (
-                Cow::Borrowed(self.simple_description()),
+                "mutation of layout constrained field",
                 "mutating layout constrained fields cannot statically be checked for valid values",
             ),
             BorrowOfLayoutConstrainedField => (
-                Cow::Borrowed(self.simple_description()),
+                "borrow of layout constrained field with interior mutability",
                 "references to fields of layout constrained fields lose the constraints. Coupled \
                  with interior mutability, the field can be changed to invalid values",
             ),
-            CallToFunctionWith(did) => (
-                Cow::from(format!(
-                    "call to function `{}` with `#[target_feature]`",
-                    tcx.def_path_str(*did)
-                )),
+            CallToFunctionWith => (
+                "call to function with `#[target_feature]`",
                 "can only be called if the required target features are available",
             ),
         }
diff --git a/compiler/rustc_mir_transform/src/check_unsafety.rs b/compiler/rustc_mir_transform/src/check_unsafety.rs
index 34093eb29eb..dde79214b16 100644
--- a/compiler/rustc_mir_transform/src/check_unsafety.rs
+++ b/compiler/rustc_mir_transform/src/check_unsafety.rs
@@ -76,7 +76,7 @@ impl<'tcx> Visitor<'tcx> for UnsafetyChecker<'_, 'tcx> {
                 if let hir::Unsafety::Unsafe = sig.unsafety() {
                     self.require_unsafe(
                         UnsafetyViolationKind::General,
-                        UnsafetyViolationDetails::CallToUnsafeFunction(func_id.copied()),
+                        UnsafetyViolationDetails::CallToUnsafeFunction,
                     )
                 }
 
@@ -381,7 +381,7 @@ impl<'tcx> UnsafetyChecker<'_, 'tcx> {
         if !callee_features.iter().all(|feature| self_features.contains(feature)) {
             self.require_unsafe(
                 UnsafetyViolationKind::General,
-                UnsafetyViolationDetails::CallToFunctionWith(func_did),
+                UnsafetyViolationDetails::CallToFunctionWith,
             )
         }
     }
@@ -580,8 +580,7 @@ pub fn check_unsafety(tcx: TyCtxt<'_>, def_id: LocalDefId) {
     let UnsafetyCheckResult { violations, unused_unsafes, .. } = tcx.unsafety_check_result(def_id);
 
     for &UnsafetyViolation { source_info, lint_root, kind, details } in violations.iter() {
-        let (description, note) =
-            ty::print::with_no_trimmed_paths!(details.description_and_note(tcx));
+        let (description, note) = details.description_and_note();
 
         // Report an error.
         let unsafe_fn_msg =
@@ -598,7 +597,7 @@ pub fn check_unsafety(tcx: TyCtxt<'_>, def_id: LocalDefId) {
                     description,
                     unsafe_fn_msg,
                 )
-                .span_label(source_info.span, details.simple_description())
+                .span_label(source_info.span, description)
                 .note(note)
                 .emit();
             }