Skip to content

Commit 61f4773

Browse files
committed
codegen_llvm: whitespace & formatting improvements
1 parent ef5c00d commit 61f4773

File tree

13 files changed

+69
-80
lines changed

13 files changed

+69
-80
lines changed

src/librustc_codegen_llvm/abi.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ impl LlvmType for CastTarget {
150150
// Create list of fields in the main structure
151151
let mut args: Vec<_> =
152152
self.prefix.iter().flat_map(|option_kind| option_kind.map(
153-
|kind| Reg { kind: kind, size: self.prefix_chunk }.llvm_type(cx)))
153+
|kind| Reg { kind: kind, size: self.prefix_chunk }.llvm_type(cx)))
154154
.chain((0..rest_count).map(|_| rest_ll_unit))
155155
.collect();
156156

@@ -259,8 +259,7 @@ impl ArgTypeExt<'ll, 'tcx> for ArgType<'tcx, Ty<'tcx>> {
259259
}
260260

261261
pub trait FnTypeExt<'tcx> {
262-
fn of_instance(cx: &CodegenCx<'ll, 'tcx>, instance: &ty::Instance<'tcx>)
263-
-> Self;
262+
fn of_instance(cx: &CodegenCx<'ll, 'tcx>, instance: &ty::Instance<'tcx>) -> Self;
264263
fn new(cx: &CodegenCx<'ll, 'tcx>,
265264
sig: ty::FnSig<'tcx>,
266265
extra_args: &[Ty<'tcx>]) -> Self;
@@ -283,25 +282,24 @@ pub trait FnTypeExt<'tcx> {
283282
}
284283

285284
impl<'tcx> FnTypeExt<'tcx> for FnType<'tcx, Ty<'tcx>> {
286-
fn of_instance(cx: &CodegenCx<'ll, 'tcx>, instance: &ty::Instance<'tcx>)
287-
-> Self {
285+
fn of_instance(cx: &CodegenCx<'ll, 'tcx>, instance: &ty::Instance<'tcx>) -> Self {
288286
let fn_ty = instance.ty(cx.tcx);
289287
let sig = ty_fn_sig(cx, fn_ty);
290288
let sig = cx.tcx.normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), &sig);
291289
FnType::new(cx, sig, &[])
292290
}
293291

294292
fn new(cx: &CodegenCx<'ll, 'tcx>,
295-
sig: ty::FnSig<'tcx>,
296-
extra_args: &[Ty<'tcx>]) -> Self {
293+
sig: ty::FnSig<'tcx>,
294+
extra_args: &[Ty<'tcx>]) -> Self {
297295
FnType::new_internal(cx, sig, extra_args, |ty, _| {
298296
ArgType::new(cx.layout_of(ty))
299297
})
300298
}
301299

302300
fn new_vtable(cx: &CodegenCx<'ll, 'tcx>,
303-
sig: ty::FnSig<'tcx>,
304-
extra_args: &[Ty<'tcx>]) -> Self {
301+
sig: ty::FnSig<'tcx>,
302+
extra_args: &[Ty<'tcx>]) -> Self {
305303
FnType::new_internal(cx, sig, extra_args, |ty, arg_idx| {
306304
let mut layout = cx.layout_of(ty);
307305
// Don't pass the vtable, it's not an argument of the virtual fn.

src/librustc_codegen_llvm/base.rs

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,8 @@ pub fn unsized_info(
213213
vtable_ptr.llvm_type(cx))
214214
}
215215
_ => bug!("unsized_info: invalid unsizing {:?} -> {:?}",
216-
source,
217-
target),
216+
source,
217+
target),
218218
}
219219
}
220220

@@ -340,11 +340,11 @@ pub fn cast_shift_expr_rhs(
340340
}
341341

342342
fn cast_shift_rhs<'ll, F, G>(op: hir::BinOpKind,
343-
lhs: &'ll Value,
344-
rhs: &'ll Value,
345-
trunc: F,
346-
zext: G)
347-
-> &'ll Value
343+
lhs: &'ll Value,
344+
rhs: &'ll Value,
345+
trunc: F,
346+
zext: G)
347+
-> &'ll Value
348348
where F: FnOnce(&'ll Value, &'ll Type) -> &'ll Value,
349349
G: FnOnce(&'ll Value, &'ll Type) -> &'ll Value
350350
{
@@ -566,8 +566,8 @@ fn maybe_create_entry_wrapper(cx: &CodegenCx) {
566566
if declare::get_defined_value(cx, "main").is_some() {
567567
// FIXME: We should be smart and show a better diagnostic here.
568568
cx.sess().struct_span_err(sp, "entry symbol `main` defined multiple times")
569-
.help("did you use #[no_mangle] on `fn main`? Use #[start] instead")
570-
.emit();
569+
.help("did you use #[no_mangle] on `fn main`? Use #[start] instead")
570+
.emit();
571571
cx.sess().abort_if_errors();
572572
bug!();
573573
}
@@ -736,9 +736,9 @@ fn determine_cgu_reuse<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
736736
}
737737

738738
pub fn codegen_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
739-
rx: mpsc::Receiver<Box<dyn Any + Send>>)
740-
-> OngoingCodegen {
741-
739+
rx: mpsc::Receiver<Box<dyn Any + Send>>)
740+
-> OngoingCodegen
741+
{
742742
check_for_rustc_errors_attr(tcx);
743743

744744
if let Some(true) = tcx.sess.opts.debugging_opts.thinlto {
@@ -803,8 +803,7 @@ pub fn codegen_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
803803

804804
// Run the monomorphization collector and partition the collected items into
805805
// codegen units.
806-
let codegen_units =
807-
tcx.collect_and_partition_mono_items(LOCAL_CRATE).1;
806+
let codegen_units = tcx.collect_and_partition_mono_items(LOCAL_CRATE).1;
808807
let codegen_units = (*codegen_units).clone();
809808

810809
// Force all codegen_unit queries so they are already either red or green
@@ -988,7 +987,7 @@ fn collect_and_partition_mono_items<'a, 'tcx>(
988987
if mode_string != "lazy" {
989988
let message = format!("Unknown codegen-item collection mode '{}'. \
990989
Falling back to 'lazy' mode.",
991-
mode_string);
990+
mode_string);
992991
tcx.sess.warn(&message);
993992
}
994993

src/librustc_codegen_llvm/builder.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,10 @@ impl Builder<'a, 'll, 'tcx> {
110110
}
111111
if self.cx.sess().count_llvm_insns() {
112112
*self.cx.stats
113-
.borrow_mut()
114-
.llvm_insns
115-
.entry(category.to_string())
116-
.or_insert(0) += 1;
113+
.borrow_mut()
114+
.llvm_insns
115+
.entry(category.to_string())
116+
.or_insert(0) += 1;
117117
}
118118
}
119119

@@ -735,9 +735,9 @@ impl Builder<'a, 'll, 'tcx> {
735735
}
736736

737737
pub fn inline_asm_call(&self, asm: *const c_char, cons: *const c_char,
738-
inputs: &[&'ll Value], output: &'ll Type,
739-
volatile: bool, alignstack: bool,
740-
dia: AsmDialect) -> Option<&'ll Value> {
738+
inputs: &[&'ll Value], output: &'ll Type,
739+
volatile: bool, alignstack: bool,
740+
dia: AsmDialect) -> Option<&'ll Value> {
741741
self.count_insn("inlineasm");
742742

743743
let volatile = if volatile { llvm::True }
@@ -1093,7 +1093,7 @@ impl Builder<'a, 'll, 'tcx> {
10931093
) -> &'ll Value {
10941094
unsafe {
10951095
llvm::LLVMRustBuildAtomicCmpXchg(self.llbuilder, dst, cmp, src,
1096-
order, failure_order, weak)
1096+
order, failure_order, weak)
10971097
}
10981098
}
10991099
pub fn atomic_rmw(

src/librustc_codegen_llvm/consts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ pub fn get_static(cx: &CodegenCx<'ll, '_>, def_id: DefId) -> &'ll Value {
124124
assert!(!defined_in_current_codegen_unit,
125125
"consts::get_static() should always hit the cache for \
126126
statics defined in the same CGU, but did not for `{:?}`",
127-
def_id);
127+
def_id);
128128

129129
let ty = instance.ty(cx.tcx);
130130
let sym = cx.tcx.symbol_name(instance).as_str();

src/librustc_codegen_llvm/context.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ pub struct CodegenCx<'a, 'tcx: 'a> {
5959
/// Cache instances of monomorphic and polymorphic items
6060
pub instances: RefCell<FxHashMap<Instance<'tcx>, &'a Value>>,
6161
/// Cache generated vtables
62-
pub vtables: RefCell<FxHashMap<(Ty<'tcx>,
63-
Option<ty::PolyExistentialTraitRef<'tcx>>), &'a Value>>,
62+
pub vtables: RefCell<FxHashMap<(Ty<'tcx>, Option<ty::PolyExistentialTraitRef<'tcx>>),
63+
&'a Value>>,
6464
/// Cache of constant strings,
6565
pub const_cstr_cache: RefCell<FxHashMap<LocalInternedString, &'a Value>>,
6666

@@ -213,9 +213,9 @@ pub unsafe fn create_module(
213213

214214
impl<'a, 'tcx> CodegenCx<'a, 'tcx> {
215215
crate fn new(tcx: TyCtxt<'a, 'tcx, 'tcx>,
216-
codegen_unit: Arc<CodegenUnit<'tcx>>,
217-
llvm_module: &'a ::ModuleLlvm)
218-
-> CodegenCx<'a, 'tcx> {
216+
codegen_unit: Arc<CodegenUnit<'tcx>>,
217+
llvm_module: &'a ::ModuleLlvm)
218+
-> CodegenCx<'a, 'tcx> {
219219
// An interesting part of Windows which MSVC forces our hand on (and
220220
// apparently MinGW didn't) is the usage of `dllimport` and `dllexport`
221221
// attributes in LLVM IR as well as native dependencies (in C these
@@ -270,8 +270,8 @@ impl<'a, 'tcx> CodegenCx<'a, 'tcx> {
270270
let dbg_cx = if tcx.sess.opts.debuginfo != DebugInfo::None {
271271
let dctx = debuginfo::CrateDebugContext::new(llmod);
272272
debuginfo::metadata::compile_unit_metadata(tcx,
273-
&codegen_unit.name().as_str(),
274-
&dctx);
273+
&codegen_unit.name().as_str(),
274+
&dctx);
275275
Some(dctx)
276276
} else {
277277
None

src/librustc_codegen_llvm/glue.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ pub fn size_and_align_of_dst(bx: &Builder<'_, 'll, 'tcx>, t: Ty<'tcx>, info: Opt
9797
C_usize(cx, std::cmp::max(sized_align, unsized_align) as u64)
9898
}
9999
_ => bx.select(bx.icmp(llvm::IntUGT, sized_align, unsized_align),
100-
sized_align,
101-
unsized_align)
100+
sized_align,
101+
unsized_align)
102102
};
103103

104104
// Issue #27023: must add any necessary padding to `size`

src/librustc_codegen_llvm/intrinsic.rs

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ pub fn codegen_intrinsic_call(
115115
let llval = match name {
116116
_ if simple.is_some() => {
117117
bx.call(simple.unwrap(),
118-
&args.iter().map(|arg| arg.immediate()).collect::<Vec<_>>(),
119-
None)
118+
&args.iter().map(|arg| arg.immediate()).collect::<Vec<_>>(),
119+
None)
120120
}
121121
"unreachable" => {
122122
return;
@@ -373,7 +373,6 @@ pub fn codegen_intrinsic_call(
373373
return;
374374
}
375375
}
376-
377376
},
378377
"fadd_fast" | "fsub_fast" | "fmul_fast" | "fdiv_fast" | "frem_fast" => {
379378
let sty = &arg_tys[0].sty;
@@ -822,8 +821,7 @@ fn codegen_msvc_try(
822821
let i64p = Type::i64(cx).ptr_to();
823822
let ptr_align = bx.tcx().data_layout.pointer_align;
824823
let slot = bx.alloca(i64p, "slot", ptr_align);
825-
bx.invoke(func, &[data], normal.llbb(), catchswitch.llbb(),
826-
None);
824+
bx.invoke(func, &[data], normal.llbb(), catchswitch.llbb(), None);
827825

828826
normal.ret(C_i32(cx, 0));
829827

@@ -911,8 +909,7 @@ fn codegen_gnu_try(
911909
// being thrown. The second value is a "selector" indicating which of
912910
// the landing pad clauses the exception's type had been matched to.
913911
// rust_try ignores the selector.
914-
let lpad_ty = Type::struct_(cx, &[Type::i8p(cx), Type::i32(cx)],
915-
false);
912+
let lpad_ty = Type::struct_(cx, &[Type::i8p(cx), Type::i32(cx)], false);
916913
let vals = catch.landing_pad(lpad_ty, bx.cx.eh_personality(), 1);
917914
catch.add_clause(vals, C_null(Type::i8p(cx)));
918915
let ptr = catch.extract_value(vals, 0);
@@ -1000,11 +997,11 @@ fn generic_simd_intrinsic(
1000997
($msg: tt, $($fmt: tt)*) => {
1001998
span_invalid_monomorphization_error(
1002999
bx.sess(), span,
1003-
&format!(concat!("invalid monomorphization of `{}` intrinsic: ",
1004-
$msg),
1000+
&format!(concat!("invalid monomorphization of `{}` intrinsic: ", $msg),
10051001
name, $($fmt)*));
10061002
}
10071003
}
1004+
10081005
macro_rules! return_error {
10091006
($($fmt: tt)*) => {
10101007
{
@@ -1021,14 +1018,13 @@ fn generic_simd_intrinsic(
10211018
}
10221019
};
10231020
}
1021+
10241022
macro_rules! require_simd {
10251023
($ty: expr, $position: expr) => {
10261024
require!($ty.is_simd(), "expected SIMD {} type, found non-SIMD `{}`", $position, $ty)
10271025
}
10281026
}
10291027

1030-
1031-
10321028
let tcx = bx.tcx();
10331029
let sig = tcx.normalize_erasing_late_bound_regions(
10341030
ty::ParamEnv::reveal_all(),
@@ -1121,17 +1117,17 @@ fn generic_simd_intrinsic(
11211117
};
11221118

11231119
return Ok(bx.shuffle_vector(args[0].immediate(),
1124-
args[1].immediate(),
1125-
C_vector(&indices)))
1120+
args[1].immediate(),
1121+
C_vector(&indices)))
11261122
}
11271123

11281124
if name == "simd_insert" {
11291125
require!(in_elem == arg_tys[2],
11301126
"expected inserted type `{}` (element of input `{}`), found `{}`",
11311127
in_elem, in_ty, arg_tys[2]);
11321128
return Ok(bx.insert_element(args[0].immediate(),
1133-
args[2].immediate(),
1134-
args[1].immediate()))
1129+
args[2].immediate(),
1130+
args[1].immediate()))
11351131
}
11361132
if name == "simd_extract" {
11371133
require!(ret_ty == in_elem,
@@ -1150,9 +1146,7 @@ fn generic_simd_intrinsic(
11501146
);
11511147
match m_elem_ty.sty {
11521148
ty::Int(_) => {},
1153-
_ => {
1154-
return_error!("mask element type is `{}`, expected `i_`", m_elem_ty);
1155-
}
1149+
_ => return_error!("mask element type is `{}`, expected `i_`", m_elem_ty)
11561150
}
11571151
// truncate the mask to a vector of i1s
11581152
let i1 = Type::i1(bx.cx);
@@ -1177,8 +1171,7 @@ fn generic_simd_intrinsic(
11771171
($msg: tt, $($fmt: tt)*) => {
11781172
span_invalid_monomorphization_error(
11791173
bx.sess(), span,
1180-
&format!(concat!("invalid monomorphization of `{}` intrinsic: ",
1181-
$msg),
1174+
&format!(concat!("invalid monomorphization of `{}` intrinsic: ", $msg),
11821175
name, $($fmt)*));
11831176
}
11841177
}
@@ -1312,7 +1305,7 @@ fn generic_simd_intrinsic(
13121305
}
13131306

13141307

1315-
if name == "simd_gather" {
1308+
if name == "simd_gather" {
13161309
// simd_gather(values: <N x T>, pointers: <N x *_ T>,
13171310
// mask: <N x i{M}>) -> <N x T>
13181311
// * N: number of elements in the input vectors
@@ -1360,7 +1353,7 @@ fn generic_simd_intrinsic(
13601353
// to the element type of the first argument
13611354
let (pointer_count, underlying_ty) = match arg_tys[1].simd_type(tcx).sty {
13621355
ty::RawPtr(p) if p.ty == in_elem => (ptr_count(arg_tys[1].simd_type(tcx)),
1363-
non_ptr(arg_tys[1].simd_type(tcx))),
1356+
non_ptr(arg_tys[1].simd_type(tcx))),
13641357
_ => {
13651358
require!(false, "expected element type `{}` of second argument `{}` \
13661359
to be a pointer to the element type `{}` of the first \
@@ -1414,7 +1407,7 @@ fn generic_simd_intrinsic(
14141407
return Ok(v);
14151408
}
14161409

1417-
if name == "simd_scatter" {
1410+
if name == "simd_scatter" {
14181411
// simd_scatter(values: <N x T>, pointers: <N x *mut T>,
14191412
// mask: <N x i{M}>) -> ()
14201413
// * N: number of elements in the input vectors
@@ -1570,7 +1563,6 @@ unsupported {} from `{}` with element `{}` of size `{}` to `{}`"#,
15701563
)
15711564
}
15721565
}
1573-
15741566
};
15751567
Ok(bx.$float_reduce(acc, args[0].immediate()))
15761568
}
@@ -1750,9 +1742,9 @@ unsupported {} from `{}` with element `{}` of size `{}` to `{}`"#,
17501742
_ => {},
17511743
}
17521744
require!(false,
1753-
"unsupported operation on `{}` with element `{}`",
1754-
in_ty,
1755-
in_elem)
1745+
"unsupported operation on `{}` with element `{}`",
1746+
in_ty,
1747+
in_elem)
17561748
})*
17571749
}
17581750
}

src/librustc_codegen_llvm/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ impl ModuleCodegen {
306306
};
307307
let bytecode_compressed = if emit_bc_compressed {
308308
Some(outputs.temp_path(OutputType::Bitcode, Some(&self.name))
309-
.with_extension(RLIB_BYTECODE_EXTENSION))
309+
.with_extension(RLIB_BYTECODE_EXTENSION))
310310
} else {
311311
None
312312
};

src/librustc_codegen_llvm/metadata.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ impl MetadataLoader for LlvmMetadataLoader {
6363
let of = ObjectFile::new(mb)
6464
.map(|of| OwningRef::new(box of))
6565
.ok_or_else(|| format!("provided path not an object file: '{}'",
66-
filename.display()))?;
66+
filename.display()))?;
6767
let buf = of.try_map(|of| search_meta_section(of, target, filename))?;
6868
Ok(rustc_erase_owner!(buf))
6969
}

0 commit comments

Comments
 (0)