Skip to content

Commit 3f07645

Browse files
committed
Lower the assume intrinsic to a MIR statement
1 parent 3c72788 commit 3f07645

File tree

33 files changed

+212
-30
lines changed

33 files changed

+212
-30
lines changed

compiler/rustc_borrowck/src/dataflow.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,7 @@ impl<'tcx> rustc_mir_dataflow::GenKillAnalysis<'tcx> for Borrows<'_, 'tcx> {
392392
| mir::StatementKind::AscribeUserType(..)
393393
| mir::StatementKind::Coverage(..)
394394
| mir::StatementKind::CopyNonOverlapping(..)
395+
| mir::StatementKind::Assume(..)
395396
| mir::StatementKind::Nop => {}
396397
}
397398
}

compiler/rustc_borrowck/src/invalidation.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,14 @@ impl<'cx, 'tcx> Visitor<'tcx> for InvalidationGenerator<'cx, 'tcx> {
7272
self.consume_operand(location, dst);
7373
self.consume_operand(location, count);
7474
}
75-
StatementKind::Nop
75+
// Only relevant for mir typeck
76+
StatementKind::AscribeUserType(..)
77+
// Doesn't have any language semantics
7678
| StatementKind::Coverage(..)
77-
| StatementKind::AscribeUserType(..)
78-
| StatementKind::Retag { .. }
79-
| StatementKind::StorageLive(..) => {
80-
// `Nop`, `AscribeUserType`, `Retag`, and `StorageLive` are irrelevant
81-
// to borrow check.
82-
}
79+
// Takes a `bool` argument, and has no return value, thus being irrelevant for borrowck
80+
| StatementKind::Assume(..)
81+
// Does not actually affect borrowck
82+
| StatementKind::StorageLive(..) => {}
8383
StatementKind::StorageDead(local) => {
8484
self.access_place(
8585
location,
@@ -88,7 +88,10 @@ impl<'cx, 'tcx> Visitor<'tcx> for InvalidationGenerator<'cx, 'tcx> {
8888
LocalMutationIsAllowed::Yes,
8989
);
9090
}
91-
StatementKind::Deinit(..) | StatementKind::SetDiscriminant { .. } => {
91+
StatementKind::Nop
92+
| StatementKind::Retag { .. }
93+
| StatementKind::Deinit(..)
94+
| StatementKind::SetDiscriminant { .. } => {
9295
bug!("Statement not allowed in this MIR phase")
9396
}
9497
}

compiler/rustc_borrowck/src/lib.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -599,14 +599,14 @@ impl<'cx, 'tcx> rustc_mir_dataflow::ResultsVisitor<'cx, 'tcx> for MirBorrowckCtx
599599
"Unexpected CopyNonOverlapping, should only appear after lower_intrinsics",
600600
)
601601
}
602-
StatementKind::Nop
602+
// Only relevant for mir typeck
603+
StatementKind::AscribeUserType(..)
604+
// Doesn't have any language semantics
603605
| StatementKind::Coverage(..)
604-
| StatementKind::AscribeUserType(..)
605-
| StatementKind::Retag { .. }
606-
| StatementKind::StorageLive(..) => {
607-
// `Nop`, `AscribeUserType`, `Retag`, and `StorageLive` are irrelevant
608-
// to borrow check.
609-
}
606+
// Takes a `bool` argument, and has no return value, thus being irrelevant for borrowck
607+
| StatementKind::Assume(..)
608+
// Does not actually affect borrowck
609+
| StatementKind::StorageLive(..) => {}
610610
StatementKind::StorageDead(local) => {
611611
self.access_place(
612612
location,
@@ -616,7 +616,10 @@ impl<'cx, 'tcx> rustc_mir_dataflow::ResultsVisitor<'cx, 'tcx> for MirBorrowckCtx
616616
flow_state,
617617
);
618618
}
619-
StatementKind::Deinit(..) | StatementKind::SetDiscriminant { .. } => {
619+
StatementKind::Nop
620+
| StatementKind::Retag { .. }
621+
| StatementKind::Deinit(..)
622+
| StatementKind::SetDiscriminant { .. } => {
620623
bug!("Statement not allowed in this MIR phase")
621624
}
622625
}

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1309,6 +1309,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
13091309
"Unexpected StatementKind::CopyNonOverlapping, should only appear after lowering_intrinsics",
13101310
),
13111311
StatementKind::FakeRead(..)
1312+
| StatementKind::Assume(..)
13121313
| StatementKind::StorageLive(..)
13131314
| StatementKind::StorageDead(..)
13141315
| StatementKind::Retag { .. }

compiler/rustc_codegen_cranelift/src/base.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -791,6 +791,8 @@ fn codegen_stmt<'tcx>(
791791
| StatementKind::Nop
792792
| StatementKind::FakeRead(..)
793793
| StatementKind::Retag { .. }
794+
// We ignore `assume` intrinsics, they are only useful for optimizations
795+
| StatementKind::Assume(..)
794796
| StatementKind::AscribeUserType(..) => {}
795797

796798
StatementKind::Coverage { .. } => fx.tcx.sess.fatal("-Zcoverage is unimplemented"),

compiler/rustc_codegen_cranelift/src/constant.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,7 @@ pub(crate) fn mir_operand_get_const_val<'tcx>(
540540
return None;
541541
} // conservative handling
542542
StatementKind::Assign(_)
543+
| StatementKind::Assume(_)
543544
| StatementKind::FakeRead(_)
544545
| StatementKind::SetDiscriminant { .. }
545546
| StatementKind::Deinit(_)

compiler/rustc_codegen_cranelift/src/intrinsics/mod.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -357,9 +357,6 @@ fn codegen_regular_intrinsic_call<'tcx>(
357357
let usize_layout = fx.layout_of(fx.tcx.types.usize);
358358

359359
match intrinsic {
360-
sym::assume => {
361-
intrinsic_args!(fx, args => (_a); intrinsic);
362-
}
363360
sym::likely | sym::unlikely => {
364361
intrinsic_args!(fx, args => (a); intrinsic);
365362

compiler/rustc_codegen_ssa/src/mir/intrinsic.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
7777
let result = PlaceRef::new_sized(llresult, fn_abi.ret.layout);
7878

7979
let llval = match name {
80-
sym::assume => {
81-
bx.assume(args[0].immediate());
82-
return;
83-
}
8480
sym::abort => {
8581
bx.abort();
8682
return;

compiler/rustc_codegen_ssa/src/mir/statement.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
9393
bx.memcpy(dst, align, src, align, bytes, crate::MemFlags::empty());
9494
bx
9595
}
96+
mir::StatementKind::Assume(box ref op) => {
97+
let op_val = self.codegen_operand(&mut bx, op);
98+
bx.assume(op_val.immediate());
99+
bx
100+
}
96101
mir::StatementKind::FakeRead(..)
97102
| mir::StatementKind::Retag { .. }
98103
| mir::StatementKind::AscribeUserType(..)

compiler/rustc_const_eval/src/interpret/intrinsics.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -506,12 +506,6 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
506506
// These just return their argument
507507
self.copy_op(&args[0], dest, /*allow_transmute*/ false)?;
508508
}
509-
sym::assume => {
510-
let cond = self.read_scalar(&args[0])?.to_bool()?;
511-
if !cond {
512-
throw_ub_format!("`assume` intrinsic called with `false`");
513-
}
514-
}
515509
sym::raw_eq => {
516510
let result = self.raw_eq_intrinsic(&args[0], &args[1])?;
517511
self.write_scalar(result, dest)?;

0 commit comments

Comments
 (0)