Skip to content

Commit 19f0255

Browse files
authored
Merge pull request rust-lang#694 from Atul9/cargo-fmt
Format code using 'cargo fmt'
2 parents 5b17cf2 + f481a4b commit 19f0255

26 files changed

+831
-518
lines changed

Diff for: src/abi/comments.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ use std::borrow::Cow;
22

33
use rustc::mir;
44

5-
use crate::prelude::*;
65
use crate::abi::pass_mode::*;
6+
use crate::prelude::*;
77

88
pub fn add_args_header_comment(fx: &mut FunctionCx<impl Backend>) {
99
fx.add_global_comment(format!(

Diff for: src/abi/mod.rs

+84-62
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
#[cfg(debug_assertions)]
22
mod comments;
3-
mod returning;
43
mod pass_mode;
4+
mod returning;
55

66
use rustc_target::spec::abi::Abi;
77

8-
use crate::prelude::*;
98
use self::pass_mode::*;
9+
use crate::prelude::*;
1010

1111
pub use self::returning::codegen_return;
1212

13-
fn clif_sig_from_fn_sig<'tcx>(tcx: TyCtxt<'tcx>, sig: FnSig<'tcx>, is_vtable_fn: bool) -> Signature {
13+
fn clif_sig_from_fn_sig<'tcx>(
14+
tcx: TyCtxt<'tcx>,
15+
sig: FnSig<'tcx>,
16+
is_vtable_fn: bool,
17+
) -> Signature {
1418
let abi = match sig.abi {
1519
Abi::System => {
1620
if tcx.sess.target.target.options.is_like_windows {
@@ -47,12 +51,18 @@ fn clif_sig_from_fn_sig<'tcx>(tcx: TyCtxt<'tcx>, sig: FnSig<'tcx>, is_vtable_fn:
4751
if i == 0 && is_vtable_fn {
4852
// Virtual calls turn their self param into a thin pointer.
4953
// See https://github.com/rust-lang/rust/blob/37b6a5e5e82497caf5353d9d856e4eb5d14cbe06/src/librustc/ty/layout.rs#L2519-L2572 for more info
50-
layout = tcx.layout_of(ParamEnv::reveal_all().and(tcx.mk_mut_ptr(tcx.mk_unit()))).unwrap();
54+
layout = tcx
55+
.layout_of(ParamEnv::reveal_all().and(tcx.mk_mut_ptr(tcx.mk_unit())))
56+
.unwrap();
5157
}
5258
get_pass_mode(tcx, layout).get_param_ty(tcx).into_iter()
53-
}).flatten();
59+
})
60+
.flatten();
5461

55-
let (params, returns) = match get_pass_mode(tcx, tcx.layout_of(ParamEnv::reveal_all().and(output)).unwrap()) {
62+
let (params, returns) = match get_pass_mode(
63+
tcx,
64+
tcx.layout_of(ParamEnv::reveal_all().and(output)).unwrap(),
65+
) {
5666
PassMode::NoPass => (inputs.map(AbiParam::new).collect(), vec![]),
5767
PassMode::ByVal(ret_ty) => (
5868
inputs.map(AbiParam::new).collect(),
@@ -87,7 +97,8 @@ pub fn get_function_name_and_sig<'tcx>(
8797
support_vararg: bool,
8898
) -> (String, Signature) {
8999
assert!(!inst.substs.needs_infer() && !inst.substs.has_param_types());
90-
let fn_sig = tcx.normalize_erasing_late_bound_regions(ParamEnv::reveal_all(), &inst.fn_sig(tcx));
100+
let fn_sig =
101+
tcx.normalize_erasing_late_bound_regions(ParamEnv::reveal_all(), &inst.fn_sig(tcx));
91102
if fn_sig.c_variadic && !support_vararg {
92103
unimpl!("Variadic function definitions are not yet supported");
93104
}
@@ -141,7 +152,8 @@ impl<'tcx, B: Backend + 'static> FunctionCx<'_, 'tcx, B> {
141152
.module
142153
.declare_func_in_func(func_id, &mut self.bcx.func);
143154
let call_inst = self.bcx.ins().call(func_ref, args);
144-
#[cfg(debug_assertions)] {
155+
#[cfg(debug_assertions)]
156+
{
145157
self.add_comment(call_inst, format!("easy_call {}", name));
146158
}
147159
let results = self.bcx.inst_results(call_inst);
@@ -185,7 +197,10 @@ impl<'tcx, B: Backend + 'static> FunctionCx<'_, 'tcx, B> {
185197
}
186198

187199
fn self_sig(&self) -> FnSig<'tcx> {
188-
self.tcx.normalize_erasing_late_bound_regions(ParamEnv::reveal_all(), &self.instance.fn_sig(self.tcx))
200+
self.tcx.normalize_erasing_late_bound_regions(
201+
ParamEnv::reveal_all(),
202+
&self.instance.fn_sig(self.tcx),
203+
)
189204
}
190205

191206
fn return_layout(&self) -> TyLayout<'tcx> {
@@ -213,10 +228,7 @@ fn local_place<'tcx>(
213228
fx.local_map[&local]
214229
}
215230

216-
pub fn codegen_fn_prelude(
217-
fx: &mut FunctionCx<'_, '_, impl Backend>,
218-
start_ebb: Ebb,
219-
) {
231+
pub fn codegen_fn_prelude(fx: &mut FunctionCx<'_, '_, impl Backend>, start_ebb: Ebb) {
220232
let ssa_analyzed = crate::analyze::analyze(fx);
221233

222234
#[cfg(debug_assertions)]
@@ -250,20 +262,13 @@ pub fn codegen_fn_prelude(
250262

251263
let mut params = Vec::new();
252264
for (i, arg_ty) in tupled_arg_tys.types().enumerate() {
253-
let param = cvalue_for_param(
254-
fx,
255-
start_ebb,
256-
local,
257-
Some(i),
258-
arg_ty,
259-
);
265+
let param = cvalue_for_param(fx, start_ebb, local, Some(i), arg_ty);
260266
params.push(param);
261267
}
262268

263269
(local, ArgKind::Spread(params), arg_ty)
264270
} else {
265-
let param =
266-
cvalue_for_param(fx, start_ebb, local, None, arg_ty);
271+
let param = cvalue_for_param(fx, start_ebb, local, None, arg_ty);
267272
(local, ArgKind::Normal(param), arg_ty)
268273
}
269274
})
@@ -354,7 +359,9 @@ pub fn codegen_terminator_call<'tcx>(
354359
destination: &Option<(Place<'tcx>, BasicBlock)>,
355360
) {
356361
let fn_ty = fx.monomorphize(&func.ty(fx.mir, fx.tcx));
357-
let sig = fx.tcx.normalize_erasing_late_bound_regions(ParamEnv::reveal_all(), &fn_ty.fn_sig(fx.tcx));
362+
let sig = fx
363+
.tcx
364+
.normalize_erasing_late_bound_regions(ParamEnv::reveal_all(), &fn_ty.fn_sig(fx.tcx));
358365

359366
let destination = destination
360367
.as_ref()
@@ -365,7 +372,13 @@ pub fn codegen_terminator_call<'tcx>(
365372
ty::Instance::resolve(fx.tcx, ty::ParamEnv::reveal_all(), def_id, substs).unwrap();
366373

367374
if fx.tcx.symbol_name(instance).as_str().starts_with("llvm.") {
368-
crate::llvm_intrinsics::codegen_llvm_intrinsic_call(fx, &fx.tcx.symbol_name(instance).as_str(), substs, args, destination);
375+
crate::llvm_intrinsics::codegen_llvm_intrinsic_call(
376+
fx,
377+
&fx.tcx.symbol_name(instance).as_str(),
378+
substs,
379+
args,
380+
destination,
381+
);
369382
return;
370383
}
371384

@@ -430,7 +443,9 @@ fn codegen_call_inner<'tcx>(
430443
args: Vec<CValue<'tcx>>,
431444
ret_place: Option<CPlace<'tcx>>,
432445
) {
433-
let fn_sig = fx.tcx.normalize_erasing_late_bound_regions(ParamEnv::reveal_all(), &fn_ty.fn_sig(fx.tcx));
446+
let fn_sig = fx
447+
.tcx
448+
.normalize_erasing_late_bound_regions(ParamEnv::reveal_all(), &fn_ty.fn_sig(fx.tcx));
434449

435450
let instance = match fn_ty.sty {
436451
ty::FnDef(def_id, substs) => {
@@ -453,15 +468,24 @@ fn codegen_call_inner<'tcx>(
453468
let nop_inst = fx.bcx.ins().nop();
454469
fx.add_comment(
455470
nop_inst,
456-
format!("virtual call; self arg pass mode: {:?}", get_pass_mode(fx.tcx, args[0].layout())),
471+
format!(
472+
"virtual call; self arg pass mode: {:?}",
473+
get_pass_mode(fx.tcx, args[0].layout())
474+
),
457475
);
458476
}
459477
let (ptr, method) = crate::vtable::get_ptr_and_method_ref(fx, args[0], idx);
460478
(Some(method), Single(ptr), true)
461479
}
462480

463481
// Normal call
464-
Some(_) => (None, args.get(0).map(|arg| adjust_arg_for_abi(fx, *arg)).unwrap_or(Empty), false),
482+
Some(_) => (
483+
None,
484+
args.get(0)
485+
.map(|arg| adjust_arg_for_abi(fx, *arg))
486+
.unwrap_or(Empty),
487+
false,
488+
),
465489

466490
// Indirect call
467491
None => {
@@ -474,36 +498,40 @@ fn codegen_call_inner<'tcx>(
474498
.load_scalar(fx);
475499
(
476500
Some(func),
477-
args.get(0).map(|arg| adjust_arg_for_abi(fx, *arg)).unwrap_or(Empty),
501+
args.get(0)
502+
.map(|arg| adjust_arg_for_abi(fx, *arg))
503+
.unwrap_or(Empty),
478504
false,
479505
)
480506
}
481507
};
482508

483-
let (call_inst, call_args) = self::returning::codegen_with_call_return_arg(fx, fn_sig, ret_place, |fx, return_ptr| {
484-
let call_args: Vec<Value> = return_ptr
485-
.into_iter()
486-
.chain(first_arg.into_iter())
487-
.chain(
488-
args.into_iter()
489-
.skip(1)
490-
.map(|arg| adjust_arg_for_abi(fx, arg).into_iter())
491-
.flatten(),
492-
)
493-
.collect::<Vec<_>>();
509+
let (call_inst, call_args) =
510+
self::returning::codegen_with_call_return_arg(fx, fn_sig, ret_place, |fx, return_ptr| {
511+
let call_args: Vec<Value> = return_ptr
512+
.into_iter()
513+
.chain(first_arg.into_iter())
514+
.chain(
515+
args.into_iter()
516+
.skip(1)
517+
.map(|arg| adjust_arg_for_abi(fx, arg).into_iter())
518+
.flatten(),
519+
)
520+
.collect::<Vec<_>>();
494521

495-
let call_inst = if let Some(func_ref) = func_ref {
496-
let sig = fx
497-
.bcx
498-
.import_signature(clif_sig_from_fn_sig(fx.tcx, fn_sig, is_virtual_call));
499-
fx.bcx.ins().call_indirect(sig, func_ref, &call_args)
500-
} else {
501-
let func_ref = fx.get_function_ref(instance.expect("non-indirect call on non-FnDef type"));
502-
fx.bcx.ins().call(func_ref, &call_args)
503-
};
522+
let call_inst = if let Some(func_ref) = func_ref {
523+
let sig =
524+
fx.bcx
525+
.import_signature(clif_sig_from_fn_sig(fx.tcx, fn_sig, is_virtual_call));
526+
fx.bcx.ins().call_indirect(sig, func_ref, &call_args)
527+
} else {
528+
let func_ref =
529+
fx.get_function_ref(instance.expect("non-indirect call on non-FnDef type"));
530+
fx.bcx.ins().call(func_ref, &call_args)
531+
};
504532

505-
(call_inst, call_args)
506-
});
533+
(call_inst, call_args)
534+
});
507535

508536
// FIXME find a cleaner way to support varargs
509537
if fn_sig.c_variadic {
@@ -526,10 +554,7 @@ fn codegen_call_inner<'tcx>(
526554
}
527555
}
528556

529-
pub fn codegen_drop<'tcx>(
530-
fx: &mut FunctionCx<'_, 'tcx, impl Backend>,
531-
drop_place: CPlace<'tcx>,
532-
) {
557+
pub fn codegen_drop<'tcx>(fx: &mut FunctionCx<'_, 'tcx, impl Backend>, drop_place: CPlace<'tcx>) {
533558
let ty = drop_place.layout().ty;
534559
let drop_fn = Instance::resolve_drop_in_place(fx.tcx, ty);
535560

@@ -542,7 +567,10 @@ pub fn codegen_drop<'tcx>(
542567
let (ptr, vtable) = drop_place.to_addr_maybe_unsized(fx);
543568
let drop_fn = crate::vtable::drop_fn_of_obj(fx, vtable.unwrap());
544569

545-
let fn_sig = fx.tcx.normalize_erasing_late_bound_regions(ParamEnv::reveal_all(), &drop_fn_ty.fn_sig(fx.tcx));
570+
let fn_sig = fx.tcx.normalize_erasing_late_bound_regions(
571+
ParamEnv::reveal_all(),
572+
&drop_fn_ty.fn_sig(fx.tcx),
573+
);
546574

547575
assert_eq!(fn_sig.output(), fx.tcx.mk_unit());
548576

@@ -564,13 +592,7 @@ pub fn codegen_drop<'tcx>(
564592
);
565593
drop_place.write_place_ref(fx, arg_place);
566594
let arg_value = arg_place.to_cvalue(fx);
567-
codegen_call_inner(
568-
fx,
569-
None,
570-
drop_fn_ty,
571-
vec![arg_value],
572-
None,
573-
);
595+
codegen_call_inner(fx, None, drop_fn_ty, vec![arg_value], None);
574596
}
575597
}
576598
}

Diff for: src/abi/pass_mode.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,14 @@ impl<T: std::fmt::Debug> EmptySinglePair<T> {
5050
pub fn assert_single(self) -> T {
5151
match self {
5252
Single(v) => v,
53-
_ => panic!("Called assert_single on {:?}", self)
53+
_ => panic!("Called assert_single on {:?}", self),
5454
}
5555
}
5656

5757
pub fn assert_pair(self) -> (T, T) {
5858
match self {
5959
Pair(a, b) => (a, b),
60-
_ => panic!("Called assert_pair on {:?}", self)
60+
_ => panic!("Called assert_pair on {:?}", self),
6161
}
6262
}
6363
}
@@ -75,10 +75,7 @@ impl PassMode {
7575
}
7676
}
7777

78-
pub fn get_pass_mode<'tcx>(
79-
tcx: TyCtxt<'tcx>,
80-
layout: TyLayout<'tcx>,
81-
) -> PassMode {
78+
pub fn get_pass_mode<'tcx>(tcx: TyCtxt<'tcx>, layout: TyLayout<'tcx>) -> PassMode {
8279
assert!(!layout.is_unsized());
8380

8481
if layout.is_zst() {

Diff for: src/abi/returning.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use crate::prelude::*;
21
use crate::abi::pass_mode::*;
2+
use crate::prelude::*;
33

44
pub fn codegen_return_param(
55
fx: &mut FunctionCx<impl Backend>,
@@ -27,10 +27,8 @@ pub fn codegen_return_param(
2727
}
2828
PassMode::ByRef => {
2929
let ret_param = fx.bcx.append_ebb_param(start_ebb, fx.pointer_type);
30-
fx.local_map.insert(
31-
RETURN_PLACE,
32-
CPlace::for_addr(ret_param, ret_layout),
33-
);
30+
fx.local_map
31+
.insert(RETURN_PLACE, CPlace::for_addr(ret_param, ret_layout));
3432

3533
Single(ret_param)
3634
}

0 commit comments

Comments
 (0)