Rollup merge of #136279 - Zalathar:ensure-ok, r=oli-obk
Rename `tcx.ensure()` to `tcx.ensure_ok()`, and improve the associated docs This is all based on my archaeology for https://rust-lang.zulipchat.com/#narrow/channel/182449-t-compiler.2Fhelp/topic/.60TyCtxtEnsure.60. The main renamings are: - `tcx.ensure()` → `tcx.ensure_ok()` - `tcx.ensure_with_value()` → `tcx.ensure_done()` - Query modifier `ensure_forwards_result_if_red` → `return_result_from_ensure_ok` Hopefully these new names are a better fit for the *actual* function and purpose of these query call modes.
This commit is contained in:
commit
58a5f891f9
34 changed files with 262 additions and 206 deletions
|
@ -418,10 +418,10 @@ fn compute_hir_hash(
|
|||
pub fn lower_to_hir(tcx: TyCtxt<'_>, (): ()) -> hir::Crate<'_> {
|
||||
let sess = tcx.sess;
|
||||
// Queries that borrow `resolver_for_lowering`.
|
||||
tcx.ensure_with_value().output_filenames(());
|
||||
tcx.ensure_with_value().early_lint_checks(());
|
||||
tcx.ensure_with_value().debugger_visualizers(LOCAL_CRATE);
|
||||
tcx.ensure_with_value().get_lang_items(());
|
||||
tcx.ensure_done().output_filenames(());
|
||||
tcx.ensure_done().early_lint_checks(());
|
||||
tcx.ensure_done().debugger_visualizers(LOCAL_CRATE);
|
||||
tcx.ensure_done().get_lang_items(());
|
||||
let (mut resolver, krate) = tcx.resolver_for_lowering().steal();
|
||||
|
||||
let ast_index = index_crate(&resolver.node_id_to_def_id, &krate);
|
||||
|
|
|
@ -692,7 +692,7 @@ pub(crate) fn run_aot(
|
|||
|
||||
if tcx.dep_graph.is_fully_enabled() {
|
||||
for cgu in cgus {
|
||||
tcx.ensure().codegen_unit(cgu.name());
|
||||
tcx.ensure_ok().codegen_unit(cgu.name());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -634,7 +634,7 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
|
|||
// unnecessarily.
|
||||
if tcx.dep_graph.is_fully_enabled() {
|
||||
for cgu in codegen_units {
|
||||
tcx.ensure().codegen_unit(cgu.name());
|
||||
tcx.ensure_ok().codegen_unit(cgu.name());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -317,7 +317,7 @@ pub fn run_compiler(at_args: &[String], callbacks: &mut (dyn Callbacks + Send))
|
|||
if let Some(pp_mode) = sess.opts.pretty {
|
||||
if pp_mode.needs_ast_map() {
|
||||
create_and_enter_global_ctxt(compiler, krate, |tcx| {
|
||||
tcx.ensure().early_lint_checks(());
|
||||
tcx.ensure_ok().early_lint_checks(());
|
||||
pretty::print(sess, pp_mode, pretty::PrintExtra::NeedsAstMap { tcx });
|
||||
passes::write_dep_info(tcx);
|
||||
});
|
||||
|
@ -365,7 +365,7 @@ pub fn run_compiler(at_args: &[String], callbacks: &mut (dyn Callbacks + Send))
|
|||
return early_exit();
|
||||
}
|
||||
|
||||
tcx.ensure().analysis(());
|
||||
tcx.ensure_ok().analysis(());
|
||||
|
||||
if callbacks.after_analysis(compiler, tcx) == Compilation::Stop {
|
||||
return early_exit();
|
||||
|
|
|
@ -222,7 +222,7 @@ impl<'tcx> PrintExtra<'tcx> {
|
|||
|
||||
pub fn print<'tcx>(sess: &Session, ppm: PpMode, ex: PrintExtra<'tcx>) {
|
||||
if ppm.needs_analysis() {
|
||||
ex.tcx().ensure().analysis(());
|
||||
ex.tcx().ensure_ok().analysis(());
|
||||
}
|
||||
|
||||
let (src, src_name) = get_source(sess);
|
||||
|
|
|
@ -778,13 +778,13 @@ fn check_static_linkage(tcx: TyCtxt<'_>, def_id: LocalDefId) {
|
|||
pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) {
|
||||
match tcx.def_kind(def_id) {
|
||||
DefKind::Static { .. } => {
|
||||
tcx.ensure().typeck(def_id);
|
||||
tcx.ensure_ok().typeck(def_id);
|
||||
maybe_check_static_with_link_section(tcx, def_id);
|
||||
check_static_inhabited(tcx, def_id);
|
||||
check_static_linkage(tcx, def_id);
|
||||
}
|
||||
DefKind::Const => {
|
||||
tcx.ensure().typeck(def_id);
|
||||
tcx.ensure_ok().typeck(def_id);
|
||||
}
|
||||
DefKind::Enum => {
|
||||
check_enum(tcx, def_id);
|
||||
|
@ -804,7 +804,7 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) {
|
|||
DefKind::Impl { of_trait } => {
|
||||
if of_trait && let Some(impl_trait_header) = tcx.impl_trait_header(def_id) {
|
||||
if tcx
|
||||
.ensure()
|
||||
.ensure_ok()
|
||||
.coherent_trait(impl_trait_header.trait_ref.instantiate_identity().def_id)
|
||||
.is_ok()
|
||||
{
|
||||
|
@ -1042,7 +1042,7 @@ fn check_impl_items_against_trait<'tcx>(
|
|||
continue;
|
||||
};
|
||||
|
||||
let res = tcx.ensure().compare_impl_item(impl_item.expect_local());
|
||||
let res = tcx.ensure_ok().compare_impl_item(impl_item.expect_local());
|
||||
|
||||
if res.is_ok() {
|
||||
match ty_impl_item.kind {
|
||||
|
@ -1488,7 +1488,7 @@ fn check_enum(tcx: TyCtxt<'_>, def_id: LocalDefId) {
|
|||
|
||||
for v in def.variants() {
|
||||
if let ty::VariantDiscr::Explicit(discr_def_id) = v.discr {
|
||||
tcx.ensure().typeck(discr_def_id.expect_local());
|
||||
tcx.ensure_ok().typeck(discr_def_id.expect_local());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2034,7 +2034,7 @@ pub(super) fn check_type_bounds<'tcx>(
|
|||
) -> Result<(), ErrorGuaranteed> {
|
||||
// Avoid bogus "type annotations needed `Foo: Bar`" errors on `impl Bar for Foo` in case
|
||||
// other `Foo` impls are incoherent.
|
||||
tcx.ensure().coherent_trait(impl_trait_ref.def_id)?;
|
||||
tcx.ensure_ok().coherent_trait(impl_trait_ref.def_id)?;
|
||||
|
||||
let param_env = tcx.param_env(impl_ty.def_id);
|
||||
debug!(?param_env);
|
||||
|
|
|
@ -1046,7 +1046,7 @@ fn check_associated_item(
|
|||
|
||||
// Avoid bogus "type annotations needed `Foo: Bar`" errors on `impl Bar for Foo` in case
|
||||
// other `Foo` impls are incoherent.
|
||||
tcx.ensure()
|
||||
tcx.ensure_ok()
|
||||
.coherent_trait(tcx.parent(item.trait_item_def_id.unwrap_or(item_id.into())))?;
|
||||
|
||||
let self_ty = match item.container {
|
||||
|
@ -1354,7 +1354,7 @@ fn check_impl<'tcx>(
|
|||
let trait_ref = tcx.impl_trait_ref(item.owner_id).unwrap().instantiate_identity();
|
||||
// Avoid bogus "type annotations needed `Foo: Bar`" errors on `impl Bar for Foo` in case
|
||||
// other `Foo` impls are incoherent.
|
||||
tcx.ensure().coherent_trait(trait_ref.def_id)?;
|
||||
tcx.ensure_ok().coherent_trait(trait_ref.def_id)?;
|
||||
let trait_span = hir_trait_ref.path.span;
|
||||
let trait_ref = wfcx.normalize(
|
||||
trait_span,
|
||||
|
@ -2268,11 +2268,13 @@ impl<'tcx> WfCheckingCtxt<'_, 'tcx> {
|
|||
fn check_mod_type_wf(tcx: TyCtxt<'_>, module: LocalModDefId) -> Result<(), ErrorGuaranteed> {
|
||||
let items = tcx.hir_module_items(module);
|
||||
let res = items
|
||||
.par_items(|item| tcx.ensure().check_well_formed(item.owner_id.def_id))
|
||||
.and(items.par_impl_items(|item| tcx.ensure().check_well_formed(item.owner_id.def_id)))
|
||||
.and(items.par_trait_items(|item| tcx.ensure().check_well_formed(item.owner_id.def_id)))
|
||||
.and(items.par_foreign_items(|item| tcx.ensure().check_well_formed(item.owner_id.def_id)))
|
||||
.and(items.par_opaques(|item| tcx.ensure().check_well_formed(item)));
|
||||
.par_items(|item| tcx.ensure_ok().check_well_formed(item.owner_id.def_id))
|
||||
.and(items.par_impl_items(|item| tcx.ensure_ok().check_well_formed(item.owner_id.def_id)))
|
||||
.and(items.par_trait_items(|item| tcx.ensure_ok().check_well_formed(item.owner_id.def_id)))
|
||||
.and(
|
||||
items.par_foreign_items(|item| tcx.ensure_ok().check_well_formed(item.owner_id.def_id)),
|
||||
)
|
||||
.and(items.par_opaques(|item| tcx.ensure_ok().check_well_formed(item)));
|
||||
if module == LocalModDefId::CRATE_DEF_ID {
|
||||
super::entry::check_for_entry_fn(tcx);
|
||||
}
|
||||
|
|
|
@ -192,7 +192,7 @@ fn visit_implementation_of_coerce_unsized(checker: &Checker<'_>) -> Result<(), E
|
|||
// errors; other parts of the code may demand it for the info of
|
||||
// course.
|
||||
let span = tcx.def_span(impl_did);
|
||||
tcx.at(span).ensure().coerce_unsized_info(impl_did)
|
||||
tcx.at(span).ensure_ok().coerce_unsized_info(impl_did)
|
||||
}
|
||||
|
||||
fn visit_implementation_of_dispatch_from_dyn(checker: &Checker<'_>) -> Result<(), ErrorGuaranteed> {
|
||||
|
|
|
@ -151,7 +151,7 @@ fn coherent_trait(tcx: TyCtxt<'_>, def_id: DefId) -> Result<(), ErrorGuaranteed>
|
|||
let Some(impls) = tcx.all_local_trait_impls(()).get(&def_id) else { return Ok(()) };
|
||||
// Trigger building the specialization graph for the trait. This will detect and report any
|
||||
// overlap errors.
|
||||
let mut res = tcx.ensure().specialization_graph_of(def_id);
|
||||
let mut res = tcx.ensure_ok().specialization_graph_of(def_id);
|
||||
|
||||
for &impl_def_id in impls {
|
||||
let trait_header = tcx.impl_trait_header(impl_def_id).unwrap();
|
||||
|
@ -162,7 +162,7 @@ fn coherent_trait(tcx: TyCtxt<'_>, def_id: DefId) -> Result<(), ErrorGuaranteed>
|
|||
.and(check_impl(tcx, impl_def_id, trait_ref, trait_def))
|
||||
.and(check_object_overlap(tcx, impl_def_id, trait_ref))
|
||||
.and(unsafety::check_item(tcx, impl_def_id, trait_header, trait_def))
|
||||
.and(tcx.ensure().orphan_check_impl(impl_def_id))
|
||||
.and(tcx.ensure_ok().orphan_check_impl(impl_def_id))
|
||||
.and(builtin::check_trait(tcx, def_id, impl_def_id, trait_header));
|
||||
}
|
||||
|
||||
|
|
|
@ -292,16 +292,16 @@ impl<'tcx> Visitor<'tcx> for CollectItemTypesVisitor<'tcx> {
|
|||
match param.kind {
|
||||
hir::GenericParamKind::Lifetime { .. } => {}
|
||||
hir::GenericParamKind::Type { default: Some(_), .. } => {
|
||||
self.tcx.ensure().type_of(param.def_id);
|
||||
self.tcx.ensure_ok().type_of(param.def_id);
|
||||
}
|
||||
hir::GenericParamKind::Type { .. } => {}
|
||||
hir::GenericParamKind::Const { default, .. } => {
|
||||
self.tcx.ensure().type_of(param.def_id);
|
||||
self.tcx.ensure_ok().type_of(param.def_id);
|
||||
if let Some(default) = default {
|
||||
// need to store default and type of default
|
||||
self.tcx.ensure().const_param_default(param.def_id);
|
||||
self.tcx.ensure_ok().const_param_default(param.def_id);
|
||||
if let hir::ConstArgKind::Anon(ac) = default.kind {
|
||||
self.tcx.ensure().type_of(ac.def_id);
|
||||
self.tcx.ensure_ok().type_of(ac.def_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -312,8 +312,8 @@ impl<'tcx> Visitor<'tcx> for CollectItemTypesVisitor<'tcx> {
|
|||
|
||||
fn visit_expr(&mut self, expr: &'tcx hir::Expr<'tcx>) {
|
||||
if let hir::ExprKind::Closure(closure) = expr.kind {
|
||||
self.tcx.ensure().generics_of(closure.def_id);
|
||||
self.tcx.ensure().codegen_fn_attrs(closure.def_id);
|
||||
self.tcx.ensure_ok().generics_of(closure.def_id);
|
||||
self.tcx.ensure_ok().codegen_fn_attrs(closure.def_id);
|
||||
// We do not call `type_of` for closures here as that
|
||||
// depends on typecheck and would therefore hide
|
||||
// any further errors in case one typeck fails.
|
||||
|
@ -325,15 +325,15 @@ impl<'tcx> Visitor<'tcx> for CollectItemTypesVisitor<'tcx> {
|
|||
/// `check_item_type` ensures that it's called instead.
|
||||
fn visit_opaque_ty(&mut self, opaque: &'tcx hir::OpaqueTy<'tcx>) {
|
||||
let def_id = opaque.def_id;
|
||||
self.tcx.ensure().generics_of(def_id);
|
||||
self.tcx.ensure().predicates_of(def_id);
|
||||
self.tcx.ensure().explicit_item_bounds(def_id);
|
||||
self.tcx.ensure().explicit_item_self_bounds(def_id);
|
||||
self.tcx.ensure().item_bounds(def_id);
|
||||
self.tcx.ensure().item_self_bounds(def_id);
|
||||
self.tcx.ensure_ok().generics_of(def_id);
|
||||
self.tcx.ensure_ok().predicates_of(def_id);
|
||||
self.tcx.ensure_ok().explicit_item_bounds(def_id);
|
||||
self.tcx.ensure_ok().explicit_item_self_bounds(def_id);
|
||||
self.tcx.ensure_ok().item_bounds(def_id);
|
||||
self.tcx.ensure_ok().item_self_bounds(def_id);
|
||||
if self.tcx.is_conditionally_const(def_id) {
|
||||
self.tcx.ensure().explicit_implied_const_bounds(def_id);
|
||||
self.tcx.ensure().const_conditions(def_id);
|
||||
self.tcx.ensure_ok().explicit_implied_const_bounds(def_id);
|
||||
self.tcx.ensure_ok().const_conditions(def_id);
|
||||
}
|
||||
intravisit::walk_opaque_ty(self, opaque);
|
||||
}
|
||||
|
@ -683,20 +683,20 @@ fn lower_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) {
|
|||
hir::ItemKind::ForeignMod { items, .. } => {
|
||||
for item in *items {
|
||||
let item = tcx.hir().foreign_item(item.id);
|
||||
tcx.ensure().generics_of(item.owner_id);
|
||||
tcx.ensure().type_of(item.owner_id);
|
||||
tcx.ensure().predicates_of(item.owner_id);
|
||||
tcx.ensure_ok().generics_of(item.owner_id);
|
||||
tcx.ensure_ok().type_of(item.owner_id);
|
||||
tcx.ensure_ok().predicates_of(item.owner_id);
|
||||
if tcx.is_conditionally_const(def_id) {
|
||||
tcx.ensure().explicit_implied_const_bounds(def_id);
|
||||
tcx.ensure().const_conditions(def_id);
|
||||
tcx.ensure_ok().explicit_implied_const_bounds(def_id);
|
||||
tcx.ensure_ok().const_conditions(def_id);
|
||||
}
|
||||
match item.kind {
|
||||
hir::ForeignItemKind::Fn(..) => {
|
||||
tcx.ensure().codegen_fn_attrs(item.owner_id);
|
||||
tcx.ensure().fn_sig(item.owner_id)
|
||||
tcx.ensure_ok().codegen_fn_attrs(item.owner_id);
|
||||
tcx.ensure_ok().fn_sig(item.owner_id)
|
||||
}
|
||||
hir::ForeignItemKind::Static(..) => {
|
||||
tcx.ensure().codegen_fn_attrs(item.owner_id);
|
||||
tcx.ensure_ok().codegen_fn_attrs(item.owner_id);
|
||||
let mut visitor = HirPlaceholderCollector::default();
|
||||
visitor.visit_foreign_item(item);
|
||||
placeholder_type_error(
|
||||
|
@ -713,40 +713,40 @@ fn lower_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) {
|
|||
}
|
||||
}
|
||||
hir::ItemKind::Enum(..) => {
|
||||
tcx.ensure().generics_of(def_id);
|
||||
tcx.ensure().type_of(def_id);
|
||||
tcx.ensure().predicates_of(def_id);
|
||||
tcx.ensure_ok().generics_of(def_id);
|
||||
tcx.ensure_ok().type_of(def_id);
|
||||
tcx.ensure_ok().predicates_of(def_id);
|
||||
lower_enum_variant_types(tcx, def_id.to_def_id());
|
||||
}
|
||||
hir::ItemKind::Impl { .. } => {
|
||||
tcx.ensure().generics_of(def_id);
|
||||
tcx.ensure().type_of(def_id);
|
||||
tcx.ensure().impl_trait_header(def_id);
|
||||
tcx.ensure().predicates_of(def_id);
|
||||
tcx.ensure().associated_items(def_id);
|
||||
tcx.ensure_ok().generics_of(def_id);
|
||||
tcx.ensure_ok().type_of(def_id);
|
||||
tcx.ensure_ok().impl_trait_header(def_id);
|
||||
tcx.ensure_ok().predicates_of(def_id);
|
||||
tcx.ensure_ok().associated_items(def_id);
|
||||
}
|
||||
hir::ItemKind::Trait(..) => {
|
||||
tcx.ensure().generics_of(def_id);
|
||||
tcx.ensure().trait_def(def_id);
|
||||
tcx.ensure_ok().generics_of(def_id);
|
||||
tcx.ensure_ok().trait_def(def_id);
|
||||
tcx.at(it.span).explicit_super_predicates_of(def_id);
|
||||
tcx.ensure().predicates_of(def_id);
|
||||
tcx.ensure().associated_items(def_id);
|
||||
tcx.ensure_ok().predicates_of(def_id);
|
||||
tcx.ensure_ok().associated_items(def_id);
|
||||
}
|
||||
hir::ItemKind::TraitAlias(..) => {
|
||||
tcx.ensure().generics_of(def_id);
|
||||
tcx.ensure_ok().generics_of(def_id);
|
||||
tcx.at(it.span).explicit_implied_predicates_of(def_id);
|
||||
tcx.at(it.span).explicit_super_predicates_of(def_id);
|
||||
tcx.ensure().predicates_of(def_id);
|
||||
tcx.ensure_ok().predicates_of(def_id);
|
||||
}
|
||||
hir::ItemKind::Struct(struct_def, _) | hir::ItemKind::Union(struct_def, _) => {
|
||||
tcx.ensure().generics_of(def_id);
|
||||
tcx.ensure().type_of(def_id);
|
||||
tcx.ensure().predicates_of(def_id);
|
||||
tcx.ensure_ok().generics_of(def_id);
|
||||
tcx.ensure_ok().type_of(def_id);
|
||||
tcx.ensure_ok().predicates_of(def_id);
|
||||
|
||||
for f in struct_def.fields() {
|
||||
tcx.ensure().generics_of(f.def_id);
|
||||
tcx.ensure().type_of(f.def_id);
|
||||
tcx.ensure().predicates_of(f.def_id);
|
||||
tcx.ensure_ok().generics_of(f.def_id);
|
||||
tcx.ensure_ok().type_of(f.def_id);
|
||||
tcx.ensure_ok().predicates_of(f.def_id);
|
||||
}
|
||||
|
||||
if let Some(ctor_def_id) = struct_def.ctor_def_id() {
|
||||
|
@ -755,15 +755,15 @@ fn lower_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) {
|
|||
}
|
||||
|
||||
hir::ItemKind::TyAlias(..) => {
|
||||
tcx.ensure().generics_of(def_id);
|
||||
tcx.ensure().type_of(def_id);
|
||||
tcx.ensure().predicates_of(def_id);
|
||||
tcx.ensure_ok().generics_of(def_id);
|
||||
tcx.ensure_ok().type_of(def_id);
|
||||
tcx.ensure_ok().predicates_of(def_id);
|
||||
}
|
||||
|
||||
hir::ItemKind::Static(ty, ..) | hir::ItemKind::Const(ty, ..) => {
|
||||
tcx.ensure().generics_of(def_id);
|
||||
tcx.ensure().type_of(def_id);
|
||||
tcx.ensure().predicates_of(def_id);
|
||||
tcx.ensure_ok().generics_of(def_id);
|
||||
tcx.ensure_ok().type_of(def_id);
|
||||
tcx.ensure_ok().predicates_of(def_id);
|
||||
if !ty.is_suggestable_infer_ty() {
|
||||
let mut visitor = HirPlaceholderCollector::default();
|
||||
visitor.visit_item(it);
|
||||
|
@ -779,11 +779,11 @@ fn lower_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) {
|
|||
}
|
||||
|
||||
hir::ItemKind::Fn { .. } => {
|
||||
tcx.ensure().generics_of(def_id);
|
||||
tcx.ensure().type_of(def_id);
|
||||
tcx.ensure().predicates_of(def_id);
|
||||
tcx.ensure().fn_sig(def_id);
|
||||
tcx.ensure().codegen_fn_attrs(def_id);
|
||||
tcx.ensure_ok().generics_of(def_id);
|
||||
tcx.ensure_ok().type_of(def_id);
|
||||
tcx.ensure_ok().predicates_of(def_id);
|
||||
tcx.ensure_ok().fn_sig(def_id);
|
||||
tcx.ensure_ok().codegen_fn_attrs(def_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -791,18 +791,18 @@ fn lower_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) {
|
|||
fn lower_trait_item(tcx: TyCtxt<'_>, trait_item_id: hir::TraitItemId) {
|
||||
let trait_item = tcx.hir().trait_item(trait_item_id);
|
||||
let def_id = trait_item_id.owner_id;
|
||||
tcx.ensure().generics_of(def_id);
|
||||
tcx.ensure_ok().generics_of(def_id);
|
||||
let icx = ItemCtxt::new(tcx, def_id.def_id);
|
||||
|
||||
match trait_item.kind {
|
||||
hir::TraitItemKind::Fn(..) => {
|
||||
tcx.ensure().codegen_fn_attrs(def_id);
|
||||
tcx.ensure().type_of(def_id);
|
||||
tcx.ensure().fn_sig(def_id);
|
||||
tcx.ensure_ok().codegen_fn_attrs(def_id);
|
||||
tcx.ensure_ok().type_of(def_id);
|
||||
tcx.ensure_ok().fn_sig(def_id);
|
||||
}
|
||||
|
||||
hir::TraitItemKind::Const(ty, body_id) => {
|
||||
tcx.ensure().type_of(def_id);
|
||||
tcx.ensure_ok().type_of(def_id);
|
||||
if !tcx.dcx().has_stashed_diagnostic(ty.span, StashKey::ItemNoType)
|
||||
&& !(ty.is_suggestable_infer_ty() && body_id.is_some())
|
||||
{
|
||||
|
@ -821,9 +821,9 @@ fn lower_trait_item(tcx: TyCtxt<'_>, trait_item_id: hir::TraitItemId) {
|
|||
}
|
||||
|
||||
hir::TraitItemKind::Type(_, Some(_)) => {
|
||||
tcx.ensure().item_bounds(def_id);
|
||||
tcx.ensure().item_self_bounds(def_id);
|
||||
tcx.ensure().type_of(def_id);
|
||||
tcx.ensure_ok().item_bounds(def_id);
|
||||
tcx.ensure_ok().item_self_bounds(def_id);
|
||||
tcx.ensure_ok().type_of(def_id);
|
||||
// Account for `type T = _;`.
|
||||
let mut visitor = HirPlaceholderCollector::default();
|
||||
visitor.visit_trait_item(trait_item);
|
||||
|
@ -838,8 +838,8 @@ fn lower_trait_item(tcx: TyCtxt<'_>, trait_item_id: hir::TraitItemId) {
|
|||
}
|
||||
|
||||
hir::TraitItemKind::Type(_, None) => {
|
||||
tcx.ensure().item_bounds(def_id);
|
||||
tcx.ensure().item_self_bounds(def_id);
|
||||
tcx.ensure_ok().item_bounds(def_id);
|
||||
tcx.ensure_ok().item_self_bounds(def_id);
|
||||
// #74612: Visit and try to find bad placeholders
|
||||
// even if there is no concrete type.
|
||||
let mut visitor = HirPlaceholderCollector::default();
|
||||
|
@ -856,20 +856,20 @@ fn lower_trait_item(tcx: TyCtxt<'_>, trait_item_id: hir::TraitItemId) {
|
|||
}
|
||||
};
|
||||
|
||||
tcx.ensure().predicates_of(def_id);
|
||||
tcx.ensure_ok().predicates_of(def_id);
|
||||
}
|
||||
|
||||
fn lower_impl_item(tcx: TyCtxt<'_>, impl_item_id: hir::ImplItemId) {
|
||||
let def_id = impl_item_id.owner_id;
|
||||
tcx.ensure().generics_of(def_id);
|
||||
tcx.ensure().type_of(def_id);
|
||||
tcx.ensure().predicates_of(def_id);
|
||||
tcx.ensure_ok().generics_of(def_id);
|
||||
tcx.ensure_ok().type_of(def_id);
|
||||
tcx.ensure_ok().predicates_of(def_id);
|
||||
let impl_item = tcx.hir().impl_item(impl_item_id);
|
||||
let icx = ItemCtxt::new(tcx, def_id.def_id);
|
||||
match impl_item.kind {
|
||||
hir::ImplItemKind::Fn(..) => {
|
||||
tcx.ensure().codegen_fn_attrs(def_id);
|
||||
tcx.ensure().fn_sig(def_id);
|
||||
tcx.ensure_ok().codegen_fn_attrs(def_id);
|
||||
tcx.ensure_ok().fn_sig(def_id);
|
||||
}
|
||||
hir::ImplItemKind::Type(_) => {
|
||||
// Account for `type T = _;`
|
||||
|
@ -904,9 +904,9 @@ fn lower_impl_item(tcx: TyCtxt<'_>, impl_item_id: hir::ImplItemId) {
|
|||
}
|
||||
|
||||
fn lower_variant_ctor(tcx: TyCtxt<'_>, def_id: LocalDefId) {
|
||||
tcx.ensure().generics_of(def_id);
|
||||
tcx.ensure().type_of(def_id);
|
||||
tcx.ensure().predicates_of(def_id);
|
||||
tcx.ensure_ok().generics_of(def_id);
|
||||
tcx.ensure_ok().type_of(def_id);
|
||||
tcx.ensure_ok().predicates_of(def_id);
|
||||
}
|
||||
|
||||
fn lower_enum_variant_types(tcx: TyCtxt<'_>, def_id: DefId) {
|
||||
|
@ -937,9 +937,9 @@ fn lower_enum_variant_types(tcx: TyCtxt<'_>, def_id: DefId) {
|
|||
);
|
||||
|
||||
for f in &variant.fields {
|
||||
tcx.ensure().generics_of(f.did);
|
||||
tcx.ensure().type_of(f.did);
|
||||
tcx.ensure().predicates_of(f.did);
|
||||
tcx.ensure_ok().generics_of(f.did);
|
||||
tcx.ensure_ok().type_of(f.did);
|
||||
tcx.ensure_ok().predicates_of(f.did);
|
||||
}
|
||||
|
||||
// Lower the ctor, if any. This also registers the variant as an item.
|
||||
|
|
|
@ -62,7 +62,7 @@ pub(crate) fn check_impl_wf(
|
|||
// Check that the args are constrained. We queryfied the check for ty/const params
|
||||
// since unconstrained type/const params cause ICEs in projection, so we want to
|
||||
// detect those specifically and project those to `TyKind::Error`.
|
||||
let mut res = tcx.ensure().enforce_impl_non_lifetime_params_are_constrained(impl_def_id);
|
||||
let mut res = tcx.ensure_ok().enforce_impl_non_lifetime_params_are_constrained(impl_def_id);
|
||||
res = res.and(enforce_impl_lifetime_params_are_constrained(tcx, impl_def_id));
|
||||
|
||||
if tcx.features().min_specialization() {
|
||||
|
|
|
@ -100,7 +100,7 @@ use rustc_middle::middle;
|
|||
use rustc_middle::mir::interpret::GlobalId;
|
||||
use rustc_middle::query::Providers;
|
||||
use rustc_middle::ty::{self, Const, Ty, TyCtxt};
|
||||
use rustc_span::Span;
|
||||
use rustc_span::{ErrorGuaranteed, Span};
|
||||
use rustc_trait_selection::traits;
|
||||
|
||||
pub use crate::collect::suggest_impl_trait;
|
||||
|
@ -139,16 +139,20 @@ pub fn check_crate(tcx: TyCtxt<'_>) {
|
|||
let _prof_timer = tcx.sess.timer("type_check_crate");
|
||||
|
||||
tcx.sess.time("coherence_checking", || {
|
||||
// When discarding query call results, use an explicit type to indicate
|
||||
// what we are intending to discard, to help future type-based refactoring.
|
||||
type R = Result<(), ErrorGuaranteed>;
|
||||
|
||||
tcx.hir().par_for_each_module(|module| {
|
||||
let _ = tcx.ensure().check_mod_type_wf(module);
|
||||
let _: R = tcx.ensure_ok().check_mod_type_wf(module);
|
||||
});
|
||||
|
||||
for &trait_def_id in tcx.all_local_trait_impls(()).keys() {
|
||||
let _ = tcx.ensure().coherent_trait(trait_def_id);
|
||||
let _: R = tcx.ensure_ok().coherent_trait(trait_def_id);
|
||||
}
|
||||
// these queries are executed for side-effects (error reporting):
|
||||
let _ = tcx.ensure().crate_inherent_impls_validity_check(());
|
||||
let _ = tcx.ensure().crate_inherent_impls_overlap_check(());
|
||||
let _: R = tcx.ensure_ok().crate_inherent_impls_validity_check(());
|
||||
let _: R = tcx.ensure_ok().crate_inherent_impls_overlap_check(());
|
||||
});
|
||||
|
||||
if tcx.features().rustc_attrs() {
|
||||
|
@ -167,12 +171,12 @@ pub fn check_crate(tcx: TyCtxt<'_>) {
|
|||
tcx.hir().par_body_owners(|item_def_id| {
|
||||
let def_kind = tcx.def_kind(item_def_id);
|
||||
match def_kind {
|
||||
DefKind::Static { .. } => tcx.ensure().eval_static_initializer(item_def_id),
|
||||
DefKind::Static { .. } => tcx.ensure_ok().eval_static_initializer(item_def_id),
|
||||
DefKind::Const if tcx.generics_of(item_def_id).is_empty() => {
|
||||
let instance = ty::Instance::new(item_def_id.into(), ty::GenericArgs::empty());
|
||||
let cid = GlobalId { instance, promoted: None };
|
||||
let typing_env = ty::TypingEnv::fully_monomorphized();
|
||||
tcx.ensure().eval_to_const_value_raw(typing_env.as_query_input(cid));
|
||||
tcx.ensure_ok().eval_to_const_value_raw(typing_env.as_query_input(cid));
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
|
@ -185,11 +189,11 @@ pub fn check_crate(tcx: TyCtxt<'_>) {
|
|||
tcx.hir().par_body_owners(|item_def_id| {
|
||||
let def_kind = tcx.def_kind(item_def_id);
|
||||
if !matches!(def_kind, DefKind::AnonConst) {
|
||||
tcx.ensure().typeck(item_def_id);
|
||||
tcx.ensure_ok().typeck(item_def_id);
|
||||
}
|
||||
});
|
||||
|
||||
tcx.ensure().check_unused_traits(());
|
||||
tcx.ensure_ok().check_unused_traits(());
|
||||
}
|
||||
|
||||
/// Lower a [`hir::Ty`] to a [`Ty`].
|
||||
|
|
|
@ -49,7 +49,7 @@ pub(crate) fn check_legal_trait_for_method_call(
|
|||
};
|
||||
return Err(tcx.dcx().emit_err(errors::ExplicitDestructorCall { span, sugg }));
|
||||
}
|
||||
tcx.ensure().coherent_trait(trait_id)
|
||||
tcx.ensure_ok().coherent_trait(trait_id)
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
|
|
|
@ -832,20 +832,20 @@ fn run_required_analyses(tcx: TyCtxt<'_>) {
|
|||
sess.time("misc_checking_1", || {
|
||||
parallel!(
|
||||
{
|
||||
sess.time("looking_for_entry_point", || tcx.ensure().entry_fn(()));
|
||||
sess.time("looking_for_entry_point", || tcx.ensure_ok().entry_fn(()));
|
||||
|
||||
sess.time("looking_for_derive_registrar", || {
|
||||
tcx.ensure().proc_macro_decls_static(())
|
||||
tcx.ensure_ok().proc_macro_decls_static(())
|
||||
});
|
||||
|
||||
CStore::from_tcx(tcx).report_unused_deps(tcx);
|
||||
},
|
||||
{
|
||||
tcx.hir().par_for_each_module(|module| {
|
||||
tcx.ensure().check_mod_loops(module);
|
||||
tcx.ensure().check_mod_attrs(module);
|
||||
tcx.ensure().check_mod_naked_functions(module);
|
||||
tcx.ensure().check_mod_unstable_api_usage(module);
|
||||
tcx.ensure_ok().check_mod_loops(module);
|
||||
tcx.ensure_ok().check_mod_attrs(module);
|
||||
tcx.ensure_ok().check_mod_naked_functions(module);
|
||||
tcx.ensure_ok().check_mod_unstable_api_usage(module);
|
||||
});
|
||||
},
|
||||
{
|
||||
|
@ -858,8 +858,8 @@ fn run_required_analyses(tcx: TyCtxt<'_>) {
|
|||
// since they might not otherwise get called.
|
||||
// This marks the corresponding crate-level attributes
|
||||
// as used, and ensures that their values are valid.
|
||||
tcx.ensure().limits(());
|
||||
tcx.ensure().stability_index(());
|
||||
tcx.ensure_ok().limits(());
|
||||
tcx.ensure_ok().stability_index(());
|
||||
}
|
||||
);
|
||||
});
|
||||
|
@ -868,7 +868,7 @@ fn run_required_analyses(tcx: TyCtxt<'_>) {
|
|||
sess.time("MIR_coroutine_by_move_body", || {
|
||||
tcx.hir().par_body_owners(|def_id| {
|
||||
if tcx.needs_coroutine_by_move_body_def_id(def_id.to_def_id()) {
|
||||
tcx.ensure_with_value().coroutine_by_move_body_def_id(def_id);
|
||||
tcx.ensure_done().coroutine_by_move_body_def_id(def_id);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
@ -883,13 +883,13 @@ fn run_required_analyses(tcx: TyCtxt<'_>) {
|
|||
tcx.hir().par_body_owners(|def_id| {
|
||||
// Run unsafety check because it's responsible for stealing and
|
||||
// deallocating THIR.
|
||||
tcx.ensure().check_unsafety(def_id);
|
||||
tcx.ensure().mir_borrowck(def_id)
|
||||
tcx.ensure_ok().check_unsafety(def_id);
|
||||
tcx.ensure_ok().mir_borrowck(def_id)
|
||||
});
|
||||
});
|
||||
sess.time("MIR_effect_checking", || {
|
||||
tcx.hir().par_body_owners(|def_id| {
|
||||
tcx.ensure().has_ffi_unwind_calls(def_id);
|
||||
tcx.ensure_ok().has_ffi_unwind_calls(def_id);
|
||||
|
||||
// If we need to codegen, ensure that we emit all errors from
|
||||
// `mir_drops_elaborated_and_const_checked` now, to avoid discovering
|
||||
|
@ -897,15 +897,15 @@ fn run_required_analyses(tcx: TyCtxt<'_>) {
|
|||
if tcx.sess.opts.output_types.should_codegen()
|
||||
|| tcx.hir().body_const_context(def_id).is_some()
|
||||
{
|
||||
tcx.ensure().mir_drops_elaborated_and_const_checked(def_id);
|
||||
tcx.ensure_ok().mir_drops_elaborated_and_const_checked(def_id);
|
||||
}
|
||||
});
|
||||
});
|
||||
sess.time("coroutine_obligations", || {
|
||||
tcx.hir().par_body_owners(|def_id| {
|
||||
if tcx.is_coroutine(def_id.to_def_id()) {
|
||||
tcx.ensure().mir_coroutine_witnesses(def_id);
|
||||
tcx.ensure().check_coroutine_obligations(
|
||||
tcx.ensure_ok().mir_coroutine_witnesses(def_id);
|
||||
tcx.ensure_ok().check_coroutine_obligations(
|
||||
tcx.typeck_root_def_id(def_id.to_def_id()).expect_local(),
|
||||
);
|
||||
}
|
||||
|
@ -950,15 +950,16 @@ fn analysis(tcx: TyCtxt<'_>, (): ()) {
|
|||
sess.time("misc_checking_3", || {
|
||||
parallel!(
|
||||
{
|
||||
tcx.ensure().effective_visibilities(());
|
||||
tcx.ensure_ok().effective_visibilities(());
|
||||
|
||||
parallel!(
|
||||
{
|
||||
tcx.ensure().check_private_in_public(());
|
||||
tcx.ensure_ok().check_private_in_public(());
|
||||
},
|
||||
{
|
||||
tcx.hir()
|
||||
.par_for_each_module(|module| tcx.ensure().check_mod_deathness(module));
|
||||
tcx.hir().par_for_each_module(|module| {
|
||||
tcx.ensure_ok().check_mod_deathness(module)
|
||||
});
|
||||
},
|
||||
{
|
||||
sess.time("lint_checking", || {
|
||||
|
@ -966,14 +967,14 @@ fn analysis(tcx: TyCtxt<'_>, (): ()) {
|
|||
});
|
||||
},
|
||||
{
|
||||
tcx.ensure().clashing_extern_declarations(());
|
||||
tcx.ensure_ok().clashing_extern_declarations(());
|
||||
}
|
||||
);
|
||||
},
|
||||
{
|
||||
sess.time("privacy_checking_modules", || {
|
||||
tcx.hir().par_for_each_module(|module| {
|
||||
tcx.ensure().check_mod_privacy(module);
|
||||
tcx.ensure_ok().check_mod_privacy(module);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@ -981,7 +982,7 @@ fn analysis(tcx: TyCtxt<'_>, (): ()) {
|
|||
|
||||
// This check has to be run after all lints are done processing. We don't
|
||||
// define a lint filter, as all lint checks should have finished at this point.
|
||||
sess.time("check_lint_expectations", || tcx.ensure().check_expectations(None));
|
||||
sess.time("check_lint_expectations", || tcx.ensure_ok().check_expectations(None));
|
||||
|
||||
// This query is only invoked normally if a diagnostic is emitted that needs any
|
||||
// diagnostic item. If the crate compiles without checking any diagnostic items,
|
||||
|
@ -1006,7 +1007,7 @@ fn check_for_rustc_errors_attr(tcx: TyCtxt<'_>) {
|
|||
)
|
||||
}) =>
|
||||
{
|
||||
tcx.ensure().trigger_delayed_bug(def_id);
|
||||
tcx.ensure_ok().trigger_delayed_bug(def_id);
|
||||
}
|
||||
|
||||
// Bare `#[rustc_error]`.
|
||||
|
|
|
@ -458,7 +458,7 @@ pub fn check_crate<'tcx>(tcx: TyCtxt<'tcx>) {
|
|||
|| {
|
||||
tcx.sess.time("module_lints", || {
|
||||
// Run per-module lints
|
||||
tcx.hir().par_for_each_module(|module| tcx.ensure().lint_mod(module));
|
||||
tcx.hir().par_for_each_module(|module| tcx.ensure_ok().lint_mod(module));
|
||||
});
|
||||
},
|
||||
);
|
||||
|
|
|
@ -118,11 +118,17 @@ struct QueryModifiers {
|
|||
/// Generate a `feed` method to set the query's value from another query.
|
||||
feedable: Option<Ident>,
|
||||
|
||||
/// Forward the result on ensure if the query gets recomputed, and
|
||||
/// return `Ok(())` otherwise. Only applicable to queries returning
|
||||
/// `Result<T, ErrorGuaranteed>`. The `T` is not returned from `ensure`
|
||||
/// invocations.
|
||||
ensure_forwards_result_if_red: Option<Ident>,
|
||||
/// When this query is called via `tcx.ensure_ok()`, it returns
|
||||
/// `Result<(), ErrorGuaranteed>` instead of `()`. If the query needs to
|
||||
/// be executed, and that execution returns an error, the error result is
|
||||
/// returned to the caller.
|
||||
///
|
||||
/// If execution is skipped, a synthetic `Ok(())` is returned, on the
|
||||
/// assumption that a query with all-green inputs must have succeeded.
|
||||
///
|
||||
/// Can only be applied to queries with a return value of
|
||||
/// `Result<_, ErrorGuaranteed>`.
|
||||
return_result_from_ensure_ok: Option<Ident>,
|
||||
}
|
||||
|
||||
fn parse_query_modifiers(input: ParseStream<'_>) -> Result<QueryModifiers> {
|
||||
|
@ -138,7 +144,7 @@ fn parse_query_modifiers(input: ParseStream<'_>) -> Result<QueryModifiers> {
|
|||
let mut depth_limit = None;
|
||||
let mut separate_provide_extern = None;
|
||||
let mut feedable = None;
|
||||
let mut ensure_forwards_result_if_red = None;
|
||||
let mut return_result_from_ensure_ok = None;
|
||||
|
||||
while !input.is_empty() {
|
||||
let modifier: Ident = input.parse()?;
|
||||
|
@ -200,8 +206,8 @@ fn parse_query_modifiers(input: ParseStream<'_>) -> Result<QueryModifiers> {
|
|||
try_insert!(separate_provide_extern = modifier);
|
||||
} else if modifier == "feedable" {
|
||||
try_insert!(feedable = modifier);
|
||||
} else if modifier == "ensure_forwards_result_if_red" {
|
||||
try_insert!(ensure_forwards_result_if_red = modifier);
|
||||
} else if modifier == "return_result_from_ensure_ok" {
|
||||
try_insert!(return_result_from_ensure_ok = modifier);
|
||||
} else {
|
||||
return Err(Error::new(modifier.span(), "unknown query modifier"));
|
||||
}
|
||||
|
@ -222,7 +228,7 @@ fn parse_query_modifiers(input: ParseStream<'_>) -> Result<QueryModifiers> {
|
|||
depth_limit,
|
||||
separate_provide_extern,
|
||||
feedable,
|
||||
ensure_forwards_result_if_red,
|
||||
return_result_from_ensure_ok,
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -354,7 +360,7 @@ pub(super) fn rustc_queries(input: TokenStream) -> TokenStream {
|
|||
eval_always,
|
||||
depth_limit,
|
||||
separate_provide_extern,
|
||||
ensure_forwards_result_if_red,
|
||||
return_result_from_ensure_ok,
|
||||
);
|
||||
|
||||
if modifiers.cache.is_some() {
|
||||
|
|
|
@ -165,7 +165,7 @@ macro_rules! provide_one {
|
|||
// doesn't need to do this (and can't, as it would cause a query cycle).
|
||||
use rustc_middle::dep_graph::dep_kinds;
|
||||
if dep_kinds::$name != dep_kinds::crate_hash && $tcx.dep_graph.is_fully_enabled() {
|
||||
$tcx.ensure().crate_hash($def_id.krate);
|
||||
$tcx.ensure_ok().crate_hash($def_id.krate);
|
||||
}
|
||||
|
||||
let cdata = rustc_data_structures::sync::FreezeReadGuard::map(CStore::from_tcx($tcx), |c| {
|
||||
|
|
|
@ -2191,13 +2191,13 @@ fn prefetch_mir(tcx: TyCtxt<'_>) {
|
|||
let (encode_const, encode_opt) = should_encode_mir(tcx, reachable_set, def_id);
|
||||
|
||||
if encode_const {
|
||||
tcx.ensure_with_value().mir_for_ctfe(def_id);
|
||||
tcx.ensure_done().mir_for_ctfe(def_id);
|
||||
}
|
||||
if encode_opt {
|
||||
tcx.ensure_with_value().optimized_mir(def_id);
|
||||
tcx.ensure_done().optimized_mir(def_id);
|
||||
}
|
||||
if encode_opt || encode_const {
|
||||
tcx.ensure_with_value().promoted_mir(def_id);
|
||||
tcx.ensure_done().promoted_mir(def_id);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ use super::{
|
|||
ReportedErrorInfo,
|
||||
};
|
||||
use crate::mir;
|
||||
use crate::query::TyCtxtEnsure;
|
||||
use crate::query::TyCtxtEnsureOk;
|
||||
use crate::ty::visit::TypeVisitableExt;
|
||||
use crate::ty::{self, GenericArgs, TyCtxt};
|
||||
|
||||
|
@ -198,7 +198,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'tcx> TyCtxtEnsure<'tcx> {
|
||||
impl<'tcx> TyCtxtEnsureOk<'tcx> {
|
||||
/// Evaluates a constant without providing any generic parameters. This is useful to evaluate consts
|
||||
/// that can't take any generic arguments like const items or enum discriminants. If a
|
||||
/// generic parameter is used within the constant `ErrorHandled::TooGeneric` will be returned.
|
||||
|
|
|
@ -91,7 +91,7 @@ pub use keys::{AsLocalKey, Key, LocalCrate};
|
|||
pub mod on_disk_cache;
|
||||
#[macro_use]
|
||||
pub mod plumbing;
|
||||
pub use plumbing::{IntoQueryParam, TyCtxtAt, TyCtxtEnsure, TyCtxtEnsureWithValue};
|
||||
pub use plumbing::{IntoQueryParam, TyCtxtAt, TyCtxtEnsureDone, TyCtxtEnsureOk};
|
||||
|
||||
// Each of these queries corresponds to a function pointer field in the
|
||||
// `Providers` struct for requesting a value of that type, and a method
|
||||
|
@ -1087,7 +1087,7 @@ rustc_queries! {
|
|||
|
||||
query check_mod_type_wf(key: LocalModDefId) -> Result<(), ErrorGuaranteed> {
|
||||
desc { |tcx| "checking that types are well-formed in {}", describe_as_module(key, tcx) }
|
||||
ensure_forwards_result_if_red
|
||||
return_result_from_ensure_ok
|
||||
}
|
||||
|
||||
/// Caches `CoerceUnsized` kinds for impls on custom types.
|
||||
|
@ -1095,7 +1095,7 @@ rustc_queries! {
|
|||
desc { |tcx| "computing CoerceUnsized info for `{}`", tcx.def_path_str(key) }
|
||||
cache_on_disk_if { key.is_local() }
|
||||
separate_provide_extern
|
||||
ensure_forwards_result_if_red
|
||||
return_result_from_ensure_ok
|
||||
}
|
||||
|
||||
query typeck(key: LocalDefId) -> &'tcx ty::TypeckResults<'tcx> {
|
||||
|
@ -1110,7 +1110,7 @@ rustc_queries! {
|
|||
|
||||
query coherent_trait(def_id: DefId) -> Result<(), ErrorGuaranteed> {
|
||||
desc { |tcx| "coherence checking all impls of trait `{}`", tcx.def_path_str(def_id) }
|
||||
ensure_forwards_result_if_red
|
||||
return_result_from_ensure_ok
|
||||
}
|
||||
|
||||
/// Borrow-checks the function body. If this is a closure, returns
|
||||
|
@ -1140,7 +1140,7 @@ rustc_queries! {
|
|||
/// </div>
|
||||
query crate_inherent_impls_validity_check(_: ()) -> Result<(), ErrorGuaranteed> {
|
||||
desc { "check for inherent impls that should not be defined in crate" }
|
||||
ensure_forwards_result_if_red
|
||||
return_result_from_ensure_ok
|
||||
}
|
||||
|
||||
/// Checks all types in the crate for overlap in their inherent impls. Reports errors.
|
||||
|
@ -1152,7 +1152,7 @@ rustc_queries! {
|
|||
/// </div>
|
||||
query crate_inherent_impls_overlap_check(_: ()) -> Result<(), ErrorGuaranteed> {
|
||||
desc { "check for overlap between inherent impls defined in this crate" }
|
||||
ensure_forwards_result_if_red
|
||||
return_result_from_ensure_ok
|
||||
}
|
||||
|
||||
/// Checks whether all impls in the crate pass the overlap check, returning
|
||||
|
@ -1162,7 +1162,7 @@ rustc_queries! {
|
|||
"checking whether impl `{}` follows the orphan rules",
|
||||
tcx.def_path_str(key),
|
||||
}
|
||||
ensure_forwards_result_if_red
|
||||
return_result_from_ensure_ok
|
||||
}
|
||||
|
||||
/// Check whether the function has any recursion that could cause the inliner to trigger
|
||||
|
@ -1479,7 +1479,7 @@ rustc_queries! {
|
|||
query specialization_graph_of(trait_id: DefId) -> Result<&'tcx specialization_graph::Graph, ErrorGuaranteed> {
|
||||
desc { |tcx| "building specialization graph of trait `{}`", tcx.def_path_str(trait_id) }
|
||||
cache_on_disk_if { true }
|
||||
ensure_forwards_result_if_red
|
||||
return_result_from_ensure_ok
|
||||
}
|
||||
query dyn_compatibility_violations(trait_id: DefId) -> &'tcx [DynCompatibilityViolation] {
|
||||
desc { |tcx| "determining dyn-compatibility of trait `{}`", tcx.def_path_str(trait_id) }
|
||||
|
@ -1715,12 +1715,12 @@ rustc_queries! {
|
|||
|
||||
query check_well_formed(key: LocalDefId) -> Result<(), ErrorGuaranteed> {
|
||||
desc { |tcx| "checking that `{}` is well-formed", tcx.def_path_str(key) }
|
||||
ensure_forwards_result_if_red
|
||||
return_result_from_ensure_ok
|
||||
}
|
||||
|
||||
query enforce_impl_non_lifetime_params_are_constrained(key: LocalDefId) -> Result<(), ErrorGuaranteed> {
|
||||
desc { |tcx| "checking that `{}`'s generics are constrained by the impl header", tcx.def_path_str(key) }
|
||||
ensure_forwards_result_if_red
|
||||
return_result_from_ensure_ok
|
||||
}
|
||||
|
||||
// The `DefId`s of all non-generic functions and statics in the given crate
|
||||
|
@ -2442,7 +2442,7 @@ rustc_queries! {
|
|||
/// Any other def id will ICE.
|
||||
query compare_impl_item(key: LocalDefId) -> Result<(), ErrorGuaranteed> {
|
||||
desc { |tcx| "checking assoc item `{}` is compatible with trait definition", tcx.def_path_str(key) }
|
||||
ensure_forwards_result_if_red
|
||||
return_result_from_ensure_ok
|
||||
}
|
||||
|
||||
query deduced_param_attrs(def_id: DefId) -> &'tcx [ty::DeducedParamAttrs] {
|
||||
|
|
|
@ -88,30 +88,68 @@ impl<'tcx> Deref for TyCtxtAt<'tcx> {
|
|||
}
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct TyCtxtEnsure<'tcx> {
|
||||
#[must_use]
|
||||
pub struct TyCtxtEnsureOk<'tcx> {
|
||||
pub tcx: TyCtxt<'tcx>,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct TyCtxtEnsureWithValue<'tcx> {
|
||||
#[must_use]
|
||||
pub struct TyCtxtEnsureDone<'tcx> {
|
||||
pub tcx: TyCtxt<'tcx>,
|
||||
}
|
||||
|
||||
impl<'tcx> TyCtxt<'tcx> {
|
||||
/// Returns a transparent wrapper for `TyCtxt`, which ensures queries
|
||||
/// are executed instead of just returning their results.
|
||||
/// Wrapper that calls queries in a special "ensure OK" mode, for callers
|
||||
/// that don't need the return value and just want to invoke a query for
|
||||
/// its potential side-effect of emitting fatal errors.
|
||||
///
|
||||
/// This can be more efficient than a normal query call, because if the
|
||||
/// query's inputs are all green, the call can return immediately without
|
||||
/// needing to obtain a value (by decoding one from disk or by executing
|
||||
/// the query).
|
||||
///
|
||||
/// (As with all query calls, execution is also skipped if the query result
|
||||
/// is already cached in memory.)
|
||||
///
|
||||
/// ## WARNING
|
||||
/// A subsequent normal call to the same query might still cause it to be
|
||||
/// executed! This can occur when the inputs are all green, but the query's
|
||||
/// result is not cached on disk, so the query must be executed to obtain a
|
||||
/// return value.
|
||||
///
|
||||
/// Therefore, this call mode is not appropriate for callers that want to
|
||||
/// ensure that the query is _never_ executed in the future.
|
||||
///
|
||||
/// ## `return_result_from_ensure_ok`
|
||||
/// If a query has the `return_result_from_ensure_ok` modifier, calls via
|
||||
/// `ensure_ok` will instead return `Result<(), ErrorGuaranteed>`. If the
|
||||
/// query needs to be executed, and execution returns an error, that error
|
||||
/// is returned to the caller.
|
||||
#[inline(always)]
|
||||
pub fn ensure(self) -> TyCtxtEnsure<'tcx> {
|
||||
TyCtxtEnsure { tcx: self }
|
||||
pub fn ensure_ok(self) -> TyCtxtEnsureOk<'tcx> {
|
||||
TyCtxtEnsureOk { tcx: self }
|
||||
}
|
||||
|
||||
/// Returns a transparent wrapper for `TyCtxt`, which ensures queries
|
||||
/// are executed instead of just returning their results.
|
||||
/// Wrapper that calls queries in a special "ensure done" mode, for callers
|
||||
/// that don't need the return value and just want to guarantee that the
|
||||
/// query won't be executed in the future, by executing it now if necessary.
|
||||
///
|
||||
/// This version verifies that the computed result exists in the cache before returning.
|
||||
/// This is useful for queries that read from a [`Steal`] value, to ensure
|
||||
/// that they are executed before the query that will steal the value.
|
||||
///
|
||||
/// Unlike [`Self::ensure_ok`], a query with all-green inputs will only be
|
||||
/// skipped if its return value is stored in the disk-cache. This is still
|
||||
/// more efficient than a regular query, because in that situation the
|
||||
/// return value doesn't necessarily need to be decoded.
|
||||
///
|
||||
/// (As with all query calls, execution is also skipped if the query result
|
||||
/// is already cached in memory.)
|
||||
///
|
||||
/// [`Steal`]: rustc_data_structures::steal::Steal
|
||||
#[inline(always)]
|
||||
pub fn ensure_with_value(self) -> TyCtxtEnsureWithValue<'tcx> {
|
||||
TyCtxtEnsureWithValue { tcx: self }
|
||||
pub fn ensure_done(self) -> TyCtxtEnsureDone<'tcx> {
|
||||
TyCtxtEnsureDone { tcx: self }
|
||||
}
|
||||
|
||||
/// Returns a transparent wrapper for `TyCtxt` which uses
|
||||
|
@ -193,7 +231,7 @@ macro_rules! query_ensure {
|
|||
([]$($args:tt)*) => {
|
||||
query_ensure($($args)*)
|
||||
};
|
||||
([(ensure_forwards_result_if_red) $($rest:tt)*]$($args:tt)*) => {
|
||||
([(return_result_from_ensure_ok) $($rest:tt)*]$($args:tt)*) => {
|
||||
query_ensure_error_guaranteed($($args)*).map(|_| ())
|
||||
};
|
||||
([$other:tt $($modifiers:tt)*]$($args:tt)*) => {
|
||||
|
@ -248,15 +286,15 @@ macro_rules! separate_provide_extern_decl {
|
|||
};
|
||||
}
|
||||
|
||||
macro_rules! ensure_result {
|
||||
([][$ty:ty]) => {
|
||||
macro_rules! ensure_ok_result {
|
||||
( [] ) => {
|
||||
()
|
||||
};
|
||||
([(ensure_forwards_result_if_red) $($rest:tt)*][$ty:ty]) => {
|
||||
( [(return_result_from_ensure_ok) $($rest:tt)*] ) => {
|
||||
Result<(), ErrorGuaranteed>
|
||||
};
|
||||
([$other:tt $($modifiers:tt)*][$($args:tt)*]) => {
|
||||
ensure_result!([$($modifiers)*][$($args)*])
|
||||
( [$other:tt $($modifiers:tt)*] ) => {
|
||||
ensure_ok_result!( [$($modifiers)*] )
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -383,10 +421,13 @@ macro_rules! define_callbacks {
|
|||
$($(#[$attr])* pub $name: queries::$name::Storage<'tcx>,)*
|
||||
}
|
||||
|
||||
impl<'tcx> TyCtxtEnsure<'tcx> {
|
||||
impl<'tcx> TyCtxtEnsureOk<'tcx> {
|
||||
$($(#[$attr])*
|
||||
#[inline(always)]
|
||||
pub fn $name(self, key: query_helper_param_ty!($($K)*)) -> ensure_result!([$($modifiers)*][$V]) {
|
||||
pub fn $name(
|
||||
self,
|
||||
key: query_helper_param_ty!($($K)*),
|
||||
) -> ensure_ok_result!([$($modifiers)*]) {
|
||||
query_ensure!(
|
||||
[$($modifiers)*]
|
||||
self.tcx,
|
||||
|
@ -398,7 +439,7 @@ macro_rules! define_callbacks {
|
|||
})*
|
||||
}
|
||||
|
||||
impl<'tcx> TyCtxtEnsureWithValue<'tcx> {
|
||||
impl<'tcx> TyCtxtEnsureDone<'tcx> {
|
||||
$($(#[$attr])*
|
||||
#[inline(always)]
|
||||
pub fn $name(self, key: query_helper_param_ty!($($K)*)) {
|
||||
|
|
|
@ -1957,7 +1957,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
) -> &'tcx rustc_hir::def_path_hash_map::DefPathHashMap {
|
||||
// Create a dependency to the crate to be sure we re-execute this when the amount of
|
||||
// definitions change.
|
||||
self.ensure().hir_crate(());
|
||||
self.ensure_ok().hir_crate(());
|
||||
// Freeze definitions once we start iterating on them, to prevent adding new ones
|
||||
// while iterating. If some query needs to add definitions, it should be `ensure`d above.
|
||||
self.untracked.definitions.freeze().def_path_hash_to_def_index_map()
|
||||
|
|
|
@ -367,7 +367,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
validate: impl Fn(Self, DefId) -> Result<(), ErrorGuaranteed>,
|
||||
) -> Option<ty::Destructor> {
|
||||
let drop_trait = self.lang_items().drop_trait()?;
|
||||
self.ensure().coherent_trait(drop_trait).ok()?;
|
||||
self.ensure_ok().coherent_trait(drop_trait).ok()?;
|
||||
|
||||
let ty = self.type_of(adt_did).instantiate_identity();
|
||||
let mut dtor_candidate = None;
|
||||
|
@ -404,7 +404,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
validate: impl Fn(Self, DefId) -> Result<(), ErrorGuaranteed>,
|
||||
) -> Option<ty::AsyncDestructor> {
|
||||
let async_drop_trait = self.lang_items().async_drop_trait()?;
|
||||
self.ensure().coherent_trait(async_drop_trait).ok()?;
|
||||
self.ensure_ok().coherent_trait(async_drop_trait).ok()?;
|
||||
|
||||
let ty = self.type_of(adt_did).instantiate_identity();
|
||||
let mut dtor_candidate = None;
|
||||
|
|
|
@ -47,7 +47,7 @@ pub(crate) fn closure_saved_names_of_captured_variables<'tcx>(
|
|||
/// Create the MIR for a given `DefId`, including unreachable code. Do not call
|
||||
/// this directly; instead use the cached version via `mir_built`.
|
||||
pub fn build_mir<'tcx>(tcx: TyCtxt<'tcx>, def: LocalDefId) -> Body<'tcx> {
|
||||
tcx.ensure_with_value().thir_abstract_const(def);
|
||||
tcx.ensure_done().thir_abstract_const(def);
|
||||
if let Err(e) = tcx.check_match(def) {
|
||||
return construct_error(tcx, def, e);
|
||||
}
|
||||
|
@ -68,7 +68,7 @@ pub fn build_mir<'tcx>(tcx: TyCtxt<'tcx>, def: LocalDefId) -> Body<'tcx> {
|
|||
// "not all control paths return a value" is reported here.
|
||||
//
|
||||
// maybe move the check to a MIR pass?
|
||||
tcx.ensure().check_liveness(def);
|
||||
tcx.ensure_ok().check_liveness(def);
|
||||
|
||||
// Don't steal here, instead steal in unsafeck. This is so that
|
||||
// pattern inline constants can be evaluated as part of building the
|
||||
|
|
|
@ -200,7 +200,7 @@ impl<'tcx> UnsafetyVisitor<'_, 'tcx> {
|
|||
fn visit_inner_body(&mut self, def: LocalDefId) {
|
||||
if let Ok((inner_thir, expr)) = self.tcx.thir_body(def) {
|
||||
// Runs all other queries that depend on THIR.
|
||||
self.tcx.ensure_with_value().mir_built(def);
|
||||
self.tcx.ensure_done().mir_built(def);
|
||||
let inner_thir = &inner_thir.steal();
|
||||
let hir_context = self.tcx.local_def_id_to_hir_id(def);
|
||||
let safety_context = mem::replace(&mut self.safety_context, SafetyContext::Safe);
|
||||
|
@ -1139,7 +1139,7 @@ pub(crate) fn check_unsafety(tcx: TyCtxt<'_>, def: LocalDefId) {
|
|||
|
||||
let Ok((thir, expr)) = tcx.thir_body(def) else { return };
|
||||
// Runs all other queries that depend on THIR.
|
||||
tcx.ensure_with_value().mir_built(def);
|
||||
tcx.ensure_done().mir_built(def);
|
||||
let thir = &thir.steal();
|
||||
|
||||
let hir_id = tcx.local_def_id_to_hir_id(def);
|
||||
|
|
|
@ -421,11 +421,11 @@ fn mir_promoted(
|
|||
};
|
||||
|
||||
// the `has_ffi_unwind_calls` query uses the raw mir, so make sure it is run.
|
||||
tcx.ensure_with_value().has_ffi_unwind_calls(def);
|
||||
tcx.ensure_done().has_ffi_unwind_calls(def);
|
||||
|
||||
// the `by_move_body` query uses the raw mir, so make sure it is run.
|
||||
if tcx.needs_coroutine_by_move_body_def_id(def.to_def_id()) {
|
||||
tcx.ensure_with_value().coroutine_by_move_body_def_id(def);
|
||||
tcx.ensure_done().coroutine_by_move_body_def_id(def);
|
||||
}
|
||||
|
||||
let mut body = tcx.mir_built(def).steal();
|
||||
|
@ -488,7 +488,7 @@ fn inner_mir_for_ctfe(tcx: TyCtxt<'_>, def: LocalDefId) -> Body<'_> {
|
|||
/// end up missing the source MIR due to stealing happening.
|
||||
fn mir_drops_elaborated_and_const_checked(tcx: TyCtxt<'_>, def: LocalDefId) -> &Steal<Body<'_>> {
|
||||
if tcx.is_coroutine(def.to_def_id()) {
|
||||
tcx.ensure_with_value().mir_coroutine_witnesses(def);
|
||||
tcx.ensure_done().mir_coroutine_witnesses(def);
|
||||
}
|
||||
|
||||
// We only need to borrowck non-synthetic MIR.
|
||||
|
@ -501,7 +501,7 @@ fn mir_drops_elaborated_and_const_checked(tcx: TyCtxt<'_>, def: LocalDefId) -> &
|
|||
if pm::should_run_pass(tcx, &inline::Inline, pm::Optimizations::Allowed)
|
||||
|| inline::ForceInline::should_run_pass_for_callee(tcx, def.to_def_id())
|
||||
{
|
||||
tcx.ensure_with_value().mir_inliner_callees(ty::InstanceKind::Item(def.to_def_id()));
|
||||
tcx.ensure_done().mir_inliner_callees(ty::InstanceKind::Item(def.to_def_id()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -733,7 +733,7 @@ fn inner_optimized_mir(tcx: TyCtxt<'_>, did: LocalDefId) -> Body<'_> {
|
|||
// Run the `mir_for_ctfe` query, which depends on `mir_drops_elaborated_and_const_checked`
|
||||
// which we are going to steal below. Thus we need to run `mir_for_ctfe` first, so it
|
||||
// computes and caches its result.
|
||||
Some(hir::ConstContext::ConstFn) => tcx.ensure_with_value().mir_for_ctfe(did),
|
||||
Some(hir::ConstContext::ConstFn) => tcx.ensure_done().mir_for_ctfe(did),
|
||||
None => {}
|
||||
Some(other) => panic!("do not use `optimized_mir` for constants: {other:?}"),
|
||||
}
|
||||
|
@ -772,7 +772,7 @@ fn promoted_mir(tcx: TyCtxt<'_>, def: LocalDefId) -> &IndexVec<Promoted, Body<'_
|
|||
}
|
||||
|
||||
if !tcx.is_synthetic_mir(def) {
|
||||
tcx.ensure_with_value().mir_borrowck(def);
|
||||
tcx.ensure_done().mir_borrowck(def);
|
||||
}
|
||||
let mut promoted = tcx.mir_promoted(def).1.steal();
|
||||
|
||||
|
|
|
@ -1222,7 +1222,7 @@ fn collect_items_of_instance<'tcx>(
|
|||
mode: CollectionMode,
|
||||
) -> (MonoItems<'tcx>, MonoItems<'tcx>) {
|
||||
// This item is getting monomorphized, do mono-time checks.
|
||||
tcx.ensure().check_mono_item(instance);
|
||||
tcx.ensure_ok().check_mono_item(instance);
|
||||
|
||||
let body = tcx.instance_mir(instance.def);
|
||||
// Naively, in "used" collection mode, all functions get added to *both* `used_items` and
|
||||
|
|
|
@ -179,7 +179,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
|||
return e;
|
||||
}
|
||||
|
||||
if let Err(guar) = self.tcx.ensure().coherent_trait(trait_pred.def_id()) {
|
||||
if let Err(guar) = self.tcx.ensure_ok().coherent_trait(trait_pred.def_id()) {
|
||||
// Avoid bogus "type annotations needed `Foo: Bar`" errors on `impl Bar for Foo` in case
|
||||
// other `Foo` impls are incoherent.
|
||||
return guar;
|
||||
|
@ -511,8 +511,10 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
|||
return e;
|
||||
}
|
||||
|
||||
if let Err(guar) =
|
||||
self.tcx.ensure().coherent_trait(self.tcx.parent(data.projection_term.def_id))
|
||||
if let Err(guar) = self
|
||||
.tcx
|
||||
.ensure_ok()
|
||||
.coherent_trait(self.tcx.parent(data.projection_term.def_id))
|
||||
{
|
||||
// Avoid bogus "type annotations needed `Foo: Bar`" errors on `impl Bar for Foo` in case
|
||||
// other `Foo` impls are incoherent.
|
||||
|
|
|
@ -575,7 +575,7 @@ fn report_conflicting_impls<'tcx>(
|
|||
match used_to_be_allowed {
|
||||
None => {
|
||||
let reported = if overlap.with_impl.is_local()
|
||||
|| tcx.ensure().orphan_check_impl(impl_def_id).is_ok()
|
||||
|| tcx.ensure_ok().orphan_check_impl(impl_def_id).is_ok()
|
||||
{
|
||||
let mut err = tcx.dcx().struct_span_err(impl_span, msg());
|
||||
err.code(E0119);
|
||||
|
|
|
@ -379,7 +379,7 @@ pub(crate) fn assoc_def(
|
|||
// Ensure that the impl is constrained, otherwise projection may give us
|
||||
// bad unconstrained infer vars.
|
||||
if let Some(impl_def_id) = impl_def_id.as_local() {
|
||||
tcx.ensure().enforce_impl_non_lifetime_params_are_constrained(impl_def_id)?;
|
||||
tcx.ensure_ok().enforce_impl_non_lifetime_params_are_constrained(impl_def_id)?;
|
||||
}
|
||||
|
||||
let item = tcx.associated_item(impl_item_id);
|
||||
|
@ -402,7 +402,7 @@ pub(crate) fn assoc_def(
|
|||
if assoc_item.item.container == ty::AssocItemContainer::Impl
|
||||
&& let Some(impl_def_id) = assoc_item.item.container_id(tcx).as_local()
|
||||
{
|
||||
tcx.ensure().enforce_impl_non_lifetime_params_are_constrained(impl_def_id)?;
|
||||
tcx.ensure_ok().enforce_impl_non_lifetime_params_are_constrained(impl_def_id)?;
|
||||
}
|
||||
|
||||
Ok(assoc_item)
|
||||
|
|
|
@ -225,7 +225,7 @@ fn resolve_associated_item<'tcx>(
|
|||
if trait_item_id != leaf_def.item.def_id
|
||||
&& let Some(leaf_def_item) = leaf_def.item.def_id.as_local()
|
||||
{
|
||||
tcx.ensure().compare_impl_item(leaf_def_item)?;
|
||||
tcx.ensure_ok().compare_impl_item(leaf_def_item)?;
|
||||
}
|
||||
|
||||
Some(ty::Instance::new(leaf_def.item.def_id, args))
|
||||
|
|
|
@ -336,14 +336,14 @@ pub(crate) fn run_global_ctxt(
|
|||
|
||||
// NOTE: These are copy/pasted from typeck/lib.rs and should be kept in sync with those changes.
|
||||
let _ = tcx.sess.time("wf_checking", || {
|
||||
tcx.hir().try_par_for_each_module(|module| tcx.ensure().check_mod_type_wf(module))
|
||||
tcx.hir().try_par_for_each_module(|module| tcx.ensure_ok().check_mod_type_wf(module))
|
||||
});
|
||||
|
||||
tcx.dcx().abort_if_errors();
|
||||
|
||||
tcx.sess.time("missing_docs", || rustc_lint::check_crate(tcx));
|
||||
tcx.sess.time("check_mod_attrs", || {
|
||||
tcx.hir().for_each_module(|module| tcx.ensure().check_mod_attrs(module))
|
||||
tcx.hir().for_each_module(|module| tcx.ensure_ok().check_mod_attrs(module))
|
||||
});
|
||||
rustc_passes::stability::check_unused_or_stable_features(tcx);
|
||||
|
||||
|
|
|
@ -21,6 +21,6 @@ impl<'tcx> LateLintPass<'tcx> for ClippyCtfe {
|
|||
_: Span,
|
||||
defid: LocalDefId,
|
||||
) {
|
||||
cx.tcx.ensure().mir_drops_elaborated_and_const_checked(defid); // Lint
|
||||
cx.tcx.ensure_ok().mir_drops_elaborated_and_const_checked(defid); // Lint
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue