Skip to content

Commit cd3da00

Browse files
committed
Clean up formatting.
Reflow overly long comments, plus some minor whitespace improvements.
1 parent bdacdfe commit cd3da00

File tree

12 files changed

+72
-48
lines changed

12 files changed

+72
-48
lines changed

compiler/rustc_codegen_ssa/src/base.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,8 @@ fn unsized_info<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
154154
let old_info =
155155
old_info.expect("unsized_info: missing old info for trait upcasting coercion");
156156
if data_a.principal_def_id() == data_b.principal_def_id() {
157-
// A NOP cast that doesn't actually change anything, should be allowed even with invalid vtables.
157+
// A NOP cast that doesn't actually change anything, should be allowed even with
158+
// invalid vtables.
158159
return old_info;
159160
}
160161

@@ -985,7 +986,8 @@ impl CrateInfo {
985986
false
986987
}
987988
CrateType::Staticlib | CrateType::Rlib => {
988-
// We don't invoke the linker for these, so we don't need to collect the NatVis for them.
989+
// We don't invoke the linker for these, so we don't need to collect the NatVis for
990+
// them.
989991
false
990992
}
991993
});

compiler/rustc_codegen_ssa/src/codegen_attrs.rs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -317,9 +317,9 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
317317
"extern mutable statics are not allowed with `#[linkage]`",
318318
);
319319
diag.note(
320-
"marking the extern static mutable would allow changing which symbol \
321-
the static references rather than make the target of the symbol \
322-
mutable",
320+
"marking the extern static mutable would allow changing which \
321+
symbol the static references rather than make the target of the \
322+
symbol mutable",
323323
);
324324
diag.emit();
325325
}
@@ -711,18 +711,19 @@ fn check_link_ordinal(tcx: TyCtxt<'_>, attr: &ast::Attribute) -> Option<u16> {
711711
if let Some(MetaItemLit { kind: LitKind::Int(ordinal, LitIntType::Unsuffixed), .. }) =
712712
sole_meta_list
713713
{
714-
// According to the table at https://docs.microsoft.com/en-us/windows/win32/debug/pe-format#import-header,
715-
// the ordinal must fit into 16 bits. Similarly, the Ordinal field in COFFShortExport (defined
716-
// in llvm/include/llvm/Object/COFFImportFile.h), which we use to communicate import information
717-
// to LLVM for `#[link(kind = "raw-dylib"_])`, is also defined to be uint16_t.
714+
// According to the table at
715+
// https://docs.microsoft.com/en-us/windows/win32/debug/pe-format#import-header, the
716+
// ordinal must fit into 16 bits. Similarly, the Ordinal field in COFFShortExport (defined
717+
// in llvm/include/llvm/Object/COFFImportFile.h), which we use to communicate import
718+
// information to LLVM for `#[link(kind = "raw-dylib"_])`, is also defined to be uint16_t.
718719
//
719-
// FIXME: should we allow an ordinal of 0? The MSVC toolchain has inconsistent support for this:
720-
// both LINK.EXE and LIB.EXE signal errors and abort when given a .DEF file that specifies
721-
// a zero ordinal. However, llvm-dlltool is perfectly happy to generate an import library
722-
// for such a .DEF file, and MSVC's LINK.EXE is also perfectly happy to consume an import
723-
// library produced by LLVM with an ordinal of 0, and it generates an .EXE. (I don't know yet
724-
// if the resulting EXE runs, as I haven't yet built the necessary DLL -- see earlier comment
725-
// about LINK.EXE failing.)
720+
// FIXME: should we allow an ordinal of 0? The MSVC toolchain has inconsistent support for
721+
// this: both LINK.EXE and LIB.EXE signal errors and abort when given a .DEF file that
722+
// specifies a zero ordinal. However, llvm-dlltool is perfectly happy to generate an import
723+
// library for such a .DEF file, and MSVC's LINK.EXE is also perfectly happy to consume an
724+
// import library produced by LLVM with an ordinal of 0, and it generates an .EXE. (I
725+
// don't know yet if the resulting EXE runs, as I haven't yet built the necessary DLL --
726+
// see earlier comment about LINK.EXE failing.)
726727
if *ordinal <= u16::MAX as u128 {
727728
Some(ordinal.get() as u16)
728729
} else {

compiler/rustc_codegen_ssa/src/common.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,8 @@ pub fn i686_decorated_name(
200200
let mut decorated_name = String::with_capacity(name.len() + 6);
201201

202202
if disable_name_mangling {
203-
// LLVM uses a binary 1 ('\x01') prefix to a name to indicate that mangling needs to be disabled.
203+
// LLVM uses a binary 1 ('\x01') prefix to a name to indicate that mangling needs to be
204+
// disabled.
204205
decorated_name.push('\x01');
205206
}
206207

compiler/rustc_codegen_ssa/src/debuginfo/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ fn tag_base_type_opt<'tcx>(
7676
Primitive::Float(f) => Integer::from_size(f.size()).unwrap(),
7777
// FIXME(erikdesjardins): handle non-default addrspace ptr sizes
7878
Primitive::Pointer(_) => {
79-
// If the niche is the NULL value of a reference, then `discr_enum_ty` will be
80-
// a RawPtr. CodeView doesn't know what to do with enums whose base type is a
81-
// pointer so we fix this up to just be `usize`.
79+
// If the niche is the NULL value of a reference, then `discr_enum_ty` will
80+
// be a RawPtr. CodeView doesn't know what to do with enums whose base type
81+
// is a pointer so we fix this up to just be `usize`.
8282
// DWARF might be able to deal with this but with an integer type we are on
8383
// the safe side there too.
8484
tcx.data_layout.ptr_sized_integer()

compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ fn push_debuginfo_type_name<'tcx>(
9595
}
9696
Err(e) => {
9797
// Computing the layout can still fail here, e.g. if the target architecture
98-
// cannot represent the type. See https://github.com/rust-lang/rust/issues/94961.
98+
// cannot represent the type. See
99+
// https://github.com/rust-lang/rust/issues/94961.
99100
tcx.dcx().emit_fatal(e.into_diagnostic());
100101
}
101102
}

compiler/rustc_codegen_ssa/src/mir/block.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -996,17 +996,18 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
996996
// To get a `*mut RcBox<Self>`, we just keep unwrapping newtypes until
997997
// we get a value of a built-in pointer type.
998998
//
999-
// This is also relevant for `Pin<&mut Self>`, where we need to peel the `Pin`.
999+
// This is also relevant for `Pin<&mut Self>`, where we need to peel the
1000+
// `Pin`.
10001001
while !op.layout.ty.is_unsafe_ptr() && !op.layout.ty.is_ref() {
10011002
let (idx, _) = op.layout.non_1zst_field(bx).expect(
10021003
"not exactly one non-1-ZST field in a `DispatchFromDyn` type",
10031004
);
10041005
op = op.extract_field(bx, idx);
10051006
}
10061007

1007-
// now that we have `*dyn Trait` or `&dyn Trait`, split it up into its
1008+
// Now that we have `*dyn Trait` or `&dyn Trait`, split it up into its
10081009
// data pointer and vtable. Look up the method in the vtable, and pass
1009-
// the data pointer as the first argument
1010+
// the data pointer as the first argument.
10101011
llfn = Some(meth::VirtualIndex::from_index(idx).get_fn(
10111012
bx,
10121013
meta,
@@ -1440,8 +1441,9 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
14401441
let (mut llval, align, by_ref) = match op.val {
14411442
Immediate(_) | Pair(..) => match arg.mode {
14421443
PassMode::Indirect { attrs, .. } => {
1443-
// Indirect argument may have higher alignment requirements than the type's alignment.
1444-
// This can happen, e.g. when passing types with <4 byte alignment on the stack on x86.
1444+
// Indirect argument may have higher alignment requirements than the type's
1445+
// alignment. This can happen, e.g. when passing types with <4 byte alignment
1446+
// on the stack on x86.
14451447
let required_align = match attrs.pointee_align {
14461448
Some(pointee_align) => cmp::max(pointee_align, arg.layout.align.abi),
14471449
None => arg.layout.align.abi,

compiler/rustc_codegen_ssa/src/mir/constant.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,27 +32,28 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
3232
/// that the given `constant` is an `Const::Unevaluated` and must be convertible to
3333
/// a `ValTree`. If you want a more general version of this, talk to `wg-const-eval` on zulip.
3434
///
35-
/// Note that this function is cursed, since usually MIR consts should not be evaluated to valtrees!
35+
/// Note that this function is cursed, since usually MIR consts should not be evaluated to
36+
/// valtrees!
3637
fn eval_unevaluated_mir_constant_to_valtree(
3738
&self,
3839
constant: &mir::ConstOperand<'tcx>,
3940
) -> Result<Result<ty::ValTree<'tcx>, Ty<'tcx>>, ErrorHandled> {
4041
let uv = match self.monomorphize(constant.const_) {
4142
mir::Const::Unevaluated(uv, _) => uv.shrink(),
4243
mir::Const::Ty(_, c) => match c.kind() {
43-
// A constant that came from a const generic but was then used as an argument to old-style
44-
// simd_shuffle (passing as argument instead of as a generic param).
44+
// A constant that came from a const generic but was then used as an argument to
45+
// old-style simd_shuffle (passing as argument instead of as a generic param).
4546
rustc_type_ir::ConstKind::Value(_, valtree) => return Ok(Ok(valtree)),
4647
other => span_bug!(constant.span, "{other:#?}"),
4748
},
4849
// We should never encounter `Const::Val` unless MIR opts (like const prop) evaluate
49-
// a constant and write that value back into `Operand`s. This could happen, but is unlikely.
50-
// Also: all users of `simd_shuffle` are on unstable and already need to take a lot of care
51-
// around intrinsics. For an issue to happen here, it would require a macro expanding to a
52-
// `simd_shuffle` call without wrapping the constant argument in a `const {}` block, but
53-
// the user pass through arbitrary expressions.
54-
// FIXME(oli-obk): replace the magic const generic argument of `simd_shuffle` with a real
55-
// const generic, and get rid of this entire function.
50+
// a constant and write that value back into `Operand`s. This could happen, but is
51+
// unlikely. Also: all users of `simd_shuffle` are on unstable and already need to take
52+
// a lot of care around intrinsics. For an issue to happen here, it would require a
53+
// macro expanding to a `simd_shuffle` call without wrapping the constant argument in a
54+
// `const {}` block, but the user pass through arbitrary expressions.
55+
// FIXME(oli-obk): replace the magic const generic argument of `simd_shuffle` with a
56+
// real const generic, and get rid of this entire function.
5657
other => span_bug!(constant.span, "{other:#?}"),
5758
};
5859
let uv = self.monomorphize(uv);

compiler/rustc_codegen_ssa/src/mir/debuginfo.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ pub struct FunctionDebugContext<'tcx, S, L> {
2424
/// Maps from an inlined function to its debug info declaration.
2525
pub inlined_function_scopes: FxHashMap<Instance<'tcx>, S>,
2626
}
27+
2728
#[derive(Copy, Clone)]
2829
pub enum VariableKind {
2930
ArgumentVariable(usize /*index*/),

compiler/rustc_codegen_ssa/src/mir/operand.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -478,8 +478,8 @@ impl<'a, 'tcx, V: CodegenObject> OperandValue<V> {
478478
debug!("OperandRef::store: operand={:?}, dest={:?}", self, dest);
479479
match self {
480480
OperandValue::ZeroSized => {
481-
// Avoid generating stores of zero-sized values, because the only way to have a zero-sized
482-
// value is through `undef`/`poison`, and the store itself is useless.
481+
// Avoid generating stores of zero-sized values, because the only way to have a
482+
// zero-sized value is through `undef`/`poison`, and the store itself is useless.
483483
}
484484
OperandValue::Ref(val) => {
485485
assert!(dest.layout.is_sized(), "cannot directly store unsized values");

compiler/rustc_codegen_ssa/src/size_of_val.rs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,13 @@ pub fn size_and_align_of_dst<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
4545
// The info in this case is the length of the str, so the size is that
4646
// times the unit size.
4747
(
48-
// All slice sizes must fit into `isize`, so this multiplication cannot (signed) wrap.
48+
// All slice sizes must fit into `isize`, so this multiplication cannot (signed)
49+
// wrap.
4950
// NOTE: ideally, we want the effects of both `unchecked_smul` and `unchecked_umul`
5051
// (resulting in `mul nsw nuw` in LLVM IR), since we know that the multiplication
51-
// cannot signed wrap, and that both operands are non-negative. But at the time of writing,
52-
// the `LLVM-C` binding can't do this, and it doesn't seem to enable any further optimizations.
52+
// cannot signed wrap, and that both operands are non-negative. But at the time of
53+
// writing, the `LLVM-C` binding can't do this, and it doesn't seem to enable any
54+
// further optimizations.
5355
bx.unchecked_smul(info.unwrap(), bx.const_usize(unit.size.bytes())),
5456
bx.const_usize(unit.align.abi.bytes()),
5557
)
@@ -67,9 +69,9 @@ pub fn size_and_align_of_dst<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
6769
let (fn_abi, llfn, _instance) =
6870
common::build_langcall(bx, None, LangItem::PanicNounwind);
6971

70-
// Generate the call.
71-
// Cannot use `do_call` since we don't have a MIR terminator so we can't create a `TerminationCodegenHelper`.
72-
// (But we are in good company, this code is duplicated plenty of times.)
72+
// Generate the call. Cannot use `do_call` since we don't have a MIR terminator so we
73+
// can't create a `TerminationCodegenHelper`. (But we are in good company, this code is
74+
// duplicated plenty of times.)
7375
let fn_ty = bx.fn_decl_backend_type(fn_abi);
7476

7577
bx.call(
@@ -148,9 +150,14 @@ pub fn size_and_align_of_dst<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
148150
// The full formula for the size would be:
149151
// let unsized_offset_adjusted = unsized_offset_unadjusted.align_to(unsized_align);
150152
// let full_size = (unsized_offset_adjusted + unsized_size).align_to(full_align);
151-
// However, `unsized_size` is a multiple of `unsized_align`.
152-
// Therefore, we can equivalently do the `align_to(unsized_align)` *after* adding `unsized_size`:
153-
// let full_size = (unsized_offset_unadjusted + unsized_size).align_to(unsized_align).align_to(full_align);
153+
// However, `unsized_size` is a multiple of `unsized_align`. Therefore, we can
154+
// equivalently do the `align_to(unsized_align)` *after* adding `unsized_size`:
155+
//
156+
// let full_size =
157+
// (unsized_offset_unadjusted + unsized_size)
158+
// .align_to(unsized_align)
159+
// .align_to(full_align);
160+
//
154161
// Furthermore, `align >= unsized_align`, and therefore we only need to do:
155162
// let full_size = (unsized_offset_unadjusted + unsized_size).align_to(full_align);
156163

compiler/rustc_codegen_ssa/src/traits/backend.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,15 @@ pub trait CodegenBackend {
5959
fn locale_resource(&self) -> &'static str;
6060

6161
fn init(&self, _sess: &Session) {}
62+
6263
fn print(&self, _req: &PrintRequest, _out: &mut String, _sess: &Session) {}
64+
6365
fn target_features(&self, _sess: &Session, _allow_unstable: bool) -> Vec<Symbol> {
6466
vec![]
6567
}
68+
6669
fn print_passes(&self) {}
70+
6771
fn print_version(&self) {}
6872

6973
/// The metadata loader used to load rlib and dylib metadata.
@@ -75,6 +79,7 @@ pub trait CodegenBackend {
7579
}
7680

7781
fn provide(&self, _providers: &mut Providers) {}
82+
7883
fn codegen_crate<'tcx>(
7984
&self,
8085
tcx: TyCtxt<'tcx>,
@@ -120,13 +125,15 @@ pub trait ExtraBackendMethods:
120125
kind: AllocatorKind,
121126
alloc_error_handler_kind: AllocatorKind,
122127
) -> Self::Module;
128+
123129
/// This generates the codegen unit and returns it along with
124130
/// a `u64` giving an estimate of the unit's processing cost.
125131
fn compile_codegen_unit(
126132
&self,
127133
tcx: TyCtxt<'_>,
128134
cgu_name: Symbol,
129135
) -> (ModuleCodegen<Self::Module>, u64);
136+
130137
fn target_machine_factory(
131138
&self,
132139
sess: &Session,

compiler/rustc_codegen_ssa/src/traits/misc.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ pub trait MiscMethods<'tcx>: BackendTypes {
2525
fn codegen_unit(&self) -> &'tcx CodegenUnit<'tcx>;
2626
fn set_frame_pointer_type(&self, llfn: Self::Function);
2727
fn apply_target_cpu_attr(&self, llfn: Self::Function);
28-
/// Declares the extern "C" main function for the entry point. Returns None if the symbol already exists.
28+
/// Declares the extern "C" main function for the entry point. Returns None if the symbol
29+
/// already exists.
2930
fn declare_c_main(&self, fn_type: Self::Type) -> Option<Self::Function>;
3031
}

0 commit comments

Comments
 (0)