Skip to content

Commit c63d6be

Browse files
Earlopaink0kubun
authored andcommitted
Explicitly use a ruby version for prism to parse the code as
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 52b3f00 commit c63d6be

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

common.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3425,6 +3425,7 @@ compile.$(OBJEXT): $(top_srcdir)/prism/util/pm_string.h
34253425
compile.$(OBJEXT): $(top_srcdir)/prism/util/pm_strncasecmp.h
34263426
compile.$(OBJEXT): $(top_srcdir)/prism/util/pm_strpbrk.h
34273427
compile.$(OBJEXT): $(top_srcdir)/prism_compile.c
3428+
compile.$(OBJEXT): $(top_srcdir)/version.h
34283429
compile.$(OBJEXT): {$(VPATH)}assert.h
34293430
compile.$(OBJEXT): {$(VPATH)}atomic.h
34303431
compile.$(OBJEXT): {$(VPATH)}backward/2/assume.h
@@ -3618,6 +3619,7 @@ compile.$(OBJEXT): {$(VPATH)}prism_compile.h
36183619
compile.$(OBJEXT): {$(VPATH)}ractor.h
36193620
compile.$(OBJEXT): {$(VPATH)}re.h
36203621
compile.$(OBJEXT): {$(VPATH)}regex.h
3622+
compile.$(OBJEXT): {$(VPATH)}revision.h
36213623
compile.$(OBJEXT): {$(VPATH)}ruby_assert.h
36223624
compile.$(OBJEXT): {$(VPATH)}ruby_atomic.h
36233625
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
@@ -11351,6 +11352,8 @@ pm_parse_file(pm_parse_result_t *result, VALUE filepath, VALUE *script_lines)
1135111352
pm_options_filepath_set(&result->options, RSTRING_PTR(filepath));
1135211353
RB_GC_GUARD(filepath);
1135311354

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

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

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

@@ -11491,6 +11496,13 @@ pm_parse_stdin(pm_parse_result_t *result)
1149111496
return pm_parse_process(result, node, NULL);
1149211497
}
1149311498

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

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)