@@ -3847,7 +3847,7 @@ enum compile_array_type_t {
3847
3847
};
3848
3848
3849
3849
static inline int
3850
- static_literal_node_p (const NODE * node )
3850
+ static_literal_node_p (const NODE * node , const rb_iseq_t * iseq )
3851
3851
{
3852
3852
node = node -> nd_head ;
3853
3853
switch (nd_type (node )) {
@@ -3856,13 +3856,19 @@ static_literal_node_p(const NODE *node)
3856
3856
case NODE_TRUE :
3857
3857
case NODE_FALSE :
3858
3858
return TRUE;
3859
+ case NODE_STR :
3860
+ if (ISEQ_COMPILE_DATA (iseq )-> option -> frozen_string_literal ) {
3861
+ return TRUE;
3862
+ } else {
3863
+ return FALSE;
3864
+ }
3859
3865
default :
3860
3866
return FALSE;
3861
3867
}
3862
3868
}
3863
3869
3864
3870
static inline VALUE
3865
- static_literal_value (const NODE * node )
3871
+ static_literal_value (const NODE * node , rb_iseq_t * iseq )
3866
3872
{
3867
3873
node = node -> nd_head ;
3868
3874
switch (nd_type (node )) {
@@ -3872,6 +3878,17 @@ static_literal_value(const NODE *node)
3872
3878
return Qtrue ;
3873
3879
case NODE_FALSE :
3874
3880
return Qfalse ;
3881
+ case NODE_STR :
3882
+ if (ISEQ_COMPILE_DATA (iseq )-> option -> debug_frozen_string_literal || RTEST (ruby_debug )) {
3883
+ VALUE lit ;
3884
+ VALUE debug_info = rb_ary_new_from_args (2 , rb_iseq_path (iseq ), INT2FIX ((int )nd_line (node )));
3885
+ lit = rb_str_dup (node -> nd_lit );
3886
+ rb_ivar_set (lit , id_debug_created_info , rb_obj_freeze (debug_info ));
3887
+ return rb_str_freeze (lit );
3888
+ }
3889
+ else {
3890
+ return rb_fstring (node -> nd_lit );
3891
+ }
3875
3892
default :
3876
3893
return node -> nd_lit ;
3877
3894
}
@@ -3921,7 +3938,7 @@ compile_array(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const node_ro
3921
3938
}
3922
3939
break ;
3923
3940
}
3924
- if (opt_p && !static_literal_node_p (node )) {
3941
+ if (opt_p && !static_literal_node_p (node , iseq )) {
3925
3942
opt_p = 0 ;
3926
3943
}
3927
3944
@@ -3943,15 +3960,15 @@ compile_array(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const node_ro
3943
3960
node = start_node ;
3944
3961
3945
3962
while (node != end_node ) {
3946
- rb_ary_push (ary , static_literal_value (node ));
3963
+ rb_ary_push (ary , static_literal_value (node , iseq ));
3947
3964
node = node -> nd_next ;
3948
3965
}
3949
3966
while (node && node -> nd_next &&
3950
- static_literal_node_p (node ) &&
3951
- static_literal_node_p (node -> nd_next )) {
3967
+ static_literal_node_p (node , iseq ) &&
3968
+ static_literal_node_p (node -> nd_next , iseq )) {
3952
3969
VALUE elem [2 ];
3953
- elem [0 ] = static_literal_value (node );
3954
- elem [1 ] = static_literal_value (node -> nd_next );
3970
+ elem [0 ] = static_literal_value (node , iseq );
3971
+ elem [1 ] = static_literal_value (node -> nd_next , iseq );
3955
3972
rb_ary_cat (ary , elem , 2 );
3956
3973
node = node -> nd_next -> nd_next ;
3957
3974
len ++ ;
0 commit comments