mirror of
https://github.com/allankoechke/rust.git
synced 2026-11-30 11:05:36 +00:00
Rollup merge of #162097 - mejrs:instrumentfnattr, r=JonathanBrouwer
Deduplicate `InstrumentFnAttr` cc @pmur Instead of having a `Default` variant (which can't be specified in the attribute, it only does on/off), use an Option to model "no attribute used".
This commit is contained in:
@@ -3799,6 +3799,7 @@ dependencies = [
|
||||
"rustc-demangle",
|
||||
"rustc_abi",
|
||||
"rustc_ast",
|
||||
"rustc_attr_ir",
|
||||
"rustc_codegen_ssa",
|
||||
"rustc_crate_store",
|
||||
"rustc_data_structures",
|
||||
@@ -3838,6 +3839,7 @@ dependencies = [
|
||||
"rustc_abi",
|
||||
"rustc_arena",
|
||||
"rustc_ast",
|
||||
"rustc_attr_ir",
|
||||
"rustc_attr_parsing",
|
||||
"rustc_crate_store",
|
||||
"rustc_data_structures",
|
||||
|
||||
@@ -12,7 +12,9 @@ use rustc_ast::token::DocFragmentKind;
|
||||
use rustc_ast::{AttrStyle, Path, ast};
|
||||
use rustc_data_structures::fx::FxIndexMap;
|
||||
use rustc_error_messages::{DiagArgValue, IntoDiagArg};
|
||||
use rustc_macros::{Decodable, Encodable, PrintAttribute, StableHash};
|
||||
use rustc_macros::{
|
||||
Decodable, Decodable_NoContext, Encodable, Encodable_NoContext, PrintAttribute, StableHash,
|
||||
};
|
||||
use rustc_span::def_id::DefId;
|
||||
use rustc_span::hygiene::Transparency;
|
||||
use rustc_span::{ErrorGuaranteed, Ident, Span, Symbol};
|
||||
@@ -108,7 +110,8 @@ pub enum InstructionSetAttr {
|
||||
ArmT32,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Encodable, Decodable, Debug, Eq, StableHash, PrintAttribute)]
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
#[derive(Encodable_NoContext, Decodable_NoContext, StableHash, PrintAttribute)]
|
||||
pub enum InstrumentFnAttr {
|
||||
/// `#[instrument_fn = "on"]`
|
||||
On,
|
||||
|
||||
@@ -20,6 +20,7 @@ object = { version = "0.39.1", default-features = false, features = ["std", "rea
|
||||
rustc-demangle = "0.1.28"
|
||||
rustc_abi = { path = "../rustc_abi" }
|
||||
rustc_ast = { path = "../rustc_ast" }
|
||||
rustc_attr_ir = { path = "../rustc_attr_ir" }
|
||||
rustc_codegen_ssa = { path = "../rustc_codegen_ssa" }
|
||||
rustc_crate_store = { path = "../rustc_crate_store" }
|
||||
rustc_data_structures = { path = "../rustc_data_structures" }
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
//! Set and unset common attributes on LLVM values.
|
||||
use rustc_hir::attrs::{InlineAttr, InstructionSetAttr, OptimizeAttr, RtsanSetting};
|
||||
use rustc_attr_ir::{
|
||||
InlineAttr, InstructionSetAttr, InstrumentFnAttr, OptimizeAttr, RtsanSetting, find_attr,
|
||||
};
|
||||
use rustc_hir::def_id::DefId;
|
||||
use rustc_hir::find_attr;
|
||||
use rustc_middle::middle::codegen_fn_attrs::{
|
||||
CodegenFnAttrFlags, CodegenFnAttrs, InstrumentFnAttr, PatchableFunctionEntry, SanitizerFnAttrs,
|
||||
TargetFeature,
|
||||
CodegenFnAttrFlags, CodegenFnAttrs, PatchableFunctionEntry, SanitizerFnAttrs, TargetFeature,
|
||||
};
|
||||
use rustc_middle::ty::{self, Instance, TyCtxt};
|
||||
use rustc_session::config::{
|
||||
@@ -236,7 +236,7 @@ fn function_return_attr<'ll>(cx: &SimpleCx<'ll>, sess: &Session) -> Option<&'ll
|
||||
fn instrument_function_attr<'ll>(
|
||||
cx: &SimpleCx<'ll>,
|
||||
sess: &Session,
|
||||
instrument_fn: InstrumentFnAttr,
|
||||
instrument_fn: Option<InstrumentFnAttr>,
|
||||
) -> SmallVec<[&'ll Attribute; 4]> {
|
||||
let mut attrs = SmallVec::new();
|
||||
if sess.opts.unstable_opts.instrument_mcount != InstrumentMcount::Disabled {
|
||||
@@ -244,8 +244,8 @@ fn instrument_function_attr<'ll>(
|
||||
// `post-inline-ee-instrument` LLVM pass.
|
||||
|
||||
let instrument_entry = match instrument_fn {
|
||||
InstrumentFnAttr::Default | InstrumentFnAttr::On => true,
|
||||
InstrumentFnAttr::Off => false,
|
||||
Some(InstrumentFnAttr::On) | None => true,
|
||||
Some(InstrumentFnAttr::Off) => false,
|
||||
};
|
||||
|
||||
if instrument_entry {
|
||||
@@ -290,13 +290,13 @@ fn instrument_function_attr<'ll>(
|
||||
|
||||
// always and never may be overridden by the #[instrument_fn = ...] attribute.
|
||||
match instrument_fn {
|
||||
InstrumentFnAttr::Default => {}
|
||||
InstrumentFnAttr::On => {
|
||||
Some(InstrumentFnAttr::On) => {
|
||||
always = true;
|
||||
}
|
||||
InstrumentFnAttr::Off => {
|
||||
Some(InstrumentFnAttr::Off) => {
|
||||
never = true;
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
|
||||
if never {
|
||||
|
||||
@@ -15,6 +15,7 @@ regex = "1.4"
|
||||
rustc_abi = { path = "../rustc_abi" }
|
||||
rustc_arena = { path = "../rustc_arena" }
|
||||
rustc_ast = { path = "../rustc_ast" }
|
||||
rustc_attr_ir = { path = "../rustc_attr_ir" }
|
||||
rustc_attr_parsing = { path = "../rustc_attr_parsing" }
|
||||
rustc_crate_store = { path = "../rustc_crate_store" }
|
||||
rustc_data_structures = { path = "../rustc_data_structures" }
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
use rustc_abi::{Align, ExternAbi};
|
||||
use rustc_hir::attrs::{
|
||||
AttributeKind, EiiImplResolution, InlineAttr, InstrumentFnAttr as HirInstrumentFnAttr, Linkage,
|
||||
OptimizeAttr, RtsanSetting, UsedBy,
|
||||
use rustc_attr_ir::{
|
||||
Attribute, AttributeKind, EiiImplResolution, InlineAttr, Linkage, OptimizeAttr, RtsanSetting,
|
||||
UsedBy, find_attr,
|
||||
};
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def::DefKind;
|
||||
use rustc_hir::def_id::{DefId, LOCAL_CRATE, LocalDefId};
|
||||
use rustc_hir::{self as hir, Attribute, find_attr};
|
||||
use rustc_lint_defs::builtin::{INLINE_NO_SANITIZE, RTSAN_NONBLOCKING_ASYNC};
|
||||
use rustc_macros::Diagnostic;
|
||||
use rustc_middle::bug;
|
||||
use rustc_middle::middle::codegen_fn_attrs::{
|
||||
CodegenFnAttrFlags, CodegenFnAttrs, InstrumentFnAttr, PatchableFunctionEntry, SanitizerFnAttrs,
|
||||
CodegenFnAttrFlags, CodegenFnAttrs, PatchableFunctionEntry, SanitizerFnAttrs,
|
||||
};
|
||||
use rustc_middle::mono::Visibility;
|
||||
use rustc_middle::query::Providers;
|
||||
@@ -292,10 +292,7 @@ fn process_builtin_attrs(
|
||||
));
|
||||
}
|
||||
AttributeKind::InstrumentFn(instrument_fn) => {
|
||||
codegen_fn_attrs.instrument_fn = match instrument_fn {
|
||||
HirInstrumentFnAttr::On => InstrumentFnAttr::On,
|
||||
HirInstrumentFnAttr::Off => InstrumentFnAttr::Off,
|
||||
};
|
||||
codegen_fn_attrs.instrument_fn = Some(*instrument_fn);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
use std::borrow::Cow;
|
||||
|
||||
use rustc_abi::Align;
|
||||
use rustc_hir::attrs::{InlineAttr, InstructionSetAttr, Linkage, OptimizeAttr, RtsanSetting};
|
||||
use rustc_attr_ir::{
|
||||
InlineAttr, InstructionSetAttr, InstrumentFnAttr, Linkage, OptimizeAttr, RtsanSetting,
|
||||
};
|
||||
use rustc_hir::def_id::DefId;
|
||||
use rustc_macros::{StableHash, TyDecodable, TyEncodable};
|
||||
use rustc_span::Symbol;
|
||||
@@ -121,23 +123,7 @@ pub struct CodegenFnAttrs {
|
||||
/// The `#[rustc_objc_selector = "..."]` attribute.
|
||||
pub objc_selector: Option<Symbol>,
|
||||
/// The `#[instrument_fn]` attribute.
|
||||
pub instrument_fn: InstrumentFnAttr,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, TyEncodable, TyDecodable, StableHash, Debug)]
|
||||
pub enum InstrumentFnAttr {
|
||||
/// Always instrument function
|
||||
On,
|
||||
/// Never instrument function
|
||||
Off,
|
||||
/// Instrument based on command line options, if any.
|
||||
Default,
|
||||
}
|
||||
|
||||
const impl Default for InstrumentFnAttr {
|
||||
fn default() -> Self {
|
||||
InstrumentFnAttr::Default
|
||||
}
|
||||
pub instrument_fn: Option<InstrumentFnAttr>,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, TyEncodable, TyDecodable, StableHash, PartialEq, Eq)]
|
||||
@@ -274,7 +260,7 @@ impl CodegenFnAttrs {
|
||||
patchable_function_entry: None,
|
||||
objc_class: None,
|
||||
objc_selector: None,
|
||||
instrument_fn: InstrumentFnAttr::default(),
|
||||
instrument_fn: None,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user