[ruby-cvs:58807] ko1:r51659 (trunk): * vm_opts.h, iseq.c, iseq.h: add compile option to force frozen
ko1 at ruby-lang.org
ko1 at ruby-lang.org
Sat Aug 22 05:47:55 JST 2015
ko1 2015-08-22 05:47:53 +0900 (Sat, 22 Aug 2015)
New Revision: 51659
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=51659
Log:
* 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.
Modified files:
trunk/ChangeLog
trunk/compile.c
trunk/iseq.c
trunk/iseq.h
trunk/test/ruby/test_iseq.rb
trunk/vm_opts.h
More information about the ruby-cvs
mailing list