Граф коммитов

31 Коммитов

Автор SHA1 Сообщение Дата
Étienne Barrié 12be40ae6b Implement chilled strings
[Feature #20205]

As a path toward enabling frozen string literals by default in the future,
this commit introduce "chilled strings". From a user perspective chilled
strings pretend to be frozen, but on the first attempt to mutate them,
they lose their frozen status and emit a warning rather than to raise a
`FrozenError`.

Implementation wise, `rb_compile_option_struct.frozen_string_literal` is
no longer a boolean but a tri-state of `enabled/disabled/unset`.

When code is compiled with frozen string literals neither explictly enabled
or disabled, string literals are compiled with a new `putchilledstring`
instruction. This instruction is identical to `putstring` except it marks
the String with the `STR_CHILLED (FL_USER3)` and `FL_FREEZE` flags.

Chilled strings have the `FL_FREEZE` flag as to minimize the need to check
for chilled strings across the codebase, and to improve compatibility with
C extensions.

Notes:
  - `String#freeze`: clears the chilled flag.
  - `String#-@`: acts as if the string was mutable.
  - `String#+@`: acts as if the string was mutable.
  - `String#clone`: copies the chilled flag.

Co-authored-by: Jean Boussier <byroot@ruby-lang.org>
2024-03-19 09:26:49 +01:00
Takashi Kokubun 38be9a9b72
Clean up OPT_STACK_CACHING (#8132) 2023-07-27 17:27:05 -07:00
Takashi Kokubun bf4d64d8d0 Remove an unused macro
We've deleted opt_call_c_function instruction before.
2023-07-27 16:50:50 -07:00
Takashi Kokubun 4ad171bb25 Remove an unused VM option
This seems to be used nowhere today.
2023-03-13 20:54:00 -07:00
Alan Wu e84083593c oops Direct threading should be default 2021-10-20 18:19:25 -04:00
Alan Wu 7662653b4c Fix compilation for OPT_THREADED_CODE=2 2021-10-20 18:19:24 -04:00
Takashi Kokubun e544a3a23c
Remove obsoleted opt_call_c_function insn (#3232)
* Remove obsoleted opt_call_c_function insn

* Keep opt_call_c_function with DEFINE_INSN_IF
2020-06-17 09:16:01 -07:00
卜部昌平 4ff3f20540 add #include guard hack
According to MSVC manual (*1), cl.exe can skip including a header file
when that:

- contains #pragma once, or
- starts with #ifndef, or
- starts with #if ! defined.

GCC has a similar trick (*2), but it acts more stricter (e. g. there
must be _no tokens_ outside of #ifndef...#endif).

Sun C lacked #pragma once for a looong time.  Oracle Developer Studio
12.5 finally implemented it, but we cannot assume such recent version.

This changeset modifies header files so that each of them include
strictly one #ifndef...#endif.  I believe this is the most portable way
to trigger compiler optimizations. [Bug #16770]

*1: https://docs.microsoft.com/en-us/cpp/preprocessor/once
*2: https://gcc.gnu.org/onlinedocs/cppinternals/Guard-Macros.html
2020-04-13 16:06:00 +09:00
Nobuyoshi Nakada 46f175ed5c
Use cppflags to pass preprocessor options 2019-10-23 02:53:36 +09:00
Takashi Kokubun beaabd2308
Unify SUPPORT_JOKE and OPT_SUPPORT_JOKE
for simplicity and consistency.

Now SUPPORT_JOKE needs to be prefixed with OPT_ to make the config
visible in `RubyVM::VmOptsH`, and the inconsistency was introduced.

As it has never been available for override in configure (no #ifndef
guard), it should be fine to rename the config.
2019-09-03 21:12:31 +09:00
Takashi Kokubun 1a9cc3b27c Avoid defining unused instructions 2019-09-03 14:22:44 +09:00
k0kubun 589d80e7e3 vm_opts.h: share USE_IC_FOR_IVAR as OPT_IC_FOR_IVAR
with mjit_compile.c (tool/ruby_vm/views/_mjit_compile_getivar.erb).

mjit_compile.c: ditto
tool/ruby_vm/views/_mjit_compile_getivar.erb: ditto
vm_opts.h: ditto

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65074 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-14 11:25:36 +00:00
ko1 d3a9ebeb1c fix OPT_CALL_THREADED_CODE issue.
* insns.def (opt_send_without_block): reorder insn position because
  `opt_str_freeze` insn refer this insn (function) when
  OPT_CALL_THREADED_CODE is true.

* vm_opts.h (OPT_THREADED_CODE): introduce new macro to select
  threaded code implementation with a compile option (-D...).


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64854 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-26 08:11:05 +00:00
ko1 cbac40b3e5 Remove "trace_instruction" compile option.
* iseq.h (rb_compile_option_struct): trace instruction is removed so that
  remove the trace_instruction compile option.
  Don't show warning (just ignore) for Ruby 2.5.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61450 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-24 17:07:53 +00:00
nobu 012368007f iseq.h: rename member
* iseq.h (rb_compile_option_struct): rename the member
  frozen_string_literal_debug as debug_frozen_string_literal.
  [Feature #11725]

* ruby.c (proc_options): do not set $DEBUG and $VERBOSE only if no
  arguments is given.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52749 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-11-25 08:02:29 +00:00
ko1 92d5da521d * iseq.c (make_compile_option_value): include frozen_string_literal*
in a made option value.

* vm_opts.h: forgot to add OPT_FROZEN_STRING_LITERAL_DEBUG
  at last commit.




git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52258 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-10-23 19:13:51 +00:00
ko1 7cf523c7db * vm_opts.h, iseq.c, iseq.h: add compile option to force frozen
string literals.
  [Feature #11473]
  This addition is not specification change, but to try frozen
  string literal world discussed on [Feature #11473].
  You can try frozen string literal world using this magical line:
    RubyVM::InstructionSequence.compile_option =
      {frozen_string_literal: true}
  Note that this is a global compilation option, so that you need to
  compile another script like that:
    p 'foo'.frozen? #=> false
    RubyVM::InstructionSequence.compile_option =
      {frozen_string_literal: true}
    p 'foo'.frozen? #=> false, because this line is already compiled.
    p eval("'foo'.frozen?") #=> true
  Details:
    * String literals are deduped by rb_fstring().
    * Dynamic string literals ("...#{xyz}...") is now only frozen,
      not deduped. Maybe you have other ideas.
  Now, please do not use this option on your productions :)
  Of course, current specification can be changed.
* compile.c: ditto.
* test/ruby/test_iseq.rb: add a test.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51659 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-08-21 20:47:53 +00:00
tmm1 5d85df5d76 fix minor code comment typos
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40411 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-22 19:40:10 +00:00
ko1 d3842de5c9 * vm_opts.h: enable optimization - operand unifications.
Operand unification technique enable to combine
  an instruction and specific operands and make new
  instruction.
* defs/opt_operand.def: add several configuration
  of operand unifications.
* insns.def: use `int' instead to suppress warning.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38173 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-12-04 04:57:50 +00:00
naruse 1dec7384d1 * Makefile.in (probes.o): add -C to ignore #include in probes.d.
* probes.d: include vm_opts.h instead of vm_core.h.

* vm_opts.h (VM_COLLECT_USAGE_DETAILS): move definition from vm_core.h.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37801 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-22 09:03:43 +00:00
shugo 960e8a419f * vm_opts.h (OPT_GLOBAL_METHOD_CACHE): new build option to
enable/disable global method caching. [ruby-dev:46203] [Bug #7111]

* vm_method.c (rb_method_entry_get_with_omod): don't use global
  method cache if OPT_GLOBAL_METHOD_CACHE is 0.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37106 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-10-06 09:36:35 +00:00
ko1 400796e87b * vm_opts.h: enable "OPT_TRACE_INSTRUCTION" on default.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18788 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-08-23 06:18:11 +00:00
ko1 559d021d20 * eval.c, vm.c, vm_core.h, vm_insnhelper.c: specify "const".
* vm_opts.h: add a OPT_TOKEN_THREADED_CODE macro.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@16524 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-05-22 04:28:13 +00:00
nobu 8a9993dfee * eval_intern.h, insnhelper.h, thread_pthread.h, vm_core.h, vm_opts.h:
prefixed include guards with RUBY.

* id.h: added include guard.

* regenc.h, regint.h, regparse.h: prefixed include guards with
  ONIGURUMA.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15112 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-01-18 08:56:11 +00:00
akr 6cdef2dc7e * $Date$ keyword removed to avoid inclusion of locale dependent
string.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14912 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-01-06 15:49:38 +00:00
ko1 d907cbc81d * blockinlining.c, compile.c, compile.h, debug.c, debug.h,
id.c, insnhelper.h, insns.def, thread.c, thread_pthread.ci,
  thread_pthread.h, thread_win32.ci, thread_win32.h, vm.h,
  vm_dump.c, vm_evalbody.ci, vm_opts.h: fix comments and
  copyright year.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13920 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-11-13 22:13:04 +00:00
ko1 0a02ad5e2e * compile.c (iseq_compile_each/NODE_RESBODY): fix to add
additional nop to prevent tailcall optimization.
* vm_opts.h: clean up comments.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13112 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-08-19 04:16:13 +00:00
ko1 affa7430b7 * compile.c, vm_macro.def: support tail call optimization
(on default, this feature is not enabled).
* iseq.c, compile.c, vm_opts.h: add "tailcall_optimization"
  option.
* sample/test.rb (test_ok): fix to adjust tailcall stack layout.
* insns.def, vm.c, compile.c, yarvcore.c, yarvcore.h:
  add opt_gt, opt_le instructions.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12304 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-05-21 04:46:51 +00:00
ko1 a73894337a * eval.c, node.h, thread.c, yarvcore.[ch], eval_intern.h:
support set_trace_func (incomplete.  id and klass
  don't be passed).  And support Thread#set_trace_func
  which hook only specified thread and Thread#add_trace_func
  which add new trace func instead of replace old one.
  C level API was modified.  See thread.c (logic) and
  yarvcore.h (data structures).
* vm.c, vm_macro.def: add hook points.
* compile.c, insns.def: fix "trace" instruction.
* iseq.c, vm_macro.h: add compile option "trace_instruction".
* test/ruby/test_settracefunc.rb: hook "c-return" of set_trace_func.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12195 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-04-19 10:37:08 +00:00
ko1 8786140206 * vm_opts.h: set properties:
svn:keywords:  Author Date Id Revision
  svn:eol-style: native



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11642 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 07:41:30 +00:00
ko1 46cceb5a74 * complement last commit.
* common.mk (*.inc): use VPATH.
* vm_opts.h: renamed from vm_opts.h.base.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11637 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 02:06:07 +00:00