Skip to content

Commit 245ff9c

Browse files
committed
add llvm writable attribute conditionally
1 parent bfc05d6 commit 245ff9c

16 files changed

Lines changed: 75 additions & 4 deletions

File tree

compiler/rustc_attr_parsing/src/attributes/rustc_internal.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,21 @@ impl<S: Stage> NoArgsAttributeParser<S> for RustcNoMirInlineParser {
541541
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcNoMirInline;
542542
}
543543

544+
pub(crate) struct RustcNoWritableParser;
545+
546+
impl<S: Stage> NoArgsAttributeParser<S> for RustcNoWritableParser {
547+
const PATH: &[Symbol] = &[sym::rustc_no_writable];
548+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Warn;
549+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
550+
Allow(Target::Fn),
551+
Allow(Target::Closure),
552+
Allow(Target::Method(MethodKind::Inherent)),
553+
Allow(Target::Method(MethodKind::TraitImpl)),
554+
Allow(Target::Method(MethodKind::Trait { body: true })),
555+
]);
556+
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcNoWritable;
557+
}
558+
544559
pub(crate) struct RustcLintQueryInstabilityParser;
545560

546561
impl<S: Stage> NoArgsAttributeParser<S> for RustcLintQueryInstabilityParser {

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ attribute_parsers!(
309309
Single<WithoutArgs<RustcNoImplicitAutorefsParser>>,
310310
Single<WithoutArgs<RustcNoImplicitBoundsParser>>,
311311
Single<WithoutArgs<RustcNoMirInlineParser>>,
312+
Single<WithoutArgs<RustcNoWritableParser>>,
312313
Single<WithoutArgs<RustcNonConstTraitMethodParser>>,
313314
Single<WithoutArgs<RustcNonnullOptimizationGuaranteedParser>>,
314315
Single<WithoutArgs<RustcNounwindParser>>,

compiler/rustc_codegen_llvm/src/abi.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,12 @@ trait ArgAttributesExt {
3838
const ABI_AFFECTING_ATTRIBUTES: [(ArgAttribute, llvm::AttributeKind); 1] =
3939
[(ArgAttribute::InReg, llvm::AttributeKind::InReg)];
4040

41-
const OPTIMIZATION_ATTRIBUTES: [(ArgAttribute, llvm::AttributeKind); 4] = [
41+
const OPTIMIZATION_ATTRIBUTES: [(ArgAttribute, llvm::AttributeKind); 5] = [
4242
(ArgAttribute::NoAlias, llvm::AttributeKind::NoAlias),
4343
(ArgAttribute::NonNull, llvm::AttributeKind::NonNull),
4444
(ArgAttribute::ReadOnly, llvm::AttributeKind::ReadOnly),
4545
(ArgAttribute::NoUndef, llvm::AttributeKind::NoUndef),
46+
(ArgAttribute::Writable, llvm::AttributeKind::Writable),
4647
];
4748

4849
const CAPTURES_ATTRIBUTES: [(ArgAttribute, llvm::AttributeKind); 3] = [

compiler/rustc_feature/src/builtin_attrs.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1414,6 +1414,9 @@ pub static BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
14141414
rustc_scalable_vector, Normal, template!(List: &["count"]), WarnFollowing, EncodeCrossCrate::Yes,
14151415
"`#[rustc_scalable_vector]` defines a scalable vector type"
14161416
),
1417+
rustc_attr!(
1418+
rustc_no_writable, Normal, template!(Word), WarnFollowing, EncodeCrossCrate::Yes, "`#[rustc_no_writable]` stops the compiler from adding the `writable` flag in LLVM, thus under Tree Borrows, mutable retags no longer count as writes"
1419+
),
14171420

14181421
// ==========================================================================
14191422
// Internal attributes, Testing:

compiler/rustc_hir/src/attrs/data_structures.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1489,6 +1489,9 @@ pub enum AttributeKind {
14891489
/// Represents `#[rustc_no_mir_inline]`
14901490
RustcNoMirInline,
14911491

1492+
/// Represents `#[rustc_no_writable]`
1493+
RustcNoWritable,
1494+
14921495
/// Represents `#[rustc_non_const_trait_method]`.
14931496
RustcNonConstTraitMethod,
14941497

compiler/rustc_hir/src/attrs/encode_cross_crate.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ impl AttributeKind {
161161
RustcNoImplicitAutorefs => Yes,
162162
RustcNoImplicitBounds => No,
163163
RustcNoMirInline => Yes,
164+
RustcNoWritable => Yes,
164165
RustcNonConstTraitMethod => No, // should be reported via other queries like `constness`
165166
RustcNonnullOptimizationGuaranteed => Yes,
166167
RustcNounwind => No,

compiler/rustc_interface/src/tests.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -817,6 +817,7 @@ fn test_unstable_options_tracking_hash() {
817817
tracked!(lint_llvm_ir, true);
818818
tracked!(llvm_module_flag, vec![("bar".to_string(), 123, "max".to_string())]);
819819
tracked!(llvm_plugins, vec![String::from("plugin_name")]);
820+
tracked!(llvm_writable, true);
820821
tracked!(location_detail, LocationDetail { file: true, line: false, column: false });
821822
tracked!(maximal_hir_to_mir_coverage, true);
822823
tracked!(merge_functions, Some(MergeFunctions::Disabled));

compiler/rustc_passes/src/check_attr.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
357357
| AttributeKind::RustcNoImplicitAutorefs
358358
| AttributeKind::RustcNoImplicitBounds
359359
| AttributeKind::RustcNoMirInline
360+
| AttributeKind::RustcNoWritable
360361
| AttributeKind::RustcNonConstTraitMethod
361362
| AttributeKind::RustcNonnullOptimizationGuaranteed
362363
| AttributeKind::RustcNounwind

compiler/rustc_session/src/options.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2449,6 +2449,8 @@ options! {
24492449
"a list LLVM plugins to enable (space separated)"),
24502450
llvm_time_trace: bool = (false, parse_bool, [UNTRACKED],
24512451
"generate JSON tracing data file from LLVM data (default: no)"),
2452+
llvm_writable: bool = (false, parse_bool, [TRACKED],
2453+
"enable insertion of the LLVM writable attribute; mutable retags count as writes under Tree Borrows"),
24522454
location_detail: LocationDetail = (LocationDetail::all(), parse_location_detail, [TRACKED],
24532455
"what location details should be tracked when using caller_location, either \
24542456
`none`, or a comma separated list of location details, for which \

compiler/rustc_span/src/symbol.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1751,6 +1751,7 @@ symbols! {
17511751
rustc_no_implicit_autorefs,
17521752
rustc_no_implicit_bounds,
17531753
rustc_no_mir_inline,
1754+
rustc_no_writable,
17541755
rustc_non_const_trait_method,
17551756
rustc_nonnull_optimization_guaranteed,
17561757
rustc_nounwind,

0 commit comments

Comments
 (0)