Skip to content

Commit 37fa495

Browse files
committed
Auto merge of #155207 - quiode:writable, r=<try>
add llvm writable attribute conditionally
2 parents 12f35ad + 0c53594 commit 37fa495

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
@@ -527,6 +527,21 @@ impl<S: Stage> NoArgsAttributeParser<S> for RustcNoMirInlineParser {
527527
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcNoMirInline;
528528
}
529529

530+
pub(crate) struct RustcNoWritableParser;
531+
532+
impl<S: Stage> NoArgsAttributeParser<S> for RustcNoWritableParser {
533+
const PATH: &[Symbol] = &[sym::rustc_no_writable];
534+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Warn;
535+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
536+
Allow(Target::Fn),
537+
Allow(Target::Closure),
538+
Allow(Target::Method(MethodKind::Inherent)),
539+
Allow(Target::Method(MethodKind::TraitImpl)),
540+
Allow(Target::Method(MethodKind::Trait { body: true })),
541+
]);
542+
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcNoWritable;
543+
}
544+
530545
pub(crate) struct RustcLintQueryInstabilityParser;
531546

532547
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
@@ -315,6 +315,7 @@ attribute_parsers!(
315315
Single<WithoutArgs<RustcNoImplicitAutorefsParser>>,
316316
Single<WithoutArgs<RustcNoImplicitBoundsParser>>,
317317
Single<WithoutArgs<RustcNoMirInlineParser>>,
318+
Single<WithoutArgs<RustcNoWritableParser>>,
318319
Single<WithoutArgs<RustcNonConstTraitMethodParser>>,
319320
Single<WithoutArgs<RustcNonnullOptimizationGuaranteedParser>>,
320321
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
@@ -955,6 +955,9 @@ pub static BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
955955
rustc_must_match_exhaustively,
956956
"enums with `#[rustc_must_match_exhaustively]` must be matched on with a match block that mentions all variants explicitly"
957957
),
958+
rustc_attr!(
959+
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"
960+
),
958961

959962
// ==========================================================================
960963
// 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
@@ -1511,6 +1511,9 @@ pub enum AttributeKind {
15111511
/// Represents `#[rustc_no_mir_inline]`
15121512
RustcNoMirInline,
15131513

1514+
/// Represents `#[rustc_no_writable]`
1515+
RustcNoWritable,
1516+
15141517
/// Represents `#[rustc_non_const_trait_method]`.
15151518
RustcNonConstTraitMethod,
15161519

compiler/rustc_hir/src/attrs/encode_cross_crate.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ impl AttributeKind {
164164
RustcNoImplicitAutorefs => Yes,
165165
RustcNoImplicitBounds => No,
166166
RustcNoMirInline => Yes,
167+
RustcNoWritable => Yes,
167168
RustcNonConstTraitMethod => No, // should be reported via other queries like `constness`
168169
RustcNonnullOptimizationGuaranteed => Yes,
169170
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
@@ -351,6 +351,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
351351
| AttributeKind::RustcNoImplicitAutorefs
352352
| AttributeKind::RustcNoImplicitBounds
353353
| AttributeKind::RustcNoMirInline
354+
| AttributeKind::RustcNoWritable
354355
| AttributeKind::RustcNonConstTraitMethod
355356
| AttributeKind::RustcNonnullOptimizationGuaranteed
356357
| AttributeKind::RustcNounwind

compiler/rustc_session/src/options.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2530,6 +2530,8 @@ options! {
25302530
"a list LLVM plugins to enable (space separated)"),
25312531
llvm_time_trace: bool = (false, parse_bool, [UNTRACKED],
25322532
"generate JSON tracing data file from LLVM data (default: no)"),
2533+
llvm_writable: bool = (false, parse_bool, [TRACKED],
2534+
"enable insertion of the LLVM writable attribute; mutable retags count as writes under Tree Borrows"),
25332535
location_detail: LocationDetail = (LocationDetail::all(), parse_location_detail, [TRACKED],
25342536
"what location details should be tracked when using caller_location, either \
25352537
`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
@@ -1768,6 +1768,7 @@ symbols! {
17681768
rustc_no_implicit_autorefs,
17691769
rustc_no_implicit_bounds,
17701770
rustc_no_mir_inline,
1771+
rustc_no_writable,
17711772
rustc_non_const_trait_method,
17721773
rustc_nonnull_optimization_guaranteed,
17731774
rustc_nounwind,

0 commit comments

Comments
 (0)