@@ -40,6 +40,12 @@ pub trait Constant: Sized {
4040 fn map_constant < Bag : ConstantBag > ( self , bag : & Bag ) -> Bag :: Constant {
4141 bag. make_constant ( self . into_data ( ) )
4242 }
43+ fn map_name < Bag : ConstantBag > (
44+ name : Self :: Name ,
45+ bag : & Bag ,
46+ ) -> <Bag :: Constant as Constant >:: Name {
47+ bag. make_name_ref ( name. as_ref ( ) )
48+ }
4349}
4450impl Constant for ConstantData {
4551 type Name = String ;
@@ -63,6 +69,9 @@ impl Constant for ConstantData {
6369 fn into_data ( self ) -> ConstantData {
6470 self
6571 }
72+ fn map_name < Bag : ConstantBag > ( name : String , bag : & Bag ) -> <Bag :: Constant as Constant >:: Name {
73+ bag. make_name ( name)
74+ }
6675}
6776
6877pub trait ConstantBag : Sized {
@@ -99,9 +108,9 @@ pub struct CodeObject<C: Constant = ConstantData> {
99108 pub posonlyarg_count : usize , // Number of positional-only arguments
100109 pub arg_count : usize ,
101110 pub kwonlyarg_count : usize ,
102- pub source_path : String ,
111+ pub source_path : C :: Name ,
103112 pub first_line_number : usize ,
104- pub obj_name : String , // Name of the object that created this code object
113+ pub obj_name : C :: Name , // Name of the object that created this code object
105114 pub cell2arg : Option < Box < [ isize ] > > ,
106115 pub constants : Box < [ C ] > ,
107116 #[ serde( bound(
@@ -549,9 +558,9 @@ impl<C: Constant> CodeObject<C> {
549558 posonlyarg_count : usize ,
550559 arg_count : usize ,
551560 kwonlyarg_count : usize ,
552- source_path : String ,
561+ source_path : C :: Name ,
553562 first_line_number : usize ,
554- obj_name : String ,
563+ obj_name : C :: Name ,
555564 ) -> Self {
556565 CodeObject {
557566 instructions : Box :: new ( [ ] ) ,
@@ -660,7 +669,7 @@ impl<C: Constant> CodeObject<C> {
660669 names
661670 . into_vec ( )
662671 . into_iter ( )
663- . map ( |x| bag . make_name_ref ( x . as_ref ( ) ) )
672+ . map ( |x| C :: map_name ( x , bag ) )
664673 . collect :: < Box < [ _ ] > > ( )
665674 } ;
666675 CodeObject {
@@ -674,16 +683,16 @@ impl<C: Constant> CodeObject<C> {
674683 varnames : map_names ( self . varnames ) ,
675684 cellvars : map_names ( self . cellvars ) ,
676685 freevars : map_names ( self . freevars ) ,
686+ source_path : C :: map_name ( self . source_path , bag) ,
687+ obj_name : C :: map_name ( self . obj_name , bag) ,
677688
678689 instructions : self . instructions ,
679690 locations : self . locations ,
680691 flags : self . flags ,
681692 posonlyarg_count : self . posonlyarg_count ,
682693 arg_count : self . arg_count ,
683694 kwonlyarg_count : self . kwonlyarg_count ,
684- source_path : self . source_path ,
685695 first_line_number : self . first_line_number ,
686- obj_name : self . obj_name ,
687696 cell2arg : self . cell2arg ,
688697 }
689698 }
@@ -705,16 +714,16 @@ impl<C: Constant> CodeObject<C> {
705714 varnames : map_names ( & self . varnames ) ,
706715 cellvars : map_names ( & self . cellvars ) ,
707716 freevars : map_names ( & self . freevars ) ,
717+ source_path : bag. make_name_ref ( self . source_path . as_ref ( ) ) ,
718+ obj_name : bag. make_name_ref ( self . obj_name . as_ref ( ) ) ,
708719
709720 instructions : self . instructions . clone ( ) ,
710721 locations : self . locations . clone ( ) ,
711722 flags : self . flags ,
712723 posonlyarg_count : self . posonlyarg_count ,
713724 arg_count : self . arg_count ,
714725 kwonlyarg_count : self . kwonlyarg_count ,
715- source_path : self . source_path . clone ( ) ,
716726 first_line_number : self . first_line_number ,
717- obj_name : self . obj_name . clone ( ) ,
718727 cell2arg : self . cell2arg . clone ( ) ,
719728 }
720729 }
@@ -955,7 +964,9 @@ impl<C: Constant> fmt::Debug for CodeObject<C> {
955964 write ! (
956965 f,
957966 "<code object {} at ??? file {:?}, line {}>" ,
958- self . obj_name, self . source_path, self . first_line_number
967+ self . obj_name. as_ref( ) ,
968+ self . source_path. as_ref( ) ,
969+ self . first_line_number
959970 )
960971 }
961972}
0 commit comments