Skip to content

Commit 083af83

Browse files
authored
simplify DropWithHeap trait (#227)
1 parent 7a9064f commit 083af83

File tree

6 files changed

+19
-28
lines changed

6 files changed

+19
-28
lines changed

crates/monty-js/package-lock.json

Lines changed: 0 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/monty/src/args.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::{
44
MontyObject, ResourceTracker, defer_drop, defer_drop_mut,
55
exception_private::{ExcType, RunError, RunResult, SimpleException},
66
expressions::{ExprLoc, Identifier},
7-
heap::{DropWithHeap, Heap, HeapGuard},
7+
heap::{ContainsHeap, DropWithHeap, Heap, HeapGuard},
88
intern::{Interns, StringId},
99
parse::ParseError,
1010
types::{Dict, dict::DictIntoIter},
@@ -300,7 +300,7 @@ impl ArgValues {
300300
}
301301

302302
impl DropWithHeap for ArgValues {
303-
fn drop_with_concrete_heap<T: ResourceTracker>(self, heap: &mut Heap<T>) {
303+
fn drop_with_heap<H: ContainsHeap>(self, heap: &mut H) {
304304
match self {
305305
Self::Empty => {}
306306
Self::One(v) => v.drop_with_heap(heap),
@@ -384,7 +384,7 @@ impl Iterator for ArgPosIter {
384384
impl ExactSizeIterator for ArgPosIter {}
385385

386386
impl DropWithHeap for ArgPosIter {
387-
fn drop_with_concrete_heap<T: ResourceTracker>(self, heap: &mut Heap<T>) {
387+
fn drop_with_heap<H: ContainsHeap>(self, heap: &mut H) {
388388
match self {
389389
Self::Empty => {}
390390
Self::One(v1) => v1.drop_with_heap(heap),
@@ -464,7 +464,7 @@ impl KwargsValues {
464464

465465
impl DropWithHeap for KwargsValues {
466466
/// Properly drops all values in the arguments, decrementing reference counts.
467-
fn drop_with_concrete_heap<T: ResourceTracker>(self, heap: &mut Heap<T>) {
467+
fn drop_with_heap<H: ContainsHeap>(self, heap: &mut H) {
468468
match self {
469469
Self::Empty => {}
470470
Self::Inline(kvs) => {
@@ -529,7 +529,7 @@ impl Iterator for KwargsValuesIter {
529529
impl ExactSizeIterator for KwargsValuesIter {}
530530

531531
impl DropWithHeap for KwargsValuesIter {
532-
fn drop_with_concrete_heap<T: ResourceTracker>(self, heap: &mut Heap<T>) {
532+
fn drop_with_heap<H: ContainsHeap>(self, heap: &mut H) {
533533
match self {
534534
Self::Empty => {}
535535
Self::Inline(iter) => {

crates/monty/src/heap.rs

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -773,8 +773,8 @@ pub(crate) struct RecursionToken(());
773773

774774
impl DropWithHeap for RecursionToken {
775775
#[inline]
776-
fn drop_with_concrete_heap<T: ResourceTracker>(self, heap: &mut Heap<T>) {
777-
heap.decr_recursion_depth();
776+
fn drop_with_heap<H: ContainsHeap>(self, heap: &mut H) {
777+
heap.heap().decr_recursion_depth();
778778
}
779779
}
780780

@@ -1779,56 +1779,51 @@ impl<T: ResourceTracker> ContainsHeap for Heap<T> {
17791779
/// types that hold heap references.
17801780
pub(crate) trait DropWithHeap: Sized {
17811781
/// Consume `self` and decrement reference counts for any heap-allocated values contained within.
1782-
fn drop_with_heap<H: ContainsHeap>(self, heap: &mut H) {
1783-
self.drop_with_concrete_heap(heap.heap_mut());
1784-
}
1785-
1786-
/// Consume `self` and decrement reference counts for any heap-allocated values contained within.
1787-
fn drop_with_concrete_heap<T: ResourceTracker>(self, heap: &mut Heap<T>);
1782+
fn drop_with_heap<H: ContainsHeap>(self, heap: &mut H);
17881783
}
17891784

17901785
impl DropWithHeap for Value {
17911786
#[inline]
1792-
fn drop_with_concrete_heap<T: ResourceTracker>(self, heap: &mut Heap<T>) {
1787+
fn drop_with_heap<H: ContainsHeap>(self, heap: &mut H) {
17931788
Self::drop_with_heap(self, heap);
17941789
}
17951790
}
17961791

17971792
impl<U: DropWithHeap> DropWithHeap for Option<U> {
17981793
#[inline]
1799-
fn drop_with_concrete_heap<T: ResourceTracker>(self, heap: &mut Heap<T>) {
1794+
fn drop_with_heap<H: ContainsHeap>(self, heap: &mut H) {
18001795
if let Some(value) = self {
18011796
value.drop_with_heap(heap);
18021797
}
18031798
}
18041799
}
18051800

18061801
impl<U: DropWithHeap> DropWithHeap for Vec<U> {
1807-
fn drop_with_concrete_heap<T: ResourceTracker>(self, heap: &mut Heap<T>) {
1802+
fn drop_with_heap<H: ContainsHeap>(self, heap: &mut H) {
18081803
for value in self {
18091804
value.drop_with_heap(heap);
18101805
}
18111806
}
18121807
}
18131808

18141809
impl<U: DropWithHeap> DropWithHeap for vec::IntoIter<U> {
1815-
fn drop_with_concrete_heap<T: ResourceTracker>(self, heap: &mut Heap<T>) {
1810+
fn drop_with_heap<H: ContainsHeap>(self, heap: &mut H) {
18161811
for value in self {
18171812
value.drop_with_heap(heap);
18181813
}
18191814
}
18201815
}
18211816

18221817
impl<const N: usize> DropWithHeap for [Value; N] {
1823-
fn drop_with_concrete_heap<T: ResourceTracker>(self, heap: &mut Heap<T>) {
1818+
fn drop_with_heap<H: ContainsHeap>(self, heap: &mut H) {
18241819
for value in self {
18251820
value.drop_with_heap(heap);
18261821
}
18271822
}
18281823
}
18291824

18301825
impl<U: DropWithHeap, V: DropWithHeap> DropWithHeap for (U, V) {
1831-
fn drop_with_concrete_heap<T: ResourceTracker>(self, heap: &mut Heap<T>) {
1826+
fn drop_with_heap<H: ContainsHeap>(self, heap: &mut H) {
18321827
let (left, right) = self;
18331828
left.drop_with_heap(heap);
18341829
right.drop_with_heap(heap);

crates/monty/src/signature.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::{
99
defer_drop_mut,
1010
exception_private::{ExcType, RunResult, SimpleException},
1111
expressions::Identifier,
12-
heap::{DropWithHeap, Heap, HeapData, HeapGuard},
12+
heap::{ContainsHeap, DropWithHeap, Heap, HeapData, HeapGuard},
1313
intern::{Interns, StringId},
1414
resource::ResourceTracker,
1515
types::{Dict, allocate_tuple},
@@ -659,7 +659,7 @@ struct NamespaceGuard<'a> {
659659
}
660660

661661
impl DropWithHeap for NamespaceGuard<'_> {
662-
fn drop_with_concrete_heap<T: ResourceTracker>(self, heap: &mut Heap<T>) {
662+
fn drop_with_heap<H: ContainsHeap>(self, heap: &mut H) {
663663
for value in self.namespace.drain(..) {
664664
value.drop_with_heap(heap);
665665
}

crates/monty/src/types/dict.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use crate::{
1414
bytecode::VM,
1515
defer_drop, defer_drop_mut,
1616
exception_private::{ExcType, RunResult},
17-
heap::{DropWithHeap, Heap, HeapData, HeapGuard, HeapId},
17+
heap::{ContainsHeap, DropWithHeap, Heap, HeapData, HeapGuard, HeapId},
1818
intern::{Interns, StaticStrings},
1919
resource::{ResourceError, ResourceTracker},
2020
types::Type,
@@ -647,7 +647,7 @@ impl PyTrait for Dict {
647647
}
648648

649649
impl DropWithHeap for Dict {
650-
fn drop_with_concrete_heap<T: ResourceTracker>(self, heap: &mut Heap<T>) {
650+
fn drop_with_heap<H: ContainsHeap>(self, heap: &mut H) {
651651
for entry in self.entries {
652652
entry.key.drop_with_heap(heap);
653653
entry.value.drop_with_heap(heap);

crates/monty/src/types/iter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -756,7 +756,7 @@ impl IterValue {
756756

757757
impl DropWithHeap for MontyIter {
758758
#[inline]
759-
fn drop_with_concrete_heap<T: ResourceTracker>(self, heap: &mut Heap<T>) {
759+
fn drop_with_heap<H: ContainsHeap>(self, heap: &mut H) {
760760
Self::drop_with_heap(self, heap);
761761
}
762762
}

0 commit comments

Comments
 (0)