From 42d1cd8f7fa62b585283e566d4be9a390631c43d Mon Sep 17 00:00:00 2001 From: Kevin Newton Date: Tue, 26 Mar 2024 15:32:01 -0400 Subject: [PRISM] Pass --enable-frozen-string-literal through to evals --- iseq.c | 2 -- prism_compile.c | 46 ++++++++++++++++++++++++++++------------------ prism_compile.h | 1 - ruby.c | 2 -- spec/prism.mspec | 1 - vm_eval.c | 2 -- 6 files changed, 28 insertions(+), 26 deletions(-) diff --git a/iseq.c b/iseq.c index c2657f29d7..2d412dfcc9 100644 --- a/iseq.c +++ b/iseq.c @@ -1253,8 +1253,6 @@ pm_iseq_compile_with_option(VALUE src, VALUE file, VALUE realpath, VALUE line, V pm_parse_result_t result = { 0 }; pm_options_line_set(&result.options, NUM2INT(line)); - pm_options_frozen_string_literal_init(&result, option.frozen_string_literal); - VALUE error; if (RB_TYPE_P(src, T_FILE)) { VALUE filepath = rb_io_path(src); diff --git a/prism_compile.c b/prism_compile.c index a5b1219d6c..aec2f80f41 100644 --- a/prism_compile.c +++ b/prism_compile.c @@ -8479,6 +8479,30 @@ pm_parse_process(pm_parse_result_t *result, pm_node_t *node) return Qnil; } +/** + * Set the frozen_string_literal option based on the default value used by the + * CRuby compiler. + */ +static void +pm_options_frozen_string_literal_init(pm_options_t *options) +{ + int frozen_string_literal = rb_iseq_opt_frozen_string_literal(); + + switch (frozen_string_literal) { + case ISEQ_FROZEN_STRING_LITERAL_UNSET: + break; + case ISEQ_FROZEN_STRING_LITERAL_DISABLED: + pm_options_frozen_string_literal_set(options, false); + break; + case ISEQ_FROZEN_STRING_LITERAL_ENABLED: + pm_options_frozen_string_literal_set(options, true); + break; + default: + rb_bug("pm_options_frozen_string_literal_init: invalid frozen_string_literal=%d", frozen_string_literal); + break; + } +} + /** * Returns an array of ruby String objects that represent the lines of the * source file that the given parser parsed. @@ -8514,24 +8538,6 @@ pm_parse_file_script_lines(const pm_scope_node_t *scope_node, const pm_parser_t return lines; } -void -pm_options_frozen_string_literal_init(pm_parse_result_t *result, int frozen_string_literal) -{ - switch (frozen_string_literal) { - case ISEQ_FROZEN_STRING_LITERAL_UNSET: - break; - case ISEQ_FROZEN_STRING_LITERAL_DISABLED: - pm_options_frozen_string_literal_set(&result->options, false); - break; - case ISEQ_FROZEN_STRING_LITERAL_ENABLED: - pm_options_frozen_string_literal_set(&result->options, true); - break; - default: - rb_bug("pm_options_frozen_string_literal_init: invalid frozen_string_literal=%d", frozen_string_literal); - break; - } -} - /** * Attempt to load the file into memory. Return a Ruby error if the file cannot * be read. @@ -8551,6 +8557,7 @@ pm_load_file(pm_parse_result_t *result, VALUE filepath) return err; } + pm_options_frozen_string_literal_init(&result->options); return Qnil; } @@ -8616,6 +8623,7 @@ pm_parse_string(pm_parse_result_t *result, VALUE source, VALUE filepath) return rb_exc_new_cstr(rb_eArgError, "invalid source encoding"); } + pm_options_frozen_string_literal_init(&result->options); pm_string_constant_init(&result->input, RSTRING_PTR(source), RSTRING_LEN(source)); pm_options_encoding_set(&result->options, rb_enc_name(encoding)); @@ -8658,6 +8666,8 @@ pm_parse_stdin_fgets(char *string, int size, void *stream) VALUE pm_parse_stdin(pm_parse_result_t *result) { + pm_options_frozen_string_literal_init(&result->options); + pm_buffer_t buffer; pm_node_t *node = pm_parse_stream(&result->parser, &buffer, (void *) rb_stdin, pm_parse_stdin_fgets, &result->options); diff --git a/prism_compile.h b/prism_compile.h index 0c1510d67f..427fa54b51 100644 --- a/prism_compile.h +++ b/prism_compile.h @@ -47,7 +47,6 @@ typedef struct { bool parsed; } pm_parse_result_t; -void pm_options_frozen_string_literal_init(pm_parse_result_t *result, int frozen_string_literal); VALUE pm_load_file(pm_parse_result_t *result, VALUE filepath); VALUE pm_parse_file(pm_parse_result_t *result, VALUE filepath); VALUE pm_load_parse_file(pm_parse_result_t *result, VALUE filepath); diff --git a/ruby.c b/ruby.c index 5c1d44ec6d..59cbbd0360 100644 --- a/ruby.c +++ b/ruby.c @@ -2116,8 +2116,6 @@ prism_script(ruby_cmdline_options_t *opt, pm_parse_result_t *result) pm_options_t *options = &result->options; pm_options_line_set(options, 1); - pm_options_frozen_string_literal_init(result, rb_iseq_opt_frozen_string_literal()); - if (opt->ext.enc.name != 0) { pm_options_encoding_set(options, StringValueCStr(opt->ext.enc.name)); } diff --git a/spec/prism.mspec b/spec/prism.mspec index 490de9e348..bd427392e2 100644 --- a/spec/prism.mspec +++ b/spec/prism.mspec @@ -5,7 +5,6 @@ MSpec.register(:exclude, "The -S command line option runs launcher found in PATH MSpec.register(:exclude, "The -x command line option runs code after the first /#!.*ruby.*/-ish line in target file") MSpec.register(:exclude, "The -x command line option fails when /#!.*ruby.*/-ish line in target file is not found") MSpec.register(:exclude, "The -x command line option behaves as -x was set when non-ruby shebang is encountered on first line") -MSpec.register(:exclude, "The --enable-frozen-string-literal flag causes string literals to produce the same object for literals with the same content in different files") MSpec.register(:exclude, "The --debug flag produces debugging info on attempted frozen string modification") ## Language diff --git a/vm_eval.c b/vm_eval.c index 50c81f79d2..a859a76f24 100644 --- a/vm_eval.c +++ b/vm_eval.c @@ -1663,8 +1663,6 @@ pm_eval_make_iseq(VALUE src, VALUE fname, int line, pm_parse_result_t result = { 0 }; pm_options_line_set(&result.options, line); - pm_options_frozen_string_literal_init(&result, rb_iseq_opt_frozen_string_literal()); - // Cout scopes, one for each parent iseq, plus one for our local scope int scopes_count = 0; do { -- cgit v1.2.3