Skip to content

Add new "types" map to smir json #46

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/printer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,8 @@ pub enum AllocInfo {
}
type LinkMap<'tcx> = HashMap<LinkMapKey<'tcx>, (ItemSource, FnSymType)>;
type AllocMap = HashMap<stable_mir::mir::alloc::AllocId, AllocInfo>;
type TyMap = HashMap<u64, (stable_mir::ty::TyKind, Option<stable_mir::abi::LayoutShape>)>;
type TyMap =
HashMap<stable_mir::ty::Ty, (stable_mir::ty::TyKind, Option<stable_mir::abi::LayoutShape>)>;

struct InternedValueCollector<'tcx, 'local> {
tcx: TyCtxt<'tcx>,
Expand Down Expand Up @@ -629,7 +630,7 @@ fn collect_ty(val_collector: &mut InternedValueCollector, val: stable_mir::ty::T

if val_collector
.visited_tys
.insert(hash(val), (val.kind(), maybe_layout_shape))
.insert(val, (val.kind(), maybe_layout_shape))
.is_some()
{
match val.kind() {
Expand Down Expand Up @@ -925,6 +926,7 @@ pub struct SmirJson<'t> {
pub functions: Vec<(LinkMapKey<'t>, FnSymType)>,
pub uneval_consts: Vec<(ConstDef, String)>,
pub items: Vec<Item>,
pub types: Vec<(stable_mir::ty::Ty, stable_mir::ty::TyKind)>,
pub debug: Option<SmirJsonDebugInfo<'t>>,
}

Expand Down Expand Up @@ -970,7 +972,7 @@ pub fn collect_smir(tcx: TyCtxt<'_>) -> SmirJson {
.collect::<Vec<_>>();
Some(SmirJsonDebugInfo {
fn_sources,
types: visited_tys,
types: visited_tys.clone(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can probably just delete this? (adapting SmirJsonDebugInfo, of course)

Suggested change
types: visited_tys.clone(),

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess so. I only put this here to suppress the compiler from erroring on using an already moved value. This line is on the debug path so I didn't feel the need to think too much about it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really mind what it printed in the debug path, is it handy to have it or is it bloating the output?

foreign_modules: get_foreign_module_details(),
})
} else {
Expand All @@ -984,13 +986,20 @@ pub fn collect_smir(tcx: TyCtxt<'_>) -> SmirJson {
let allocs = visited_allocs.into_iter().collect::<Vec<_>>();
let crate_id = tcx.stable_crate_id(LOCAL_CRATE).as_u64();

let types = visited_tys
.into_iter()
.map(|(k, (v, _))| (k, v))
.filter(|(_, v)| v.is_primitive())
.collect::<Vec<_>>();

SmirJson {
name: local_crate.name,
crate_id,
allocs,
functions: called_functions,
uneval_consts: unevaluated_consts.into_iter().collect(),
items,
types,
debug,
}
}
Expand Down
7 changes: 6 additions & 1 deletion tests/integration/normalise-filter.jq
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,10 @@
( [ .items[] ]
# sort items by symbol name they refer to and by the function name for functions
| sort_by(.symbol_name, .mono_item_kind.MonoItemFn.name)
),
types:
( [ .types[] ]
# sort types by their ID (int, first in list)
| sort_by(.[0])
)
}
}
48 changes: 48 additions & 0 deletions tests/integration/programs/assert_eq.smir.json.expected
Original file line number Diff line number Diff line change
Expand Up @@ -3143,5 +3143,53 @@
},
"symbol_name": "_ZN9assert_eq4main17h"
}
],
"types": [
[
2,
{
"RigidTy": {
"Int": "I8"
}
}
],
[
6,
{
"RigidTy": {
"Int": "Isize"
}
}
],
[
9,
{
"RigidTy": {
"Uint": "U8"
}
}
],
[
16,
{
"RigidTy": {
"Int": "I32"
}
}
],
[
26,
{
"RigidTy": {
"Uint": "U32"
}
}
],
[
40,
{
"RigidTy": "Bool"
}
]
]
}
48 changes: 48 additions & 0 deletions tests/integration/programs/binop.smir.json.expected
Original file line number Diff line number Diff line change
Expand Up @@ -9730,5 +9730,53 @@
},
"symbol_name": "_ZN5binop4main17h"
}
],
"types": [
[
2,
{
"RigidTy": {
"Int": "I8"
}
}
],
[
6,
{
"RigidTy": {
"Int": "Isize"
}
}
],
[
9,
{
"RigidTy": {
"Uint": "U8"
}
}
],
[
16,
{
"RigidTy": {
"Int": "I32"
}
}
],
[
25,
{
"RigidTy": "Bool"
}
],
[
28,
{
"RigidTy": {
"Uint": "U32"
}
}
]
]
}
40 changes: 40 additions & 0 deletions tests/integration/programs/char-trivial.smir.json.expected
Original file line number Diff line number Diff line change
Expand Up @@ -1654,5 +1654,45 @@
},
"symbol_name": "_ZN54_$LT$$LP$$RP$$u20$as$u20$std..process..Termination$GT$6report17h"
}
],
"types": [
[
2,
{
"RigidTy": {
"Int": "I8"
}
}
],
[
6,
{
"RigidTy": {
"Int": "Isize"
}
}
],
[
9,
{
"RigidTy": {
"Uint": "U8"
}
}
],
[
16,
{
"RigidTy": {
"Int": "I32"
}
}
],
[
25,
{
"RigidTy": "Char"
}
]
]
}
40 changes: 40 additions & 0 deletions tests/integration/programs/closure-args.smir.json.expected
Original file line number Diff line number Diff line change
Expand Up @@ -1947,5 +1947,45 @@
},
"symbol_name": "_ZN54_$LT$$LP$$RP$$u20$as$u20$std..process..Termination$GT$6report17h"
}
],
"types": [
[
2,
{
"RigidTy": {
"Int": "I8"
}
}
],
[
6,
{
"RigidTy": {
"Int": "Isize"
}
}
],
[
9,
{
"RigidTy": {
"Uint": "U8"
}
}
],
[
16,
{
"RigidTy": {
"Int": "I32"
}
}
],
[
32,
{
"RigidTy": "Bool"
}
]
]
}
42 changes: 42 additions & 0 deletions tests/integration/programs/closure-no-args.smir.json.expected
Original file line number Diff line number Diff line change
Expand Up @@ -1767,5 +1767,47 @@
},
"symbol_name": "_ZN54_$LT$$LP$$RP$$u20$as$u20$std..process..Termination$GT$6report17h"
}
],
"types": [
[
2,
{
"RigidTy": {
"Int": "I8"
}
}
],
[
6,
{
"RigidTy": {
"Int": "Isize"
}
}
],
[
9,
{
"RigidTy": {
"Uint": "U8"
}
}
],
[
16,
{
"RigidTy": {
"Int": "I32"
}
}
],
[
29,
{
"RigidTy": {
"Uint": "U32"
}
}
]
]
}
48 changes: 48 additions & 0 deletions tests/integration/programs/const-arithm-simple.smir.json.expected
Original file line number Diff line number Diff line change
Expand Up @@ -1910,5 +1910,53 @@
},
"symbol_name": "_ZN54_$LT$$LP$$RP$$u20$as$u20$std..process..Termination$GT$6report17h"
}
],
"types": [
[
2,
{
"RigidTy": {
"Int": "I8"
}
}
],
[
6,
{
"RigidTy": {
"Int": "Isize"
}
}
],
[
9,
{
"RigidTy": {
"Uint": "U8"
}
}
],
[
16,
{
"RigidTy": {
"Int": "I32"
}
}
],
[
25,
{
"RigidTy": "Bool"
}
],
[
26,
{
"RigidTy": {
"Uint": "Usize"
}
}
]
]
}
Loading