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

Commit 452656b

Browse files
authored
Merge pull request rust-lang#1079 from CohenArthur/fmt-master
Run cargo fmt on the whole project
2 parents 5dec38e + fc9f16b commit 452656b

40 files changed

+1566
-789
lines changed

src/abi/comments.rs

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,10 @@ pub(super) fn add_local_place_comments<'tcx>(
8080
}
8181
CPlaceInner::VarPair(place_local, var1, var2) => {
8282
assert_eq!(local, place_local);
83-
("ssa", Cow::Owned(format!(",var=({}, {})", var1.index(), var2.index())))
83+
(
84+
"ssa",
85+
Cow::Owned(format!(",var=({}, {})", var1.index(), var2.index())),
86+
)
8487
}
8588
CPlaceInner::VarLane(_local, _var, _lane) => unreachable!(),
8689
CPlaceInner::Addr(ptr, meta) => {
@@ -90,15 +93,18 @@ pub(super) fn add_local_place_comments<'tcx>(
9093
Cow::Borrowed("")
9194
};
9295
match ptr.base_and_offset() {
93-
(crate::pointer::PointerBase::Addr(addr), offset) => {
94-
("reuse", format!("storage={}{}{}", addr, offset, meta).into())
95-
}
96-
(crate::pointer::PointerBase::Stack(stack_slot), offset) => {
97-
("stack", format!("storage={}{}{}", stack_slot, offset, meta).into())
98-
}
99-
(crate::pointer::PointerBase::Dangling(align), offset) => {
100-
("zst", format!("align={},offset={}", align.bytes(), offset).into())
101-
}
96+
(crate::pointer::PointerBase::Addr(addr), offset) => (
97+
"reuse",
98+
format!("storage={}{}{}", addr, offset, meta).into(),
99+
),
100+
(crate::pointer::PointerBase::Stack(stack_slot), offset) => (
101+
"stack",
102+
format!("storage={}{}{}", stack_slot, offset, meta).into(),
103+
),
104+
(crate::pointer::PointerBase::Dangling(align), offset) => (
105+
"zst",
106+
format!("align={},offset={}", align.bytes(), offset).into(),
107+
),
102108
}
103109
}
104110
};
@@ -111,7 +117,11 @@ pub(super) fn add_local_place_comments<'tcx>(
111117
size.bytes(),
112118
align.abi.bytes(),
113119
align.pref.bytes(),
114-
if extra.is_empty() { "" } else { " " },
120+
if extra.is_empty() {
121+
""
122+
} else {
123+
" "
124+
},
115125
extra,
116126
));
117127
}

src/abi/mod.rs

Lines changed: 75 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ mod comments;
33
mod pass_mode;
44
mod returning;
55

6-
use rustc_target::spec::abi::Abi;
76
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
7+
use rustc_target::spec::abi::Abi;
88

99
use cranelift_codegen::ir::{AbiParam, ArgumentPurpose};
1010

@@ -14,6 +14,7 @@ use crate::prelude::*;
1414
pub(crate) use self::returning::{can_return_to_ssa_var, codegen_return};
1515

1616
// Copied from https://github.com/rust-lang/rust/blob/f52c72948aa1dd718cc1f168d21c91c584c0a662/src/librustc_middle/ty/layout.rs#L2301
17+
#[rustfmt::skip]
1718
pub(crate) fn fn_sig_for_fn_abi<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) -> ty::PolyFnSig<'tcx> {
1819
use rustc_middle::ty::subst::Subst;
1920

@@ -102,8 +103,16 @@ fn clif_sig_from_fn_sig<'tcx>(
102103
abi => abi,
103104
};
104105
let (call_conv, inputs, output): (CallConv, Vec<Ty<'tcx>>, Ty<'tcx>) = match abi {
105-
Abi::Rust => (CallConv::triple_default(triple), sig.inputs().to_vec(), sig.output()),
106-
Abi::C | Abi::Unadjusted => (CallConv::triple_default(triple), sig.inputs().to_vec(), sig.output()),
106+
Abi::Rust => (
107+
CallConv::triple_default(triple),
108+
sig.inputs().to_vec(),
109+
sig.output(),
110+
),
111+
Abi::C | Abi::Unadjusted => (
112+
CallConv::triple_default(triple),
113+
sig.inputs().to_vec(),
114+
sig.output(),
115+
),
107116
Abi::SysV64 => (CallConv::SystemV, sig.inputs().to_vec(), sig.output()),
108117
Abi::RustCall => {
109118
assert_eq!(sig.inputs().len(), 2);
@@ -116,7 +125,11 @@ fn clif_sig_from_fn_sig<'tcx>(
116125
(CallConv::triple_default(triple), inputs, sig.output())
117126
}
118127
Abi::System => unreachable!(),
119-
Abi::RustIntrinsic => (CallConv::triple_default(triple), sig.inputs().to_vec(), sig.output()),
128+
Abi::RustIntrinsic => (
129+
CallConv::triple_default(triple),
130+
sig.inputs().to_vec(),
131+
sig.output(),
132+
),
120133
_ => unimplemented!("unsupported abi {:?}", sig.abi),
121134
};
122135

@@ -163,10 +176,7 @@ fn clif_sig_from_fn_sig<'tcx>(
163176
tcx.layout_of(ParamEnv::reveal_all().and(output)).unwrap(),
164177
) {
165178
PassMode::NoPass => (inputs.collect(), vec![]),
166-
PassMode::ByVal(ret_ty) => (
167-
inputs.collect(),
168-
vec![AbiParam::new(ret_ty)],
169-
),
179+
PassMode::ByVal(ret_ty) => (inputs.collect(), vec![AbiParam::new(ret_ty)]),
170180
PassMode::ByValPair(ret_ty_a, ret_ty_b) => (
171181
inputs.collect(),
172182
vec![AbiParam::new(ret_ty_a), AbiParam::new(ret_ty_b)],
@@ -202,12 +212,24 @@ pub(crate) fn get_function_name_and_sig<'tcx>(
202212
support_vararg: bool,
203213
) -> (String, Signature) {
204214
assert!(!inst.substs.needs_infer());
205-
let fn_sig =
206-
tcx.normalize_erasing_late_bound_regions(ParamEnv::reveal_all(), &fn_sig_for_fn_abi(tcx, inst));
215+
let fn_sig = tcx.normalize_erasing_late_bound_regions(
216+
ParamEnv::reveal_all(),
217+
&fn_sig_for_fn_abi(tcx, inst),
218+
);
207219
if fn_sig.c_variadic && !support_vararg {
208-
tcx.sess.span_fatal(tcx.def_span(inst.def_id()), "Variadic function definitions are not yet supported");
220+
tcx.sess.span_fatal(
221+
tcx.def_span(inst.def_id()),
222+
"Variadic function definitions are not yet supported",
223+
);
209224
}
210-
let sig = clif_sig_from_fn_sig(tcx, triple, fn_sig, tcx.def_span(inst.def_id()), false, inst.def.requires_caller_location(tcx));
225+
let sig = clif_sig_from_fn_sig(
226+
tcx,
227+
triple,
228+
fn_sig,
229+
tcx.def_span(inst.def_id()),
230+
false,
231+
inst.def.requires_caller_location(tcx),
232+
);
211233
(tcx.symbol_name(inst).name.to_string(), sig)
212234
}
213235

@@ -228,7 +250,8 @@ impl<'tcx, B: Backend + 'static> FunctionCx<'_, 'tcx, B> {
228250
pub(crate) fn get_function_ref(&mut self, inst: Instance<'tcx>) -> FuncRef {
229251
let func_id = import_function(self.tcx, &mut self.cx.module, inst);
230252
let func_ref = self
231-
.cx.module
253+
.cx
254+
.module
232255
.declare_func_in_func(func_id, &mut self.bcx.func);
233256

234257
#[cfg(debug_assertions)]
@@ -250,11 +273,13 @@ impl<'tcx, B: Backend + 'static> FunctionCx<'_, 'tcx, B> {
250273
call_conv: CallConv::triple_default(self.triple()),
251274
};
252275
let func_id = self
253-
.cx.module
276+
.cx
277+
.module
254278
.declare_function(&name, Linkage::Import, &sig)
255279
.unwrap();
256280
let func_ref = self
257-
.cx.module
281+
.cx
282+
.module
258283
.declare_func_in_func(func_id, &mut self.bcx.func);
259284
let call_inst = self.bcx.ins().call(func_ref, args);
260285
#[cfg(debug_assertions)]
@@ -376,7 +401,9 @@ pub(crate) fn codegen_fn_prelude<'tcx>(
376401
assert!(fx.caller_location.is_none());
377402
if fx.instance.def.requires_caller_location(fx.tcx) {
378403
// Store caller location for `#[track_caller]`.
379-
fx.caller_location = Some(cvalue_for_param(fx, start_block, None, None, fx.tcx.caller_location_ty()).unwrap());
404+
fx.caller_location = Some(
405+
cvalue_for_param(fx, start_block, None, None, fx.tcx.caller_location_ty()).unwrap(),
406+
);
380407
}
381408

382409
fx.bcx.switch_to_block(start_block);
@@ -502,17 +529,20 @@ pub(crate) fn codegen_terminator_call<'tcx>(
502529
fx.bcx.ins().jump(ret_block, &[]);
503530
return;
504531
}
505-
_ => Some(instance)
532+
_ => Some(instance),
506533
}
507534
} else {
508535
None
509536
};
510537

511-
let is_cold =
512-
instance.map(|inst|
513-
fx.tcx.codegen_fn_attrs(inst.def_id())
514-
.flags.contains(CodegenFnAttrFlags::COLD))
515-
.unwrap_or(false);
538+
let is_cold = instance
539+
.map(|inst| {
540+
fx.tcx
541+
.codegen_fn_attrs(inst.def_id())
542+
.flags
543+
.contains(CodegenFnAttrFlags::COLD)
544+
})
545+
.unwrap_or(false);
516546
if is_cold {
517547
fx.cold_blocks.insert(current_block);
518548
}
@@ -524,9 +554,7 @@ pub(crate) fn codegen_terminator_call<'tcx>(
524554
let pack_arg = trans_operand(fx, &args[1]);
525555

526556
let tupled_arguments = match pack_arg.layout().ty.kind {
527-
ty::Tuple(ref tupled_arguments) => {
528-
tupled_arguments
529-
}
557+
ty::Tuple(ref tupled_arguments) => tupled_arguments,
530558
_ => bug!("argument to function with \"rust-call\" ABI is not a tuple"),
531559
};
532560

@@ -582,8 +610,7 @@ pub(crate) fn codegen_terminator_call<'tcx>(
582610
let nop_inst = fx.bcx.ins().nop();
583611
fx.add_comment(nop_inst, "indirect call");
584612
}
585-
let func = trans_operand(fx, func)
586-
.load_scalar(fx);
613+
let func = trans_operand(fx, func).load_scalar(fx);
587614
(
588615
Some(func),
589616
args.get(0)
@@ -608,7 +635,10 @@ pub(crate) fn codegen_terminator_call<'tcx>(
608635
)
609636
.collect::<Vec<_>>();
610637

611-
if instance.map(|inst| inst.def.requires_caller_location(fx.tcx)).unwrap_or(false) {
638+
if instance
639+
.map(|inst| inst.def.requires_caller_location(fx.tcx))
640+
.unwrap_or(false)
641+
{
612642
// Pass the caller location for `#[track_caller]`.
613643
let caller_location = fx.get_caller_location(span);
614644
call_args.extend(adjust_arg_for_abi(fx, caller_location).into_iter());
@@ -637,7 +667,10 @@ pub(crate) fn codegen_terminator_call<'tcx>(
637667
// FIXME find a cleaner way to support varargs
638668
if fn_sig.c_variadic {
639669
if fn_sig.abi != Abi::C {
640-
fx.tcx.sess.span_fatal(span, &format!("Variadic call for non-C abi {:?}", fn_sig.abi));
670+
fx.tcx.sess.span_fatal(
671+
span,
672+
&format!("Variadic call for non-C abi {:?}", fn_sig.abi),
673+
);
641674
}
642675
let sig_ref = fx.bcx.func.dfg.call_signature(call_inst).unwrap();
643676
let abi_params = call_args
@@ -646,7 +679,9 @@ pub(crate) fn codegen_terminator_call<'tcx>(
646679
let ty = fx.bcx.func.dfg.value_type(arg);
647680
if !ty.is_int() {
648681
// FIXME set %al to upperbound on float args once floats are supported
649-
fx.tcx.sess.span_fatal(span, &format!("Non int ty {:?} for variadic call", ty));
682+
fx.tcx
683+
.sess
684+
.span_fatal(span, &format!("Non int ty {:?} for variadic call", ty));
650685
}
651686
AbiParam::new(ty)
652687
})
@@ -700,13 +735,16 @@ pub(crate) fn codegen_drop<'tcx>(
700735
_ => {
701736
assert!(!matches!(drop_fn.def, InstanceDef::Virtual(_, _)));
702737

703-
let arg_value = drop_place.place_ref(fx, fx.layout_of(fx.tcx.mk_ref(
704-
&ty::RegionKind::ReErased,
705-
TypeAndMut {
706-
ty,
707-
mutbl: crate::rustc_hir::Mutability::Mut,
708-
},
709-
)));
738+
let arg_value = drop_place.place_ref(
739+
fx,
740+
fx.layout_of(fx.tcx.mk_ref(
741+
&ty::RegionKind::ReErased,
742+
TypeAndMut {
743+
ty,
744+
mutbl: crate::rustc_hir::Mutability::Mut,
745+
},
746+
)),
747+
);
710748
let arg_value = adjust_arg_for_abi(fx, arg_value);
711749

712750
let mut call_args: Vec<Value> = arg_value.into_iter().collect::<Vec<_>>();

src/abi/pass_mode.rs

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -83,17 +83,17 @@ pub(super) fn get_pass_mode<'tcx>(tcx: TyCtxt<'tcx>, layout: TyAndLayout<'tcx>)
8383
} else {
8484
match &layout.abi {
8585
Abi::Uninhabited => PassMode::NoPass,
86-
Abi::Scalar(scalar) => {
87-
PassMode::ByVal(scalar_to_clif_type(tcx, scalar.clone()))
88-
}
86+
Abi::Scalar(scalar) => PassMode::ByVal(scalar_to_clif_type(tcx, scalar.clone())),
8987
Abi::ScalarPair(a, b) => {
9088
let a = scalar_to_clif_type(tcx, a.clone());
9189
let b = scalar_to_clif_type(tcx, b.clone());
9290
if a == types::I128 && b == types::I128 {
9391
// Returning (i128, i128) by-val-pair would take 4 regs, while only 3 are
9492
// available on x86_64. Cranelift gets confused when too many return params
9593
// are used.
96-
PassMode::ByRef { size: Some(layout.size) }
94+
PassMode::ByRef {
95+
size: Some(layout.size),
96+
}
9797
} else {
9898
PassMode::ByValPair(a, b)
9999
}
@@ -104,11 +104,15 @@ pub(super) fn get_pass_mode<'tcx>(tcx: TyCtxt<'tcx>, layout: TyAndLayout<'tcx>)
104104
if let Some(vector_ty) = crate::intrinsics::clif_vector_type(tcx, layout) {
105105
PassMode::ByVal(vector_ty)
106106
} else {
107-
PassMode::ByRef { size: Some(layout.size) }
107+
PassMode::ByRef {
108+
size: Some(layout.size),
109+
}
108110
}
109111
}
110112

111-
Abi::Aggregate { sized: true } => PassMode::ByRef { size: Some(layout.size) },
113+
Abi::Aggregate { sized: true } => PassMode::ByRef {
114+
size: Some(layout.size),
115+
},
112116
Abi::Aggregate { sized: false } => PassMode::ByRef { size: None },
113117
}
114118
}
@@ -125,22 +129,18 @@ pub(super) fn adjust_arg_for_abi<'tcx>(
125129
let (a, b) = arg.load_scalar_pair(fx);
126130
Pair(a, b)
127131
}
128-
PassMode::ByRef { size: _ } => {
129-
match arg.force_stack(fx) {
130-
(ptr, None) => Single(ptr.get_addr(fx)),
131-
(ptr, Some(meta)) => Pair(ptr.get_addr(fx), meta),
132-
}
133-
}
132+
PassMode::ByRef { size: _ } => match arg.force_stack(fx) {
133+
(ptr, None) => Single(ptr.get_addr(fx)),
134+
(ptr, Some(meta)) => Pair(ptr.get_addr(fx), meta),
135+
},
134136
}
135137
}
136138

137139
pub(super) fn cvalue_for_param<'tcx>(
138140
fx: &mut FunctionCx<'_, 'tcx, impl Backend>,
139141
start_block: Block,
140-
#[cfg_attr(not(debug_assertions), allow(unused_variables))]
141-
local: Option<mir::Local>,
142-
#[cfg_attr(not(debug_assertions), allow(unused_variables))]
143-
local_field: Option<usize>,
142+
#[cfg_attr(not(debug_assertions), allow(unused_variables))] local: Option<mir::Local>,
143+
#[cfg_attr(not(debug_assertions), allow(unused_variables))] local_field: Option<usize>,
144144
arg_ty: Ty<'tcx>,
145145
) -> Option<CValue<'tcx>> {
146146
let layout = fx.layout_of(arg_ty);
@@ -171,7 +171,10 @@ pub(super) fn cvalue_for_param<'tcx>(
171171
let (a, b) = block_params.assert_pair();
172172
Some(CValue::by_val_pair(a, b, layout))
173173
}
174-
PassMode::ByRef { size: Some(_) } => Some(CValue::by_ref(Pointer::new(block_params.assert_single()), layout)),
174+
PassMode::ByRef { size: Some(_) } => Some(CValue::by_ref(
175+
Pointer::new(block_params.assert_single()),
176+
layout,
177+
)),
175178
PassMode::ByRef { size: None } => {
176179
let (ptr, meta) = block_params.assert_pair();
177180
Some(CValue::by_ref_unsized(Pointer::new(ptr), meta, layout))

0 commit comments

Comments
 (0)