Skip to content

Rollup of 8 pull requests #141672

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 33 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
b21c9e7
Split `autodiff` into `autodiff_forward` and `autodiff_reverse`
Sa4dUs May 6, 2025
9efad3a
Add data_ptr method to Mutex and RwLock
jplatte Apr 27, 2025
9d6c5a8
Add more docs to new data_ptr methods
jplatte May 21, 2025
20589bd
Add ReentrantLock::data_ptr
jplatte May 21, 2025
b725cf6
Disable autodiff bootstrapping
Sa4dUs May 10, 2025
2041de7
Update codegen and pretty tests
Sa4dUs May 10, 2025
f92d84c
Initial naive implementation using `Symbols` to represent autodiff mo…
Sa4dUs May 10, 2025
8dd62e8
Update UI tests
Sa4dUs May 10, 2025
8917ff6
Update generic tests
Sa4dUs May 20, 2025
1e9e177
Move some code around in codegen_call_terminator
bjorn3 May 21, 2025
e4700e7
Always use fn_span in codegen_call_terminator
bjorn3 May 22, 2025
c83358b
Move caller_location handling into codegen_intrinsic_call
bjorn3 May 22, 2025
6016f84
Pass PlaceRef rather than Bx::Value to codegen_intrinsic_call
bjorn3 May 22, 2025
0a14e1b
Remove usage of FnAbi in codegen_intrinsic_call
bjorn3 May 22, 2025
7122648
Don't depend on FnAbi for intrinsics
bjorn3 May 22, 2025
165fb98
Reduce indentation in codegen_panic_intrinsic
bjorn3 May 23, 2025
c6c2fde
Minor macro docs fixes
Sa4dUs May 26, 2025
df09fed
Remove `DropNodeKey::kind`.
nnethercote May 20, 2025
bf4532c
Rename `DropTree::drops` as `DropTree::drop_nodes`.
nnethercote May 20, 2025
84bb48f
Factor out some repeated code in `build_exit_tree`.
nnethercote May 20, 2025
ec8baa5
Avoid `fold`/`flat_map`.
nnethercote May 20, 2025
f83ecd8
Refactor the two-phase check for impls and impl items
mu001999 May 22, 2025
871327e
rustdoc: linking to a local proc macro no longer warns
lolbinarycat May 22, 2025
e908094
consider glob imports in cfg suggestion
bvanjoi May 25, 2025
adcd0bf
Fix ICE in tokenstream with contracts from parser recovery
chenyukang May 28, 2025
66772ca
Rollup merge of #140369 - jplatte:mutex-rwlock-data-ptr, r=Amanieu
tgross35 May 28, 2025
d69340d
Rollup merge of #140697 - Sa4dUs:split-autodiff, r=ZuseZ4
tgross35 May 28, 2025
0a72c96
Rollup merge of #141404 - bjorn3:refactor_cg_ssa_call_codegen, r=davi…
tgross35 May 28, 2025
784e30f
Rollup merge of #141407 - mu001999-contrib:dead-code/refactor, r=petr…
tgross35 May 28, 2025
b1fe746
Rollup merge of #141411 - lolbinarycat:rustdoc-link-proc-macro-91274,…
tgross35 May 28, 2025
6f2a01b
Rollup merge of #141548 - bvanjoi:issue-141256, r=petrochenkov
tgross35 May 28, 2025
e5f46ee
Rollup merge of #141627 - nnethercote:drop-cleanups, r=matthewjasper
tgross35 May 28, 2025
28ce71b
Rollup merge of #141670 - chenyukang:yukang-fix-ice-from-contracts, r…
tgross35 May 28, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Move some code around in codegen_call_terminator
  • Loading branch information
bjorn3 committed May 26, 2025
commit 1e9e17704adfc6bd6b01a0031b73fbc1682a0f1f
202 changes: 103 additions & 99 deletions compiler/rustc_codegen_ssa/src/mir/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use rustc_hir::lang_items::LangItem;
use rustc_middle::mir::{self, AssertKind, InlineAsmMacro, SwitchTargets, UnwindTerminateReason};
use rustc_middle::ty::layout::{HasTyCtxt, LayoutOf, ValidityRequirement};
use rustc_middle::ty::print::{with_no_trimmed_paths, with_no_visible_paths};
use rustc_middle::ty::{self, Instance, Ty};
use rustc_middle::ty::{self, Instance, List, Ty};
use rustc_middle::{bug, span_bug};
use rustc_session::config::OptLevel;
use rustc_span::source_map::Spanned;
Expand Down Expand Up @@ -827,7 +827,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
helper: &TerminatorCodegenHelper<'tcx>,
bx: &mut Bx,
intrinsic: ty::IntrinsicDef,
instance: Option<Instance<'tcx>>,
instance: Instance<'tcx>,
source_info: mir::SourceInfo,
target: Option<mir::BasicBlock>,
unwind: mir::UnwindAction,
Expand All @@ -837,7 +837,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
// These are intrinsics that compile to panics so that we can get a message
// which mentions the offending type, even from a const context.
if let Some(requirement) = ValidityRequirement::from_intrinsic(intrinsic.name) {
let ty = instance.unwrap().args.type_at(0);
let ty = instance.args.type_at(0);

let do_panic = !bx
.tcx()
Expand Down Expand Up @@ -910,35 +910,116 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
let callee = self.codegen_operand(bx, func);

let (instance, mut llfn) = match *callee.layout.ty.kind() {
ty::FnDef(def_id, args) => (
Some(ty::Instance::expect_resolve(
ty::FnDef(def_id, generic_args) => {
let instance = ty::Instance::expect_resolve(
bx.tcx(),
bx.typing_env(),
def_id,
args,
generic_args,
fn_span,
)),
None,
),
);

let instance = match instance.def {
// We don't need AsyncDropGlueCtorShim here because it is not `noop func`,
// it is `func returning noop future`
ty::InstanceKind::DropGlue(_, None) => {
// Empty drop glue; a no-op.
let target = target.unwrap();
return helper.funclet_br(self, bx, target, mergeable_succ);
}
ty::InstanceKind::Intrinsic(def_id) => {
let intrinsic = bx.tcx().intrinsic(def_id).unwrap();
if let Some(merging_succ) = self.codegen_panic_intrinsic(
&helper,
bx,
intrinsic,
instance,
source_info,
target,
unwind,
mergeable_succ,
) {
return merging_succ;
}

let fn_abi = bx.fn_abi_of_instance(instance, List::empty());

let mut llargs = Vec::with_capacity(1);
let ret_dest = self.make_return_dest(
bx,
destination,
&fn_abi.ret,
&mut llargs,
Some(intrinsic),
);
let dest = match ret_dest {
_ if fn_abi.ret.is_indirect() => llargs[0],
ReturnDest::Nothing => bx.const_undef(bx.type_ptr()),
ReturnDest::IndirectOperand(dst, _) | ReturnDest::Store(dst) => {
dst.val.llval
}
ReturnDest::DirectOperand(_) => {
bug!("Cannot use direct operand with an intrinsic call")
}
};

let args: Vec<_> =
args.iter().map(|arg| self.codegen_operand(bx, &arg.node)).collect();

if matches!(intrinsic, ty::IntrinsicDef { name: sym::caller_location, .. })
{
let location = self.get_caller_location(
bx,
mir::SourceInfo { span: fn_span, ..source_info },
);

assert_eq!(llargs, []);
if let ReturnDest::IndirectOperand(tmp, _) = ret_dest {
location.val.store(bx, tmp);
}
self.store_return(bx, ret_dest, &fn_abi.ret, location.immediate());
return helper.funclet_br(self, bx, target.unwrap(), mergeable_succ);
}

match Self::codegen_intrinsic_call(bx, instance, fn_abi, &args, dest, span)
{
Ok(()) => {
if let ReturnDest::IndirectOperand(dst, _) = ret_dest {
self.store_return(bx, ret_dest, &fn_abi.ret, dst.val.llval);
}

return if let Some(target) = target {
helper.funclet_br(self, bx, target, mergeable_succ)
} else {
bx.unreachable();
MergingSucc::False
};
}
Err(instance) => {
if intrinsic.must_be_overridden {
span_bug!(
span,
"intrinsic {} must be overridden by codegen backend, but isn't",
intrinsic.name,
);
}
instance
}
}
}
_ => instance,
};

(Some(instance), None)
}
ty::FnPtr(..) => (None, Some(callee.immediate())),
_ => bug!("{} is not callable", callee.layout.ty),
};

let def = instance.map(|i| i.def);

// We don't need AsyncDropGlueCtorShim here because it is not `noop func`,
// it is `func returning noop future`
if let Some(ty::InstanceKind::DropGlue(_, None)) = def {
// Empty drop glue; a no-op.
let target = target.unwrap();
return helper.funclet_br(self, bx, target, mergeable_succ);
}

// FIXME(eddyb) avoid computing this if possible, when `instance` is
// available - right now `sig` is only needed for getting the `abi`
// and figuring out how many extra args were passed to a C-variadic `fn`.
let sig = callee.layout.ty.fn_sig(bx.tcx());
let abi = sig.abi();

let extra_args = &args[sig.inputs().skip_binder().len()..];
let extra_args = bx.tcx().mk_type_list_from_iter(extra_args.iter().map(|op_arg| {
Expand All @@ -954,83 +1035,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
// The arguments we'll be passing. Plus one to account for outptr, if used.
let arg_count = fn_abi.args.len() + fn_abi.ret.is_indirect() as usize;

let instance = match def {
Some(ty::InstanceKind::Intrinsic(def_id)) => {
let intrinsic = bx.tcx().intrinsic(def_id).unwrap();
if let Some(merging_succ) = self.codegen_panic_intrinsic(
&helper,
bx,
intrinsic,
instance,
source_info,
target,
unwind,
mergeable_succ,
) {
return merging_succ;
}

let mut llargs = Vec::with_capacity(1);
let ret_dest = self.make_return_dest(
bx,
destination,
&fn_abi.ret,
&mut llargs,
Some(intrinsic),
);
let dest = match ret_dest {
_ if fn_abi.ret.is_indirect() => llargs[0],
ReturnDest::Nothing => bx.const_undef(bx.type_ptr()),
ReturnDest::IndirectOperand(dst, _) | ReturnDest::Store(dst) => dst.val.llval,
ReturnDest::DirectOperand(_) => {
bug!("Cannot use direct operand with an intrinsic call")
}
};

let args: Vec<_> =
args.iter().map(|arg| self.codegen_operand(bx, &arg.node)).collect();

if matches!(intrinsic, ty::IntrinsicDef { name: sym::caller_location, .. }) {
let location = self
.get_caller_location(bx, mir::SourceInfo { span: fn_span, ..source_info });

assert_eq!(llargs, []);
if let ReturnDest::IndirectOperand(tmp, _) = ret_dest {
location.val.store(bx, tmp);
}
self.store_return(bx, ret_dest, &fn_abi.ret, location.immediate());
return helper.funclet_br(self, bx, target.unwrap(), mergeable_succ);
}

let instance = *instance.as_ref().unwrap();
match Self::codegen_intrinsic_call(bx, instance, fn_abi, &args, dest, span) {
Ok(()) => {
if let ReturnDest::IndirectOperand(dst, _) = ret_dest {
self.store_return(bx, ret_dest, &fn_abi.ret, dst.val.llval);
}

return if let Some(target) = target {
helper.funclet_br(self, bx, target, mergeable_succ)
} else {
bx.unreachable();
MergingSucc::False
};
}
Err(instance) => {
if intrinsic.must_be_overridden {
span_bug!(
span,
"intrinsic {} must be overridden by codegen backend, but isn't",
intrinsic.name,
);
}
Some(instance)
}
}
}
_ => instance,
};

let mut llargs = Vec::with_capacity(arg_count);

// We still need to call `make_return_dest` even if there's no `target`, since
Expand All @@ -1040,7 +1044,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
let destination = target.map(|target| (return_dest, target));

// Split the rust-call tupled arguments off.
let (first_args, untuple) = if abi == ExternAbi::RustCall
let (first_args, untuple) = if sig.abi() == ExternAbi::RustCall
&& let Some((tup, args)) = args.split_last()
{
(args, Some(tup))
Expand All @@ -1055,7 +1059,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
'make_args: for (i, arg) in first_args.iter().enumerate() {
let mut op = self.codegen_operand(bx, &arg.node);

if let (0, Some(ty::InstanceKind::Virtual(_, idx))) = (i, def) {
if let (0, Some(ty::InstanceKind::Virtual(_, idx))) = (i, instance.map(|i| i.def)) {
match op.val {
Pair(data_ptr, meta) => {
// In the case of Rc<Self>, we need to explicitly pass a
Expand Down