Add ItemKind::Ctor
to stable mir
This commit is contained in:
parent
48c7cc2090
commit
7ab38b80eb
3 changed files with 22 additions and 11 deletions
|
@ -7,7 +7,7 @@
|
||||||
//!
|
//!
|
||||||
//! For now, we are developing everything inside `rustc`, thus, we keep this module private.
|
//! For now, we are developing everything inside `rustc`, thus, we keep this module private.
|
||||||
|
|
||||||
use rustc_hir::def::{CtorKind, DefKind};
|
use rustc_hir::def::DefKind;
|
||||||
use rustc_middle::mir;
|
use rustc_middle::mir;
|
||||||
use rustc_middle::mir::interpret::AllocId;
|
use rustc_middle::mir::interpret::AllocId;
|
||||||
use rustc_middle::ty::{self, Instance, Ty, TyCtxt};
|
use rustc_middle::ty::{self, Instance, Ty, TyCtxt};
|
||||||
|
@ -15,7 +15,7 @@ use rustc_span::def_id::{CrateNum, DefId, LOCAL_CRATE};
|
||||||
use stable_mir::abi::Layout;
|
use stable_mir::abi::Layout;
|
||||||
use stable_mir::mir::mono::InstanceDef;
|
use stable_mir::mir::mono::InstanceDef;
|
||||||
use stable_mir::ty::{ConstId, Span};
|
use stable_mir::ty::{ConstId, Span};
|
||||||
use stable_mir::ItemKind;
|
use stable_mir::{CtorKind, ItemKind};
|
||||||
use std::ops::RangeInclusive;
|
use std::ops::RangeInclusive;
|
||||||
use tracing::debug;
|
use tracing::debug;
|
||||||
|
|
||||||
|
@ -91,15 +91,13 @@ pub(crate) fn new_item_kind(kind: DefKind) -> ItemKind {
|
||||||
| DefKind::GlobalAsm => {
|
| DefKind::GlobalAsm => {
|
||||||
unreachable!("Not a valid item kind: {kind:?}");
|
unreachable!("Not a valid item kind: {kind:?}");
|
||||||
}
|
}
|
||||||
DefKind::Ctor(_, CtorKind::Fn) | DefKind::Closure | DefKind::AssocFn | DefKind::Fn => {
|
DefKind::Closure | DefKind::AssocFn | DefKind::Fn => ItemKind::Fn,
|
||||||
ItemKind::Fn
|
DefKind::Const | DefKind::InlineConst | DefKind::AssocConst | DefKind::AnonConst => {
|
||||||
|
ItemKind::Const
|
||||||
}
|
}
|
||||||
DefKind::Ctor(_, CtorKind::Const)
|
|
||||||
| DefKind::Const
|
|
||||||
| DefKind::InlineConst
|
|
||||||
| DefKind::AssocConst
|
|
||||||
| DefKind::AnonConst => ItemKind::Const,
|
|
||||||
DefKind::Static(_) => ItemKind::Static,
|
DefKind::Static(_) => ItemKind::Static,
|
||||||
|
DefKind::Ctor(_, rustc_hir::def::CtorKind::Const) => ItemKind::Ctor(CtorKind::Const),
|
||||||
|
DefKind::Ctor(_, rustc_hir::def::CtorKind::Fn) => ItemKind::Ctor(CtorKind::Fn),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -91,6 +91,13 @@ pub enum ItemKind {
|
||||||
Fn,
|
Fn,
|
||||||
Static,
|
Static,
|
||||||
Const,
|
Const,
|
||||||
|
Ctor(CtorKind),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash)]
|
||||||
|
pub enum CtorKind {
|
||||||
|
Const,
|
||||||
|
Fn,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type Filename = String;
|
pub type Filename = String;
|
||||||
|
|
|
@ -29,12 +29,13 @@ const CRATE_NAME: &str = "input";
|
||||||
/// This function uses the Stable MIR APIs to get information about the test crate.
|
/// This function uses the Stable MIR APIs to get information about the test crate.
|
||||||
fn test_item_kind(_tcx: TyCtxt<'_>) -> ControlFlow<()> {
|
fn test_item_kind(_tcx: TyCtxt<'_>) -> ControlFlow<()> {
|
||||||
let items = stable_mir::all_local_items();
|
let items = stable_mir::all_local_items();
|
||||||
assert_eq!(items.len(), 3);
|
assert_eq!(items.len(), 4);
|
||||||
// Constructor item.
|
// Constructor item.
|
||||||
for item in items {
|
for item in items {
|
||||||
let expected_kind = match item.name().as_str() {
|
let expected_kind = match item.name().as_str() {
|
||||||
"Dummy" => ItemKind::Fn,
|
"Dummy" => ItemKind::Ctor(CtorKind::Fn),
|
||||||
"dummy" => ItemKind::Fn,
|
"dummy" => ItemKind::Fn,
|
||||||
|
"unit" => ItemKind::Fn,
|
||||||
"DUMMY_CONST" => ItemKind::Const,
|
"DUMMY_CONST" => ItemKind::Const,
|
||||||
name => unreachable!("Unexpected item {name}"),
|
name => unreachable!("Unexpected item {name}"),
|
||||||
};
|
};
|
||||||
|
@ -68,10 +69,15 @@ fn generate_input(path: &str) -> std::io::Result<()> {
|
||||||
r#"
|
r#"
|
||||||
pub struct Dummy(u32);
|
pub struct Dummy(u32);
|
||||||
pub const DUMMY_CONST: Dummy = Dummy(0);
|
pub const DUMMY_CONST: Dummy = Dummy(0);
|
||||||
|
pub struct DummyUnit;
|
||||||
|
|
||||||
pub fn dummy() -> Dummy {{
|
pub fn dummy() -> Dummy {{
|
||||||
Dummy(5)
|
Dummy(5)
|
||||||
}}
|
}}
|
||||||
|
|
||||||
|
pub fn unit() -> DummyUnit {{
|
||||||
|
DummyUnit
|
||||||
|
}}
|
||||||
"#
|
"#
|
||||||
)?;
|
)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue