1
Fork 0

Rename functions reflect that inline const is also "typeck_child"

This commit is contained in:
Gary Guo 2021-11-06 20:01:35 +00:00
parent d0f59f6d65
commit c4103d438f
18 changed files with 64 additions and 73 deletions

View file

@ -797,7 +797,7 @@ rustc_queries! {
/// additional requirements that the closure's creator must verify.
query mir_borrowck(key: LocalDefId) -> &'tcx mir::BorrowCheckResult<'tcx> {
desc { |tcx| "borrow-checking `{}`", tcx.def_path_str(key.to_def_id()) }
cache_on_disk_if(tcx) { tcx.is_closure_or_inline_const(key.to_def_id()) }
cache_on_disk_if(tcx) { tcx.is_typeck_child(key.to_def_id()) }
}
query mir_borrowck_const_arg(key: (LocalDefId, DefId)) -> &'tcx mir::BorrowCheckResult<'tcx> {
desc {

View file

@ -56,7 +56,7 @@ impl<'tcx> Const<'tcx> {
let ty = tcx.type_of(def.def_id_for_type_of());
match Self::try_eval_body_expr(tcx, ty, expr) {
match Self::try_eval_lit_or_param(tcx, ty, expr) {
Some(v) => v,
None => tcx.mk_const(ty::Const {
val: ty::ConstKind::Unevaluated(ty::Unevaluated {
@ -69,7 +69,7 @@ impl<'tcx> Const<'tcx> {
}
}
fn try_eval_body_expr(
fn try_eval_lit_or_param(
tcx: TyCtxt<'tcx>,
ty: Ty<'tcx>,
expr: &'tcx hir::Expr<'tcx>,
@ -141,12 +141,12 @@ impl<'tcx> Const<'tcx> {
let ty = tcx.typeck(def_id).node_type(hir_id);
let ret = match Self::try_eval_body_expr(tcx, ty, expr) {
let ret = match Self::try_eval_lit_or_param(tcx, ty, expr) {
Some(v) => v,
None => {
let outer_def_id = tcx.closure_base_def_id(def_id.to_def_id());
let typeck_root_def_id = tcx.typeck_root_def_id(def_id.to_def_id());
let parent_substs =
tcx.erase_regions(InternalSubsts::identity_for_item(tcx, outer_def_id));
tcx.erase_regions(InternalSubsts::identity_for_item(tcx, typeck_root_def_id));
let substs =
InlineConstSubsts::new(tcx, InlineConstSubstsParts { parent_substs, ty })
.substs;

View file

@ -423,8 +423,9 @@ impl<'tcx> TyCtxt<'tcx> {
matches!(self.def_kind(def_id), DefKind::Closure | DefKind::Generator)
}
/// Returns `true` if `def_id` refers to a closure, generator or inline const.
pub fn is_closure_or_inline_const(self, def_id: DefId) -> bool {
/// Returns `true` if `def_id` refers to a definition that does not have its own
/// type-checking context, i.e. closure, generator or inline const.
pub fn is_typeck_child(self, def_id: DefId) -> bool {
matches!(
self.def_kind(def_id),
DefKind::Closure | DefKind::Generator | DefKind::InlineConst
@ -458,9 +459,9 @@ impl<'tcx> TyCtxt<'tcx> {
/// Therefore, when we fetch the
/// `typeck` the closure, for example, we really wind up
/// fetching the `typeck` the enclosing fn item.
pub fn closure_base_def_id(self, def_id: DefId) -> DefId {
pub fn typeck_root_def_id(self, def_id: DefId) -> DefId {
let mut def_id = def_id;
while self.is_closure_or_inline_const(def_id) {
while self.is_typeck_child(def_id) {
def_id = self.parent(def_id).unwrap_or_else(|| {
bug!("closure {:?} has no parent", def_id);
});