Skip to content

Commit ea8d493

Browse files
authored
Explicitly use a ruby version for prism to parse the code as (ruby#14523)
Prism can parse multiple versions of ruby. Because of that branch release managers are ok with simply bumping prism to its latest version. However, if no version is specified, it will parse as the latest known version, which can be ahead of the maintenance branch. So we need to explicitly pass a version to not accidentally introduce new syntax to maintenance branches.
1 parent d3cb347 commit ea8d493

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

depend

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1415,6 +1415,7 @@ compile.$(OBJEXT): $(top_srcdir)/prism/util/pm_strncasecmp.h
14151415
compile.$(OBJEXT): $(top_srcdir)/prism/util/pm_strpbrk.h
14161416
compile.$(OBJEXT): $(top_srcdir)/prism/version.h
14171417
compile.$(OBJEXT): $(top_srcdir)/prism_compile.c
1418+
compile.$(OBJEXT): $(top_srcdir)/version.h
14181419
compile.$(OBJEXT): {$(VPATH)}assert.h
14191420
compile.$(OBJEXT): {$(VPATH)}atomic.h
14201421
compile.$(OBJEXT): {$(VPATH)}backward/2/assume.h
@@ -1605,6 +1606,7 @@ compile.$(OBJEXT): {$(VPATH)}prism_compile.h
16051606
compile.$(OBJEXT): {$(VPATH)}ractor.h
16061607
compile.$(OBJEXT): {$(VPATH)}re.h
16071608
compile.$(OBJEXT): {$(VPATH)}regex.h
1609+
compile.$(OBJEXT): {$(VPATH)}revision.h
16081610
compile.$(OBJEXT): {$(VPATH)}ruby_assert.h
16091611
compile.$(OBJEXT): {$(VPATH)}ruby_atomic.h
16101612
compile.$(OBJEXT): {$(VPATH)}rubyparser.h

prism_compile.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "prism.h"
2+
#include "version.h"
23

34
/**
45
* This compiler defines its own concept of the location of a node. We do this
@@ -11352,6 +11353,8 @@ pm_parse_file(pm_parse_result_t *result, VALUE filepath, VALUE *script_lines)
1135211353
pm_options_filepath_set(&result->options, RSTRING_PTR(filepath));
1135311354
RB_GC_GUARD(filepath);
1135411355

11356+
pm_options_version_for_current_ruby_set(&result->options);
11357+
1135511358
pm_parser_init(&result->parser, pm_string_source(&result->input), pm_string_length(&result->input), &result->options);
1135611359
pm_node_t *node = pm_parse(&result->parser);
1135711360

@@ -11410,6 +11413,8 @@ pm_parse_string(pm_parse_result_t *result, VALUE source, VALUE filepath, VALUE *
1141011413
pm_options_filepath_set(&result->options, RSTRING_PTR(filepath));
1141111414
RB_GC_GUARD(filepath);
1141211415

11416+
pm_options_version_for_current_ruby_set(&result->options);
11417+
1141311418
pm_parser_init(&result->parser, pm_string_source(&result->input), pm_string_length(&result->input), &result->options);
1141411419
pm_node_t *node = pm_parse(&result->parser);
1141511420

@@ -11492,6 +11497,13 @@ pm_parse_stdin(pm_parse_result_t *result)
1149211497
return pm_parse_process(result, node, NULL);
1149311498
}
1149411499

11500+
#define PM_VERSION_FOR_RELEASE(major, minor) PM_VERSION_FOR_RELEASE_IMPL(major, minor)
11501+
#define PM_VERSION_FOR_RELEASE_IMPL(major, minor) PM_OPTIONS_VERSION_CRUBY_##major##_##minor
11502+
11503+
void pm_options_version_for_current_ruby_set(pm_options_t *options) {
11504+
options->version = PM_VERSION_FOR_RELEASE(RUBY_VERSION_MAJOR, RUBY_VERSION_MINOR);
11505+
}
11506+
1149511507
#undef NEW_ISEQ
1149611508
#define NEW_ISEQ OLD_ISEQ
1149711509

prism_compile.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ VALUE pm_parse_file(pm_parse_result_t *result, VALUE filepath, VALUE *script_lin
9494
VALUE pm_load_parse_file(pm_parse_result_t *result, VALUE filepath, VALUE *script_lines);
9595
VALUE pm_parse_string(pm_parse_result_t *result, VALUE source, VALUE filepath, VALUE *script_lines);
9696
VALUE pm_parse_stdin(pm_parse_result_t *result);
97+
void pm_options_version_for_current_ruby_set(pm_options_t *options);
9798
void pm_parse_result_free(pm_parse_result_t *result);
9899

99100
rb_iseq_t *pm_iseq_new(pm_scope_node_t *node, VALUE name, VALUE path, VALUE realpath, const rb_iseq_t *parent, enum rb_iseq_type, int *error_state);

0 commit comments

Comments
 (0)