@@ -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
0 commit comments