Skip to main content

luaur_code_gen/methods/
scoped_spills_drop.rs

1use crate::macros::codegen_assert::CODEGEN_ASSERT;
2use crate::records::scoped_spills::ScopedSpills;
3
4impl Drop for ScopedSpills {
5    fn drop(&mut self) {
6        if self.owner.is_null() {
7            return;
8        }
9
10        let owner = unsafe { &mut *self.owner };
11        let end_spill_id = owner.next_spill_id;
12
13        let mut i = 0;
14        while i < owner.spills.len() {
15            let spill = &owner.spills[i];
16
17            // Restoring spills inside this scope cannot create new spills.
18            CODEGEN_ASSERT!(spill.spill_id < end_spill_id);
19
20            if spill.spill_id >= self.start_spill_id {
21                let inst_idx = spill.inst_idx as usize;
22                let inst =
23                    unsafe { &mut *(*owner.function).instructions.as_mut_ptr().add(inst_idx) };
24
25                owner.restore(inst, true);
26            } else {
27                i += 1;
28            }
29        }
30    }
31}