Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ast.c
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,10 @@ node_locations(VALUE ast_value, const NODE *node)
location_new(nd_code_loc(node)),
location_new(&RNODE_COLON3(node)->delimiter_loc),
location_new(&RNODE_COLON3(node)->name_loc));
case NODE_DEFINED:
return rb_ary_new_from_args(2,
location_new(nd_code_loc(node)),
location_new(&RNODE_DEFINED(node)->keyword_loc));
case NODE_DOT2:
return rb_ary_new_from_args(2,
location_new(nd_code_loc(node)),
Expand Down
1 change: 0 additions & 1 deletion debug_counter.h
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,6 @@ RB_DEBUG_COUNTER(obj_imemo_svar)
RB_DEBUG_COUNTER(obj_imemo_throw_data)
RB_DEBUG_COUNTER(obj_imemo_ifunc)
RB_DEBUG_COUNTER(obj_imemo_memo)
RB_DEBUG_COUNTER(obj_imemo_parser_strterm)
RB_DEBUG_COUNTER(obj_imemo_callinfo)
RB_DEBUG_COUNTER(obj_imemo_callcache)
RB_DEBUG_COUNTER(obj_imemo_constcache)
Expand Down
1 change: 0 additions & 1 deletion ext/objspace/objspace.c
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,6 @@ count_imemo_objects(int argc, VALUE *argv, VALUE self)
INIT_IMEMO_TYPE_ID(imemo_iseq);
INIT_IMEMO_TYPE_ID(imemo_tmpbuf);
INIT_IMEMO_TYPE_ID(imemo_ast);
INIT_IMEMO_TYPE_ID(imemo_parser_strterm);
INIT_IMEMO_TYPE_ID(imemo_callinfo);
INIT_IMEMO_TYPE_ID(imemo_callcache);
INIT_IMEMO_TYPE_ID(imemo_constcache);
Expand Down
9 changes: 0 additions & 9 deletions imemo.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ rb_imemo_name(enum imemo_type type)
IMEMO_NAME(iseq);
IMEMO_NAME(memo);
IMEMO_NAME(ment);
IMEMO_NAME(parser_strterm);
IMEMO_NAME(svar);
IMEMO_NAME(throw_data);
IMEMO_NAME(tmpbuf);
Expand Down Expand Up @@ -248,8 +247,6 @@ rb_imemo_memsize(VALUE obj)
case imemo_ment:
size += sizeof(((rb_method_entry_t *)obj)->def);

break;
case imemo_parser_strterm:
break;
case imemo_svar:
break;
Expand Down Expand Up @@ -460,8 +457,6 @@ rb_imemo_mark_and_move(VALUE obj, bool reference_updating)
case imemo_ment:
mark_and_move_method_entry((rb_method_entry_t *)obj, reference_updating);
break;
case imemo_parser_strterm:
break;
case imemo_svar: {
struct vm_svar *svar = (struct vm_svar *)obj;

Expand Down Expand Up @@ -657,10 +652,6 @@ rb_imemo_free(VALUE obj)
rb_free_method_entry((rb_method_entry_t *)obj);
RB_DEBUG_COUNTER_INC(obj_imemo_ment);

break;
case imemo_parser_strterm:
RB_DEBUG_COUNTER_INC(obj_imemo_parser_strterm);

break;
case imemo_svar:
RB_DEBUG_COUNTER_INC(obj_imemo_svar);
Expand Down
9 changes: 4 additions & 5 deletions internal/imemo.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,10 @@ enum imemo_type {
imemo_iseq = 7,
imemo_tmpbuf = 8,
imemo_ast = 9, // Obsolete due to the universal parser
imemo_parser_strterm = 10,
imemo_callinfo = 11,
imemo_callcache = 12,
imemo_constcache = 13,
imemo_fields = 14,
imemo_callinfo = 10,
imemo_callcache = 11,
imemo_constcache = 12,
imemo_fields = 13,
};

/* CREF (Class REFerence) is defined in method.h */
Expand Down
3 changes: 2 additions & 1 deletion node_dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -1105,8 +1105,9 @@ dump_node(VALUE buf, VALUE indent, int comment, const NODE * node)
ANN("defined? expression");
ANN("format: defined?([nd_head])");
ANN("example: defined?(foo)");
LAST_NODE;
F_NODE(nd_head, RNODE_DEFINED, "expr");
LAST_NODE;
F_LOC(keyword_loc, RNODE_DEFINED);
return;

case NODE_POSTEXE:
Expand Down
19 changes: 10 additions & 9 deletions parse.y
Original file line number Diff line number Diff line change
Expand Up @@ -1156,7 +1156,7 @@ static rb_node_nil_t *rb_node_nil_new(struct parser_params *p, const YYLTYPE *lo
static rb_node_true_t *rb_node_true_new(struct parser_params *p, const YYLTYPE *loc);
static rb_node_false_t *rb_node_false_new(struct parser_params *p, const YYLTYPE *loc);
static rb_node_errinfo_t *rb_node_errinfo_new(struct parser_params *p, const YYLTYPE *loc);
static rb_node_defined_t *rb_node_defined_new(struct parser_params *p, NODE *nd_head, const YYLTYPE *loc);
static rb_node_defined_t *rb_node_defined_new(struct parser_params *p, NODE *nd_head, const YYLTYPE *loc, const YYLTYPE *keyword_loc);
static rb_node_postexe_t *rb_node_postexe_new(struct parser_params *p, NODE *nd_body, const YYLTYPE *loc, const YYLTYPE *keyword_loc, const YYLTYPE *opening_loc, const YYLTYPE *closing_loc);
static rb_node_sym_t *rb_node_sym_new(struct parser_params *p, VALUE str, const YYLTYPE *loc);
static rb_node_dsym_t *rb_node_dsym_new(struct parser_params *p, rb_parser_string_t *string, long nd_alen, NODE *nd_next, const YYLTYPE *loc);
Expand Down Expand Up @@ -1264,7 +1264,7 @@ static rb_node_error_t *rb_node_error_new(struct parser_params *p, const YYLTYPE
#define NEW_TRUE(loc) (NODE *)rb_node_true_new(p,loc)
#define NEW_FALSE(loc) (NODE *)rb_node_false_new(p,loc)
#define NEW_ERRINFO(loc) (NODE *)rb_node_errinfo_new(p,loc)
#define NEW_DEFINED(e,loc) (NODE *)rb_node_defined_new(p,e,loc)
#define NEW_DEFINED(e,loc,k_loc) (NODE *)rb_node_defined_new(p,e,loc, k_loc)
#define NEW_POSTEXE(b,loc,k_loc,o_loc,c_loc) (NODE *)rb_node_postexe_new(p,b,loc,k_loc,o_loc,c_loc)
#define NEW_SYM(str,loc) (NODE *)rb_node_sym_new(p,str,loc)
#define NEW_DSYM(s,l,n,loc) (NODE *)rb_node_dsym_new(p,s,l,n,loc)
Expand Down Expand Up @@ -1470,7 +1470,7 @@ static rb_node_kw_arg_t *kwd_append(rb_node_kw_arg_t*, rb_node_kw_arg_t*);
static NODE *new_hash(struct parser_params *p, NODE *hash, const YYLTYPE *loc);
static NODE *new_unique_key_hash(struct parser_params *p, NODE *hash, const YYLTYPE *loc);

static NODE *new_defined(struct parser_params *p, NODE *expr, const YYLTYPE *loc);
static NODE *new_defined(struct parser_params *p, NODE *expr, const YYLTYPE *loc, const YYLTYPE *keyword_loc);

static NODE *new_regexp(struct parser_params *, NODE *, int, const YYLTYPE *, const YYLTYPE *, const YYLTYPE *, const YYLTYPE *);

Expand Down Expand Up @@ -4041,7 +4041,7 @@ arg : asgn(arg_rhs)
| keyword_defined '\n'? begin_defined arg
{
p->ctxt.in_defined = $3.in_defined;
$$ = new_defined(p, $4, &@$);
$$ = new_defined(p, $4, &@$, &@1);
p->ctxt.has_trailing_semicolon = $3.has_trailing_semicolon;
/*% ripper: defined!($:4) %*/
}
Expand Down Expand Up @@ -4429,7 +4429,7 @@ primary : inline_primary
| keyword_defined '\n'? '(' begin_defined expr rparen
{
p->ctxt.in_defined = $4.in_defined;
$$ = new_defined(p, $5, &@$);
$$ = new_defined(p, $5, &@$, &@1);
p->ctxt.has_trailing_semicolon = $4.has_trailing_semicolon;
/*% ripper: defined!($:5) %*/
}
Expand Down Expand Up @@ -12240,10 +12240,11 @@ rb_node_errinfo_new(struct parser_params *p, const YYLTYPE *loc)
}

static rb_node_defined_t *
rb_node_defined_new(struct parser_params *p, NODE *nd_head, const YYLTYPE *loc)
rb_node_defined_new(struct parser_params *p, NODE *nd_head, const YYLTYPE *loc, const YYLTYPE *keyword_loc)
{
rb_node_defined_t *n = NODE_NEWNODE(NODE_DEFINED, rb_node_defined_t, loc);
n->nd_head = nd_head;
n->keyword_loc = *keyword_loc;

return n;
}
Expand Down Expand Up @@ -13021,7 +13022,7 @@ kwd_append(rb_node_kw_arg_t *kwlist, rb_node_kw_arg_t *kw)
}

static NODE *
new_defined(struct parser_params *p, NODE *expr, const YYLTYPE *loc)
new_defined(struct parser_params *p, NODE *expr, const YYLTYPE *loc, const YYLTYPE *keyword_loc)
{
int had_trailing_semicolon = p->ctxt.has_trailing_semicolon;
p->ctxt.has_trailing_semicolon = 0;
Expand All @@ -13041,10 +13042,10 @@ new_defined(struct parser_params *p, NODE *expr, const YYLTYPE *loc)

if (had_trailing_semicolon && !nd_type_p(expr, NODE_BLOCK)) {
NODE *block = NEW_BLOCK(expr, loc);
return NEW_DEFINED(block, loc);
return NEW_DEFINED(block, loc, keyword_loc);
}

return NEW_DEFINED(n, loc);
return NEW_DEFINED(n, loc, keyword_loc);
}

static NODE*
Expand Down
1 change: 1 addition & 0 deletions rubyparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -962,6 +962,7 @@ typedef struct RNode_DEFINED {
NODE node;

struct RNode *nd_head;
rb_code_location_t keyword_loc;
} rb_node_defined_t;

typedef struct RNode_POSTEXE {
Expand Down
8 changes: 8 additions & 0 deletions test/ruby/test_ast.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1415,6 +1415,14 @@ def test_colon3_locations
assert_locations(node.children[-1].children[0].locations, [[1, 0, 1, 3], [1, 0, 1, 2], [1, 2, 1, 3]])
end

def test_defined_locations
node = ast_parse("defined? x")
assert_locations(node.children[-1].locations, [[1, 0, 1, 10], [1, 0, 1, 8]])

node = ast_parse("defined?(x)")
assert_locations(node.children[-1].locations, [[1, 0, 1, 11], [1, 0, 1, 8]])
end

def test_dot2_locations
node = ast_parse("1..2")
assert_locations(node.children[-1].locations, [[1, 0, 1, 4], [1, 1, 1, 3]])
Expand Down
8 changes: 3 additions & 5 deletions yjit/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2091,11 +2091,9 @@ pub extern "C" fn rb_yjit_iseq_update_references(iseq: IseqPtr) {

// Only write when the VALUE moves, to be copy-on-write friendly.
if new_addr != object {
for (byte_idx, &byte) in new_addr.as_u64().to_le_bytes().iter().enumerate() {
let byte_code_ptr = value_code_ptr.add_bytes(byte_idx);
cb.write_mem(byte_code_ptr, byte)
.expect("patching existing code should be within bounds");
}
// SAFETY: Since we already set code memory writable before the compacting phase,
// we can use raw memory accesses directly.
unsafe { value_ptr.write_unaligned(new_addr); }
}
}
}
Expand Down
9 changes: 4 additions & 5 deletions yjit/src/cruby_bindings.inc.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 4 additions & 5 deletions zjit/src/cruby_bindings.inc.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.