Skip to content

Commit

Permalink
rename absolute_path to realpath internally and introduce pathobj.
Browse files Browse the repository at this point in the history
* vm_core.h: rename absolute_path to realpath because it is expected name.
  external APIs (#absolute_path methods) are remained.

* vm_core.h: remove rb_iseq_location_struct::path and
  rb_iseq_location_struct::absolute_path and introduce pathobj.
  if given path equals to given absolute_path (and most of case
  it is true), pathobj is simply given path String. If it is not same,
  pathobj is Array and pathobj[0] is path and pathobj[1] is realpath.

  This size optimization reduce 8 bytes and
  sizeof(struct rb_iseq_constant_body) is 200 bytes -> 192 bytes
  on 64bit CPU.

  To support this change, the following functions are introduced:
    * pathobj_path() (defined in vm_core.h)
    * pathobj_realpath() (ditto)
    * rb_iseq_path() (decl. in vm_core.h)
    * rb_iseq_realpath() (ditto)
    * rb_iseq_pathobj_new() (ditto)
    * rb_iseq_pathobj_set() (ditto)

* vm_core.h (rb_binding_t): use pathobj instead of path. If binding
  is given at eval methods, realpath (absolute_path) was caller's
  realpath. However, they should use binding's realpath.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58979 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
ko1 committed Jun 1, 2017
1 parent d0015e4 commit 478003f
Show file tree
Hide file tree
Showing 13 changed files with 165 additions and 117 deletions.
35 changes: 15 additions & 20 deletions compile.c
Expand Up @@ -175,9 +175,6 @@ struct iseq_compile_data_ensure_node_stack {
#define NEW_LABEL(l) new_label_body(iseq, (l))
#define LABEL_FORMAT "<L%03d>"

#define iseq_path(iseq) ((iseq)->body->location.path)
#define iseq_absolute_path(iseq) ((iseq)->body->location.absolute_path)

#define NEW_ISEQ(node, name, type, line_no) \
new_child_iseq(iseq, (node), rb_fstring(name), 0, (type), (line_no))

Expand Down Expand Up @@ -328,7 +325,7 @@ static void
append_compile_error(rb_iseq_t *iseq, int line, const char *fmt, ...)
{
VALUE err_info = ISEQ_COMPILE_DATA(iseq)->err_info;
VALUE file = iseq->body->location.path;
VALUE file = rb_iseq_path(iseq);
VALUE err = err_info == Qtrue ? Qfalse : err_info;
va_list args;

Expand All @@ -349,7 +346,7 @@ compile_bug(rb_iseq_t *iseq, int line, const char *fmt, ...)
{
va_list args;
va_start(args, fmt);
rb_report_bug_valist(iseq->body->location.path, line, fmt, args);
rb_report_bug_valist(rb_iseq_path(iseq), line, fmt, args);
va_end(args);
abort();
}
Expand Down Expand Up @@ -532,7 +529,7 @@ iseq_add_mark_object(const rb_iseq_t *iseq, VALUE v)
return COMPILE_OK;
}

#define ruby_sourcefile RSTRING_PTR(iseq->body->location.path)
#define ruby_sourcefile RSTRING_PTR(rb_iseq_path(iseq))

static int
iseq_add_mark_object_compile_time(const rb_iseq_t *iseq, VALUE v)
Expand Down Expand Up @@ -1116,7 +1113,7 @@ new_child_iseq(rb_iseq_t *iseq, NODE *node,

debugs("[new_child_iseq]> ---------------------------------------\n");
ret_iseq = rb_iseq_new_with_opt(node, name,
iseq_path(iseq), iseq_absolute_path(iseq),
rb_iseq_path(iseq), rb_iseq_realpath(iseq),
INT2FIX(line_no), parent, type, ISEQ_COMPILE_DATA(iseq)->option);
debugs("[new_child_iseq]< ---------------------------------------\n");
iseq_add_mark_object(iseq, (VALUE)ret_iseq);
Expand Down Expand Up @@ -5809,7 +5806,7 @@ iseq_compile_each0(rb_iseq_t *iseq, LINK_ANCHOR *const ret, NODE *node, int popp
}
else {
if (ISEQ_COMPILE_DATA(iseq)->option->debug_frozen_string_literal || RTEST(ruby_debug)) {
VALUE debug_info = rb_ary_new_from_args(2, iseq->body->location.path, INT2FIX(line));
VALUE debug_info = rb_ary_new_from_args(2, rb_iseq_path(iseq), INT2FIX(line));
VALUE str = rb_str_dup(node->nd_lit);
rb_ivar_set(str, id_debug_created_info, rb_obj_freeze(debug_info));
ADD_INSN1(ret, line, putobject, rb_obj_freeze(str));
Expand All @@ -5832,7 +5829,7 @@ iseq_compile_each0(rb_iseq_t *iseq, LINK_ANCHOR *const ret, NODE *node, int popp
if (ISEQ_COMPILE_DATA(iseq)->option->frozen_string_literal) {
VALUE debug_info = Qnil;
if (ISEQ_COMPILE_DATA(iseq)->option->debug_frozen_string_literal || RTEST(ruby_debug)) {
debug_info = rb_ary_new_from_args(2, iseq->body->location.path, INT2FIX(line));
debug_info = rb_ary_new_from_args(2, rb_iseq_path(iseq), INT2FIX(line));
iseq_add_mark_object_compile_time(iseq, rb_obj_freeze(debug_info));
}
ADD_INSN1(ret, line, freezestring, debug_info);
Expand Down Expand Up @@ -7148,21 +7145,21 @@ rb_local_defined(ID id, const struct rb_block *base_block)
}

static int
caller_location(VALUE *path, VALUE *absolute_path)
caller_location(VALUE *path, VALUE *realpath)
{
const rb_thread_t *const th = GET_THREAD();
const rb_control_frame_t *const cfp =
rb_vm_get_ruby_level_next_cfp(th, th->ec.cfp);

if (cfp) {
int line = rb_vm_get_sourceline(cfp);
*path = cfp->iseq->body->location.path;
*absolute_path = cfp->iseq->body->location.absolute_path;
*path = rb_iseq_path(cfp->iseq);
*realpath = rb_iseq_realpath(cfp->iseq);
return line;
}
else {
*path = rb_fstring_cstr("<compiled>");
*absolute_path = *path;
*realpath = *path;
return 1;
}
}
Expand All @@ -7177,14 +7174,14 @@ static const rb_iseq_t *
method_for_self(VALUE name, VALUE arg, rb_insn_func_t func,
VALUE (*build)(rb_iseq_t *, LINK_ANCHOR *const, VALUE))
{
VALUE path, absolute_path;
VALUE path, realpath;
accessor_args acc;

acc.arg = arg;
acc.func = func;
acc.line = caller_location(&path, &absolute_path);
acc.line = caller_location(&path, &realpath);
return rb_iseq_new_with_opt((NODE *)IFUNC_NEW(build, (VALUE)&acc, 0),
rb_sym2str(name), path, absolute_path,
rb_sym2str(name), path, realpath,
INT2FIX(acc.line), 0, ISEQ_TYPE_METHOD, 0);
}

Expand Down Expand Up @@ -7797,8 +7794,7 @@ ibf_dump_iseq_each(struct ibf_dump *dump, const rb_iseq_t *iseq)
struct rb_iseq_constant_body dump_body;
dump_body = *iseq->body;

dump_body.location.path = ibf_dump_object(dump, dump_body.location.path);
dump_body.location.absolute_path = ibf_dump_object(dump, dump_body.location.absolute_path);
dump_body.location.pathobj = ibf_dump_object(dump, dump_body.location.pathobj); /* TODO: freeze */
dump_body.location.base_label = ibf_dump_object(dump, dump_body.location.base_label);
dump_body.location.label = ibf_dump_object(dump, dump_body.location.label);

Expand Down Expand Up @@ -7847,8 +7843,7 @@ ibf_load_iseq_each(const struct ibf_load *load, rb_iseq_t *iseq, ibf_offset_t of

RB_OBJ_WRITE(iseq, &load_body->mark_ary, iseq_mark_ary_create((int)body->mark_ary));

RB_OBJ_WRITE(iseq, &load_body->location.path, ibf_load_location_str(load, body->location.path));
RB_OBJ_WRITE(iseq, &load_body->location.absolute_path, ibf_load_location_str(load, body->location.absolute_path));
RB_OBJ_WRITE(iseq, &load_body->location.pathobj, ibf_load_location_str(load, body->location.pathobj));
RB_OBJ_WRITE(iseq, &load_body->location.base_label, ibf_load_location_str(load, body->location.base_label));
RB_OBJ_WRITE(iseq, &load_body->location.label, ibf_load_location_str(load, body->location.label));
load_body->location.first_lineno = body->location.first_lineno;
Expand Down
5 changes: 5 additions & 0 deletions debug_counter.h
Expand Up @@ -61,6 +61,11 @@ RB_DEBUG_COUNTER(obj_ary_embed)

RB_DEBUG_COUNTER(obj_obj_ptr)
RB_DEBUG_COUNTER(obj_obj_embed)

/* load */
RB_DEBUG_COUNTER(load_files)
RB_DEBUG_COUNTER(load_path_is_not_realpath)

#endif

#ifndef RUBY_DEBUG_COUNTER_H
Expand Down
2 changes: 1 addition & 1 deletion gc.c
Expand Up @@ -9210,7 +9210,7 @@ rb_raw_iseq_info(char *buff, const int buff_size, const rb_iseq_t *iseq)
if (iseq->body->location.label) {
snprintf(buff, buff_size, "%s %s@%s:%d", buff,
RSTRING_PTR(iseq->body->location.label),
RSTRING_PTR(iseq->body->location.path),
RSTRING_PTR(rb_iseq_path(iseq)),
FIX2INT(iseq->body->location.first_lineno));
}
}
Expand Down

0 comments on commit 478003f

Please sign in to comment.