Skip to content

Commit 87fb309

Browse files
committed
Auto merge of #158395 - JonathanBrouwer:rollup-d7BTVnf, r=JonathanBrouwer
Rollup of 17 pull requests Successful merges: - #153697 (Add arg splat experiment initial tuple impl) - #155535 (export symbols: support macos/windows(32/64)) - #158253 (codegen_ssa: multiply scalable vec size by `vscale`) - #158308 (Fix bug when rustdoc "go to only result" setting is not working as expected") - #158345 (Use `transmute_neo` in `assume_init`) - #158369 (std: abort when `resume_unwind` is called inside the panic hook) - #158374 (disallow tail calling extern "rust-call" functions) - #158380 (Revert "rebuild LLVM when `bootstrap.toml` config changes") - #154398 (Add test for async Send with PhantomData<*mut ()> + unsafe impl Send + dyn Trait) - #157181 (autodiff: stop always needing an alloca) - #158278 (autodiff - typtree cleanups) - #158311 (doc(unstable-book): fix typo "earier" -> "earlier" in default-visibility flag) - #158318 (Make normalization in a test case resilient to dist compilation) - #158338 (Reorganize `tests/ui/issues` [14/N]) - #158343 (Include `Item::const_stability` info in rustdoc JSON.) - #158355 (Fixup the refactoring errors in #156246) - #158390 (Fix: auto trait, const trait bound)
2 parents 973ad0d + 24c190c commit 87fb309

151 files changed

Lines changed: 3928 additions & 655 deletions

File tree

Some content is hidden

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

compiler/rustc_abi/src/extern_abi.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,10 +343,16 @@ impl ExternAbi {
343343
// This ABI does not support calls at all (except via assembly).
344344
false
345345
}
346+
Self::RustCall => {
347+
// Argument untupling requires additional support for tail calls to be possible,
348+
// see <https://github.com/rust-lang/rust/pull/158248>. There is no real uses of
349+
// tail calling `extern "rust-call"` functions
350+
false
351+
}
352+
346353
Self::C { .. }
347354
| Self::System { .. }
348355
| Self::Rust
349-
| Self::RustCall
350356
| Self::RustCold
351357
| Self::RustInvalid
352358
| Self::Unadjusted

compiler/rustc_ast/src/ast.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3059,21 +3059,23 @@ impl FnDecl {
30593059
}
30603060

30613061
/// The marker index for "no splatted arguments".
3062+
/// Higher values are also not supported, for performance reasons.
3063+
///
30623064
/// Must have the same value as `FnSigKind::NO_SPLATTED_ARG_INDEX` and `FnDeclFlags::NO_SPLATTED_ARG_INDEX`.
3063-
pub const NO_SPLATTED_ARG_INDEX: u16 = u16::MAX;
3065+
pub const NO_SPLATTED_ARG_INDEX: u8 = u8::MAX;
30643066

30653067
/// Returns a splatted argument index, if any are present.
3066-
pub fn splatted(&self) -> Option<u16> {
3068+
pub fn splatted(&self) -> Option<u8> {
30673069
self.inputs.iter().enumerate().find_map(|(index, arg)| {
3068-
if index == Self::NO_SPLATTED_ARG_INDEX as usize {
3070+
if index >= usize::from(Self::NO_SPLATTED_ARG_INDEX) {
30693071
// AST validation has already checked the splatted argument index is valid, so just
30703072
// ignore invalid indexes here.
30713073
None
30723074
} else {
30733075
arg.attrs
30743076
.iter()
30753077
.any(|attr| attr.has_name(sym::splat))
3076-
.then_some(u16::try_from(index).unwrap())
3078+
.then_some(u8::try_from(index).unwrap())
30773079
}
30783080
})
30793081
}

compiler/rustc_ast_lowering/src/delegation.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ struct ParamInfo {
9393
pub c_variadic: bool,
9494

9595
/// The index of the splatted parameter, if any.
96-
pub splatted: Option<u16>,
96+
pub splatted: Option<u8>,
9797
}
9898

9999
const PARENT_ID: hir::ItemLocalId = hir::ItemLocalId::ZERO;
@@ -364,11 +364,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
364364
fn param_info(&self, def_id: DefId) -> ParamInfo {
365365
let sig = self.tcx.fn_sig(def_id).skip_binder().skip_binder();
366366

367-
// FIXME(splat): use `sig.splatted()` once FnSig has it
368367
ParamInfo {
369368
param_count: sig.inputs().len() + usize::from(sig.c_variadic()),
370369
c_variadic: sig.c_variadic(),
371-
splatted: None,
370+
splatted: sig.splatted(),
372371
}
373372
}
374373

compiler/rustc_ast_passes/src/ast_validation.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -412,11 +412,11 @@ impl<'a> AstValidator<'a> {
412412
})
413413
.unzip();
414414

415-
// A splatted argument at the "no splatted" marker index is not supported (this is an
416-
// unlikely edge case).
415+
// A splatted argument greater than or equal to the "no splatted" marker index is not
416+
// supported.
417417
if let (Some(&splatted_arg_index), Some(&splatted_span)) =
418418
(splatted_arg_indexes.last(), splatted_spans.last())
419-
&& splatted_arg_index == FnDecl::NO_SPLATTED_ARG_INDEX
419+
&& splatted_arg_index >= u16::from(FnDecl::NO_SPLATTED_ARG_INDEX)
420420
{
421421
self.dcx().emit_err(diagnostics::InvalidSplattedArg {
422422
splatted_arg_index,

compiler/rustc_codegen_cranelift/src/abi/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@ pub(crate) fn codegen_fn_prelude<'tcx>(fx: &mut FunctionCx<'_, '_, 'tcx>, start_
271271
.map(|local| {
272272
let arg_ty = fx.monomorphize(fx.mir.local_decls[local].ty);
273273

274+
// FIXME(splat): un-tuple splatted arguments in codegen, for performance
274275
// Adapted from https://github.com/rust-lang/rust/blob/145155dc96757002c7b2e9de8489416e2fdbbd57/src/librustc_codegen_llvm/mir/mod.rs#L442-L482
275276
if Some(local) == fx.mir.spread_arg {
276277
// This argument (e.g. the last argument in the "rust-call" ABI)

compiler/rustc_codegen_gcc/src/builder.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1459,6 +1459,10 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
14591459
);
14601460
}
14611461

1462+
fn vscale(&mut self, _: Self::Type) -> Self::Value {
1463+
unimplemented!("`rustc_codegen_gcc` doesn't support scalable vectors yet")
1464+
}
1465+
14621466
fn select(
14631467
&mut self,
14641468
cond: RValue<'gcc>,

compiler/rustc_codegen_llvm/src/builder.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1226,6 +1226,10 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
12261226
}
12271227
}
12281228

1229+
fn vscale(&mut self, ty: &'ll Type) -> &'ll Value {
1230+
unsafe { llvm::LLVMRustBuildVScale(self.llbuilder, ty) }
1231+
}
1232+
12291233
fn select(
12301234
&mut self,
12311235
cond: &'ll Value,

compiler/rustc_codegen_llvm/src/builder/autodiff.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ use std::ptr;
33
use rustc_ast::expand::autodiff_attrs::{DiffActivity, DiffMode};
44
use rustc_ast::expand::typetree::FncTree;
55
use rustc_codegen_ssa::common::TypeKind;
6+
use rustc_codegen_ssa::mir::IntrinsicResult;
7+
use rustc_codegen_ssa::mir::operand::{OperandRef, OperandValue};
8+
use rustc_codegen_ssa::mir::place::PlaceValue;
69
use rustc_codegen_ssa::traits::{BaseTypeCodegenMethods, BuilderMethods};
710
use rustc_data_structures::thin_vec::ThinVec;
811
use rustc_hir::attrs::RustcAutodiff;
@@ -11,7 +14,7 @@ use rustc_middle::{bug, ty};
1114
use rustc_target::callconv::PassMode;
1215
use tracing::debug;
1316

14-
use crate::builder::{Builder, PlaceRef, UNNAMED};
17+
use crate::builder::{Builder, UNNAMED};
1518
use crate::context::SimpleCx;
1619
use crate::declare::declare_simple_fn;
1720
use crate::llvm::{self, TRUE, Type, Value};
@@ -296,9 +299,10 @@ pub(crate) fn generate_enzyme_call<'ll, 'tcx>(
296299
ret_ty: &'ll Type,
297300
fn_args: &[&'ll Value],
298301
attrs: &RustcAutodiff,
299-
dest: PlaceRef<'tcx, &'ll Value>,
302+
dest_layout: ty::layout::TyAndLayout<'tcx>,
303+
dest_place: Option<PlaceValue<&'ll Value>>,
300304
fnc_tree: FncTree,
301-
) {
305+
) -> IntrinsicResult<'tcx, &'ll Value> {
302306
// We have to pick the name depending on whether we want forward or reverse mode autodiff.
303307
let mut ad_name: String = match attrs.mode {
304308
DiffMode::Forward => "__enzyme_fwddiff",
@@ -381,11 +385,18 @@ pub(crate) fn generate_enzyme_call<'ll, 'tcx>(
381385
let call = builder.call(enzyme_ty, None, None, ad_fn, &args, None, None);
382386

383387
let fn_ret_ty = builder.cx.val_ty(call);
384-
if fn_ret_ty != builder.cx.type_void() && fn_ret_ty != builder.cx.type_struct(&[], false) {
388+
if fn_ret_ty == builder.cx.type_void() || fn_ret_ty == builder.cx.type_struct(&[], false) {
385389
// If we return void or an empty struct, then our caller (due to how we generated it)
386390
// does not expect a return value. As such, we have no pointer (or place) into which
387391
// we could store our value, and would store into an undef, which would cause UB.
388392
// As such, we just ignore the return value in those cases.
389-
builder.store_to_place(call, dest.val);
393+
IntrinsicResult::Operand(OperandValue::ZeroSized)
394+
} else if let Some(dest_place) = dest_place {
395+
builder.store_to_place(call, dest_place);
396+
IntrinsicResult::WroteIntoPlace
397+
} else {
398+
IntrinsicResult::Operand(
399+
OperandRef::from_immediate_or_packed_pair(builder, call, dest_layout).val,
400+
)
390401
}
391402
}

compiler/rustc_codegen_llvm/src/context.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -978,10 +978,7 @@ impl<'ll, 'tcx> MiscCodegenMethods<'tcx> for CodegenCx<'ll, 'tcx> {
978978
}
979979

980980
fn intrinsic_call_expects_place_always(&self, name: Symbol) -> bool {
981-
matches!(
982-
name,
983-
sym::autodiff | sym::volatile_load | sym::unaligned_volatile_load | sym::black_box
984-
)
981+
matches!(name, sym::volatile_load | sym::unaligned_volatile_load | sym::black_box)
985982
}
986983
}
987984

compiler/rustc_codegen_llvm/src/intrinsic.rs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ use crate::errors::{
4343
AutoDiffWithoutEnable, AutoDiffWithoutLto, IntrinsicSignatureMismatch, IntrinsicWrongArch,
4444
OffloadWithoutEnable, OffloadWithoutFatLTO, UnknownIntrinsic,
4545
};
46+
use crate::intrinsic::ty::typetree::fnc_typetrees;
4647
use crate::llvm::{self, Type, Value};
4748
use crate::type_of::LayoutLlvmExt;
4849
use crate::va_arg::emit_va_arg;
@@ -223,12 +224,7 @@ impl<'ll, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
223224
)
224225
}
225226
sym::autodiff => {
226-
let result = PlaceRef {
227-
val: result_place.unwrap(),
228-
layout: result_layout,
229-
};
230-
codegen_autodiff(self, tcx, instance, args, result);
231-
return IntrinsicResult::WroteIntoPlace;
227+
return codegen_autodiff(self, tcx, instance, args, result_layout, result_place);
232228
}
233229
sym::offload => {
234230
if tcx.sess.opts.unstable_opts.offload.is_empty() {
@@ -1728,8 +1724,9 @@ fn codegen_autodiff<'ll, 'tcx>(
17281724
tcx: TyCtxt<'tcx>,
17291725
instance: ty::Instance<'tcx>,
17301726
args: &[OperandRef<'tcx, &'ll Value>],
1731-
result: PlaceRef<'tcx, &'ll Value>,
1732-
) {
1727+
result_layout: ty::layout::TyAndLayout<'tcx>,
1728+
result_place: Option<PlaceValue<&'ll Value>>,
1729+
) -> IntrinsicResult<'tcx, &'ll Value> {
17331730
if !tcx.sess.opts.unstable_opts.autodiff.contains(&rustc_session::config::AutoDiff::Enable) {
17341731
let _ = tcx.dcx().emit_almost_fatal(AutoDiffWithoutEnable);
17351732
}
@@ -1769,9 +1766,9 @@ fn codegen_autodiff<'ll, 'tcx>(
17691766
diff_id,
17701767
diff_args
17711768
),
1772-
Err(_) => {
1769+
Err(err) => {
17731770
// An error has already been emitted
1774-
return;
1771+
return IntrinsicResult::Err(err);
17751772
}
17761773
};
17771774

@@ -1791,7 +1788,7 @@ fn codegen_autodiff<'ll, 'tcx>(
17911788
&mut diff_attrs.input_activity,
17921789
);
17931790

1794-
let fnc_tree = rustc_middle::ty::fnc_typetrees(tcx, source_fn_ptr_ty);
1791+
let fnc_tree = fnc_typetrees(tcx, source_fn_ptr_ty);
17951792

17961793
// Build body
17971794
generate_enzyme_call(
@@ -1802,9 +1799,10 @@ fn codegen_autodiff<'ll, 'tcx>(
18021799
llret_ty,
18031800
&val_arr,
18041801
&diff_attrs,
1805-
result,
1802+
result_layout,
1803+
result_place,
18061804
fnc_tree,
1807-
);
1805+
)
18081806
}
18091807

18101808
// Generates the LLVM code to offload a Rust function to a target device (e.g., GPU).

0 commit comments

Comments
 (0)