Skip to content

Commit 5a72bc9

Browse files
committed
Auto merge of #145681 - jhpratt:rollup-7hn0ii7, r=jhpratt
Rollup of 14 pull requests Successful merges: - #143383 (stabilize `const_array_each_ref`) - #144443 (Make target pointer width in target json an integer) - #144758 ([Doc] Add links to the various collections) - #144915 (Defer tail call ret ty equality to check_tail_calls) - #145137 (Consolidate panicking functions in `slice/index.rs`) - #145256 (Add new `--test-codegen-backend` bootstrap option) - #145297 (fix(debuginfo): handle false positives in overflow check) - #145415 (std_detect: RISC-V: implement implication to "C") - #145642 (Do not use effective_visibilities query for Adt types of a local trait while proving a where-clause) - #145650 (Fix JS search scripts path) - #145654 (Download CI GCC into the correct directory) - #145662 (Enforce correct number of arguments for `"x86-interrupt"` functions) - #145674 (Enable triagebot `[review-changes-since]` feature) - #145678 (Fix typo in docstring) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 040a98a + 920fe4e commit 5a72bc9

File tree

88 files changed

+712
-378
lines changed

Some content is hidden

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

88 files changed

+712
-378
lines changed

compiler/rustc_abi/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ pub enum TargetDataLayoutErrors<'a> {
315315
MissingAlignment { cause: &'a str },
316316
InvalidAlignment { cause: &'a str, err: AlignFromBytesError },
317317
InconsistentTargetArchitecture { dl: &'a str, target: &'a str },
318-
InconsistentTargetPointerWidth { pointer_size: u64, target: u32 },
318+
InconsistentTargetPointerWidth { pointer_size: u64, target: u16 },
319319
InvalidBitsSize { err: String },
320320
UnknownPointerSpecification { err: String },
321321
}

compiler/rustc_ast_ir/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ impl IntTy {
6969
})
7070
}
7171

72-
pub fn normalize(&self, target_width: u32) -> Self {
72+
pub fn normalize(&self, target_width: u16) -> Self {
7373
match self {
7474
IntTy::Isize => match target_width {
7575
16 => IntTy::I16,
@@ -148,7 +148,7 @@ impl UintTy {
148148
})
149149
}
150150

151-
pub fn normalize(&self, target_width: u32) -> Self {
151+
pub fn normalize(&self, target_width: u16) -> Self {
152152
match self {
153153
UintTy::Usize => match target_width {
154154
16 => UintTy::U16,

compiler/rustc_ast_passes/messages.ftl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ ast_passes_abi_must_not_have_return_type=
2020
.note = functions with the {$abi} ABI cannot have a return type
2121
.help = remove the return type
2222
23+
ast_passes_abi_x86_interrupt =
24+
invalid signature for `extern "x86-interrupt"` function
25+
.note = functions with the "x86-interrupt" ABI must be have either 1 or 2 parameters (but found {$param_count})
26+
2327
ast_passes_assoc_const_without_body =
2428
associated constant in `impl` without body
2529
.suggestion = provide a definition for the constant

compiler/rustc_ast_passes/src/ast_validation.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,17 @@ impl<'a> AstValidator<'a> {
405405
if let InterruptKind::X86 = interrupt_kind {
406406
// "x86-interrupt" is special because it does have arguments.
407407
// FIXME(workingjubilee): properly lint on acceptable input types.
408+
let inputs = &sig.decl.inputs;
409+
let param_count = inputs.len();
410+
if !matches!(param_count, 1 | 2) {
411+
let mut spans: Vec<Span> =
412+
inputs.iter().map(|arg| arg.span).collect();
413+
if spans.is_empty() {
414+
spans = vec![sig.span];
415+
}
416+
self.dcx().emit_err(errors::AbiX86Interrupt { spans, param_count });
417+
}
418+
408419
if let FnRetTy::Ty(ref ret_ty) = sig.decl.output
409420
&& match &ret_ty.kind {
410421
TyKind::Never => false,

compiler/rustc_ast_passes/src/errors.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -891,3 +891,12 @@ pub(crate) struct AbiMustNotHaveReturnType {
891891
pub span: Span,
892892
pub abi: ExternAbi,
893893
}
894+
895+
#[derive(Diagnostic)]
896+
#[diag(ast_passes_abi_x86_interrupt)]
897+
#[note]
898+
pub(crate) struct AbiX86Interrupt {
899+
#[primary_span]
900+
pub spans: Vec<Span>,
901+
pub param_count: usize,
902+
}

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1895,7 +1895,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
18951895
if !output_ty
18961896
.is_privately_uninhabited(self.tcx(), self.infcx.typing_env(self.infcx.param_env))
18971897
{
1898-
span_mirbug!(self, term, "call to converging function {:?} w/o dest", sig);
1898+
span_mirbug!(self, term, "call to non-diverging function {:?} w/o dest", sig);
18991899
}
19001900
} else {
19011901
let dest_ty = destination.ty(self.body, tcx).ty;

compiler/rustc_codegen_gcc/target_specs/m68k-unknown-linux-gnu.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@
2222
"unix"
2323
],
2424
"target-mcount": "_mcount",
25-
"target-pointer-width": "32"
25+
"target-pointer-width": 32
2626
}

compiler/rustc_codegen_llvm/src/debuginfo/metadata/type_map.rs

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ pub(super) fn build_type_with_children<'ll, 'tcx>(
276276
&& let ty::Adt(adt_def, args) = ty.kind()
277277
{
278278
let def_id = adt_def.did();
279-
// If any sub type reference the original type definition and the sub type has a type
279+
// If any child type references the original type definition and the child type has a type
280280
// parameter that strictly contains the original parameter, the original type is a recursive
281281
// type that can expanding indefinitely. Example,
282282
// ```
@@ -285,21 +285,43 @@ pub(super) fn build_type_with_children<'ll, 'tcx>(
285285
// Item(T),
286286
// }
287287
// ```
288-
let is_expanding_recursive = adt_def.is_enum()
289-
&& debug_context(cx).adt_stack.borrow().iter().any(|(parent_def_id, parent_args)| {
290-
if def_id == *parent_def_id {
291-
args.iter().zip(parent_args.iter()).any(|(arg, parent_arg)| {
292-
if let (Some(arg), Some(parent_arg)) = (arg.as_type(), parent_arg.as_type())
293-
{
294-
arg != parent_arg && arg.contains(parent_arg)
295-
} else {
296-
false
297-
}
298-
})
299-
} else {
300-
false
301-
}
302-
});
288+
let is_expanding_recursive = {
289+
let stack = debug_context(cx).adt_stack.borrow();
290+
stack
291+
.iter()
292+
.enumerate()
293+
.rev()
294+
.skip(1)
295+
.filter(|(_, (ancestor_def_id, _))| def_id == *ancestor_def_id)
296+
.any(|(ancestor_index, (_, ancestor_args))| {
297+
args.iter()
298+
.zip(ancestor_args.iter())
299+
.filter_map(|(arg, ancestor_arg)| arg.as_type().zip(ancestor_arg.as_type()))
300+
.any(|(arg, ancestor_arg)|
301+
// Strictly contains.
302+
(arg != ancestor_arg && arg.contains(ancestor_arg))
303+
// Check all types between current and ancestor use the
304+
// ancestor_arg.
305+
// Otherwise, duplicate wrappers in normal recursive type may be
306+
// regarded as expanding.
307+
// ```
308+
// struct Recursive {
309+
// a: Box<Box<Recursive>>,
310+
// }
311+
// ```
312+
// It can produce an ADT stack like this,
313+
// - Box<Recursive>
314+
// - Recursive
315+
// - Box<Box<Recursive>>
316+
&& stack[ancestor_index + 1..stack.len()].iter().all(
317+
|(_, intermediate_args)|
318+
intermediate_args
319+
.iter()
320+
.filter_map(|arg| arg.as_type())
321+
.any(|mid_arg| mid_arg.contains(ancestor_arg))
322+
))
323+
})
324+
};
303325
if is_expanding_recursive {
304326
// FIXME: indicate that this is an expanding recursive type in stub metadata?
305327
return DINodeCreationResult::new(stub_info.metadata, false);

compiler/rustc_mir_build/src/check_tail_calls.rs

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -135,30 +135,23 @@ impl<'tcx> TailCallCkVisitor<'_, 'tcx> {
135135
self.report_abi_mismatch(expr.span, caller_sig.abi, callee_sig.abi);
136136
}
137137

138+
// FIXME(explicit_tail_calls): this currently fails for cases where opaques are used.
139+
// e.g.
140+
// ```
141+
// fn a() -> impl Sized { become b() } // ICE
142+
// fn b() -> u8 { 0 }
143+
// ```
144+
// we should think what is the expected behavior here.
145+
// (we should probably just accept this by revealing opaques?)
138146
if caller_sig.inputs_and_output != callee_sig.inputs_and_output {
139-
if caller_sig.inputs() != callee_sig.inputs() {
140-
self.report_arguments_mismatch(
141-
expr.span,
142-
self.tcx.liberate_late_bound_regions(
143-
CRATE_DEF_ID.to_def_id(),
144-
self.caller_ty.fn_sig(self.tcx),
145-
),
146-
self.tcx
147-
.liberate_late_bound_regions(CRATE_DEF_ID.to_def_id(), ty.fn_sig(self.tcx)),
148-
);
149-
}
150-
151-
// FIXME(explicit_tail_calls): this currently fails for cases where opaques are used.
152-
// e.g.
153-
// ```
154-
// fn a() -> impl Sized { become b() } // ICE
155-
// fn b() -> u8 { 0 }
156-
// ```
157-
// we should think what is the expected behavior here.
158-
// (we should probably just accept this by revealing opaques?)
159-
if caller_sig.output() != callee_sig.output() {
160-
span_bug!(expr.span, "hir typeck should have checked the return type already");
161-
}
147+
self.report_signature_mismatch(
148+
expr.span,
149+
self.tcx.liberate_late_bound_regions(
150+
CRATE_DEF_ID.to_def_id(),
151+
self.caller_ty.fn_sig(self.tcx),
152+
),
153+
self.tcx.liberate_late_bound_regions(CRATE_DEF_ID.to_def_id(), ty.fn_sig(self.tcx)),
154+
);
162155
}
163156

164157
{
@@ -365,7 +358,7 @@ impl<'tcx> TailCallCkVisitor<'_, 'tcx> {
365358
self.found_errors = Err(err);
366359
}
367360

368-
fn report_arguments_mismatch(
361+
fn report_signature_mismatch(
369362
&mut self,
370363
sp: Span,
371364
caller_sig: ty::FnSig<'_>,

compiler/rustc_target/src/spec/json.rs

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,7 @@ impl Target {
2525
let mut base = Target {
2626
llvm_target: json.llvm_target,
2727
metadata: Default::default(),
28-
pointer_width: json
29-
.target_pointer_width
30-
.parse()
31-
.map_err(|err| format!("invalid target-pointer-width: {err}"))?,
28+
pointer_width: json.target_pointer_width,
3229
data_layout: json.data_layout,
3330
arch: json.arch,
3431
options: Default::default(),
@@ -245,19 +242,17 @@ impl ToJson for Target {
245242
target.update_to_cli();
246243

247244
macro_rules! target_val {
248-
($attr:ident) => {{
249-
let name = (stringify!($attr)).replace("_", "-");
250-
d.insert(name, target.$attr.to_json());
245+
($attr:ident) => {
246+
target_val!($attr, (stringify!($attr)).replace("_", "-"))
247+
};
248+
($attr:ident, $json_name:expr) => {{
249+
let name = $json_name;
250+
d.insert(name.into(), target.$attr.to_json());
251251
}};
252252
}
253253

254254
macro_rules! target_option_val {
255-
($attr:ident) => {{
256-
let name = (stringify!($attr)).replace("_", "-");
257-
if default.$attr != target.$attr {
258-
d.insert(name, target.$attr.to_json());
259-
}
260-
}};
255+
($attr:ident) => {{ target_option_val!($attr, (stringify!($attr)).replace("_", "-")) }};
261256
($attr:ident, $json_name:expr) => {{
262257
let name = $json_name;
263258
if default.$attr != target.$attr {
@@ -290,7 +285,7 @@ impl ToJson for Target {
290285

291286
target_val!(llvm_target);
292287
target_val!(metadata);
293-
d.insert("target-pointer-width".to_string(), self.pointer_width.to_string().to_json());
288+
target_val!(pointer_width, "target-pointer-width");
294289
target_val!(arch);
295290
target_val!(data_layout);
296291

@@ -463,7 +458,7 @@ struct TargetSpecJsonMetadata {
463458
#[serde(deny_unknown_fields)]
464459
struct TargetSpecJson {
465460
llvm_target: StaticCow<str>,
466-
target_pointer_width: String,
461+
target_pointer_width: u16,
467462
data_layout: StaticCow<str>,
468463
arch: StaticCow<str>,
469464

0 commit comments

Comments
 (0)