Skip to content

Commit

Permalink
Revert "allow enabling Prism via flag or env var"
Browse files Browse the repository at this point in the history
This reverts commit 9b76c7f.
  • Loading branch information
HParker authored and mame committed Dec 6, 2023
1 parent c146da5 commit b8b319d
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 550 deletions.
414 changes: 0 additions & 414 deletions common.mk

Large diffs are not rendered by default.

17 changes: 0 additions & 17 deletions iseq.c
Expand Up @@ -1487,23 +1487,6 @@ iseqw_s_compile_file_prism(int argc, VALUE *argv, VALUE self)
return iseqw_new(iseq);
}

rb_iseq_t *
rb_iseq_new_main_prism(pm_string_t *input, pm_options_t *options, VALUE path)
{
pm_parser_t parser;
pm_parser_init(&parser, pm_string_source(input), pm_string_length(input), options);

if (NIL_P(path)) path = rb_fstring_lit("<compiled>");
int start_line = 0;
pm_options_line_set(options, start_line);

rb_iseq_t *iseq = iseq_alloc();
iseqw_s_compile_prism_compile(&parser, Qnil, iseq, path, path, start_line);

pm_parser_free(&parser);
return iseq;
}

/*
* call-seq:
* InstructionSequence.compile_file(file[, options]) -> iseq
Expand Down
2 changes: 0 additions & 2 deletions iseq.h
Expand Up @@ -13,7 +13,6 @@
#include "internal/gc.h"
#include "shape.h"
#include "vm_core.h"
#include "prism/prism.h"

RUBY_EXTERN const int ruby_api_version[];
#define ISEQ_MAJOR_VERSION ((unsigned int)ruby_api_version[0])
Expand Down Expand Up @@ -174,7 +173,6 @@ void rb_iseq_init_trace(rb_iseq_t *iseq);
int rb_iseq_add_local_tracepoint_recursively(const rb_iseq_t *iseq, rb_event_flag_t turnon_events, VALUE tpval, unsigned int target_line, bool target_bmethod);
int rb_iseq_remove_local_tracepoint_recursively(const rb_iseq_t *iseq, VALUE tpval);
const rb_iseq_t *rb_iseq_load_iseq(VALUE fname);
rb_iseq_t * rb_iseq_new_main_prism(pm_string_t *input, pm_options_t *options, VALUE path);

#if VM_INSN_INFO_TABLE_IMPL == 2
unsigned int *rb_iseq_insns_info_decode_positions(const struct rb_iseq_constant_body *body);
Expand Down
49 changes: 16 additions & 33 deletions load.c
Expand Up @@ -16,7 +16,6 @@
#include "probes.h"
#include "darray.h"
#include "ruby/encoding.h"
#include "prism/prism.h"
#include "ruby/util.h"

static VALUE ruby_dln_librefs;
Expand Down Expand Up @@ -718,39 +717,23 @@ static inline void
load_iseq_eval(rb_execution_context_t *ec, VALUE fname)
{
const rb_iseq_t *iseq = rb_iseq_load_iseq(fname);
if (!iseq) {
if (*rb_ruby_prism_ptr()) {
pm_string_t input;
pm_options_t options = { 0 };

pm_string_mapped_init(&input, RSTRING_PTR(fname));
pm_options_filepath_set(&options, RSTRING_PTR(fname));

pm_parser_t parser;
pm_parser_init(&parser, pm_string_source(&input), pm_string_length(&input), &options);

iseq = rb_iseq_new_main_prism(&input, &options, fname);

pm_string_free(&input);
pm_options_free(&options);
}
else {
rb_execution_context_t *ec = GET_EC();
VALUE v = rb_vm_push_frame_fname(ec, fname);
rb_ast_t *ast;
VALUE parser = rb_parser_new();
rb_parser_set_context(parser, NULL, FALSE);
ast = (rb_ast_t *)rb_parser_load_file(parser, fname);

rb_thread_t *th = rb_ec_thread_ptr(ec);
VALUE realpath_map = get_loaded_features_realpath_map(th->vm);

iseq = rb_iseq_new_top(&ast->body, rb_fstring_lit("<top (required)>"),
fname, realpath_internal_cached(realpath_map, fname), NULL);
rb_ast_dispose(ast);
rb_vm_pop_frame(ec);
RB_GC_GUARD(v);
}
if (!iseq) {
rb_execution_context_t *ec = GET_EC();
VALUE v = rb_vm_push_frame_fname(ec, fname);
rb_ast_t *ast;
VALUE parser = rb_parser_new();
rb_parser_set_context(parser, NULL, FALSE);
ast = (rb_ast_t *)rb_parser_load_file(parser, fname);

rb_thread_t *th = rb_ec_thread_ptr(ec);
VALUE realpath_map = get_loaded_features_realpath_map(th->vm);

iseq = rb_iseq_new_top(&ast->body, rb_fstring_lit("<top (required)>"),
fname, realpath_internal_cached(realpath_map, fname), NULL);
rb_ast_dispose(ast);
rb_vm_pop_frame(ec);
RB_GC_GUARD(v);
}
rb_exec_event_hook_script_compiled(ec, iseq, Qnil);
rb_iseq_eval(iseq);
Expand Down
11 changes: 0 additions & 11 deletions prism/prism.h
Expand Up @@ -42,17 +42,6 @@
*/
PRISM_EXPORTED_FUNCTION const char * pm_version(void);


/**
* @private
*
* This is used to decide of the prism parser should be used.
*
* @retval true Use Prism to parse files
* @retval false Use standard parser
*/
bool *rb_ruby_prism_ptr(void);

/**
* Initialize a parser with the given start and end pointers.
*
Expand Down
1 change: 0 additions & 1 deletion ractor_core.h
Expand Up @@ -186,7 +186,6 @@ struct rb_ractor_struct {
VALUE r_stderr;
VALUE verbose;
VALUE debug;
bool prism;

rb_ractor_newobj_cache_t newobj_cache;

Expand Down
101 changes: 36 additions & 65 deletions ruby.c
Expand Up @@ -362,7 +362,6 @@ usage(const char *name, int help, int highlight, int columns)
"enable or disable features. see below for available features"),
M("--external-encoding=encoding", ", --internal-encoding=encoding",
"specify the default external or internal character encoding"),
M("--prism", "", "parse and compile using prism"),
M("--backtrace-limit=num", "", "limit the maximum length of backtrace"),
M("--verbose", "", "turn on verbose mode and disable script from stdin"),
M("--version", "", "print the version number, then exit"),
Expand Down Expand Up @@ -1421,9 +1420,6 @@ proc_long_options(ruby_cmdline_options_t *opt, const char *s, long argc, char **
opt->verbose = 1;
ruby_verbose = Qtrue;
}
else if (strcmp("prism", s) == 0) {
(*rb_ruby_prism_ptr()) = true;
}
else if (strcmp("jit", s) == 0) {
#if !USE_RJIT
rb_warn("Ruby was built without JIT support");
Expand Down Expand Up @@ -1757,9 +1753,6 @@ ruby_opt_init(ruby_cmdline_options_t *opt)
rb_warn_deprecated("The environment variable RUBY_GC_HEAP_INIT_SLOTS",
"environment variables RUBY_GC_HEAP_%d_INIT_SLOTS");
}
if (getenv("RUBY_PRISM")) {
(*rb_ruby_prism_ptr()) = true;
}

#if USE_RJIT
// rb_call_builtin_inits depends on RubyVM::RJIT.enabled?
Expand Down Expand Up @@ -1978,7 +1971,7 @@ process_options(int argc, char **argv, ruby_cmdline_options_t *opt)
rb_ast_t *ast = 0;
VALUE parser;
VALUE script_name;
rb_iseq_t *iseq;
const rb_iseq_t *iseq;
rb_encoding *enc, *lenc;
#if UTF8_PATH
rb_encoding *ienc = 0;
Expand Down Expand Up @@ -2246,41 +2239,39 @@ process_options(int argc, char **argv, ruby_cmdline_options_t *opt)
ruby_set_argv(argc, argv);
opt->sflag = process_sflag(opt->sflag);

if (!(*rb_ruby_prism_ptr())) {
if (opt->e_script) {
VALUE progname = rb_progname;
rb_encoding *eenc;
rb_parser_set_context(parser, 0, TRUE);
if (opt->e_script) {
VALUE progname = rb_progname;
rb_encoding *eenc;
rb_parser_set_context(parser, 0, TRUE);

if (opt->src.enc.index >= 0) {
eenc = rb_enc_from_index(opt->src.enc.index);
}
else {
eenc = lenc;
#if UTF8_PATH
if (ienc) eenc = ienc;
#endif
}
if (opt->src.enc.index >= 0) {
eenc = rb_enc_from_index(opt->src.enc.index);
}
else {
eenc = lenc;
#if UTF8_PATH
if (eenc != uenc) {
opt->e_script = str_conv_enc(opt->e_script, uenc, eenc);
}
if (ienc) eenc = ienc;
#endif
rb_enc_associate(opt->e_script, eenc);
ruby_opt_init(opt);
ruby_set_script_name(progname);
rb_parser_set_options(parser, opt->do_print, opt->do_loop,
opt->do_line, opt->do_split);
ast = rb_parser_compile_string(parser, opt->script, opt->e_script, 1);
}
else {
VALUE f;
int xflag = opt->xflag;
f = open_load_file(script_name, &xflag);
opt->xflag = xflag != 0;
rb_parser_set_context(parser, 0, f == rb_stdin);
ast = load_file(parser, opt->script_name, f, 1, opt);
#if UTF8_PATH
if (eenc != uenc) {
opt->e_script = str_conv_enc(opt->e_script, uenc, eenc);
}
#endif
rb_enc_associate(opt->e_script, eenc);
ruby_opt_init(opt);
ruby_set_script_name(progname);
rb_parser_set_options(parser, opt->do_print, opt->do_loop,
opt->do_line, opt->do_split);
ast = rb_parser_compile_string(parser, opt->script, opt->e_script, 1);
}
else {
VALUE f;
int xflag = opt->xflag;
f = open_load_file(script_name, &xflag);
opt->xflag = xflag != 0;
rb_parser_set_context(parser, 0, f == rb_stdin);
ast = load_file(parser, opt->script_name, f, 1, opt);
}
ruby_set_script_name(opt->script_name);
if (dump & DUMP_BIT(yydebug)) {
Expand All @@ -2305,7 +2296,7 @@ process_options(int argc, char **argv, ruby_cmdline_options_t *opt)
rb_enc_set_default_internal(Qnil);
rb_stdio_set_default_encoding();

if (!(*rb_ruby_prism_ptr()) && !ast->body.root) {
if (!ast->body.root) {
rb_ast_dispose(ast);
return Qfalse;
}
Expand Down Expand Up @@ -2381,32 +2372,13 @@ process_options(int argc, char **argv, ruby_cmdline_options_t *opt)
}
}

if ((*rb_ruby_prism_ptr())) {
pm_string_t input;
pm_options_t options = { 0 };

if (opt->e_script) {
pm_string_constant_init(&input, RSTRING_PTR(opt->e_script), RSTRING_LEN(opt->e_script));
pm_options_filepath_set(&options, "-e");
}
else {
pm_string_mapped_init(&input, RSTRING_PTR(opt->script_name));
pm_options_filepath_set(&options, RSTRING_PTR(opt->script_name));
}

iseq = rb_iseq_new_main_prism(&input, &options, path);

pm_string_free(&input);
pm_options_free(&options);
}
else {
rb_binding_t *toplevel_binding;
GetBindingPtr(rb_const_get(rb_cObject, rb_intern("TOPLEVEL_BINDING")),
toplevel_binding);
const struct rb_block *base_block = toplevel_context(toplevel_binding);
iseq = rb_iseq_new_main(&ast->body, opt->script_name, path, vm_block_iseq(base_block), !(dump & DUMP_BIT(insns_without_opt)));
rb_ast_dispose(ast);
}
rb_binding_t *toplevel_binding;
GetBindingPtr(rb_const_get(rb_cObject, rb_intern("TOPLEVEL_BINDING")),
toplevel_binding);
const struct rb_block *base_block = toplevel_context(toplevel_binding);
iseq = rb_iseq_new_main(&ast->body, opt->script_name, path, vm_block_iseq(base_block), !(dump & DUMP_BIT(insns_without_opt)));
rb_ast_dispose(ast);
}

if (dump & (DUMP_BIT(insns) | DUMP_BIT(insns_without_opt))) {
Expand Down Expand Up @@ -2962,7 +2934,6 @@ ruby_process_options(int argc, char **argv)
ruby_cmdline_options_t opt;
VALUE iseq;
const char *script_name = (argc > 0 && argv[0]) ? argv[0] : ruby_engine;
(*rb_ruby_prism_ptr()) = false;

if (!origarg.argv || origarg.argc <= 0) {
origarg.argc = argc;
Expand Down
7 changes: 0 additions & 7 deletions vm.c
Expand Up @@ -4192,13 +4192,6 @@ rb_ruby_verbose_ptr(void)
return &cr->verbose;
}

bool *
rb_ruby_prism_ptr(void)
{
rb_ractor_t *cr = GET_RACTOR();
return &cr->prism;
}

VALUE *
rb_ruby_debug_ptr(void)
{
Expand Down

0 comments on commit b8b319d

Please sign in to comment.