Skip to content
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ rustup-clear-toolchain:
rustup override unset --nonexistent
rustup toolchain uninstall "${TOOLCHAIN_NAME}"

TESTDIR=$(CURDIR)/tests/integration/programs
TESTDIR=tests/integration/programs

.PHONY: integration-test
integration-test: TESTS ?= $(shell find $(TESTDIR) -type f -name "*.rs")
Expand Down
14 changes: 10 additions & 4 deletions src/printer/ty_visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
//! type trees, recording each relevant type along with its `TyKind` and
//! `LayoutShape`. These collected types are later transformed into
//! [`TypeMetadata`](super::schema::TypeMetadata) entries in the final output.
//! Note that some special kinds (closures, function definitions/pointers, and
//! coroutine witnesses) are traversed only to gather the types they reference
//! and are not themselves stored as entries in the type map.
//! Note that some special kinds (function definitions/pointers and coroutine
//! witnesses) are traversed only to gather the types they reference and are
//! not themselves stored as entries in the type map.

extern crate rustc_middle;
extern crate rustc_smir;
Expand Down Expand Up @@ -63,7 +63,13 @@ impl Visitor for TyCollector<'_> {
self.resolved.insert(*ty);
let instance =
Instance::resolve_closure(def, args, stable_mir::ty::ClosureKind::Fn).unwrap();
self.visit_instance(instance)
let control = self.visit_instance(instance);
// Mirror other branches: record closure Ty only when traversal succeeds.
if matches!(control, ControlFlow::Continue(_)) {
let maybe_layout_shape = ty.layout().ok().map(|layout| layout.shape());
self.types.insert(*ty, (ty.kind(), maybe_layout_shape));
}
control
}
// Break on CoroutineWitnesses, because they aren't expected when getting the layout
TyKind::RigidTy(RigidTy::CoroutineWitness(..)) => {
Expand Down
5 changes: 5 additions & 0 deletions tests/integration/programs/assert_eq.smir.json.expected
Original file line number Diff line number Diff line change
Expand Up @@ -5745,6 +5745,11 @@
"pointee_type": "elided"
}
}
],
[
{
"FunType": "{closure@std::rt::lang_start<()>::{closure#0}}"
}
]
]
}
5 changes: 5 additions & 0 deletions tests/integration/programs/binop.smir.json.expected
Original file line number Diff line number Diff line change
Expand Up @@ -10113,6 +10113,11 @@
"pointee_type": "elided"
}
}
],
[
{
"FunType": "{closure@std::rt::lang_start<()>::{closure#0}}"
}
]
]
}
5 changes: 5 additions & 0 deletions tests/integration/programs/char-trivial.smir.json.expected
Original file line number Diff line number Diff line change
Expand Up @@ -2174,6 +2174,11 @@
"pointee_type": "elided"
}
}
],
[
{
"FunType": "{closure@std::rt::lang_start<()>::{closure#0}}"
}
]
]
}
10 changes: 10 additions & 0 deletions tests/integration/programs/closure-args.smir.json.expected
Original file line number Diff line number Diff line change
Expand Up @@ -2612,6 +2612,16 @@
"pointee_type": "elided"
}
}
],
[
{
"FunType": "{closure@std::rt::lang_start<()>::{closure#0}}"
}
],
[
{
"FunType": "{closure@tests/integration/programs/closure-args.rs:2:15: 2:28}"
}
]
]
}
10 changes: 10 additions & 0 deletions tests/integration/programs/closure-no-args.smir.json.expected
Original file line number Diff line number Diff line change
Expand Up @@ -2307,6 +2307,16 @@
"pointee_type": "elided"
}
}
],
[
{
"FunType": "{closure@std::rt::lang_start<()>::{closure#0}}"
}
],
[
{
"FunType": "{closure@tests/integration/programs/closure-no-args.rs:2:15: 2:24}"
}
]
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -2427,6 +2427,11 @@
"pointee_type": "elided"
}
}
],
[
{
"FunType": "{closure@std::rt::lang_start<()>::{closure#0}}"
}
]
]
}
5 changes: 5 additions & 0 deletions tests/integration/programs/div.smir.json.expected
Original file line number Diff line number Diff line change
Expand Up @@ -2528,6 +2528,11 @@
"pointee_type": "elided"
}
}
],
[
{
"FunType": "{closure@std::rt::lang_start<()>::{closure#0}}"
}
]
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -2350,6 +2350,11 @@
"pointee_type": "elided"
}
}
],
[
{
"FunType": "{closure@std::rt::lang_start<()>::{closure#0}}"
}
]
]
}
5 changes: 5 additions & 0 deletions tests/integration/programs/enum.smir.json.expected
Original file line number Diff line number Diff line change
Expand Up @@ -1959,6 +1959,11 @@
"pointee_type": "elided"
}
}
],
[
{
"FunType": "{closure@std::rt::lang_start<()>::{closure#0}}"
}
]
]
}
5 changes: 5 additions & 0 deletions tests/integration/programs/fibonacci.smir.json.expected
Original file line number Diff line number Diff line change
Expand Up @@ -2891,6 +2891,11 @@
"pointee_type": "elided"
}
}
],
[
{
"FunType": "{closure@std::rt::lang_start<()>::{closure#0}}"
}
]
]
}
5 changes: 5 additions & 0 deletions tests/integration/programs/float.smir.json.expected
Original file line number Diff line number Diff line change
Expand Up @@ -2740,6 +2740,11 @@
"pointee_type": "elided"
}
}
],
[
{
"FunType": "{closure@std::rt::lang_start<()>::{closure#0}}"
}
]
]
}
5 changes: 5 additions & 0 deletions tests/integration/programs/fn-ptr-in-arg.smir.json.expected
Original file line number Diff line number Diff line change
Expand Up @@ -7507,6 +7507,11 @@
"pointee_type": "elided"
}
}
],
[
{
"FunType": "{closure@std::rt::lang_start<()>::{closure#0}}"
}
]
]
}
5 changes: 5 additions & 0 deletions tests/integration/programs/modulo.smir.json.expected
Original file line number Diff line number Diff line change
Expand Up @@ -2526,6 +2526,11 @@
"pointee_type": "elided"
}
}
],
[
{
"FunType": "{closure@std::rt::lang_start<()>::{closure#0}}"
}
]
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -2843,6 +2843,11 @@
"pointee_type": "elided"
}
}
],
[
{
"FunType": "{closure@std::rt::lang_start<()>::{closure#0}}"
}
]
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -2467,6 +2467,11 @@
"pointee_type": "elided"
}
}
],
[
{
"FunType": "{closure@std::rt::lang_start<()>::{closure#0}}"
}
]
]
}
5 changes: 5 additions & 0 deletions tests/integration/programs/param_types.smir.json.expected
Original file line number Diff line number Diff line change
Expand Up @@ -5285,6 +5285,11 @@
"pointee_type": "elided"
}
}
],
[
{
"FunType": "{closure@std::rt::lang_start<()>::{closure#0}}"
}
]
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -2459,6 +2459,11 @@
"pointee_type": "elided"
}
}
],
[
{
"FunType": "{closure@std::rt::lang_start<()>::{closure#0}}"
}
]
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -2658,6 +2658,11 @@
"pointee_type": "elided"
}
}
],
[
{
"FunType": "{closure@std::rt::lang_start<()>::{closure#0}}"
}
]
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -2658,6 +2658,11 @@
"pointee_type": "elided"
}
}
],
[
{
"FunType": "{closure@std::rt::lang_start<()>::{closure#0}}"
}
]
]
}
5 changes: 5 additions & 0 deletions tests/integration/programs/ref-deref.smir.json.expected
Original file line number Diff line number Diff line change
Expand Up @@ -2265,6 +2265,11 @@
"pointee_type": "elided"
}
}
],
[
{
"FunType": "{closure@std::rt::lang_start<()>::{closure#0}}"
}
]
]
}
5 changes: 5 additions & 0 deletions tests/integration/programs/shl_min.smir.json.expected
Original file line number Diff line number Diff line change
Expand Up @@ -3992,6 +3992,11 @@
"pointee_type": "elided"
}
}
],
[
{
"FunType": "{closure@std::rt::lang_start<()>::{closure#0}}"
}
]
]
}
5 changes: 5 additions & 0 deletions tests/integration/programs/slice.smir.json.expected
Original file line number Diff line number Diff line change
Expand Up @@ -5869,6 +5869,11 @@
"pointee_type": "elided"
}
}
],
[
{
"FunType": "{closure@std::rt::lang_start<()>::{closure#0}}"
}
]
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -2353,6 +2353,11 @@
"pointee_type": "elided"
}
}
],
[
{
"FunType": "{closure@std::rt::lang_start<()>::{closure#0}}"
}
]
]
}
5 changes: 5 additions & 0 deletions tests/integration/programs/struct.smir.json.expected
Original file line number Diff line number Diff line change
Expand Up @@ -2558,6 +2558,11 @@
"pointee_type": "elided"
}
}
],
[
{
"FunType": "{closure@std::rt::lang_start<()>::{closure#0}}"
}
]
]
}
5 changes: 5 additions & 0 deletions tests/integration/programs/sum-to-n.smir.json.expected
Original file line number Diff line number Diff line change
Expand Up @@ -3079,6 +3079,11 @@
"pointee_type": "elided"
}
}
],
[
{
"FunType": "{closure@std::rt::lang_start<()>::{closure#0}}"
}
]
]
}
5 changes: 5 additions & 0 deletions tests/integration/programs/tuple-eq.smir.json.expected
Original file line number Diff line number Diff line change
Expand Up @@ -3097,6 +3097,11 @@
"pointee_type": "elided"
}
}
],
[
{
"FunType": "{closure@std::rt::lang_start<()>::{closure#0}}"
}
]
]
}
5 changes: 5 additions & 0 deletions tests/integration/programs/tuples-simple.smir.json.expected
Original file line number Diff line number Diff line change
Expand Up @@ -2345,6 +2345,11 @@
"pointee_type": "elided"
}
}
],
[
{
"FunType": "{closure@std::rt::lang_start<()>::{closure#0}}"
}
]
]
}
5 changes: 5 additions & 0 deletions tests/integration/programs/weirdRefs.smir.json.expected
Original file line number Diff line number Diff line change
Expand Up @@ -3863,6 +3863,11 @@
"pointee_type": "elided"
}
}
],
[
{
"FunType": "{closure@std::rt::lang_start<()>::{closure#0}}"
}
]
]
}