Skip to content

Commit 0c4fa26

Browse files
committed
Auto merge of #143434 - matthiaskrgr:rollup-eyr4rcb, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - #140643 (Refactor StableMIR) - #143286 (Make -Ztrack-diagnostics emit like a note) - #143308 (Remove `PointerLike` trait) - #143387 (Make __rust_alloc_error_handler_should_panic a function) - #143400 (Port `#[rustc_pass_by_value]` to the new attribute system) - #143417 (bump termize dep) - #143420 (rustc-dev-guide subtree update) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 556d20a + 3a5da6c commit 0c4fa26

File tree

87 files changed

+3908
-2638
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+3908
-2638
lines changed

Cargo.lock

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ dependencies = [
581581
"serde_json",
582582
"syn 2.0.104",
583583
"tempfile",
584-
"termize",
584+
"termize 0.1.1",
585585
"tokio",
586586
"toml 0.7.8",
587587
"ui_test",
@@ -3761,7 +3761,7 @@ dependencies = [
37613761
"serde",
37623762
"serde_json",
37633763
"termcolor",
3764-
"termize",
3764+
"termize 0.2.0",
37653765
"tracing",
37663766
"windows 0.61.3",
37673767
]
@@ -4522,7 +4522,7 @@ dependencies = [
45224522
"rustc_serialize",
45234523
"rustc_span",
45244524
"rustc_target",
4525-
"termize",
4525+
"termize 0.2.0",
45264526
"tracing",
45274527
"windows 0.61.3",
45284528
]
@@ -5294,6 +5294,16 @@ dependencies = [
52945294
"winapi",
52955295
]
52965296

5297+
[[package]]
5298+
name = "termize"
5299+
version = "0.2.0"
5300+
source = "registry+https://github.com/rust-lang/crates.io-index"
5301+
checksum = "6a8da106d1a19c5b9c53c03311936568a0439926a7607815bd3461139cbab1cc"
5302+
dependencies = [
5303+
"libc",
5304+
"windows-sys 0.60.2",
5305+
]
5306+
52975307
[[package]]
52985308
name = "test-float-parse"
52995309
version = "0.1.0"

compiler/rustc_abi/src/layout/ty.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc_macros::HashStable_Generic;
66

77
use crate::{
88
AbiAlign, Align, BackendRepr, FieldsShape, Float, HasDataLayout, LayoutData, Niche,
9-
PointeeInfo, Primitive, Scalar, Size, TargetDataLayout, Variants,
9+
PointeeInfo, Primitive, Size, Variants,
1010
};
1111

1212
// Explicitly import `Float` to avoid ambiguity with `Primitive::Float`.
@@ -115,16 +115,6 @@ impl<'a> Layout<'a> {
115115
pub fn unadjusted_abi_align(self) -> Align {
116116
self.0.0.unadjusted_abi_align
117117
}
118-
119-
/// Whether the layout is from a type that implements [`std::marker::PointerLike`].
120-
///
121-
/// Currently, that means that the type is pointer-sized, pointer-aligned,
122-
/// and has a initialized (non-union), scalar ABI.
123-
pub fn is_pointer_like(self, data_layout: &TargetDataLayout) -> bool {
124-
self.size() == data_layout.pointer_size
125-
&& self.align().abi == data_layout.pointer_align.abi
126-
&& matches!(self.backend_repr(), BackendRepr::Scalar(Scalar::Initialized { .. }))
127-
}
128118
}
129119

130120
/// The layout of a type, alongside the type itself.

compiler/rustc_attr_data_structures/src/attributes.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,9 @@ pub enum AttributeKind {
287287
/// Represents `#[optimize(size|speed)]`
288288
Optimize(OptimizeAttr, Span),
289289

290+
/// Represents `#[rustc_pass_by_value]` (used by the `rustc_pass_by_value` lint).
291+
PassByValue(Span),
292+
290293
/// Represents `#[rustc_pub_transparent]` (used by the `repr_transparent_external_private_fields` lint).
291294
PubTransparent(Span),
292295

compiler/rustc_attr_data_structures/src/encode_cross_crate.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,40 +12,43 @@ impl AttributeKind {
1212
use EncodeCrossCrate::*;
1313

1414
match self {
15+
// tidy-alphabetical-start
1516
Align { .. } => No,
1617
AllowConstFnUnstable(..) => No,
1718
AllowInternalUnstable(..) => Yes,
1819
AsPtr(..) => Yes,
1920
BodyStability { .. } => No,
21+
Cold(..) => No,
2022
Confusables { .. } => Yes,
23+
ConstContinue(..) => No,
2124
ConstStability { .. } => Yes,
2225
ConstStabilityIndirect => No,
2326
Deprecation { .. } => Yes,
2427
DocComment { .. } => Yes,
2528
ExportName { .. } => Yes,
2629
Inline(..) => No,
27-
LinkSection { .. } => No,
28-
MacroTransparency(..) => Yes,
29-
Repr(..) => No,
30-
Stability { .. } => Yes,
31-
Cold(..) => No,
32-
ConstContinue(..) => No,
3330
LinkName { .. } => Yes,
31+
LinkSection { .. } => No,
3432
LoopMatch(..) => No,
33+
MacroTransparency(..) => Yes,
3534
MayDangle(..) => No,
3635
MustUse { .. } => Yes,
3736
Naked(..) => No,
3837
NoImplicitPrelude(..) => No,
3938
NoMangle(..) => No,
4039
Optimize(..) => No,
40+
PassByValue(..) => Yes,
4141
PubTransparent(..) => Yes,
42+
Repr(..) => No,
4243
RustcLayoutScalarValidRangeEnd(..) => Yes,
4344
RustcLayoutScalarValidRangeStart(..) => Yes,
4445
RustcObjectLifetimeDefault => No,
4546
SkipDuringMethodDispatch { .. } => No,
47+
Stability { .. } => Yes,
4648
TargetFeature(..) => No,
4749
TrackCaller(..) => Yes,
4850
Used { .. } => No,
51+
// tidy-alphabetical-end
4952
}
5053
}
5154
}

compiler/rustc_attr_parsing/src/attributes/lint_helpers.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,10 @@ impl<S: Stage> NoArgsAttributeParser<S> for PubTransparentParser {
1717
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
1818
const CREATE: fn(Span) -> AttributeKind = AttributeKind::PubTransparent;
1919
}
20+
21+
pub(crate) struct PassByValueParser;
22+
impl<S: Stage> NoArgsAttributeParser<S> for PassByValueParser {
23+
const PATH: &[Symbol] = &[sym::rustc_pass_by_value];
24+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
25+
const CREATE: fn(Span) -> AttributeKind = AttributeKind::PassByValue;
26+
}

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use crate::attributes::confusables::ConfusablesParser;
2323
use crate::attributes::deprecation::DeprecationParser;
2424
use crate::attributes::inline::{InlineParser, RustcForceInlineParser};
2525
use crate::attributes::link_attrs::{LinkNameParser, LinkSectionParser};
26-
use crate::attributes::lint_helpers::{AsPtrParser, PubTransparentParser};
26+
use crate::attributes::lint_helpers::{AsPtrParser, PassByValueParser, PubTransparentParser};
2727
use crate::attributes::loop_match::{ConstContinueParser, LoopMatchParser};
2828
use crate::attributes::must_use::MustUseParser;
2929
use crate::attributes::no_implicit_prelude::NoImplicitPreludeParser;
@@ -144,6 +144,7 @@ attribute_parsers!(
144144
Single<WithoutArgs<MayDangleParser>>,
145145
Single<WithoutArgs<NoImplicitPreludeParser>>,
146146
Single<WithoutArgs<NoMangleParser>>,
147+
Single<WithoutArgs<PassByValueParser>>,
147148
Single<WithoutArgs<PubTransparentParser>>,
148149
Single<WithoutArgs<TrackCallerParser>>,
149150
// tidy-alphabetical-end

compiler/rustc_codegen_cranelift/src/allocator.rs

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -84,19 +84,34 @@ fn codegen_inner(
8484
&mangle_internal_symbol(tcx, alloc_error_handler_name(alloc_error_handler_kind)),
8585
);
8686

87-
let data_id = module
88-
.declare_data(
89-
&mangle_internal_symbol(tcx, OomStrategy::SYMBOL),
90-
Linkage::Export,
91-
false,
92-
false,
93-
)
94-
.unwrap();
95-
let mut data = DataDescription::new();
96-
data.set_align(1);
97-
let val = oom_strategy.should_panic();
98-
data.define(Box::new([val]));
99-
module.define_data(data_id, &data).unwrap();
87+
{
88+
let sig = Signature {
89+
call_conv: module.target_config().default_call_conv,
90+
params: vec![],
91+
returns: vec![AbiParam::new(types::I8)],
92+
};
93+
let func_id = module
94+
.declare_function(
95+
&mangle_internal_symbol(tcx, OomStrategy::SYMBOL),
96+
Linkage::Export,
97+
&sig,
98+
)
99+
.unwrap();
100+
let mut ctx = Context::new();
101+
ctx.func.signature = sig;
102+
{
103+
let mut func_ctx = FunctionBuilderContext::new();
104+
let mut bcx = FunctionBuilder::new(&mut ctx.func, &mut func_ctx);
105+
106+
let block = bcx.create_block();
107+
bcx.switch_to_block(block);
108+
let value = bcx.ins().iconst(types::I8, oom_strategy.should_panic() as i64);
109+
bcx.ins().return_(&[value]);
110+
bcx.seal_all_blocks();
111+
bcx.finalize();
112+
}
113+
module.define_function(func_id, &mut ctx).unwrap();
114+
}
100115

101116
{
102117
let sig = Signature {

compiler/rustc_codegen_gcc/src/allocator.rs

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use gccjit::{Context, FunctionType, GlobalKind, ToRValue, Type};
21
#[cfg(feature = "master")]
3-
use gccjit::{FnAttribute, VarAttribute};
2+
use gccjit::FnAttribute;
3+
use gccjit::{Context, FunctionType, RValue, ToRValue, Type};
44
use rustc_ast::expand::allocator::{
55
ALLOCATOR_METHODS, AllocatorKind, AllocatorTy, NO_ALLOC_SHIM_IS_UNSTABLE,
66
alloc_error_handler_name, default_fn_name, global_fn_name,
@@ -71,15 +71,13 @@ pub(crate) unsafe fn codegen(
7171
None,
7272
);
7373

74-
let name = mangle_internal_symbol(tcx, OomStrategy::SYMBOL);
75-
let global = context.new_global(None, GlobalKind::Exported, i8, name);
76-
#[cfg(feature = "master")]
77-
global.add_attribute(VarAttribute::Visibility(symbol_visibility_to_gcc(
78-
tcx.sess.default_visibility(),
79-
)));
80-
let value = tcx.sess.opts.unstable_opts.oom.should_panic();
81-
let value = context.new_rvalue_from_int(i8, value as i32);
82-
global.global_set_initializer_rvalue(value);
74+
create_const_value_function(
75+
tcx,
76+
context,
77+
&mangle_internal_symbol(tcx, OomStrategy::SYMBOL),
78+
i8,
79+
context.new_rvalue_from_int(i8, tcx.sess.opts.unstable_opts.oom.should_panic() as i32),
80+
);
8381

8482
create_wrapper_function(
8583
tcx,
@@ -91,6 +89,30 @@ pub(crate) unsafe fn codegen(
9189
);
9290
}
9391

92+
fn create_const_value_function(
93+
tcx: TyCtxt<'_>,
94+
context: &Context<'_>,
95+
name: &str,
96+
output: Type<'_>,
97+
value: RValue<'_>,
98+
) {
99+
let func = context.new_function(None, FunctionType::Exported, output, &[], name, false);
100+
101+
#[cfg(feature = "master")]
102+
func.add_attribute(FnAttribute::Visibility(symbol_visibility_to_gcc(
103+
tcx.sess.default_visibility(),
104+
)));
105+
106+
func.add_attribute(FnAttribute::AlwaysInline);
107+
108+
if tcx.sess.must_emit_unwind_tables() {
109+
// TODO(antoyo): emit unwind tables.
110+
}
111+
112+
let block = func.new_block("entry");
113+
block.end_with_return(None, value);
114+
}
115+
94116
fn create_wrapper_function(
95117
tcx: TyCtxt<'_>,
96118
context: &Context<'_>,

compiler/rustc_codegen_llvm/src/allocator.rs

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use rustc_symbol_mangling::mangle_internal_symbol;
1111

1212
use crate::builder::SBuilder;
1313
use crate::declare::declare_simple_fn;
14-
use crate::llvm::{self, False, True, Type};
14+
use crate::llvm::{self, False, True, Type, Value};
1515
use crate::{SimpleCx, attributes, debuginfo};
1616

1717
pub(crate) unsafe fn codegen(
@@ -73,13 +73,14 @@ pub(crate) unsafe fn codegen(
7373
);
7474

7575
unsafe {
76-
// __rust_alloc_error_handler_should_panic
77-
let name = mangle_internal_symbol(tcx, OomStrategy::SYMBOL);
78-
let ll_g = cx.declare_global(&name, i8);
79-
llvm::set_visibility(ll_g, llvm::Visibility::from_generic(tcx.sess.default_visibility()));
80-
let val = tcx.sess.opts.unstable_opts.oom.should_panic();
81-
let llval = llvm::LLVMConstInt(i8, val as u64, False);
82-
llvm::set_initializer(ll_g, llval);
76+
// __rust_alloc_error_handler_should_panic_v2
77+
create_const_value_function(
78+
tcx,
79+
&cx,
80+
&mangle_internal_symbol(tcx, OomStrategy::SYMBOL),
81+
&i8,
82+
&llvm::LLVMConstInt(i8, tcx.sess.opts.unstable_opts.oom.should_panic() as u64, False),
83+
);
8384

8485
// __rust_no_alloc_shim_is_unstable_v2
8586
create_wrapper_function(
@@ -100,6 +101,34 @@ pub(crate) unsafe fn codegen(
100101
}
101102
}
102103

104+
fn create_const_value_function(
105+
tcx: TyCtxt<'_>,
106+
cx: &SimpleCx<'_>,
107+
name: &str,
108+
output: &Type,
109+
value: &Value,
110+
) {
111+
let ty = cx.type_func(&[], output);
112+
let llfn = declare_simple_fn(
113+
&cx,
114+
name,
115+
llvm::CallConv::CCallConv,
116+
llvm::UnnamedAddr::Global,
117+
llvm::Visibility::from_generic(tcx.sess.default_visibility()),
118+
ty,
119+
);
120+
121+
attributes::apply_to_llfn(
122+
llfn,
123+
llvm::AttributePlace::Function,
124+
&[llvm::AttributeKind::AlwaysInline.create_attr(cx.llcx)],
125+
);
126+
127+
let llbb = unsafe { llvm::LLVMAppendBasicBlockInContext(cx.llcx, llfn, c"entry".as_ptr()) };
128+
let mut bx = SBuilder::build(&cx, llbb);
129+
bx.ret(value);
130+
}
131+
103132
fn create_wrapper_function(
104133
tcx: TyCtxt<'_>,
105134
cx: &SimpleCx<'_>,

compiler/rustc_errors/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ rustc_type_ir = { path = "../rustc_type_ir" }
2828
serde = { version = "1.0.125", features = [ "derive" ] }
2929
serde_json = "1.0.59"
3030
termcolor = "1.2.0"
31-
termize = "0.1.1"
31+
termize = "0.2"
3232
tracing = "0.1"
3333
# tidy-alphabetical-end
3434

compiler/rustc_errors/src/diagnostic.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,15 @@ impl DiagInner {
417417
self.args = std::mem::take(&mut self.reserved_args);
418418
}
419419

420+
pub fn emitted_at_sub_diag(&self) -> Subdiag {
421+
let track = format!("-Ztrack-diagnostics: created at {}", self.emitted_at);
422+
Subdiag {
423+
level: crate::Level::Note,
424+
messages: vec![(DiagMessage::Str(Cow::Owned(track)), Style::NoStyle)],
425+
span: MultiSpan::new(),
426+
}
427+
}
428+
420429
/// Fields used for Hash, and PartialEq trait.
421430
fn keys(
422431
&self,

0 commit comments

Comments
 (0)