55mod object_pool;
66
77// Use ObjectPoolV2 as the main ObjectPool
8+ use crate :: lua_value:: LuaValue ;
89pub use object_pool:: {
9- ObjectPoolV2 as ObjectPool ,
10- StringId , TableId , FunctionId , UpvalueId , UserdataId , ThreadId ,
11- Arena , GcHeader , GcTable , GcFunction , GcUpvalue , GcString , GcThread , UpvalueState ,
10+ Arena , FunctionId , GcFunction , GcHeader , GcString , GcTable , GcThread , GcUpvalue ,
11+ ObjectPoolV2 as ObjectPool , StringId , TableId , ThreadId , UpvalueId , UpvalueState , UserdataId ,
1212} ;
13- use crate :: lua_value:: LuaValue ;
1413use std:: collections:: { HashMap , HashSet } ;
1514
1615/// GC Generation
@@ -269,11 +268,7 @@ impl GC {
269268
270269 /// Perform garbage collection (chooses minor or major)
271270 /// Takes root set (stack, globals, etc.) and marks reachable objects
272- pub fn collect (
273- & mut self ,
274- roots : & [ LuaValue ] ,
275- object_pool : & mut ObjectPool ,
276- ) -> usize {
271+ pub fn collect ( & mut self , roots : & [ LuaValue ] , object_pool : & mut ObjectPool ) -> usize {
277272 // For public API, determine which to run based on state
278273 if self . minor_gc_count >= 10 {
279274 self . major_collect_internal ( roots, object_pool)
@@ -514,16 +509,12 @@ impl GC {
514509 // Mark children
515510 match key. 0 {
516511 GcObjectType :: Table => {
517- if let Some ( table) =
518- object_pool. get_table ( TableId ( key. 1 ) )
519- {
512+ if let Some ( table) = object_pool. get_table ( TableId ( key. 1 ) ) {
520513 self . mark_table ( table, & mut worklist) ;
521514 }
522515 }
523516 GcObjectType :: Function => {
524- if let Some ( func) =
525- object_pool. get_function ( FunctionId ( key. 1 ) )
526- {
517+ if let Some ( func) = object_pool. get_function ( FunctionId ( key. 1 ) ) {
527518 self . mark_function ( func, object_pool, & mut worklist) ;
528519 }
529520 }
@@ -545,7 +536,12 @@ impl GC {
545536 }
546537
547538 /// Mark function upvalues
548- fn mark_function ( & self , func : & GcFunction , object_pool : & ObjectPool , worklist : & mut Vec < LuaValue > ) {
539+ fn mark_function (
540+ & self ,
541+ func : & GcFunction ,
542+ object_pool : & ObjectPool ,
543+ worklist : & mut Vec < LuaValue > ,
544+ ) {
549545 for upval_id in & func. upvalues {
550546 // Only mark closed upvalues (open ones are on the stack already)
551547 if let Some ( upval) = object_pool. get_upvalue ( * upval_id) {
@@ -594,7 +590,7 @@ impl GC {
594590 }
595591 }
596592 }
597-
593+
598594 /// Check if a value is collectable (needs GC barrier)
599595 #[ inline( always) ]
600596 pub fn is_collectable ( value : & LuaValue ) -> bool {
@@ -696,11 +692,7 @@ impl GC {
696692
697693 /// Check if table has weak mode (__mode metamethod)
698694 /// Returns: None if no weak mode, Some("k") for weak keys, Some("v") for weak values, Some("kv") for both
699- pub fn get_weak_mode (
700- & self ,
701- table_id : TableId ,
702- object_pool : & ObjectPool ,
703- ) -> Option < String > {
695+ pub fn get_weak_mode ( & self , table_id : TableId , object_pool : & ObjectPool ) -> Option < String > {
704696 if let Some ( table) = object_pool. get_table ( table_id) {
705697 if let Some ( meta_value) = table. get_metatable ( ) {
706698 if let Some ( meta_id) = meta_value. as_table_id ( ) {
@@ -745,15 +737,19 @@ impl GC {
745737
746738 // First pass: collect keys to remove (immutable borrow)
747739 let keys_to_remove: Vec < LuaValue > = if let Some ( table) = object_pool. get_table ( table_id) {
748- table. iter_all ( )
740+ table
741+ . iter_all ( )
749742 . into_iter ( )
750743 . filter ( |( key, value) | {
751744 let mut should_remove = false ;
752-
745+
753746 // Check if weak key was collected
754747 if has_weak_keys {
755748 if let Some ( key_table_id) = key. as_table_id ( ) {
756- if !self . objects . contains_key ( & ( GcObjectType :: Table , key_table_id. 0 ) ) {
749+ if !self
750+ . objects
751+ . contains_key ( & ( GcObjectType :: Table , key_table_id. 0 ) )
752+ {
757753 should_remove = true ;
758754 }
759755 }
@@ -762,12 +758,15 @@ impl GC {
762758 // Check if weak value was collected
763759 if has_weak_values && !should_remove {
764760 if let Some ( val_table_id) = value. as_table_id ( ) {
765- if !self . objects . contains_key ( & ( GcObjectType :: Table , val_table_id. 0 ) ) {
761+ if !self
762+ . objects
763+ . contains_key ( & ( GcObjectType :: Table , val_table_id. 0 ) )
764+ {
766765 should_remove = true ;
767766 }
768767 }
769768 }
770-
769+
771770 should_remove
772771 } )
773772 . map ( |( key, _) | key)
0 commit comments