Skip to content

Commit 33c975b

Browse files
maximecbXrXr
authored andcommitted
Merge pull request #114 from Shopify/yjit-dup-comments
YJIT: Avoid adding duplicate code comments
1 parent 23f8895 commit 33c975b

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

yjit_codegen.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,25 @@ _counted_side_exit(uint8_t *existing_side_exit, int64_t *counter)
218218
return start;
219219
}
220220

221+
// Add a comment at the current position in the code block
222+
static void
223+
_add_comment(codeblock_t* cb, const char* comment_str)
224+
{
225+
// Avoid adding duplicate comment strings (can happen due to deferred codegen)
226+
size_t num_comments = rb_darray_size(yjit_code_comments);
227+
if (num_comments > 0) {
228+
struct yjit_comment last_comment = rb_darray_get(yjit_code_comments, num_comments - 1);
229+
if (last_comment.offset == cb->write_pos && strcmp(last_comment.comment, comment_str) == 0) {
230+
return;
231+
}
232+
}
233+
234+
struct yjit_comment new_comment = (struct yjit_comment){ cb->write_pos, comment_str };
235+
rb_darray_append(&yjit_code_comments, new_comment);
236+
}
237+
221238
// Comments for generated machine code
222-
#define ADD_COMMENT(cb, comment) rb_darray_append(&yjit_code_comments, ((struct yjit_comment){(cb)->write_pos, (comment)}))
239+
#define ADD_COMMENT(cb, comment) _add_comment((cb), (comment))
223240
yjit_comment_array_t yjit_code_comments;
224241

225242
#else

yjit_iface.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ YJIT_DECLARE_COUNTERS(
7070
#undef YJIT_DECLARE_COUNTERS
7171

7272
struct yjit_comment {
73-
int32_t offset;
73+
uint32_t offset;
7474
const char *comment;
7575
};
7676

0 commit comments

Comments
 (0)