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
15 changes: 1 addition & 14 deletions imemo.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,6 @@ rb_free_tmp_buffer(volatile VALUE *store)
}
}

rb_imemo_tmpbuf_t *
rb_imemo_tmpbuf_parser_heap(void *buf, rb_imemo_tmpbuf_t *old_heap, size_t cnt)
{
rb_imemo_tmpbuf_t *tmpbuf = (rb_imemo_tmpbuf_t *)rb_imemo_tmpbuf_new();
tmpbuf->ptr = buf;
tmpbuf->next = old_heap;
tmpbuf->cnt = cnt;

return tmpbuf;
}

static VALUE
imemo_fields_new(VALUE owner, size_t capa)
{
Expand Down Expand Up @@ -478,9 +467,7 @@ rb_imemo_mark_and_move(VALUE obj, bool reference_updating)
const rb_imemo_tmpbuf_t *m = (const rb_imemo_tmpbuf_t *)obj;

if (!reference_updating) {
do {
rb_gc_mark_locations(m->ptr, m->ptr + m->cnt);
} while ((m = m->next) != NULL);
rb_gc_mark_locations(m->ptr, m->ptr + m->cnt);
}

break;
Expand Down
2 changes: 0 additions & 2 deletions internal/imemo.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ struct vm_ifunc {
struct rb_imemo_tmpbuf_struct {
VALUE flags;
VALUE *ptr; /* malloc'ed buffer */
struct rb_imemo_tmpbuf_struct *next; /* next imemo */
size_t cnt; /* buffer size in VALUE */
};

Expand Down Expand Up @@ -133,7 +132,6 @@ struct MEMO {
typedef struct rb_imemo_tmpbuf_struct rb_imemo_tmpbuf_t;
#endif
VALUE rb_imemo_tmpbuf_new(void);
rb_imemo_tmpbuf_t *rb_imemo_tmpbuf_parser_heap(void *buf, rb_imemo_tmpbuf_t *old_heap, size_t cnt);
struct vm_ifunc *rb_vm_ifunc_new(rb_block_call_func_t func, const void *data, int min_argc, int max_argc);
static inline enum imemo_type imemo_type(VALUE imemo);
static inline int imemo_type_p(VALUE imemo, enum imemo_type imemo_type);
Expand Down
121 changes: 109 additions & 12 deletions lib/erb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,17 @@
#
# When you call method #result,
# the method executes the code and removes the entire execution tag
# (generating no text in the result).
# (generating no text in the result):
#
# ```
# ERB.new('foo <% Dir.chdir("C:/") %> bar').result # => "foo bar"
# ```
#
# Whitespace before and after the embedded code is optional:
#
# ```
# ERB.new('foo <%Dir.chdir("C:/")%> bar').result # => "foo bar"
# ```
#
# You can interleave text with execution tags to form a control structure
# such as a conditional, a loop, or a `case` statements.
Expand Down Expand Up @@ -261,7 +271,7 @@
#
# #### Shorthand Format for Execution Tags
#
# You can give `trim_mode: '%'` to enable a shorthand format for execution tags;
# You can use keyword argument `trim_mode: '%'` to enable a shorthand format for execution tags;
# this example uses the shorthand format `% _code_` instead of `<% _code_ %>`:
#
# ```
Expand All @@ -283,6 +293,90 @@
# Note that in the shorthand format, the character `'%'` must be the first character in the code line
# (no leading whitespace).
#
# #### Suppressing Unwanted Blank Lines
#
# With keyword argument `trim_mode` not given,
# all blank lines go into the result:
#
# ```
# s = <<EOT
# <% if true %>
# <%= RUBY_VERSION %>
# <% end %>
# EOT
# ERB.new(s).result.lines.each {|line| puts line.inspect }
# "\n"
# "3.4.5\n"
# "\n"
# ```
#
# You can give `trim_mode: '-'`, you can suppress each blank line
# whose source line ends with `-%>` (instead of `%>`):
#
# ```
# s = <<EOT
# <% if true -%>
# <%= RUBY_VERSION %>
# <% end -%>
# EOT
# ERB.new(s, trim_mode: '-').result.lines.each {|line| puts line.inspect }
# "3.4.5\n"
# ```
#
# It is an error to use the trailing `'-%>'` notation without `trim_mode: '-'`:
#
# ```
# ERB.new(s).result.lines.each {|line| puts line.inspect } # Raises SyntaxError.
# ```
#
# #### Suppressing Unwanted Newlines
#
# Consider this input string:
#
# ```
# s = <<EOT
# <% RUBY_VERSION %>
# <%= RUBY_VERSION %>
# foo <% RUBY_VERSION %>
# foo <%= RUBY_VERSION %>
# EOT
# ```
#
# With keyword argument `trim_mode` not given, all newlines go into the result:
#
# ```
# ERB.new(s).result.lines.each {|line| puts line.inspect }
# "\n"
# "3.4.5\n"
# "foo \n"
# "foo 3.4.5\n"
# ```
#
# You can give `trim_mode: '>'` to suppress the trailing newline
# for each line that ends with `'%<'` (regardless of its beginning):
#
# ```
# ERB.new(s, trim_mode: '>').result.lines.each {|line| puts line.inspect }
# "3.4.5foo foo 3.4.5"
# ```
#
# You can give `trim_mode: '<>'` to suppress the trailing newline
# for each line that both begins with `'<%'` and ends with `'%<'`:
#
# ```
# ERB.new(s, trim_mode: '<>').result.lines.each {|line| puts line.inspect }
# "3.4.5foo \n"
# "foo 3.4.5\n"
# ```
#
# #### Combining Trim Modes
#
# You can combine certain trim modes:
#
# - `'%-'`: Enable shorthand and omit each blank line ending with `'%>'`.
# - `'%>'`: Enable shorthand and omit newline for each line ending with `'%>'`.
# - `'%<>'`: Enable shorthand and omit newline for each line starting with `'<%'` and ending with `'%>'`.
#
# ### Comment Tags
#
# You can embed a comment in a template using a *comment tag*;
Expand Down Expand Up @@ -537,19 +631,19 @@ def self.version
#
# **Keyword Argument `trim_mode`**
#
# When keyword argument `trim_mode` has a string value,
# that value may be one of:
# You can use keyword argument `trim_mode: '%'`
# to enable the [shorthand format][shorthand format] for execution tags.
#
# This value allows [blank line control][blank line control]:
#
# - `'%'`: Enable [shorthand format][shorthand format] for execution tags.
# - `'-'`: Omit each blank line ending with `'%>'`.
#
# Other values allow [newline control][newline control]:
#
# - `'>'`: Omit newline for each line ending with `'%>'`.
# - `'<>'`: Omit newline for each line starting with `'<%'` and ending with `'%>'`.
#
# The value may also be certain combinations of the above.
#
# - `'%-'`: Enable shorthand and omit each blank line ending with `'%>'`.
# - `'%>'`: Enable shorthand and omit newline for each line ending with `'%>'`.
# - `'%<>'`: Enable shorthand and omit newline for each line starting with `'<%'` and ending with `'%>'`.
# You can also [combine trim modes][combine trim modes].
#
# **Keyword Argument `eoutvar`**
#
Expand Down Expand Up @@ -578,9 +672,12 @@ def self.version
# However, their values, if given, are handled thus:
#
# - `safe_level`: ignored.
# - `legacy_trim_mode: overrides keyword argument `trim_mode`.
# - `legacy_eoutvar: overrides keyword argument `eoutvar`.
# - `legacy_trim_mode`: overrides keyword argument `trim_mode`.
# - `legacy_eoutvar`: overrides keyword argument `eoutvar`.
#
# [blank line control]: rdoc-ref:ERB@Suppressing+Unwanted+Blank+Lines
# [combine trim modes]: rdoc-ref:ERB@Combining+Trim+Modes
# [newline control]: rdoc-ref:ERB@Suppressing+Unwanted+Newlines
# [shorthand format]: rdoc-ref:ERB@Shorthand+Format+for+Execution+Tags
#
def initialize(str, safe_level=NOT_GIVEN, legacy_trim_mode=NOT_GIVEN, legacy_eoutvar=NOT_GIVEN, trim_mode: nil, eoutvar: '_erbout')
Expand Down
15 changes: 15 additions & 0 deletions test/ruby/test_zjit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,21 @@ def entry = [test(1), test(3, 4)]
}, call_threshold: 2
end

def test_send_nil_block_arg
assert_compiles 'false', %q{
def test = block_given?
def entry = test(&nil)
test
}
end

def test_send_symbol_block_arg
assert_compiles '["1", "2"]', %q{
def test = [1, 2].map(&:to_s)
test
}
end

def test_forwardable_iseq
assert_compiles '1', %q{
def test(...) = 1
Expand Down
7 changes: 1 addition & 6 deletions zjit/src/backend/lir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::cruby::{Qundef, RUBY_OFFSET_CFP_PC, RUBY_OFFSET_CFP_SP, SIZEOF_VALUE_
use crate::hir::SideExitReason;
use crate::options::{debug, get_option};
use crate::cruby::VALUE;
use crate::stats::{exit_counter_ptr, exit_counter_ptr_for_call_type, exit_counter_ptr_for_opcode, CompileError};
use crate::stats::{exit_counter_ptr, exit_counter_ptr_for_opcode, CompileError};
use crate::virtualmem::CodePtr;
use crate::asm::{CodeBlock, Label};

Expand Down Expand Up @@ -1601,11 +1601,6 @@ impl Assembler
self.load_into(SCRATCH_OPND, Opnd::const_ptr(exit_counter_ptr_for_opcode(opcode)));
self.incr_counter_with_reg(Opnd::mem(64, SCRATCH_OPND, 0), 1.into(), C_RET_OPND);
}
if let SideExitReason::UnhandledCallType(call_type) = reason {
asm_comment!(self, "increment an unknown call type counter");
self.load_into(SCRATCH_OPND, Opnd::const_ptr(exit_counter_ptr_for_call_type(call_type)));
self.incr_counter_with_reg(Opnd::mem(64, SCRATCH_OPND, 0), 1.into(), C_RET_OPND);
}
}

asm_comment!(self, "exit to the interpreter");
Expand Down
Loading