Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 4c6e809

Browse files
committed
Auto merge of rust-lang#128698 - tgross35:rollup-oan6ari, r=tgross35
Rollup of 8 pull requests Successful merges: - rust-lang#122049 (Promote riscv64gc-unknown-linux-musl to tier 2) - rust-lang#125558 (Tweak type inference for `const` operands in inline asm) - rust-lang#128638 (run-make: enable msvc for `link-dedup`) - rust-lang#128647 (Enable msvc for link-args-order) - rust-lang#128649 (run-make: Enable msvc for `no-duplicate-libs` and `zero-extend-abi-param-passing`) - rust-lang#128656 (Enable msvc for run-make/rust-lld) - rust-lang#128688 (custom MIR: add support for tail calls) - rust-lang#128691 (Update `compiler-builtins` to 0.1.115) r? `@ghost` `@rustbot` modify labels: rollup
2 parents f7eefec + e6cdde2 commit 4c6e809

File tree

37 files changed

+496
-319
lines changed

37 files changed

+496
-319
lines changed

compiler/rustc_hir_analysis/src/check/intrinsicck.rs

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use rustc_ast::InlineAsmTemplatePiece;
22
use rustc_data_structures::fx::FxIndexSet;
33
use rustc_hir::{self as hir, LangItem};
44
use rustc_middle::bug;
5-
use rustc_middle::ty::{self, Article, FloatTy, IntTy, Ty, TyCtxt, TypeVisitableExt, UintTy};
5+
use rustc_middle::ty::{self, FloatTy, IntTy, Ty, TyCtxt, TypeVisitableExt, UintTy};
66
use rustc_session::lint;
77
use rustc_span::def_id::LocalDefId;
88
use rustc_span::Symbol;
@@ -455,32 +455,22 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
455455
);
456456
}
457457
}
458-
// No special checking is needed for these:
459-
// - Typeck has checked that Const operands are integers.
460-
// - AST lowering guarantees that SymStatic points to a static.
461-
hir::InlineAsmOperand::Const { .. } | hir::InlineAsmOperand::SymStatic { .. } => {}
462-
// Check that sym actually points to a function. Later passes
463-
// depend on this.
458+
// Typeck has checked that Const operands are integers.
459+
hir::InlineAsmOperand::Const { anon_const } => {
460+
debug_assert!(matches!(
461+
self.tcx.type_of(anon_const.def_id).instantiate_identity().kind(),
462+
ty::Error(_) | ty::Int(_) | ty::Uint(_)
463+
));
464+
}
465+
// Typeck has checked that SymFn refers to a function.
464466
hir::InlineAsmOperand::SymFn { anon_const } => {
465-
let ty = self.tcx.type_of(anon_const.def_id).instantiate_identity();
466-
match ty.kind() {
467-
ty::Never | ty::Error(_) => {}
468-
ty::FnDef(..) => {}
469-
_ => {
470-
self.tcx
471-
.dcx()
472-
.struct_span_err(*op_sp, "invalid `sym` operand")
473-
.with_span_label(
474-
self.tcx.def_span(anon_const.def_id),
475-
format!("is {} `{}`", ty.kind().article(), ty),
476-
)
477-
.with_help(
478-
"`sym` operands must refer to either a function or a static",
479-
)
480-
.emit();
481-
}
482-
};
467+
debug_assert!(matches!(
468+
self.tcx.type_of(anon_const.def_id).instantiate_identity().kind(),
469+
ty::Error(_) | ty::FnDef(..)
470+
));
483471
}
472+
// AST lowering guarantees that SymStatic points to a static.
473+
hir::InlineAsmOperand::SymStatic { .. } => {}
484474
// No special checking is needed for labels.
485475
hir::InlineAsmOperand::Label { .. } => {}
486476
}

compiler/rustc_hir_analysis/src/collect/type_of.rs

Lines changed: 59 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_hir::HirId;
77
use rustc_middle::query::plumbing::CyclePlaceholder;
88
use rustc_middle::ty::print::with_forced_trimmed_paths;
99
use rustc_middle::ty::util::IntTypeExt;
10-
use rustc_middle::ty::{self, IsSuggestable, Ty, TyCtxt, TypeVisitableExt};
10+
use rustc_middle::ty::{self, Article, IsSuggestable, Ty, TyCtxt, TypeVisitableExt};
1111
use rustc_middle::{bug, span_bug};
1212
use rustc_span::symbol::Ident;
1313
use rustc_span::{Span, DUMMY_SP};
@@ -34,6 +34,20 @@ fn anon_const_type_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Ty<'tcx> {
3434
let parent_node_id = tcx.parent_hir_id(hir_id);
3535
let parent_node = tcx.hir_node(parent_node_id);
3636

37+
let find_sym_fn = |&(op, op_sp)| match op {
38+
hir::InlineAsmOperand::SymFn { anon_const } if anon_const.hir_id == hir_id => {
39+
Some((anon_const, op_sp))
40+
}
41+
_ => None,
42+
};
43+
44+
let find_const = |&(op, op_sp)| match op {
45+
hir::InlineAsmOperand::Const { anon_const } if anon_const.hir_id == hir_id => {
46+
Some((anon_const, op_sp))
47+
}
48+
_ => None,
49+
};
50+
3751
match parent_node {
3852
// Anon consts "inside" the type system.
3953
Node::ConstArg(&ConstArg {
@@ -45,13 +59,51 @@ fn anon_const_type_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Ty<'tcx> {
4559
// Anon consts outside the type system.
4660
Node::Expr(&Expr { kind: ExprKind::InlineAsm(asm), .. })
4761
| Node::Item(&Item { kind: ItemKind::GlobalAsm(asm), .. })
48-
if asm.operands.iter().any(|(op, _op_sp)| match op {
49-
hir::InlineAsmOperand::Const { anon_const }
50-
| hir::InlineAsmOperand::SymFn { anon_const } => anon_const.hir_id == hir_id,
51-
_ => false,
52-
}) =>
62+
if let Some((anon_const, op_sp)) = asm.operands.iter().find_map(find_sym_fn) =>
5363
{
54-
tcx.typeck(def_id).node_type(hir_id)
64+
let ty = tcx.typeck(def_id).node_type(hir_id);
65+
66+
match ty.kind() {
67+
ty::Error(_) => ty,
68+
ty::FnDef(..) => ty,
69+
_ => {
70+
let guar = tcx
71+
.dcx()
72+
.struct_span_err(op_sp, "invalid `sym` operand")
73+
.with_span_label(
74+
tcx.def_span(anon_const.def_id),
75+
format!("is {} `{}`", ty.kind().article(), ty),
76+
)
77+
.with_help("`sym` operands must refer to either a function or a static")
78+
.emit();
79+
80+
Ty::new_error(tcx, guar)
81+
}
82+
}
83+
}
84+
Node::Expr(&Expr { kind: ExprKind::InlineAsm(asm), .. })
85+
| Node::Item(&Item { kind: ItemKind::GlobalAsm(asm), .. })
86+
if let Some((anon_const, op_sp)) = asm.operands.iter().find_map(find_const) =>
87+
{
88+
let ty = tcx.typeck(def_id).node_type(hir_id);
89+
90+
match ty.kind() {
91+
ty::Error(_) => ty,
92+
ty::Int(_) | ty::Uint(_) => ty,
93+
_ => {
94+
let guar = tcx
95+
.dcx()
96+
.struct_span_err(op_sp, "invalid type for `const` operand")
97+
.with_span_label(
98+
tcx.def_span(anon_const.def_id),
99+
format!("is {} `{}`", ty.kind().article(), ty),
100+
)
101+
.with_help("`const` operands must be of an integer type")
102+
.emit();
103+
104+
Ty::new_error(tcx, guar)
105+
}
106+
}
55107
}
56108
Node::Variant(Variant { disr_expr: Some(ref e), .. }) if e.hir_id == hir_id => {
57109
tcx.adt_def(tcx.hir().get_parent_item(hir_id)).repr().discr_type().to_ty(tcx)

compiler/rustc_hir_typeck/src/lib.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -265,11 +265,10 @@ fn infer_type_if_missing<'tcx>(fcx: &FnCtxt<'_, 'tcx>, node: Node<'tcx>) -> Opti
265265
Node::Expr(&hir::Expr { kind: hir::ExprKind::InlineAsm(asm), span, .. })
266266
| Node::Item(&hir::Item { kind: hir::ItemKind::GlobalAsm(asm), span, .. }) => {
267267
asm.operands.iter().find_map(|(op, _op_sp)| match op {
268-
hir::InlineAsmOperand::Const { anon_const } if anon_const.hir_id == id => {
269-
// Inline assembly constants must be integers.
270-
Some(fcx.next_int_var())
271-
}
272-
hir::InlineAsmOperand::SymFn { anon_const } if anon_const.hir_id == id => {
268+
hir::InlineAsmOperand::Const { anon_const }
269+
| hir::InlineAsmOperand::SymFn { anon_const }
270+
if anon_const.hir_id == id =>
271+
{
273272
Some(fcx.next_ty_var(span))
274273
}
275274
_ => None,

compiler/rustc_mir_build/src/build/custom/parse/instruction.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ impl<'tcx, 'body> ParseCtxt<'tcx, 'body> {
7575
@call(mir_call, args) => {
7676
self.parse_call(args)
7777
},
78+
@call(mir_tail_call, args) => {
79+
self.parse_tail_call(args)
80+
},
7881
ExprKind::Match { scrutinee, arms, .. } => {
7982
let discr = self.parse_operand(*scrutinee)?;
8083
self.parse_match(arms, expr.span).map(|t| TerminatorKind::SwitchInt { discr, targets: t })
@@ -187,6 +190,25 @@ impl<'tcx, 'body> ParseCtxt<'tcx, 'body> {
187190
)
188191
}
189192

193+
fn parse_tail_call(&self, args: &[ExprId]) -> PResult<TerminatorKind<'tcx>> {
194+
parse_by_kind!(self, args[0], _, "tail call",
195+
ExprKind::Call { fun, args, fn_span, .. } => {
196+
let fun = self.parse_operand(*fun)?;
197+
let args = args
198+
.iter()
199+
.map(|arg|
200+
Ok(Spanned { node: self.parse_operand(*arg)?, span: self.thir.exprs[*arg].span } )
201+
)
202+
.collect::<PResult<Box<[_]>>>()?;
203+
Ok(TerminatorKind::TailCall {
204+
func: fun,
205+
args,
206+
fn_span: *fn_span,
207+
})
208+
},
209+
)
210+
}
211+
190212
fn parse_rvalue(&self, expr_id: ExprId) -> PResult<Rvalue<'tcx>> {
191213
parse_by_kind!(self, expr_id, expr, "rvalue",
192214
@call(mir_discriminant, args) => self.parse_place(args[0]).map(Rvalue::Discriminant),

compiler/rustc_span/src/symbol.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,6 +1216,7 @@ symbols! {
12161216
mir_static_mut,
12171217
mir_storage_dead,
12181218
mir_storage_live,
1219+
mir_tail_call,
12191220
mir_unreachable,
12201221
mir_unwind_cleanup,
12211222
mir_unwind_continue,

compiler/rustc_target/src/spec/targets/riscv64gc_unknown_linux_musl.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ pub fn target() -> Target {
2121
llvm_abiname: "lp64d".into(),
2222
max_atomic_width: Some(64),
2323
supported_split_debuginfo: Cow::Borrowed(&[SplitDebuginfo::Off]),
24+
crt_static_default: false,
2425
..base::linux_musl::opts()
2526
},
2627
}

library/Cargo.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ dependencies = [
5858

5959
[[package]]
6060
name = "compiler_builtins"
61-
version = "0.1.114"
61+
version = "0.1.115"
6262
source = "registry+https://github.com/rust-lang/crates.io-index"
63-
checksum = "eb58b199190fcfe0846f55a3b545cd6b07a34bdd5930a476ff856f3ebcc5558a"
63+
checksum = "3358508f8fe5c43b1d59deef1c190287490a00cce3d7b4a3744e4a35e3f220d0"
6464
dependencies = [
6565
"cc",
6666
"rustc-std-workspace-core",

library/alloc/Cargo.toml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@ edition = "2021"
1010

1111
[dependencies]
1212
core = { path = "../core" }
13-
compiler_builtins = { version = "0.1.114", features = ['rustc-dep-of-std'] }
14-
15-
[target.'cfg(not(any(target_arch = "aarch64", target_arch = "x86", target_arch = "x86_64")))'.dependencies]
16-
compiler_builtins = { version = "0.1.114", features = ["no-f16-f128"] }
13+
compiler_builtins = { version = "0.1.115", features = ['rustc-dep-of-std'] }
1714

1815
[dev-dependencies]
1916
rand = { version = "0.8.5", default-features = false, features = ["alloc"] }

library/core/src/intrinsics/mir.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,8 @@
247247
//! otherwise branch.
248248
//! - [`Call`] has an associated function as well, with special syntax:
249249
//! `Call(ret_val = function(arg1, arg2, ...), ReturnTo(next_block), UnwindContinue())`.
250+
//! - [`TailCall`] does not have a return destination or next block, so its syntax is just
251+
//! `TailCall(function(arg1, arg2, ...))`.
250252
251253
#![unstable(
252254
feature = "custom_mir",
@@ -350,6 +352,12 @@ define!("mir_call",
350352
/// - [`UnwindCleanup`]
351353
fn Call(call: (), goto: ReturnToArg, unwind_action: UnwindActionArg)
352354
);
355+
define!("mir_tail_call",
356+
/// Call a function.
357+
///
358+
/// The argument must be of the form `fun(arg1, arg2, ...)`.
359+
fn TailCall<T>(call: T)
360+
);
353361
define!("mir_unwind_resume",
354362
/// A terminator that resumes the unwinding.
355363
fn UnwindResume()

library/std/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ cfg-if = { version = "1.0", features = ['rustc-dep-of-std'] }
1717
panic_unwind = { path = "../panic_unwind", optional = true }
1818
panic_abort = { path = "../panic_abort" }
1919
core = { path = "../core", public = true }
20-
compiler_builtins = { version = "0.1.114" }
20+
compiler_builtins = { version = "0.1.115" }
2121
profiler_builtins = { path = "../profiler_builtins", optional = true }
2222
unwind = { path = "../unwind" }
2323
hashbrown = { version = "0.14", default-features = false, features = [

0 commit comments

Comments
 (0)