@@ -132,8 +132,11 @@ pub struct CodeInfo {
132132}
133133
134134impl CodeInfo {
135- pub fn finalize_code ( mut self , optimize : u8 ) -> crate :: InternalResult < CodeObject > {
136- if optimize > 0 {
135+ pub fn finalize_code (
136+ mut self ,
137+ opts : & crate :: compile:: CompileOpts ,
138+ ) -> crate :: InternalResult < CodeObject > {
139+ if opts. optimize > 0 {
137140 self . dce ( ) ;
138141 }
139142
@@ -219,7 +222,11 @@ impl CodeInfo {
219222 }
220223
221224 // Generate linetable from locations
222- let linetable = generate_linetable ( & locations, first_line_number. get ( ) as i32 ) ;
225+ let linetable = generate_linetable (
226+ & locations,
227+ first_line_number. get ( ) as i32 ,
228+ opts. debug_ranges ,
229+ ) ;
223230
224231 Ok ( CodeObject {
225232 flags,
@@ -417,6 +424,7 @@ fn iter_blocks(blocks: &[Block]) -> impl Iterator<Item = (BlockIdx, &Block)> + '
417424fn generate_linetable (
418425 locations : & [ ( SourceLocation , SourceLocation ) ] ,
419426 first_line : i32 ,
427+ debug_ranges : bool ,
420428) -> Box < [ u8 ] > {
421429 if locations. is_empty ( ) {
422430 return Box :: new ( [ ] ) ;
@@ -441,15 +449,31 @@ fn generate_linetable(
441449 while length > 0 {
442450 let entry_length = length. min ( 8 ) ;
443451
444- // Get line and column information
452+ // Get line information
445453 let line = loc. line . get ( ) as i32 ;
446- let col = loc. character_offset . to_zero_indexed ( ) as i32 ;
447454 let end_line = end_loc. line . get ( ) as i32 ;
448- let end_col = end_loc. character_offset . to_zero_indexed ( ) as i32 ;
449-
450455 let line_delta = line - prev_line;
451456 let end_line_delta = end_line - line;
452457
458+ // When debug_ranges is disabled, only emit line info (NoColumns format)
459+ if !debug_ranges {
460+ // NoColumns format (code 13): line info only, no column data
461+ linetable. push (
462+ 0x80 | ( ( PyCodeLocationInfoKind :: NoColumns as u8 ) << 3 )
463+ | ( ( entry_length - 1 ) as u8 ) ,
464+ ) ;
465+ write_signed_varint ( & mut linetable, line_delta) ;
466+
467+ prev_line = line;
468+ length -= entry_length;
469+ i += entry_length;
470+ continue ;
471+ }
472+
473+ // Get column information (only when debug_ranges is enabled)
474+ let col = loc. character_offset . to_zero_indexed ( ) as i32 ;
475+ let end_col = end_loc. character_offset . to_zero_indexed ( ) as i32 ;
476+
453477 // Choose the appropriate encoding based on line delta and column info
454478 if line_delta == 0 && end_line_delta == 0 {
455479 if col < 80 && end_col - col < 16 && end_col >= col {
0 commit comments