Skip to content

Commit 5a9ec09

Browse files
committed
WIP: investigating changing genv::no_panic return type from bool --> Expr
1 parent dde20f0 commit 5a9ec09

File tree

11 files changed

+59
-28
lines changed

11 files changed

+59
-28
lines changed

crates/flux-fhir-analysis/src/conv/mod.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,9 @@ impl<'genv, 'tcx: 'genv, P: ConvPhase<'genv, 'tcx>> ConvCtxt<P> {
665665
fn_id: MaybeExternId,
666666
fn_sig: &fhir::FnSig,
667667
) -> QueryResult<rty::PolyFnSig> {
668+
let fn_name = self.tcx().def_path_str(fn_id.resolved_id());
669+
eprintln!("trying to conv fn sig for `{fn_name}` with id `{fn_id:?}`");
670+
668671
let decl = &fn_sig.decl;
669672
let header = fn_sig.header;
670673

@@ -680,9 +683,12 @@ impl<'genv, 'tcx: 'genv, P: ConvPhase<'genv, 'tcx>> ConvCtxt<P> {
680683
let no_panic = if let Some(e) = fn_sig.no_panic_if {
681684
self.conv_expr(&mut env, &e)?
682685
} else {
683-
if self.genv().no_panic(fn_id) { Expr::tt() } else { Expr::ff() }
686+
// if self.genv().no_panic(fn_id) { Expr::tt() } else { Expr::ff() }
687+
self.genv().no_panic(fn_id)
684688
};
685689

690+
let fn_name = self.tcx().def_path_str(fn_id.resolved_id());
691+
686692
let fn_sig =
687693
self.conv_fn_decl(&mut env, header.safety(), header.abi, decl, body_id, no_panic)?;
688694

crates/flux-metadata/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ pub struct Tables<K: Eq + Hash> {
177177
func_sort: UnordMap<FluxId<K>, rty::PolyFuncSort>,
178178
func_span: UnordMap<FluxId<K>, Span>,
179179
sort_decl_param_count: UnordMap<FluxId<K>, usize>,
180-
no_panic: UnordMap<K, bool>,
180+
no_panic: UnordMap<K, rty::Expr>,
181181
}
182182

183183
impl CStore {
@@ -256,7 +256,7 @@ impl CrateStore for CStore {
256256
get!(self, adt_sort_def, def_id)
257257
}
258258

259-
fn no_panic(&self, def_id: DefId) -> Option<bool> {
259+
fn no_panic(&self, def_id: DefId) -> Option<rty::Expr> {
260260
get!(self, no_panic, def_id)
261261
}
262262

crates/flux-middle/src/builtin_assoc_refts.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,7 @@ impl<'tcx> GlobalEnv<'_, 'tcx> {
117117
{
118118
let self_ty = alias_reft.self_ty();
119119
let body = match self_ty.as_bty_skipping_binder() {
120-
BaseTy::Closure(_, _, _, no_panic) => {
121-
if *no_panic {
122-
rty::Expr::tt()
123-
} else {
124-
rty::Expr::ff()
125-
}
126-
}
120+
BaseTy::Closure(_, _, _, no_panic) => no_panic.clone(),
127121
_ => rty::Expr::ff(),
128122
};
129123
rty::Lambda::bind_with_vars(body, List::empty(), rty::Sort::Bool)

crates/flux-middle/src/cstore.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pub trait CrateStore {
3636
fn func_sort(&self, def_id: FluxDefId) -> Option<rty::PolyFuncSort>;
3737
fn func_span(&self, def_id: FluxDefId) -> Option<rustc_span::Span>;
3838
fn sort_decl_param_count(&self, def_id: FluxDefId) -> Option<usize>;
39-
fn no_panic(&self, def_id: DefId) -> Option<bool>;
39+
fn no_panic(&self, def_id: DefId) -> Option<rty::Expr>;
4040
}
4141

4242
pub type CrateStoreDyn = dyn CrateStore;

crates/flux-middle/src/global_env.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ impl<'genv, 'tcx> GlobalEnv<'genv, 'tcx> {
457457
}
458458

459459
/// Whether the function is marked with `#[flux::no_panic]`
460-
pub fn no_panic(self, def_id: impl IntoQueryParam<DefId>) -> bool {
460+
pub fn no_panic(self, def_id: impl IntoQueryParam<DefId>) -> rty::Expr {
461461
self.inner.queries.no_panic(self, def_id.into_query_param())
462462
}
463463

crates/flux-middle/src/queries.rs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ pub struct Queries<'genv, 'tcx> {
286286
fn_sig: Cache<DefId, QueryResult<rty::EarlyBinder<rty::PolyFnSig>>>,
287287
lower_late_bound_vars: Cache<LocalDefId, QueryResult<List<ty::BoundVariableKind>>>,
288288
sort_decl_param_count: Cache<FluxDefId, usize>,
289-
no_panic: Cache<DefId, bool>,
289+
no_panic: Cache<DefId, rty::Expr>,
290290
}
291291

292292
impl<'genv, 'tcx> Queries<'genv, 'tcx> {
@@ -629,7 +629,7 @@ impl<'genv, 'tcx> Queries<'genv, 'tcx> {
629629
})
630630
}
631631

632-
pub(crate) fn no_panic(&self, genv: GlobalEnv, def_id: DefId) -> bool {
632+
pub(crate) fn no_panic(&self, genv: GlobalEnv, def_id: DefId) -> Expr {
633633
run_with_cache(&self.no_panic, def_id, || {
634634
def_id.dispatch_query(
635635
genv,
@@ -645,13 +645,22 @@ impl<'genv, 'tcx> Queries<'genv, 'tcx> {
645645
current_id = parent;
646646
continue;
647647
} else {
648-
return false; // Reached top without finding non-dummy
648+
return Expr::ff();
649649
}
650650
}
651651

652-
// Check if current non-dummy item has the `no_panic` attribute
652+
// Check if current non-dummy item has the `no_panic` attribute, or
653+
// a `no_panic_if` attribute.
653654
if genv.fhir_attr_map(current_id).no_panic() {
654-
return true;
655+
return Expr::tt();
656+
} else if let Ok(fn_sig) = genv.fn_sig(current_id) {
657+
let fn_sig = fn_sig.skip_binder().skip_binder();
658+
eprintln!(
659+
"found fn_sig for {}, no_panic_if = {:?}",
660+
genv.tcx().def_path_str(current_id.to_def_id()),
661+
fn_sig.no_panic()
662+
);
663+
return fn_sig.no_panic();
655664
}
656665

657666
// Move to the next parent
@@ -662,10 +671,10 @@ impl<'genv, 'tcx> Queries<'genv, 'tcx> {
662671
}
663672
}
664673

665-
config::no_panic()
674+
Expr::from_bool(config::no_panic())
666675
},
667676
|def_id| genv.cstore().no_panic(def_id),
668-
|_| false,
677+
|_| Expr::ff(),
669678
)
670679
})
671680
}

crates/flux-middle/src/rty/expr.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,13 @@ impl Expr {
476476
}
477477
}
478478

479+
pub fn from_bool(b: bool) -> Expr {
480+
match b {
481+
true => Expr::tt(),
482+
false => Expr::ff(),
483+
}
484+
}
485+
479486
fn const_op(op: &BinOp, c1: &Constant, c2: &Constant) -> Option<Constant> {
480487
match op {
481488
BinOp::Iff => c1.iff(c2),

crates/flux-middle/src/rty/fold.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -938,7 +938,12 @@ impl TypeSuperFoldable for BaseTy {
938938
BaseTy::Array(ty.try_fold_with(folder)?, c.try_fold_with(folder)?)
939939
}
940940
BaseTy::Closure(did, args, gen_args, no_panic) => {
941-
BaseTy::Closure(*did, args.try_fold_with(folder)?, gen_args.clone(), *no_panic)
941+
BaseTy::Closure(
942+
*did,
943+
args.try_fold_with(folder)?,
944+
gen_args.clone(),
945+
no_panic.clone(),
946+
)
942947
}
943948
BaseTy::Coroutine(did, resume_ty, args, gen_args) => {
944949
BaseTy::Coroutine(

crates/flux-middle/src/rty/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ use crate::{
6868
global_env::GlobalEnv,
6969
pretty::{Pretty, PrettyCx},
7070
queries::{QueryErr, QueryResult},
71-
rty::subst::SortSubst,
71+
rty::{self, subst::SortSubst},
7272
};
7373

7474
/// The definition of the data sort automatically generated for a struct or enum.
@@ -713,7 +713,7 @@ pub fn to_closure_sig(
713713
tys: &[Ty],
714714
args: &flux_rustc_bridge::ty::GenericArgs,
715715
poly_sig: &PolyFnSig,
716-
no_panic: bool,
716+
no_panic: Expr,
717717
) -> PolyFnSig {
718718
let closure_args = args.as_closure();
719719
let kind_ty = closure_args.kind_ty().to_rustc(tcx);
@@ -723,7 +723,7 @@ pub fn to_closure_sig(
723723

724724
let mut vars = poly_sig.vars().clone().to_vec();
725725
let fn_sig = poly_sig.clone().skip_binder();
726-
let closure_ty = Ty::closure(closure_id.into(), tys, args, no_panic);
726+
let closure_ty = Ty::closure(closure_id.into(), tys, args, no_panic.clone());
727727
let env_ty = match kind {
728728
ClosureKind::Fn => {
729729
vars.push(BoundVariableKind::Region(BoundRegionKind::ClosureEnv));
@@ -755,7 +755,7 @@ pub fn to_closure_sig(
755755
fn_sig.requires.clone(),
756756
inputs.into(),
757757
output,
758-
if no_panic { crate::rty::Expr::tt() } else { crate::rty::Expr::ff() },
758+
no_panic,
759759
false,
760760
);
761761

@@ -1616,7 +1616,7 @@ impl Ty {
16161616
did: DefId,
16171617
tys: impl Into<List<Ty>>,
16181618
args: &flux_rustc_bridge::ty::GenericArgs,
1619-
no_panic: bool,
1619+
no_panic: rty::Expr,
16201620
) -> Ty {
16211621
BaseTy::Closure(did, tys.into(), args.clone(), no_panic).to_ty()
16221622
}
@@ -1830,7 +1830,7 @@ pub enum BaseTy {
18301830
Alias(AliasKind, AliasTy),
18311831
Array(Ty, Const),
18321832
Never,
1833-
Closure(DefId, /* upvar_tys */ List<Ty>, flux_rustc_bridge::ty::GenericArgs, bool),
1833+
Closure(DefId, /* upvar_tys */ List<Ty>, flux_rustc_bridge::ty::GenericArgs, rty::Expr),
18341834
Coroutine(
18351835
DefId,
18361836
/*resume_ty: */ Ty,

crates/flux-refineck/src/checker.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -943,6 +943,16 @@ impl<'ck, 'genv, 'tcx, M: Mode> Checker<'ck, 'genv, 'tcx, M> {
943943
.deeply_normalize(&mut infcx.at(span))
944944
.with_span(span)?;
945945

946+
// let caller_fn_name = tcx.def_path_str(self.checker_id.root_id().to_def_id());
947+
// let caller_no_panic = self.fn_sig.no_panic();
948+
949+
// println!("caller: no panic for {} is {caller_no_panic:?}", caller_fn_name);
950+
951+
// let callee_fn_name = tcx.def_path_str(callee_def_id.unwrap());
952+
// let callee_no_panic = fn_sig.no_panic();
953+
954+
// println!("callee: no panic for {} is {callee_no_panic:?}", callee_fn_name);
955+
946956
let mut at = infcx.at(span);
947957

948958
if let Some(callee_def_id) = callee_def_id

0 commit comments

Comments
 (0)