Skip to content

Commit 8fb9f80

Browse files
committed
erase asserts
1 parent ac7ddb3 commit 8fb9f80

File tree

4 files changed

+65
-21
lines changed

4 files changed

+65
-21
lines changed

source/rust_verify/src/config.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ pub struct ArgsX {
109109
pub solver: SmtSolver,
110110
#[cfg(feature = "axiom-usage-info")]
111111
pub axiom_usage_info: bool,
112+
pub new_lifetime: bool,
112113
}
113114

114115
impl ArgsX {
@@ -153,6 +154,7 @@ impl ArgsX {
153154
solver: Default::default(),
154155
#[cfg(feature = "axiom-usage-info")]
155156
axiom_usage_info: Default::default(),
157+
new_lifetime: Default::default(),
156158
}
157159
}
158160
}
@@ -211,6 +213,7 @@ pub fn parse_args_with_imports(
211213
const OPT_NO_EXTERNAL_BY_DEFAULT: &str = "no-external-by-default";
212214
const OPT_NO_VERIFY: &str = "no-verify";
213215
const OPT_NO_LIFETIME: &str = "no-lifetime";
216+
const OPT_NEW_LIFETIME: &str = "new-lifetime";
214217
const OPT_NO_AUTO_RECOMMENDS_CHECK: &str = "no-auto-recommends-check";
215218
const OPT_TIME: &str = "time";
216219
const OPT_TIME_EXPANDED: &str = "time-expanded";
@@ -359,6 +362,7 @@ pub fn parse_args_with_imports(
359362
opts.optflag("", OPT_NO_EXTERNAL_BY_DEFAULT, "(deprecated) Verify all items, even those declared outside the verus! macro, and even if they aren't marked #[verifier::verify]");
360363
opts.optflag("", OPT_NO_VERIFY, "Do not run verification");
361364
opts.optflag("", OPT_NO_LIFETIME, "Do not run lifetime checking on proofs");
365+
opts.optflag("", OPT_NEW_LIFETIME, "New lifetime checking");
362366
opts.optflag(
363367
"",
364368
OPT_NO_AUTO_RECOMMENDS_CHECK,
@@ -561,6 +565,7 @@ pub fn parse_args_with_imports(
561565
no_external_by_default: matches.opt_present(OPT_NO_EXTERNAL_BY_DEFAULT),
562566
no_verify: matches.opt_present(OPT_NO_VERIFY),
563567
no_lifetime: matches.opt_present(OPT_NO_LIFETIME),
568+
new_lifetime: matches.opt_present(OPT_NEW_LIFETIME),
564569
no_auto_recommends_check: matches.opt_present(OPT_NO_AUTO_RECOMMENDS_CHECK),
565570
time: matches.opt_present(OPT_TIME) || matches.opt_present(OPT_TIME_EXPANDED),
566571
time_expanded: matches.opt_present(OPT_TIME_EXPANDED),

source/rust_verify/src/verifier.rs

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2816,25 +2816,34 @@ fn hir_crate<'tcx>(tcx: TyCtxt<'tcx>, _: ()) -> rustc_hir::Crate<'tcx> {
28162816

28172817
impl rustc_driver::Callbacks for VerifierCallbacksEraseMacro {
28182818
fn config(&mut self, config: &mut rustc_interface::interface::Config) {
2819-
config.override_queries = Some(|_session, providers| {
2820-
providers.hir_crate = hir_crate;
2821-
2822-
// Hooking mir_const_qualif solves constness issue in function body,
2823-
// but const-eval will still do check-const when evaluating const
2824-
// value. Thus const_header_wrapper is still needed.
2825-
providers.mir_const_qualif = |_, _| rustc_middle::mir::ConstQualifs::default();
2826-
// Prevent the borrow checker from running, as we will run our own lifetime analysis.
2827-
// Stopping after `after_expansion` used to be enough, but now borrow check is triggered
2828-
// by const evaluation through the mir interpreter.
2829-
providers.mir_borrowck = |tcx, _local_def_id| {
2830-
tcx.arena.alloc(rustc_middle::mir::BorrowCheckResult {
2831-
concrete_opaque_types: rustc_data_structures::fx::FxIndexMap::default(),
2832-
closure_requirements: None,
2833-
used_mut_upvars: smallvec::SmallVec::new(),
2834-
tainted_by_errors: None,
2835-
})
2836-
};
2837-
});
2819+
if !self.verifier.args.new_lifetime {
2820+
config.override_queries = Some(|_session, providers| {
2821+
providers.hir_crate = hir_crate;
2822+
2823+
// Hooking mir_const_qualif solves constness issue in function body,
2824+
// but const-eval will still do check-const when evaluating const
2825+
// value. Thus const_header_wrapper is still needed.
2826+
providers.mir_const_qualif = |_, _| rustc_middle::mir::ConstQualifs::default();
2827+
2828+
// Prevent the borrow checker from running, as we will run our own lifetime analysis.
2829+
// Stopping after `after_expansion` used to be enough, but now borrow check is triggered
2830+
// by const evaluation through the mir interpreter.
2831+
providers.mir_borrowck = |tcx, _local_def_id| {
2832+
tcx.arena.alloc(rustc_middle::mir::BorrowCheckResult {
2833+
concrete_opaque_types: rustc_data_structures::fx::FxIndexMap::default(),
2834+
closure_requirements: None,
2835+
used_mut_upvars: smallvec::SmallVec::new(),
2836+
tainted_by_errors: None,
2837+
})
2838+
};
2839+
});
2840+
} else {
2841+
config.override_queries = Some(|_session, providers| {
2842+
providers.hir_crate = hir_crate;
2843+
providers.mir_const_qualif = |_, _| rustc_middle::mir::ConstQualifs::default();
2844+
rustc_mir_build_verus::verus_provide(providers);
2845+
});
2846+
}
28382847
}
28392848

28402849
fn after_expansion<'tcx>(
@@ -3004,6 +3013,10 @@ impl rustc_driver::Callbacks for VerifierCallbacksEraseMacro {
30043013
}
30053014
);
30063015
}
3007-
rustc_driver::Compilation::Stop
3016+
if self.verifier.args.new_lifetime {
3017+
rustc_driver::Compilation::Continue
3018+
} else {
3019+
rustc_driver::Compilation::Stop
3020+
}
30083021
}
30093022
}

source/rustc_mir_build/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ use rustc_middle::util::Providers;
4141

4242
rustc_fluent_macro::fluent_messages! { "../messages.ftl" }
4343

44+
pub fn verus_provide(providers: &mut Providers) {
45+
providers.thir_body = thir::cx::thir_body;
46+
}
47+
4448
pub fn provide(providers: &mut Providers) {
4549
providers.check_match = thir::pattern::check_match;
4650
providers.lit_to_const = thir::constant::lit_to_const;

source/rustc_mir_build/src/thir/cx/expr.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,29 @@ impl<'tcx> Cx<'tcx> {
258258
}
259259

260260
hir::ExprKind::Call(fun, ref args) => {
261-
if self.typeck_results().is_method_call(expr) {
261+
let fake = match &fun.kind {
262+
hir::ExprKind::Path(qpath) => {
263+
let res = self.typeck_results().qpath_res(&qpath, fun.hir_id);
264+
match res {
265+
hir::def::Res::Def(_, def_id) => {
266+
let f_name = tcx.def_path_str(def_id);
267+
if f_name == "builtin::assert_" {
268+
Some(ExprKind::Tuple {
269+
fields: Box::new([]),
270+
})
271+
} else {
272+
None
273+
}
274+
}
275+
_ => None
276+
}
277+
}
278+
_ => None
279+
};
280+
281+
if fake.is_some() {
282+
fake.unwrap()
283+
} else if self.typeck_results().is_method_call(expr) {
262284
// The callee is something implementing Fn, FnMut, or FnOnce.
263285
// Find the actual method implementation being called and
264286
// build the appropriate UFCS call expression with the

0 commit comments

Comments
 (0)