Skip to content
Draft
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ format:
bash -O globstar -c 'nixfmt **/*.nix'

style-check: format
cargo clippy
cargo clippy -- -Dwarnings

.PHONY: remake-ui-tests test-ui

Expand Down
39 changes: 33 additions & 6 deletions src/printer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1137,6 +1137,10 @@ pub enum TypeMetadata {
PrimitiveType(RigidTy),
EnumType {
name: String,
// adt_def serializes as a non-deterministic interned index (DefId), but
// downstream consumers need it to cross-reference AggregateKind::Adt in
// MIR bodies with the type metadata here. We can't stabilize it without
// also controlling AggregateKind serialization (which comes from stable_mir).
adt_def: AdtDef,
discriminants: Vec<u128>,
fields: Vec<Vec<stable_mir::ty::Ty>>,
Expand Down Expand Up @@ -1372,6 +1376,15 @@ impl AllocInfo {
}
}

fn alloc_sort_key(info: &AllocInfo) -> String {
match info.global_alloc() {
GlobalAlloc::Memory(alloc) => format!("0_Memory_{:020}", alloc.bytes.len()),
GlobalAlloc::Static(def) => format!("1_Static_{}", def.name()),
GlobalAlloc::VTable(ty, _) => format!("2_VTable_{}", ty),
GlobalAlloc::Function(inst) => format!("3_Function_{}", inst.name()),
}
}

// Serialization Entrypoint
// ========================

Expand Down Expand Up @@ -1435,19 +1448,33 @@ pub fn collect_smir(tcx: TyCtxt<'_>) -> SmirJson {

let mut spans = span_map.into_iter().collect::<Vec<_>>();

// sort output vectors to stabilise output (a bit)
allocs.sort_by(|a, b| a.alloc_id.to_index().cmp(&b.alloc_id.to_index()));
functions.sort_by(|a, b| a.0 .0.to_index().cmp(&b.0 .0.to_index()));
// sort output vectors by content-derived keys for deterministic output.
// Ty's Display impl (ty_pretty) should be injective for monomorphized types,
// but we use the interned index as a tiebreaker just in case two distinct
// types produce the same display string.
allocs.sort_by_key(alloc_sort_key);
functions.sort_by(|a, b| {
format!("{}", a.0 .0)
.cmp(&format!("{}", b.0 .0))
.then_with(|| a.0 .0.to_index().cmp(&b.0 .0.to_index()))
});
items.sort();
types.sort_by(|a, b| a.0.to_index().cmp(&b.0.to_index()));
spans.sort();
types.sort_by(|a, b| {
format!("{}", a.0)
.cmp(&format!("{}", b.0))
.then_with(|| a.0.to_index().cmp(&b.0.to_index()))
});
spans.sort_by(|a, b| a.1.cmp(&b.1));

let mut uneval_consts: Vec<_> = unevaluated_consts.into_iter().collect();
uneval_consts.sort_by(|a, b| a.1.cmp(&b.1));

SmirJson {
name: local_crate.name,
crate_id,
allocs,
functions,
uneval_consts: unevaluated_consts.into_iter().collect(),
uneval_consts,
items,
types,
spans,
Expand Down
104 changes: 52 additions & 52 deletions tests/integration/programs/assert_eq.smir.json.expected
Original file line number Diff line number Diff line change
Expand Up @@ -4760,34 +4760,6 @@
}
}
],
[
{
"TupleType": {
"layout": {
"abi": {
"Aggregate": {
"sized": true
}
},
"abi_align": 1,
"fields": {
"Arbitrary": {
"offsets": []
}
},
"size": {
"num_bits": 0
},
"variants": {
"Single": {
"index": 0
}
}
},
"types": "elided"
}
}
],
[
{
"TupleType": {
Expand All @@ -4797,48 +4769,70 @@
{
"Initialized": {
"valid_range": {
"end": 4294967295,
"start": 0
"end": 18446744073709551615,
"start": 1
},
"value": {
"Int": {
"length": "I32",
"signed": true
}
"Pointer": 0
}
}
},
{
"Initialized": {
"valid_range": {
"end": 1,
"start": 0
"end": 18446744073709551615,
"start": 1
},
"value": {
"Int": {
"length": "I8",
"signed": false
}
"Pointer": 0
}
}
}
]
},
"abi_align": 4,
"abi_align": 8,
"fields": {
"Arbitrary": {
"offsets": [
{
"num_bits": 0
},
{
"num_bits": 32
"num_bits": 64
}
]
}
},
"size": {
"num_bits": 64
"num_bits": 128
},
"variants": {
"Single": {
"index": 0
}
}
},
"types": "elided"
}
}
],
[
{
"TupleType": {
"layout": {
"abi": {
"Aggregate": {
"sized": true
}
},
"abi_align": 1,
"fields": {
"Arbitrary": {
"offsets": []
}
},
"size": {
"num_bits": 0
},
"variants": {
"Single": {
Expand All @@ -4859,42 +4853,48 @@
{
"Initialized": {
"valid_range": {
"end": 18446744073709551615,
"start": 1
"end": 4294967295,
"start": 0
},
"value": {
"Pointer": 0
"Int": {
"length": "I32",
"signed": true
}
}
}
},
{
"Initialized": {
"valid_range": {
"end": 18446744073709551615,
"start": 1
"end": 1,
"start": 0
},
"value": {
"Pointer": 0
"Int": {
"length": "I8",
"signed": false
}
}
}
}
]
},
"abi_align": 8,
"abi_align": 4,
"fields": {
"Arbitrary": {
"offsets": [
{
"num_bits": 0
},
{
"num_bits": 64
"num_bits": 32
}
]
}
},
"size": {
"num_bits": 128
"num_bits": 64
},
"variants": {
"Single": {
Expand Down
12 changes: 6 additions & 6 deletions tests/integration/programs/closure-args.smir.json.expected
Original file line number Diff line number Diff line change
Expand Up @@ -2131,13 +2131,13 @@
{
"Initialized": {
"valid_range": {
"end": 4294967295,
"end": 1,
"start": 0
},
"value": {
"Int": {
"length": "I32",
"signed": true
"length": "I8",
"signed": false
}
}
}
Expand Down Expand Up @@ -2193,13 +2193,13 @@
{
"Initialized": {
"valid_range": {
"end": 1,
"end": 4294967295,
"start": 0
},
"value": {
"Int": {
"length": "I8",
"signed": false
"length": "I32",
"signed": true
}
}
}
Expand Down
Loading