Skip to content

Commit 13b79cf

Browse files
committed
WIP: Handle MIR aggregate assignments in an attempt to fix the problems introduced by the new nightly compiler.
Related issue: rust-lang/rust#107678 The commit that caused the issue: rust-lang/rust@9dee4e4
1 parent 1ad2ed7 commit 13b79cf

File tree

3 files changed

+76
-2
lines changed

3 files changed

+76
-2
lines changed

src/translator.rs

+20-2
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ use netcrab::petri_net::{PetriNet, PlaceRef};
3838
use rustc_middle::mir::visit::Visitor;
3939
use special_function::{call_diverging_function, call_panic_function, is_panic_function};
4040
use sync::{
41-
handle_ref_assignment, handle_use_copy_assignment, handle_use_move_assignment, ArcManager,
42-
CondvarManager, MutexManager, ThreadManager,
41+
handle_aggregate_assignment, handle_ref_assignment, handle_use_copy_assignment,
42+
handle_use_move_assignment, ArcManager, CondvarManager, MutexManager, ThreadManager,
4343
};
4444

4545
pub struct Translator<'tcx> {
@@ -270,4 +270,22 @@ impl<'tcx> Translator<'tcx> {
270270
let function = self.call_stack.peek_mut();
271271
handle_ref_assignment(place, rhs, &mut function.memory, function.def_id, self.tcx);
272272
}
273+
274+
/// Handles MIR assignments of the form: `_X = { copy_data: move _Y }`.
275+
/// This is the handler for the enum variant `rustc_middle::mir::Rvalue::Aggregate` in the MIR Visitor.
276+
/// <https://doc.rust-lang.org/stable/nightly-rustc/rustc_middle/mir/enum.Rvalue.html#variant.Aggregate>
277+
fn handle_aggregate_assignment(
278+
&mut self,
279+
place: &rustc_middle::mir::Place<'tcx>,
280+
operands: &Vec<rustc_middle::mir::Operand<'tcx>>,
281+
) {
282+
let function = self.call_stack.peek_mut();
283+
handle_aggregate_assignment(
284+
place,
285+
operands,
286+
&mut function.memory,
287+
function.def_id,
288+
self.tcx,
289+
);
290+
}
273291
}

src/translator/mir_visitor.rs

+3
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ impl<'tcx> Visitor<'tcx> for Translator<'tcx> {
4040
rustc_middle::mir::Rvalue::Ref(_, _, rhs) => {
4141
self.handle_ref_assignment(place, rhs);
4242
}
43+
rustc_middle::mir::Rvalue::Aggregate(_, operands) => {
44+
self.handle_aggregate_assignment(place, operands);
45+
}
4346
// No need to do anything for the other cases for now.
4447
_ => {}
4548
}

src/translator/sync.rs

+53
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,56 @@ pub fn handle_ref_assignment<'tcx>(
124124
memory.link_place_to_same_condvar(*place, *rhs);
125125
}
126126
}
127+
128+
/// Handles MIR assignments of the form: `_X = { copy_data: move _Y }`.
129+
/// If the right-hand side contains a synchronization variable, link it to the left-hand side.
130+
pub fn handle_aggregate_assignment<'tcx>(
131+
place: &rustc_middle::mir::Place<'tcx>,
132+
operands: &Vec<rustc_middle::mir::Operand<'tcx>>,
133+
memory: &mut Memory<'tcx>,
134+
caller_function_def_id: rustc_hir::def_id::DefId,
135+
tcx: rustc_middle::ty::TyCtxt<'tcx>,
136+
) {
137+
for operand in operands {
138+
// Extract the place to be assignment
139+
let rhs = match operand {
140+
rustc_middle::mir::Operand::Copy(place) | rustc_middle::mir::Operand::Move(place) => {
141+
place
142+
}
143+
// Nothing to do if we found a constant as one of the operands.
144+
rustc_middle::mir::Operand::Constant(_) => continue,
145+
};
146+
147+
if is_place_with_concrete_type(rhs, "std::sync::Mutex<T>", caller_function_def_id, tcx)
148+
|| is_place_with_concrete_type(
149+
rhs,
150+
"std::sync::Arc<std::sync::Mutex<T>>",
151+
caller_function_def_id,
152+
tcx,
153+
)
154+
{
155+
memory.link_place_to_same_mutex(*place, *rhs);
156+
} else if is_place_with_concrete_type(
157+
rhs,
158+
"std::sync::MutexGuard<'a, T>",
159+
caller_function_def_id,
160+
tcx,
161+
) {
162+
memory.link_place_to_same_lock_guard(*place, *rhs);
163+
} else if is_place_with_concrete_type(
164+
rhs,
165+
"std::thread::JoinHandle<T>",
166+
caller_function_def_id,
167+
tcx,
168+
) {
169+
memory.link_place_to_same_join_handle(*place, *rhs);
170+
} else if is_place_with_concrete_type(
171+
rhs,
172+
"std::sync::Condvar",
173+
caller_function_def_id,
174+
tcx,
175+
) {
176+
memory.link_place_to_same_condvar(*place, *rhs);
177+
}
178+
}
179+
}

0 commit comments

Comments
 (0)