@@ -67,7 +67,7 @@ fn annotate_c_method(props_map: &mut HashMap<*mut c_void, FnProperties>, class:
6767}
6868
6969/// Look up a method and find its builtin function pointer by parsing its ISEQ
70- fn annotate_builtin_method ( props_map : & mut HashMap < * mut c_void , FnProperties > , class : VALUE , method_name : & ' static str , props : FnProperties ) {
70+ fn annotate_builtin_method ( props_map : & mut HashMap < * mut c_void , FnProperties > , class : VALUE , method_name : & ' static str , mut props : FnProperties ) {
7171 unsafe {
7272 let method_id = rb_intern2 ( method_name. as_ptr ( ) . cast ( ) , method_name. len ( ) . try_into ( ) . unwrap ( ) ) ;
7373 let method = rb_method_entry_at ( class, method_id) ;
@@ -93,6 +93,15 @@ fn annotate_builtin_method(props_map: &mut HashMap<*mut c_void, FnProperties>, c
9393 method_name) ;
9494 }
9595
96+ // Check if the ISEQ has the BUILTIN_ATTR_LEAF attribute
97+ let builtin_attrs = rb_zjit_get_iseq_body_builtin_attrs ( iseq) ;
98+ if ( builtin_attrs & BUILTIN_ATTR_LEAF ) != 0 {
99+ // If the method is marked as leaf via Primitive.attr!, set leaf to true
100+ props. leaf = true ;
101+ // Leaf methods don't trigger GC
102+ props. no_gc = true ;
103+ }
104+
96105 // Get the size of the ISEQ in instruction units
97106 let encoded_size = rb_iseq_encoded_size ( iseq) ;
98107
@@ -163,6 +172,7 @@ pub fn init() -> Annotations {
163172 annotate ! ( rb_mKernel, "nil?" , types:: FalseClass , no_gc, leaf, elidable) ;
164173
165174 // Annotate builtin functions using the new method-based approach
175+ // The leaf property will be automatically detected from Primitive.attr! :leaf in the Ruby code
166176 annotate_builtin ! ( rb_mKernel, "Float" , types:: Flonum ) ;
167177 annotate_builtin ! ( rb_mKernel, "Integer" , types:: Integer ) ;
168178 annotate_builtin ! ( rb_mKernel, "class" , types:: Class ) ;
0 commit comments