Commit graph

1340 commits

Author SHA1 Message Date
Nobuyoshi Nakada
7b2bea42a2
Unfreeze string-literal-only interpolated string-literal
[Feature #17104]
2020-09-30 22:15:28 +09:00
Benoit Daloze
9b535f3ff7 Interpolated strings are no longer frozen with frozen-string-literal: true
* Remove freezestring instruction since this was the only usage for it.
* [Feature #17104]
2020-09-15 21:32:35 +02:00
Koichi Sasada
79df14c04b Introduce Ractor mechanism for parallel execution
This commit introduces Ractor mechanism to run Ruby program in
parallel. See doc/ractor.md for more details about Ractor.
See ticket [Feature #17100] to see the implementation details
and discussions.

[Feature #17100]

This commit does not complete the implementation. You can find
many bugs on using Ractor. Also the specification will be changed
so that this feature is experimental. You will see a warning when
you make the first Ractor with `Ractor.new`.

I hope this feature can help programmers from thread-safety issues.
2020-09-03 21:11:06 +09:00
Nobuyoshi Nakada
a90f29ebb2
procnames-start-lines [ci skip] 2020-08-17 14:27:34 +09:00
Nobuyoshi Nakada
352e923242
Revisit "Refactor to reduce "swap" instruction of pattern matching"
Just moved "case base" after allocating cache space.
2020-08-17 14:25:09 +09:00
Kazuhiro NISHIYAMA
5849309c5a
Revert "Refactor to reduce "swap" instruction of pattern matching"
This reverts commit 3a4be429b5.

To fix following warning:

```
compiling ../compile.c
../compile.c:6336:20: warning: variable 'line' is uninitialized when used here [-Wuninitialized]
    ADD_INSN(head, line, putnil); /* allocate stack for cached #deconstruct value */
                   ^~~~
../compile.c:220:57: note: expanded from macro 'ADD_INSN'
  ADD_ELEM((seq), (LINK_ELEMENT *) new_insn_body(iseq, (line), BIN(insn), 0))
                                                        ^~~~
../compile.c:6327:13: note: initialize the variable 'line' to silence this warning
    int line;
            ^
             = 0
1 warning generated.
```
2020-08-17 09:28:15 +09:00
wanabe
3a4be429b5 Refactor to reduce "swap" instruction of pattern matching 2020-08-16 18:53:39 +09:00
wanabe
5c40c88a3e Adjust sp for case ... in a: 0 ... end 2020-08-16 18:39:08 +09:00
wanabe
691f10dd89 Adjust sp for case ... in *, a, * end 2020-08-16 18:39:08 +09:00
wanabe
6c407b3668 Adjust sp for case ... in *v end/case ... in v1, v2 end 2020-08-16 18:39:08 +09:00
wanabe
c866d6563f Adjust sp for case ... in v1 ... in v2 end 2020-08-16 18:39:08 +09:00
wanabe
d594078426 Adjust sp for case ... in v1, v2 ... end 2020-08-16 18:39:08 +09:00
wanabe
2bbb7c3d1f Adjust sp for case ... in pat => var ... end 2020-08-16 18:39:08 +09:00
wanabe
6bc0c6c18b Adjust sp for case ... in pat1 | pat2 ... end 2020-08-16 18:39:08 +09:00
wanabe
0759862458 Adjust sp for pattern matching implicit/explicit "else" 2020-08-16 18:39:08 +09:00
wanabe
a7bd0ec570 Warn sp overwriting on compile time 2020-08-16 08:43:29 +09:00
wanabe
ac399c2c7a Show hidden object and TS_BUILTIN for halfbaked insn data 2020-08-16 08:43:29 +09:00
Koichi Sasada
a0f12a0258
Use ID instead of GENTRY for gvars. (#3278)
Use ID instead of GENTRY for gvars.

Global variables are compiled into GENTRY (a pointer to struct
rb_global_entry). This patch replace this GENTRY to ID and
make the code simple.

We need to search GENTRY from ID every time (st_lookup), so
additional overhead will be introduced.
However, the performance of accessing global variables is not
important now a day and this simplicity helps Ractor development.
2020-07-03 16:56:44 +09:00
卜部昌平
bacd03ebdf compile_redo: fix wrong condition 2020-06-29 11:05:41 +09:00
卜部昌平
9c92dcf366 ibf_dump_object_object: do not goto into a branch
I'm not necessarily against every goto in general, but jumping into a
branch is definitely a bad idea.  Better refactor.
2020-06-29 11:05:41 +09:00
卜部昌平
a8d992ac00 compile_call: do not goto into a branch
I'm not necessarily against every goto in general, but jumping into a
branch is definitely a bad idea.  Better refactor.
2020-06-29 11:05:41 +09:00
卜部昌平
aa2cb7f722 compile_redo: do not goto into a branch
I'm not necessarily against every goto in general, but jumping into a
branch is definitely a bad idea.  Better refactor.
2020-06-29 11:05:41 +09:00
卜部昌平
cf29de7e6e compile_next: do not goto into a branch
I'm not necessarily against every goto in general, but jumping into a
branch is definitely a bad idea.  Better refactor.
2020-06-29 11:05:41 +09:00
卜部昌平
cc1e9b8e11 compile_break: do not goto into a branch
I'm not necessarily against every goto in general, but jumping into a
branch is definitely a bad idea.  Better refactor.
2020-06-29 11:05:41 +09:00
卜部昌平
1f90690a1d compile_branch_condition: do not goto into a branch
I'm not necessarily against every goto in general, but jumping into a
branch is definitely a bad idea.  Better refactor.
2020-06-29 11:05:41 +09:00
卜部昌平
a6b1454a5d optimize_checktype: do not goto into a branch
I'm not necessarily against every goto in general, but jumping into a
branch is definitely a bad idea.  Better refactor.
2020-06-29 11:05:41 +09:00
卜部昌平
a5342f46e6 iseq_set_exception_table: do not goto into a branch
I'm not necessarily against every goto in general, but jumping into a
branch is definitely a bad idea.  Better refactor.
2020-06-29 11:05:41 +09:00
Nobuyoshi Nakada
25fbc88666
Removed non-ASCII code to suppress warnings by localized compilers 2020-06-27 23:15:13 +09:00
Kazuki Tsujimoto
600f3990d6
Cosmetic change 2020-06-27 13:53:47 +09:00
Vladimir Dementyev
c9ee34a18b Add #deconstruct cache to find pattern 2020-06-27 13:51:03 +09:00
Vladimir Dementyev
5320375732 Optimize array pattern matching by caching #deconstruct value 2020-06-27 13:51:03 +09:00
Nobuyoshi Nakada
74c345c7b8 Removed no longer used flags 2020-06-27 10:55:18 +09:00
Nobuyoshi Nakada
61984d4760 Not to rewrite node while compiling
Moved this hack mark to an argument to `compile_hash`.
> Bad Hack: temporarily mark hash node with flag so
> compile_hash can compile call differently.
2020-06-27 10:55:18 +09:00
Takashi Kokubun
7561db8c00
Introduce Primitive.attr! to annotate 'inline' (#3242)
[Feature #15589]
2020-06-20 17:13:03 -07:00
Yusuke Endoh
50efa18c6c compile.c: Improve branch coverage instrumentation [Bug #16967]
Formerly, branch coverage measurement counters are generated for each
compilation traverse of the AST.  However, ensure clause node is
traversed twice; one is for normal-exit case (the resulted bytecode is
embedded in its outer scope), and the other is for exceptional case (the
resulted bytecode is used in catch table).  Two branch coverage counters
are generated for the two cases, but it is not desired.

This changeset revamps the internal representation of branch coverage
measurement.  Branch coverage counters are generated only at the first
visit of a branch node.  Visiting the same node reuses the
already-generated counter, so double counting is avoided.
2020-06-20 09:28:03 +09:00
Yusuke Endoh
bc0aea0804 compile.c: pass NODE* instead of a quadruple of code location 2020-06-20 09:28:03 +09:00
Yusuke Endoh
4b523e79a0 compile.c (branch_coverage_valid_p): Refactored out 2020-06-20 09:28:03 +09:00
Yusuke Endoh
37cd877dbd compile.c: Use functions for building branch coverage instructions
instead of maros.  Just refactoring.
2020-06-20 09:28:03 +09:00
Nobuyoshi Nakada
49f0fd21e4 [Feature #16254] Allow Primitive.func style 2020-06-19 18:46:55 +09:00
Nobuyoshi Nakada
c8703a17ce [Feature #16254] Allow __builtin.func style 2020-06-19 18:46:55 +09:00
Jeremy Evans
aae8223c70 Dup splat array in certain cases where there is a block argument
This makes:

```ruby
  args = [1, 2, -> {}]; foo(*args, &args.pop)
```

call `foo` with 1, 2, and the lambda, in addition to passing the
lambda as a block.  This is different from the previous behavior,
which passed the lambda as a block but not as a regular argument,
which goes against the expected left-to-right evaluation order.

This is how Ruby already compiled arguments if using leading
arguments, trailing arguments, or keywords in the same call.

This works by disabling the optimization that skipped duplicating
the array during the splat (splatarray instruction argument
switches from false to true).  In the above example, the splat
call duplicates the array.  I've tested and cases where a
local variable or symbol are used do not duplicate the array,
so I don't expect this to decrease the performance of most Ruby
programs.  However, programs such as:

```ruby
  foo(*args, &bar)
```

could see a decrease in performance, if `bar` is a method call
and not a local variable.

This is not a perfect solution, there are ways to get around
this:

```ruby
  args = Struct.new(:a).new([:x, :y])
  def args.to_a; a; end
  def args.to_proc; a.pop; ->{}; end
  foo(*args, &args)
  # calls foo with 1 argument (:x)
  # not 2 arguments (:x and :y)
```

A perfect solution would require completely disabling the
optimization.

Fixes [Bug #16504]
Fixes [Bug #16500]
2020-06-18 08:19:33 -07:00
Nobuyoshi Nakada
ccb7a4b9f2
Replaced accessors of Struct with invokebuiltin 2020-06-17 08:18:46 +09:00
Nobuyoshi Nakada
318d52e820
Revert "Replaced accessors of Struct with invokebuiltin"
This reverts commit 19cabe8b09,
which didn't support tool/lib/iseq_loader_checker.rb.
2020-06-16 18:44:58 +09:00
Nobuyoshi Nakada
19cabe8b09
Replaced accessors of Struct with invokebuiltin 2020-06-16 18:24:02 +09:00
Kazuki Tsujimoto
ddded1157a
Introduce find pattern [Feature #16828] 2020-06-14 09:24:36 +09:00
Jeremy Evans
0ba27259d3 Fix crashes in the peephole optimizer on OpenBSD/sparc64
These crashes are due to alignment issues, casting ADJUST to INSN
and then accessing after the end of the ADJUST.  These patches
come from Stefan Sperling <stsp@apache.org>, who reported the
issue.
2020-06-08 11:11:27 -07:00
Nobuyoshi Nakada
6dcd10ce56
compile.c: Mark cursor in debug list 2020-05-31 03:07:30 +09:00
Nobuyoshi Nakada
2c711273bb
compile.c: Removed wrong conversion 2020-05-31 03:05:10 +09:00
Nobuyoshi Nakada
57fd44d374
Adjusted an indent 2020-05-30 21:20:50 +09:00
Koichi Sasada
03d7f3cdb2 add indent for debug disasm output 2020-05-29 11:25:45 +09:00