Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 28e684b

Browse files
committedJul 25, 2024·
Auto merge of rust-lang#127995 - workingjubilee:say-turings-prayer, r=BoxyUwU
compiler: Never debug_assert in codegen In the name of Turing and his Hoarey heralds, assert our truths before creating a monster! The `rustc_codegen_llvm` and `rustc_codegen_ssa` crates are fairly critical for rustc's correctness. Small mistakes here can easily result in undefined behavior, since a "small mistake" can mean something like "link and execute the wrong code". We should probably run any and all asserts in these modules unconditionally on whether this is a "debug build", and damn the costs in performance. ...Especially because the costs in performance seem to be *nothing*. It is not clear how much correctness we gain here, but I'll take free correctness improvements.
2 parents 004e155 + ce7b069 commit 28e684b

File tree

16 files changed

+57
-65
lines changed

16 files changed

+57
-65
lines changed
 

‎compiler/rustc_codegen_llvm/src/consts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ impl<'ll> CodegenCx<'ll, '_> {
330330

331331
// If this assertion triggers, there's something wrong with commandline
332332
// argument validation.
333-
debug_assert!(
333+
assert!(
334334
!(self.tcx.sess.opts.cg.linker_plugin_lto.enabled()
335335
&& self.tcx.sess.target.is_like_windows
336336
&& self.tcx.sess.opts.cg.prefer_dynamic)

‎compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ fn build_pointer_or_reference_di_node<'ll, 'tcx>(
170170
) -> DINodeCreationResult<'ll> {
171171
// The debuginfo generated by this function is only valid if `ptr_type` is really just
172172
// a (fat) pointer. Make sure it is not called for e.g. `Box<T, NonZSTAllocator>`.
173-
debug_assert_eq!(
173+
assert_eq!(
174174
cx.size_and_align_of(ptr_type),
175175
cx.size_and_align_of(Ty::new_mut_ptr(cx.tcx, pointee_type))
176176
);
@@ -185,7 +185,7 @@ fn build_pointer_or_reference_di_node<'ll, 'tcx>(
185185
match fat_pointer_kind(cx, pointee_type) {
186186
None => {
187187
// This is a thin pointer. Create a regular pointer type and give it the correct name.
188-
debug_assert_eq!(
188+
assert_eq!(
189189
(data_layout.pointer_size, data_layout.pointer_align.abi),
190190
cx.size_and_align_of(ptr_type),
191191
"ptr_type={ptr_type}, pointee_type={pointee_type}",
@@ -240,8 +240,8 @@ fn build_pointer_or_reference_di_node<'ll, 'tcx>(
240240
FatPtrKind::Slice => ("data_ptr", "length"),
241241
};
242242

243-
debug_assert_eq!(abi::FAT_PTR_ADDR, 0);
244-
debug_assert_eq!(abi::FAT_PTR_EXTRA, 1);
243+
assert_eq!(abi::FAT_PTR_ADDR, 0);
244+
assert_eq!(abi::FAT_PTR_EXTRA, 1);
245245

246246
// The data pointer type is a regular, thin pointer, regardless of whether this
247247
// is a slice or a trait object.
@@ -498,7 +498,7 @@ pub fn type_di_node<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>, t: Ty<'tcx>) -> &'ll D
498498
}
499499
};
500500

501-
debug_assert_eq!(di_node_for_uid as *const _, di_node as *const _);
501+
assert_eq!(di_node_for_uid as *const _, di_node as *const _);
502502
} else {
503503
debug_context(cx).type_map.insert(unique_type_id, di_node);
504504
}
@@ -1060,7 +1060,7 @@ fn build_struct_type_di_node<'ll, 'tcx>(
10601060
let ty::Adt(adt_def, _) = struct_type.kind() else {
10611061
bug!("build_struct_type_di_node() called with non-struct-type: {:?}", struct_type);
10621062
};
1063-
debug_assert!(adt_def.is_struct());
1063+
assert!(adt_def.is_struct());
10641064
let containing_scope = get_namespace_for_item(cx, adt_def.did());
10651065
let struct_type_and_layout = cx.layout_of(struct_type);
10661066
let variant_def = adt_def.non_enum_variant();
@@ -1130,7 +1130,7 @@ fn build_upvar_field_di_nodes<'ll, 'tcx>(
11301130
}
11311131
};
11321132

1133-
debug_assert!(
1133+
assert!(
11341134
up_var_tys.iter().all(|t| t == cx.tcx.normalize_erasing_regions(ParamEnv::reveal_all(), t))
11351135
);
11361136

‎compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/cpp_like.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ pub(super) fn build_enum_type_di_node<'ll, 'tcx>(
204204
let enum_type_and_layout = cx.layout_of(enum_type);
205205
let enum_type_name = compute_debuginfo_type_name(cx.tcx, enum_type, false);
206206

207-
debug_assert!(!wants_c_like_enum_debuginfo(enum_type_and_layout));
207+
assert!(!wants_c_like_enum_debuginfo(enum_type_and_layout));
208208

209209
type_map::build_type_with_children(
210210
cx,
@@ -279,7 +279,7 @@ pub(super) fn build_coroutine_di_node<'ll, 'tcx>(
279279
let coroutine_type_and_layout = cx.layout_of(coroutine_type);
280280
let coroutine_type_name = compute_debuginfo_type_name(cx.tcx, coroutine_type, false);
281281

282-
debug_assert!(!wants_c_like_enum_debuginfo(coroutine_type_and_layout));
282+
assert!(!wants_c_like_enum_debuginfo(coroutine_type_and_layout));
283283

284284
type_map::build_type_with_children(
285285
cx,
@@ -517,7 +517,7 @@ fn build_variant_struct_wrapper_type_di_node<'ll, 'tcx>(
517517
if is_128_bits {
518518
DiscrKind::Exact128(discr_val)
519519
} else {
520-
debug_assert_eq!(discr_val, discr_val as u64 as u128);
520+
assert_eq!(discr_val, discr_val as u64 as u128);
521521
DiscrKind::Exact(discr_val as u64)
522522
}
523523
}
@@ -526,8 +526,8 @@ fn build_variant_struct_wrapper_type_di_node<'ll, 'tcx>(
526526
if is_128_bits {
527527
DiscrKind::Range128(min, max)
528528
} else {
529-
debug_assert_eq!(min, min as u64 as u128);
530-
debug_assert_eq!(max, max as u64 as u128);
529+
assert_eq!(min, min as u64 as u128);
530+
assert_eq!(max, max as u64 as u128);
531531
DiscrKind::Range(min as u64, max as u64)
532532
}
533533
}
@@ -815,7 +815,7 @@ fn build_union_fields_for_direct_tag_enum_or_coroutine<'ll, 'tcx>(
815815
}
816816
}));
817817

818-
debug_assert_eq!(
818+
assert_eq!(
819819
cx.size_and_align_of(enum_type_and_layout.field(cx, tag_field).ty),
820820
cx.size_and_align_of(super::tag_base_type(cx, enum_type_and_layout))
821821
);

‎compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ fn tag_base_type<'ll, 'tcx>(
106106
cx: &CodegenCx<'ll, 'tcx>,
107107
enum_type_and_layout: TyAndLayout<'tcx>,
108108
) -> Ty<'tcx> {
109-
debug_assert!(match enum_type_and_layout.ty.kind() {
109+
assert!(match enum_type_and_layout.ty.kind() {
110110
ty::Coroutine(..) => true,
111111
ty::Adt(adt_def, _) => adt_def.is_enum(),
112112
_ => false,
@@ -251,7 +251,7 @@ fn build_enum_variant_struct_type_di_node<'ll, 'tcx>(
251251
variant_layout: TyAndLayout<'tcx>,
252252
di_flags: DIFlags,
253253
) -> &'ll DIType {
254-
debug_assert_eq!(variant_layout.ty, enum_type_and_layout.ty);
254+
assert_eq!(variant_layout.ty, enum_type_and_layout.ty);
255255

256256
type_map::build_type_with_children(
257257
cx,

‎compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/native.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ pub(super) fn build_enum_type_di_node<'ll, 'tcx>(
6565

6666
let visibility_flags = visibility_di_flags(cx, enum_adt_def.did(), enum_adt_def.did());
6767

68-
debug_assert!(!wants_c_like_enum_debuginfo(enum_type_and_layout));
68+
assert!(!wants_c_like_enum_debuginfo(enum_type_and_layout));
6969

7070
type_map::build_type_with_children(
7171
cx,
@@ -142,7 +142,7 @@ pub(super) fn build_coroutine_di_node<'ll, 'tcx>(
142142
let containing_scope = get_namespace_for_item(cx, coroutine_def_id);
143143
let coroutine_type_and_layout = cx.layout_of(coroutine_type);
144144

145-
debug_assert!(!wants_c_like_enum_debuginfo(coroutine_type_and_layout));
145+
assert!(!wants_c_like_enum_debuginfo(coroutine_type_and_layout));
146146

147147
let coroutine_type_name = compute_debuginfo_type_name(cx.tcx, coroutine_type, false);
148148

‎compiler/rustc_codegen_llvm/src/debuginfo/metadata/type_map.rs

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ mod private {
3636

3737
/// A unique identifier for anything that we create a debuginfo node for.
3838
/// The types it contains are expected to already be normalized (which
39-
/// is debug_asserted in the constructors).
39+
/// is asserted in the constructors).
4040
///
4141
/// Note that there are some things that only show up in debuginfo, like
4242
/// the separate type descriptions for each enum variant. These get an ID
@@ -58,12 +58,12 @@ pub(super) enum UniqueTypeId<'tcx> {
5858

5959
impl<'tcx> UniqueTypeId<'tcx> {
6060
pub fn for_ty(tcx: TyCtxt<'tcx>, t: Ty<'tcx>) -> Self {
61-
debug_assert_eq!(t, tcx.normalize_erasing_regions(ParamEnv::reveal_all(), t));
61+
assert_eq!(t, tcx.normalize_erasing_regions(ParamEnv::reveal_all(), t));
6262
UniqueTypeId::Ty(t, private::HiddenZst)
6363
}
6464

6565
pub fn for_enum_variant_part(tcx: TyCtxt<'tcx>, enum_ty: Ty<'tcx>) -> Self {
66-
debug_assert_eq!(enum_ty, tcx.normalize_erasing_regions(ParamEnv::reveal_all(), enum_ty));
66+
assert_eq!(enum_ty, tcx.normalize_erasing_regions(ParamEnv::reveal_all(), enum_ty));
6767
UniqueTypeId::VariantPart(enum_ty, private::HiddenZst)
6868
}
6969

@@ -72,7 +72,7 @@ impl<'tcx> UniqueTypeId<'tcx> {
7272
enum_ty: Ty<'tcx>,
7373
variant_idx: VariantIdx,
7474
) -> Self {
75-
debug_assert_eq!(enum_ty, tcx.normalize_erasing_regions(ParamEnv::reveal_all(), enum_ty));
75+
assert_eq!(enum_ty, tcx.normalize_erasing_regions(ParamEnv::reveal_all(), enum_ty));
7676
UniqueTypeId::VariantStructType(enum_ty, variant_idx, private::HiddenZst)
7777
}
7878

@@ -81,7 +81,7 @@ impl<'tcx> UniqueTypeId<'tcx> {
8181
enum_ty: Ty<'tcx>,
8282
variant_idx: VariantIdx,
8383
) -> Self {
84-
debug_assert_eq!(enum_ty, tcx.normalize_erasing_regions(ParamEnv::reveal_all(), enum_ty));
84+
assert_eq!(enum_ty, tcx.normalize_erasing_regions(ParamEnv::reveal_all(), enum_ty));
8585
UniqueTypeId::VariantStructTypeCppLikeWrapper(enum_ty, variant_idx, private::HiddenZst)
8686
}
8787

@@ -90,11 +90,8 @@ impl<'tcx> UniqueTypeId<'tcx> {
9090
self_type: Ty<'tcx>,
9191
implemented_trait: Option<PolyExistentialTraitRef<'tcx>>,
9292
) -> Self {
93-
debug_assert_eq!(
94-
self_type,
95-
tcx.normalize_erasing_regions(ParamEnv::reveal_all(), self_type)
96-
);
97-
debug_assert_eq!(
93+
assert_eq!(self_type, tcx.normalize_erasing_regions(ParamEnv::reveal_all(), self_type));
94+
assert_eq!(
9895
implemented_trait,
9996
tcx.normalize_erasing_regions(ParamEnv::reveal_all(), implemented_trait)
10097
);
@@ -252,10 +249,7 @@ pub(super) fn build_type_with_children<'ll, 'tcx>(
252249
members: impl FnOnce(&CodegenCx<'ll, 'tcx>, &'ll DIType) -> SmallVec<&'ll DIType>,
253250
generics: impl FnOnce(&CodegenCx<'ll, 'tcx>) -> SmallVec<&'ll DIType>,
254251
) -> DINodeCreationResult<'ll> {
255-
debug_assert_eq!(
256-
debug_context(cx).type_map.di_node_for_unique_id(stub_info.unique_type_id),
257-
None
258-
);
252+
assert_eq!(debug_context(cx).type_map.di_node_for_unique_id(stub_info.unique_type_id), None);
259253

260254
debug_context(cx).type_map.insert(stub_info.unique_type_id, stub_info.metadata);
261255

‎compiler/rustc_codegen_llvm/src/debuginfo/utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ pub(crate) fn fat_pointer_kind<'ll, 'tcx>(
8181
ty::Dynamic(..) => Some(FatPtrKind::Dyn),
8282
ty::Foreign(_) => {
8383
// Assert that pointers to foreign types really are thin:
84-
debug_assert_eq!(
84+
assert_eq!(
8585
cx.size_of(Ty::new_imm_ptr(cx.tcx, pointee_tail_ty)),
8686
cx.size_of(Ty::new_imm_ptr(cx.tcx, cx.tcx.types.u8))
8787
);

‎compiler/rustc_codegen_ssa/src/back/symbol_export.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ fn exported_symbols_provider_local(
352352
}
353353
MonoItem::Fn(Instance { def: InstanceKind::DropGlue(def_id, Some(ty)), args }) => {
354354
// A little sanity-check
355-
debug_assert_eq!(
355+
assert_eq!(
356356
args.non_erasable_generics(tcx, def_id).next(),
357357
Some(GenericArgKind::Type(ty))
358358
);
@@ -370,7 +370,7 @@ fn exported_symbols_provider_local(
370370
args,
371371
}) => {
372372
// A little sanity-check
373-
debug_assert_eq!(
373+
assert_eq!(
374374
args.non_erasable_generics(tcx, def_id).next(),
375375
Some(GenericArgKind::Type(ty))
376376
);
@@ -462,7 +462,7 @@ fn upstream_monomorphizations_for_provider(
462462
tcx: TyCtxt<'_>,
463463
def_id: DefId,
464464
) -> Option<&UnordMap<GenericArgsRef<'_>, CrateNum>> {
465-
debug_assert!(!def_id.is_local());
465+
assert!(!def_id.is_local());
466466
tcx.upstream_monomorphizations(()).get(&def_id)
467467
}
468468

‎compiler/rustc_codegen_ssa/src/back/write.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1512,7 +1512,7 @@ fn start_executing_work<B: ExtraBackendMethods>(
15121512
// We reduce the `running` counter by one. The
15131513
// `tokens.truncate()` below will take care of
15141514
// giving the Token back.
1515-
debug_assert!(running_with_own_token > 0);
1515+
assert!(running_with_own_token > 0);
15161516
running_with_own_token -= 1;
15171517
main_thread_state = MainThreadState::Lending;
15181518
}

‎compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ fn push_debuginfo_type_name<'tcx>(
459459
output: &mut String,
460460
visited: &mut FxHashSet<Ty<'tcx>>,
461461
) {
462-
debug_assert!(!wants_c_like_enum_debuginfo(ty_and_layout));
462+
assert!(!wants_c_like_enum_debuginfo(ty_and_layout));
463463
output.push_str("enum2$<");
464464
push_inner(output, visited);
465465
push_close_angle_bracket(true, output);
@@ -660,7 +660,7 @@ fn push_generic_params_internal<'tcx>(
660660
output: &mut String,
661661
visited: &mut FxHashSet<Ty<'tcx>>,
662662
) -> bool {
663-
debug_assert_eq!(args, tcx.normalize_erasing_regions(ty::ParamEnv::reveal_all(), args));
663+
assert_eq!(args, tcx.normalize_erasing_regions(ty::ParamEnv::reveal_all(), args));
664664
let mut args = args.non_erasable_generics(tcx, def_id).peekable();
665665
if args.peek().is_none() {
666666
return false;

‎compiler/rustc_codegen_ssa/src/mir/block.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ impl<'a, 'tcx> TerminatorCodegenHelper<'tcx> {
8484
}
8585
if is_cleanupret {
8686
// Cross-funclet jump - need a trampoline
87-
debug_assert!(base::wants_new_eh_instructions(fx.cx.tcx().sess));
87+
assert!(base::wants_new_eh_instructions(fx.cx.tcx().sess));
8888
debug!("llbb_with_cleanup: creating cleanup trampoline for {:?}", target);
8989
let name = &format!("{:?}_cleanup_trampoline_{:?}", self.bb, target);
9090
let trampoline_llbb = Bx::append_block(fx.cx, fx.llfn, name);

‎compiler/rustc_codegen_ssa/src/mir/debuginfo.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ fn calculate_debuginfo_offset<
194194
}
195195
_ => {
196196
// Sanity check for `can_use_in_debuginfo`.
197-
debug_assert!(!elem.can_use_in_debuginfo());
197+
assert!(!elem.can_use_in_debuginfo());
198198
bug!("unsupported var debuginfo projection `{:?}`", projection)
199199
}
200200
}
@@ -502,7 +502,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
502502

503503
let DebugInfoOffset { direct_offset, indirect_offsets, result: fragment_layout } =
504504
calculate_debuginfo_offset(bx, &fragment.projection, var_layout);
505-
debug_assert!(indirect_offsets.is_empty());
505+
assert!(indirect_offsets.is_empty());
506506

507507
if fragment_layout.size == Size::ZERO {
508508
// Fragment is a ZST, so does not represent anything. Avoid generating anything

‎compiler/rustc_codegen_ssa/src/mir/operand.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
565565
for elem in place_ref.projection.iter() {
566566
match elem {
567567
mir::ProjectionElem::Field(ref f, _) => {
568-
debug_assert!(
568+
assert!(
569569
!o.layout.ty.is_any_ptr(),
570570
"Bad PlaceRef: destructing pointers should use cast/PtrMetadata, \
571571
but tried to access field {f:?} of pointer {o:?}",

‎compiler/rustc_codegen_ssa/src/mir/place.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ impl<V: CodegenObject> PlaceValue<V> {
5555

5656
/// Creates a `PlaceRef` to this location with the given type.
5757
pub fn with_type<'tcx>(self, layout: TyAndLayout<'tcx>) -> PlaceRef<'tcx, V> {
58-
debug_assert!(
58+
assert!(
5959
layout.is_unsized() || layout.abi.is_uninhabited() || self.llextra.is_none(),
6060
"Had pointer metadata {:?} for sized type {layout:?}",
6161
self.llextra,
@@ -488,7 +488,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
488488
cg_base = match *elem {
489489
mir::ProjectionElem::Deref => bx.load_operand(cg_base).deref(bx.cx()),
490490
mir::ProjectionElem::Field(ref field, _) => {
491-
debug_assert!(
491+
assert!(
492492
!cg_base.layout.ty.is_any_ptr(),
493493
"Bad PlaceRef: destructing pointers should use cast/PtrMetadata, \
494494
but tried to access field {field:?} of pointer {cg_base:?}",

‎compiler/rustc_codegen_ssa/src/mir/rvalue.rs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,8 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
168168
dst: PlaceRef<'tcx, Bx::Value>,
169169
) {
170170
// The MIR validator enforces no unsized transmutes.
171-
debug_assert!(src.layout.is_sized());
172-
debug_assert!(dst.layout.is_sized());
171+
assert!(src.layout.is_sized());
172+
assert!(dst.layout.is_sized());
173173

174174
if let Some(val) = self.codegen_transmute_operand(bx, src, dst.layout) {
175175
val.store(bx, dst);
@@ -223,8 +223,8 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
223223

224224
match operand.val {
225225
OperandValue::Ref(source_place_val) => {
226-
debug_assert_eq!(source_place_val.llextra, None);
227-
debug_assert!(matches!(operand_kind, OperandValueKind::Ref));
226+
assert_eq!(source_place_val.llextra, None);
227+
assert!(matches!(operand_kind, OperandValueKind::Ref));
228228
Some(bx.load_operand(source_place_val.with_type(cast)).val)
229229
}
230230
OperandValue::ZeroSized => {
@@ -295,7 +295,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
295295
to_scalar: abi::Scalar,
296296
to_backend_ty: Bx::Type,
297297
) -> Bx::Value {
298-
debug_assert_eq!(from_scalar.size(self.cx), to_scalar.size(self.cx));
298+
assert_eq!(from_scalar.size(self.cx), to_scalar.size(self.cx));
299299

300300
use abi::Primitive::*;
301301
imm = bx.from_immediate(imm);
@@ -639,9 +639,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
639639
(OperandValue::Immediate(llval), operand.layout)
640640
}
641641
mir::UnOp::PtrMetadata => {
642-
debug_assert!(
643-
operand.layout.ty.is_unsafe_ptr() || operand.layout.ty.is_ref(),
644-
);
642+
assert!(operand.layout.ty.is_unsafe_ptr() || operand.layout.ty.is_ref(),);
645643
let (_, meta) = operand.val.pointer_parts();
646644
assert_eq!(operand.layout.fields.count() > 1, meta.is_some());
647645
if let Some(meta) = meta {
@@ -651,7 +649,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
651649
}
652650
}
653651
};
654-
debug_assert!(
652+
assert!(
655653
val.is_expected_variant_for_type(self.cx, layout),
656654
"Made wrong variant {val:?} for type {layout:?}",
657655
);
@@ -742,7 +740,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
742740
bug!("Field {field_idx:?} is {p:?} making {layout:?}");
743741
});
744742
let scalars = self.value_kind(op.layout).scalars().unwrap();
745-
debug_assert_eq!(values.len(), scalars.len());
743+
assert_eq!(values.len(), scalars.len());
746744
inputs.extend(values);
747745
input_scalars.extend(scalars);
748746
}
@@ -760,7 +758,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
760758
);
761759

762760
let val = OperandValue::from_immediates(inputs);
763-
debug_assert!(
761+
assert!(
764762
val.is_expected_variant_for_type(self.cx, layout),
765763
"Made wrong variant {val:?} for type {layout:?}",
766764
);
@@ -805,7 +803,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
805803
let val = cg_place.val.address();
806804

807805
let ty = cg_place.layout.ty;
808-
debug_assert!(
806+
assert!(
809807
if bx.cx().type_has_metadata(ty) {
810808
matches!(val, OperandValue::Pair(..))
811809
} else {
@@ -927,7 +925,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
927925
}
928926
mir::BinOp::Cmp => {
929927
use std::cmp::Ordering;
930-
debug_assert!(!is_float);
928+
assert!(!is_float);
931929
let pred = |op| base::bin_op_to_icmp_predicate(op, is_signed);
932930
if bx.cx().tcx().sess.opts.optimize == OptLevel::No {
933931
// FIXME: This actually generates tighter assembly, and is a classic trick
@@ -1111,7 +1109,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
11111109
if layout.is_zst() {
11121110
OperandValueKind::ZeroSized
11131111
} else if self.cx.is_backend_immediate(layout) {
1114-
debug_assert!(!self.cx.is_backend_scalar_pair(layout));
1112+
assert!(!self.cx.is_backend_scalar_pair(layout));
11151113
OperandValueKind::Immediate(match layout.abi {
11161114
abi::Abi::Scalar(s) => s,
11171115
abi::Abi::Vector { element, .. } => element,

‎compiler/rustc_codegen_ssa/src/traits/builder.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ pub trait BuilderMethods<'a, 'tcx>:
165165
size: Size,
166166
) -> Self::Value;
167167
fn load_from_place(&mut self, ty: Self::Type, place: PlaceValue<Self::Value>) -> Self::Value {
168-
debug_assert_eq!(place.llextra, None);
168+
assert_eq!(place.llextra, None);
169169
self.load(ty, place.llval, place.align)
170170
}
171171
fn load_operand(&mut self, place: PlaceRef<'tcx, Self::Value>)
@@ -184,7 +184,7 @@ pub trait BuilderMethods<'a, 'tcx>:
184184

185185
fn store(&mut self, val: Self::Value, ptr: Self::Value, align: Align) -> Self::Value;
186186
fn store_to_place(&mut self, val: Self::Value, place: PlaceValue<Self::Value>) -> Self::Value {
187-
debug_assert_eq!(place.llextra, None);
187+
assert_eq!(place.llextra, None);
188188
self.store(val, place.llval, place.align)
189189
}
190190
fn store_with_flags(
@@ -200,7 +200,7 @@ pub trait BuilderMethods<'a, 'tcx>:
200200
place: PlaceValue<Self::Value>,
201201
flags: MemFlags,
202202
) -> Self::Value {
203-
debug_assert_eq!(place.llextra, None);
203+
assert_eq!(place.llextra, None);
204204
self.store_with_flags(val, place.llval, place.align, flags)
205205
}
206206
fn atomic_store(
@@ -320,9 +320,9 @@ pub trait BuilderMethods<'a, 'tcx>:
320320
layout: TyAndLayout<'tcx>,
321321
flags: MemFlags,
322322
) {
323-
debug_assert!(layout.is_sized(), "cannot typed-copy an unsigned type");
324-
debug_assert!(src.llextra.is_none(), "cannot directly copy from unsized values");
325-
debug_assert!(dst.llextra.is_none(), "cannot directly copy into unsized values");
323+
assert!(layout.is_sized(), "cannot typed-copy an unsigned type");
324+
assert!(src.llextra.is_none(), "cannot directly copy from unsized values");
325+
assert!(dst.llextra.is_none(), "cannot directly copy into unsized values");
326326
if flags.contains(MemFlags::NONTEMPORAL) {
327327
// HACK(nox): This is inefficient but there is no nontemporal memcpy.
328328
let ty = self.backend_type(layout);

0 commit comments

Comments
 (0)
This repository has been archived.