add generator_kind query
This commit is contained in:
parent
245062cdcd
commit
66500effea
9 changed files with 60 additions and 40 deletions
|
@ -308,6 +308,9 @@ rustc_queries! {
|
||||||
/// Returns `Some(mutability)` if the node pointed to by `def_id` is a static item.
|
/// Returns `Some(mutability)` if the node pointed to by `def_id` is a static item.
|
||||||
query static_mutability(_: DefId) -> Option<hir::Mutability> {}
|
query static_mutability(_: DefId) -> Option<hir::Mutability> {}
|
||||||
|
|
||||||
|
/// Returns `Some(generator_kind)` if the node pointed to by `def_id` is a generator.
|
||||||
|
query generator_kind(_: DefId) -> Option<hir::GeneratorKind> {}
|
||||||
|
|
||||||
/// Gets a map with the variance of every item; use `item_variance` instead.
|
/// Gets a map with the variance of every item; use `item_variance` instead.
|
||||||
query crate_variances(_: CrateNum) -> &'tcx ty::CrateVariancesMap<'tcx> {
|
query crate_variances(_: CrateNum) -> &'tcx ty::CrateVariancesMap<'tcx> {
|
||||||
desc { "computing the variances for items in this crate" }
|
desc { "computing the variances for items in this crate" }
|
||||||
|
|
|
@ -5,7 +5,7 @@ use crate::dep_graph::DepGraph;
|
||||||
use crate::dep_graph::{self, DepConstructor};
|
use crate::dep_graph::{self, DepConstructor};
|
||||||
use crate::hir::exports::Export;
|
use crate::hir::exports::Export;
|
||||||
use crate::hir::map as hir_map;
|
use crate::hir::map as hir_map;
|
||||||
use crate::hir::map::DefPathHash;
|
use crate::hir::map::{DefPathData, DefPathHash};
|
||||||
use crate::ich::{NodeIdHashingMode, StableHashingContext};
|
use crate::ich::{NodeIdHashingMode, StableHashingContext};
|
||||||
use crate::infer::canonical::{Canonical, CanonicalVarInfo, CanonicalVarInfos};
|
use crate::infer::canonical::{Canonical, CanonicalVarInfo, CanonicalVarInfos};
|
||||||
use crate::lint::{struct_lint_level, LintSource};
|
use crate::lint::{struct_lint_level, LintSource};
|
||||||
|
@ -1513,14 +1513,18 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a displayable description and article for the given `def_id` (e.g. `("a", "closure")`).
|
/// Returns a displayable description and article for the given `def_id` (e.g. `("a", "struct")`).
|
||||||
pub fn article_and_description(
|
pub fn article_and_description(&self, def_id: DefId) -> (&'static str, &'static str) {
|
||||||
&self,
|
match self.def_key(def_id).disambiguated_data.data {
|
||||||
def_id: crate::hir::def_id::DefId,
|
DefPathData::TypeNs(..) | DefPathData::ValueNs(..) | DefPathData::MacroNs(..) => {
|
||||||
) -> (&'static str, &'static str) {
|
let kind = self.def_kind(def_id).unwrap();
|
||||||
match self.def_kind(def_id) {
|
(kind.article(), kind.descr(def_id))
|
||||||
Some(def_kind) => (def_kind.article(), def_kind.descr(def_id)),
|
}
|
||||||
None => self.type_of(def_id).kind.article_and_description(),
|
DefPathData::ClosureExpr => {
|
||||||
|
// TODO
|
||||||
|
todo!();
|
||||||
|
}
|
||||||
|
_ => bug!("article_and_description called on def_id {:?}", def_id),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -500,7 +500,7 @@ impl MetadataBlob {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> EntryKind<'tcx> {
|
impl EntryKind {
|
||||||
fn def_kind(&self) -> Option<DefKind> {
|
fn def_kind(&self) -> Option<DefKind> {
|
||||||
Some(match *self {
|
Some(match *self {
|
||||||
EntryKind::Const(..) => DefKind::Const,
|
EntryKind::Const(..) => DefKind::Const,
|
||||||
|
@ -614,11 +614,11 @@ impl<'a, 'tcx> CrateMetadata {
|
||||||
self.root.proc_macro_data.and_then(|data| data.decode(self).find(|x| *x == id)).is_some()
|
self.root.proc_macro_data.and_then(|data| data.decode(self).find(|x| *x == id)).is_some()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn maybe_kind(&self, item_id: DefIndex) -> Option<EntryKind<'tcx>> {
|
fn maybe_kind(&self, item_id: DefIndex) -> Option<EntryKind> {
|
||||||
self.root.per_def.kind.get(self, item_id).map(|k| k.decode(self))
|
self.root.per_def.kind.get(self, item_id).map(|k| k.decode(self))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn kind(&self, item_id: DefIndex) -> EntryKind<'tcx> {
|
fn kind(&self, item_id: DefIndex) -> EntryKind {
|
||||||
assert!(!self.is_proc_macro(item_id));
|
assert!(!self.is_proc_macro(item_id));
|
||||||
self.maybe_kind(item_id).unwrap_or_else(|| {
|
self.maybe_kind(item_id).unwrap_or_else(|| {
|
||||||
bug!(
|
bug!(
|
||||||
|
@ -723,7 +723,7 @@ impl<'a, 'tcx> CrateMetadata {
|
||||||
fn get_variant(
|
fn get_variant(
|
||||||
&self,
|
&self,
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
kind: &EntryKind<'_>,
|
kind: &EntryKind,
|
||||||
index: DefIndex,
|
index: DefIndex,
|
||||||
parent_did: DefId,
|
parent_did: DefId,
|
||||||
) -> ty::VariantDef {
|
) -> ty::VariantDef {
|
||||||
|
@ -1390,6 +1390,13 @@ impl<'a, 'tcx> CrateMetadata {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn generator_kind(&self, id: DefIndex) -> Option<hir::GeneratorKind> {
|
||||||
|
match self.kind(id) {
|
||||||
|
EntryKind::Generator(data) => Some(data.decode(self)),
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn fn_sig(&self, id: DefIndex, tcx: TyCtxt<'tcx>) -> ty::PolyFnSig<'tcx> {
|
fn fn_sig(&self, id: DefIndex, tcx: TyCtxt<'tcx>) -> ty::PolyFnSig<'tcx> {
|
||||||
self.root.per_def.fn_sig.get(self, id).unwrap().decode((self, tcx))
|
self.root.per_def.fn_sig.get(self, id).unwrap().decode((self, tcx))
|
||||||
}
|
}
|
||||||
|
@ -1499,8 +1506,8 @@ impl<'a, 'tcx> CrateMetadata {
|
||||||
);
|
);
|
||||||
debug!(
|
debug!(
|
||||||
"CrateMetaData::imported_source_files alloc \
|
"CrateMetaData::imported_source_files alloc \
|
||||||
source_file {:?} original (start_pos {:?} end_pos {:?}) \
|
source_file {:?} original (start_pos {:?} end_pos {:?}) \
|
||||||
translated (start_pos {:?} end_pos {:?})",
|
translated (start_pos {:?} end_pos {:?})",
|
||||||
local_version.name,
|
local_version.name,
|
||||||
start_pos,
|
start_pos,
|
||||||
end_pos,
|
end_pos,
|
||||||
|
|
|
@ -134,6 +134,7 @@ provide! { <'tcx> tcx, def_id, other, cdata,
|
||||||
asyncness => { cdata.asyncness(def_id.index) }
|
asyncness => { cdata.asyncness(def_id.index) }
|
||||||
is_foreign_item => { cdata.is_foreign_item(def_id.index) }
|
is_foreign_item => { cdata.is_foreign_item(def_id.index) }
|
||||||
static_mutability => { cdata.static_mutability(def_id.index) }
|
static_mutability => { cdata.static_mutability(def_id.index) }
|
||||||
|
generator_kind => { cdata.generator_kind(def_id.index) }
|
||||||
def_kind => { cdata.def_kind(def_id.index) }
|
def_kind => { cdata.def_kind(def_id.index) }
|
||||||
def_span => { cdata.get_span(def_id.index, &tcx.sess) }
|
def_span => { cdata.get_span(def_id.index, &tcx.sess) }
|
||||||
lookup_stability => {
|
lookup_stability => {
|
||||||
|
|
|
@ -306,7 +306,7 @@ impl<'tcx> EncodeContext<'tcx> {
|
||||||
assert!(
|
assert!(
|
||||||
last_min_end <= lazy.position,
|
last_min_end <= lazy.position,
|
||||||
"make sure that the calls to `lazy*` \
|
"make sure that the calls to `lazy*` \
|
||||||
are in the same order as the metadata fields",
|
are in the same order as the metadata fields",
|
||||||
);
|
);
|
||||||
lazy.position.get() - last_min_end.get()
|
lazy.position.get() - last_min_end.get()
|
||||||
}
|
}
|
||||||
|
@ -1248,12 +1248,7 @@ impl EncodeContext<'tcx> {
|
||||||
self.encode_deprecation(def_id);
|
self.encode_deprecation(def_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn encode_info_for_generic_param(
|
fn encode_info_for_generic_param(&mut self, def_id: DefId, kind: EntryKind, encode_type: bool) {
|
||||||
&mut self,
|
|
||||||
def_id: DefId,
|
|
||||||
kind: EntryKind<'tcx>,
|
|
||||||
encode_type: bool,
|
|
||||||
) {
|
|
||||||
record!(self.per_def.kind[def_id] <- kind);
|
record!(self.per_def.kind[def_id] <- kind);
|
||||||
record!(self.per_def.visibility[def_id] <- ty::Visibility::Public);
|
record!(self.per_def.visibility[def_id] <- ty::Visibility::Public);
|
||||||
record!(self.per_def.span[def_id] <- self.tcx.def_span(def_id));
|
record!(self.per_def.span[def_id] <- self.tcx.def_span(def_id));
|
||||||
|
@ -1271,11 +1266,8 @@ impl EncodeContext<'tcx> {
|
||||||
let ty = self.tcx.typeck_tables_of(def_id).node_type(hir_id);
|
let ty = self.tcx.typeck_tables_of(def_id).node_type(hir_id);
|
||||||
|
|
||||||
record!(self.per_def.kind[def_id] <- match ty.kind {
|
record!(self.per_def.kind[def_id] <- match ty.kind {
|
||||||
ty::Generator(def_id, ..) => {
|
ty::Generator(..) => {
|
||||||
let layout = self.tcx.generator_layout(def_id);
|
let data = self.tcx.generator_kind(def_id).unwrap();
|
||||||
let data = GeneratorData {
|
|
||||||
layout: layout.clone(),
|
|
||||||
};
|
|
||||||
EntryKind::Generator(self.lazy(data))
|
EntryKind::Generator(self.lazy(data))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -252,7 +252,7 @@ macro_rules! define_per_def_tables {
|
||||||
}
|
}
|
||||||
|
|
||||||
define_per_def_tables! {
|
define_per_def_tables! {
|
||||||
kind: Table<DefIndex, Lazy!(EntryKind<'tcx>)>,
|
kind: Table<DefIndex, Lazy<EntryKind>>,
|
||||||
visibility: Table<DefIndex, Lazy<ty::Visibility>>,
|
visibility: Table<DefIndex, Lazy<ty::Visibility>>,
|
||||||
span: Table<DefIndex, Lazy<Span>>,
|
span: Table<DefIndex, Lazy<Span>>,
|
||||||
attributes: Table<DefIndex, Lazy<[ast::Attribute]>>,
|
attributes: Table<DefIndex, Lazy<[ast::Attribute]>>,
|
||||||
|
@ -279,7 +279,7 @@ define_per_def_tables! {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, RustcEncodable, RustcDecodable)]
|
#[derive(Copy, Clone, RustcEncodable, RustcDecodable)]
|
||||||
enum EntryKind<'tcx> {
|
enum EntryKind {
|
||||||
Const(mir::ConstQualifs, Lazy<RenderedConst>),
|
Const(mir::ConstQualifs, Lazy<RenderedConst>),
|
||||||
ImmStatic,
|
ImmStatic,
|
||||||
MutStatic,
|
MutStatic,
|
||||||
|
@ -302,7 +302,7 @@ enum EntryKind<'tcx> {
|
||||||
Mod(Lazy<ModData>),
|
Mod(Lazy<ModData>),
|
||||||
MacroDef(Lazy<MacroDef>),
|
MacroDef(Lazy<MacroDef>),
|
||||||
Closure,
|
Closure,
|
||||||
Generator(Lazy!(GeneratorData<'tcx>)),
|
Generator(Lazy<hir::GeneratorKind>),
|
||||||
Trait(Lazy<TraitData>),
|
Trait(Lazy<TraitData>),
|
||||||
Impl(Lazy<ImplData>),
|
Impl(Lazy<ImplData>),
|
||||||
Method(Lazy<MethodData>),
|
Method(Lazy<MethodData>),
|
||||||
|
|
|
@ -427,15 +427,17 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
||||||
errci.outlived_fr,
|
errci.outlived_fr,
|
||||||
);
|
);
|
||||||
|
|
||||||
let (_, escapes_from) =
|
let (_, escapes_from) = self
|
||||||
self.infcx.tcx.article_and_description(self.universal_regions.defining_ty.def_id());
|
.infcx
|
||||||
|
.tcx
|
||||||
|
.article_and_description(self.regioncx.universal_regions().defining_ty.def_id());
|
||||||
|
|
||||||
// Revert to the normal error in these cases.
|
// Revert to the normal error in these cases.
|
||||||
// Assignments aren't "escapes" in function items.
|
// Assignments aren't "escapes" in function items.
|
||||||
if (fr_name_and_span.is_none() && outlived_fr_name_and_span.is_none())
|
if (fr_name_and_span.is_none() && outlived_fr_name_and_span.is_none())
|
||||||
|| (*category == ConstraintCategory::Assignment
|
|| (*category == ConstraintCategory::Assignment
|
||||||
&& self.universal_regions.defining_ty.is_fn_def())
|
&& self.regioncx.universal_regions().defining_ty.is_fn_def())
|
||||||
|| self.universal_regions.defining_ty.is_const()
|
|| self.regioncx.universal_regions().defining_ty.is_const()
|
||||||
{
|
{
|
||||||
return self.report_general_error(&ErrorConstraintInfo {
|
return self.report_general_error(&ErrorConstraintInfo {
|
||||||
fr_is_local: true,
|
fr_is_local: true,
|
||||||
|
|
|
@ -132,16 +132,16 @@ impl<'tcx> DefiningTy<'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_closure(&self) -> bool {
|
pub fn is_fn_def(&self) -> bool {
|
||||||
match *self {
|
match *self {
|
||||||
DefiningTy::Closure(..) => true,
|
DefiningTy::FnDef(..) => true,
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_fn_def(&self) -> bool {
|
pub fn is_const(&self) -> bool {
|
||||||
match *self {
|
match *self {
|
||||||
DefiningTy::FnDef(..) => true,
|
DefiningTy::Const(..) => true,
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,6 +76,7 @@ pub fn provide(providers: &mut Providers<'_>) {
|
||||||
impl_polarity,
|
impl_polarity,
|
||||||
is_foreign_item,
|
is_foreign_item,
|
||||||
static_mutability,
|
static_mutability,
|
||||||
|
generator_kind,
|
||||||
codegen_fn_attrs,
|
codegen_fn_attrs,
|
||||||
collect_mod_item_types,
|
collect_mod_item_types,
|
||||||
..*providers
|
..*providers
|
||||||
|
@ -1006,7 +1007,7 @@ fn trait_def(tcx: TyCtxt<'_>, def_id: DefId) -> &ty::TraitDef {
|
||||||
.struct_span_err(
|
.struct_span_err(
|
||||||
item.span,
|
item.span,
|
||||||
"the `#[rustc_paren_sugar]` attribute is a temporary means of controlling \
|
"the `#[rustc_paren_sugar]` attribute is a temporary means of controlling \
|
||||||
which traits can use parenthetical notation",
|
which traits can use parenthetical notation",
|
||||||
)
|
)
|
||||||
.help("add `#![feature(unboxed_closures)]` to the crate attributes to use it")
|
.help("add `#![feature(unboxed_closures)]` to the crate attributes to use it")
|
||||||
.emit();
|
.emit();
|
||||||
|
@ -2106,7 +2107,7 @@ fn compute_sig_of_foreign_fn_decl<'tcx>(
|
||||||
ast_ty.span,
|
ast_ty.span,
|
||||||
&format!(
|
&format!(
|
||||||
"use of SIMD type `{}` in FFI is highly experimental and \
|
"use of SIMD type `{}` in FFI is highly experimental and \
|
||||||
may result in invalid code",
|
may result in invalid code",
|
||||||
tcx.hir().hir_to_pretty_string(ast_ty.hir_id)
|
tcx.hir().hir_to_pretty_string(ast_ty.hir_id)
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
@ -2145,6 +2146,16 @@ fn static_mutability(tcx: TyCtxt<'_>, def_id: DefId) -> Option<hir::Mutability>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn generator_kind(tcx: TyCtxt<'_>, def_id: DefId) -> Option<hir::GeneratorKind> {
|
||||||
|
match tcx.hir().get_if_local(def_id) {
|
||||||
|
Some(Node::Item(&hir::Item { kind: hir::ItemKind::Fn(_, _, body_id), .. })) => {
|
||||||
|
tcx.hir().body(body_id).generator_kind()
|
||||||
|
}
|
||||||
|
Some(_) => None,
|
||||||
|
_ => bug!("generator_kind applied to non-local def-id {:?}", def_id),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn from_target_feature(
|
fn from_target_feature(
|
||||||
tcx: TyCtxt<'_>,
|
tcx: TyCtxt<'_>,
|
||||||
id: DefId,
|
id: DefId,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue