-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Warn on modified future frozen string literal #10262
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Warn on modified future frozen string literal #10262
Conversation
Ref: https://bugs.ruby-lang.org/issues/20205 Ref: ruby/ruby#10262 Ruby 3.4 will very likely add a `putchilledstring` instruction which for what concerns typeprof is pretty much an alias of `putstring`.
This comment was marked as outdated.
This comment was marked as outdated.
84be7d6
to
548ed3b
Compare
This comment has been minimized.
This comment has been minimized.
628e076
to
557f0bb
Compare
Ref: https://bugs.ruby-lang.org/issues/20205 Ref: ruby/ruby#10262 Ruby 3.4 will very likely add a `putchilledstring` instruction which for what concerns typeprof is pretty much an alias of `putstring`.
47e125e
to
504d4fc
Compare
Ref: https://bugs.ruby-lang.org/issues/20205 Ref: ruby/ruby#10262 Ruby 3.4 will very likely add a `putchilledstring` instruction which for what concerns typeprof is pretty much an alias of `putstring`.
2ec1aa6
to
af2895e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Specs look great
851fc04
to
2774757
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had a couple of questions but overall it looks right to me 👍
[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 <[email protected]>
2774757
to
5dc8ddc
Compare
…gainst Ruby 3.4.0dev This commit addresses the following Rails Nightly CI error since ruby/ruby#10262 . https://buildkite.com/rails/rails-nightly/builds/310#018e5929-ff70-4397-b978-9a0a03cd4706/1255-1265 - Without this commit: ```ruby $ ruby -v ruby 3.4.0dev (2024-03-19T08:26:49Z master 12be40ae6b) [x86_64-linux] $ cd actionpack $ RAILS_STRICT_WARNINGS=true bin/test test/controller/renderer_test.rb:37 Running 25 tests in a single process (parallelization threshold is 50) Run options: --seed 14013 /home/yahonda/src/github.com/rails/rails/actionpack/test/fixtures/ruby_template.ruby:2: warning: literal string will be frozen in the future E Error: RendererTest#test_rendering_with_a_class_renderer: RuntimeError: Neutered Exception ActionView::Template::Error: /home/yahonda/src/github.com/rails/rails/actionpack/test/fixtures/ruby_template.ruby:2: warning: literal string will be frozen in the future /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/testing/strict_warnings.rb:33:in 'ActiveSupport::RaiseWarnings#warn' test/fixtures/ruby_template.ruby:2:in '_home_yahonda_src_github_com_rails_rails_actionpack_test_fixtures_ruby_template_ruby__3648742137162546161_6360' /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/base.rb:282:in 'Kernel#public_send' /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/base.rb:282:in 'ActionView::Base#_run' /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/template.rb:275:in 'block in ActionView::Template#render' /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/notifications.rb:212:in 'ActiveSupport::Notifications.instrument' /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/template.rb:567:in 'ActionView::Template#instrument_render_template' /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/template.rb:263:in 'ActionView::Template#render' /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/renderer/template_renderer.rb:66:in 'block (2 levels) in ActionView::TemplateRenderer#render_template' /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/notifications.rb:212:in 'ActiveSupport::Notifications.instrument' /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/renderer/template_renderer.rb:60:in 'block in ActionView::TemplateRenderer#render_template' /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/renderer/template_renderer.rb:80:in 'ActionView::TemplateRenderer#render_with_layout' /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/renderer/template_renderer.rb:59:in 'ActionView::TemplateRenderer#render_template' /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/renderer/template_renderer.rb:11:in 'ActionView::TemplateRenderer#render' /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/renderer/renderer.rb:58:in 'ActionView::Renderer#render_template_to_object' /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/renderer/renderer.rb:31:in 'ActionView::Renderer#render_to_object' /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/rendering.rb:135:in 'block in ActionView::Rendering#_render_template' /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/base.rb:309:in 'ActionView::Base#in_rendering_context' /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/rendering.rb:134:in 'ActionView::Rendering#_render_template' lib/action_controller/metal/streaming.rb:258:in 'ActionController::Streaming#_render_template' /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/rendering.rb:121:in 'ActionView::Rendering#render_to_body' lib/action_controller/metal/rendering.rb:186:in 'ActionController::Rendering#render_to_body' lib/action_controller/metal/renderers.rb:142:in 'ActionController::Renderers#render_to_body' lib/abstract_controller/rendering.rb:47:in 'AbstractController::Rendering#render_to_string' lib/action_controller/metal/rendering.rb:175:in 'ActionController::Rendering#render_to_string' lib/action_controller/renderer.rb:136:in 'ActionController::Renderer#render' test/controller/renderer_test.rb:37:in 'block in <class:RendererTest>' bin/test test/controller/renderer_test.rb:35 Finished in 0.294798s, 3.3921 runs/s, 0.0000 assertions/s. 1 runs, 0 assertions, 0 failures, 1 errors, 0 skips $ ``` Refer to these Ruby issue and pull request for this change: https://bugs.ruby-lang.org/issues/20205 ruby/ruby#10262
…gainst Ruby 3.4.0dev This commit addresses the following Rails Nightly CI error since ruby/ruby#10262 . https://buildkite.com/rails/rails-nightly/builds/310#018e5929-ff70-4397-b978-9a0a03cd4706/1255-1265 - Without this commit: ```ruby $ ruby -v ruby 3.4.0dev (2024-03-19T08:26:49Z master 12be40ae6b) [x86_64-linux] $ cd actionpack $ RAILS_STRICT_WARNINGS=true bin/test test/controller/renderer_test.rb:37 Running 25 tests in a single process (parallelization threshold is 50) Run options: --seed 14013 /home/yahonda/src/github.com/rails/rails/actionpack/test/fixtures/ruby_template.ruby:2: warning: literal string will be frozen in the future E Error: RendererTest#test_rendering_with_a_class_renderer: RuntimeError: Neutered Exception ActionView::Template::Error: /home/yahonda/src/github.com/rails/rails/actionpack/test/fixtures/ruby_template.ruby:2: warning: literal string will be frozen in the future /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/testing/strict_warnings.rb:33:in 'ActiveSupport::RaiseWarnings#warn' test/fixtures/ruby_template.ruby:2:in '_home_yahonda_src_github_com_rails_rails_actionpack_test_fixtures_ruby_template_ruby__3648742137162546161_6360' /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/base.rb:282:in 'Kernel#public_send' /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/base.rb:282:in 'ActionView::Base#_run' /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/template.rb:275:in 'block in ActionView::Template#render' /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/notifications.rb:212:in 'ActiveSupport::Notifications.instrument' /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/template.rb:567:in 'ActionView::Template#instrument_render_template' /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/template.rb:263:in 'ActionView::Template#render' /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/renderer/template_renderer.rb:66:in 'block (2 levels) in ActionView::TemplateRenderer#render_template' /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/notifications.rb:212:in 'ActiveSupport::Notifications.instrument' /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/renderer/template_renderer.rb:60:in 'block in ActionView::TemplateRenderer#render_template' /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/renderer/template_renderer.rb:80:in 'ActionView::TemplateRenderer#render_with_layout' /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/renderer/template_renderer.rb:59:in 'ActionView::TemplateRenderer#render_template' /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/renderer/template_renderer.rb:11:in 'ActionView::TemplateRenderer#render' /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/renderer/renderer.rb:58:in 'ActionView::Renderer#render_template_to_object' /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/renderer/renderer.rb:31:in 'ActionView::Renderer#render_to_object' /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/rendering.rb:135:in 'block in ActionView::Rendering#_render_template' /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/base.rb:309:in 'ActionView::Base#in_rendering_context' /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/rendering.rb:134:in 'ActionView::Rendering#_render_template' lib/action_controller/metal/streaming.rb:258:in 'ActionController::Streaming#_render_template' /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/rendering.rb:121:in 'ActionView::Rendering#render_to_body' lib/action_controller/metal/rendering.rb:186:in 'ActionController::Rendering#render_to_body' lib/action_controller/metal/renderers.rb:142:in 'ActionController::Renderers#render_to_body' lib/abstract_controller/rendering.rb:47:in 'AbstractController::Rendering#render_to_string' lib/action_controller/metal/rendering.rb:175:in 'ActionController::Rendering#render_to_string' lib/action_controller/renderer.rb:136:in 'ActionController::Renderer#render' test/controller/renderer_test.rb:37:in 'block in <class:RendererTest>' bin/test test/controller/renderer_test.rb:35 Finished in 0.294798s, 3.3921 runs/s, 0.0000 assertions/s. 1 runs, 0 assertions, 0 failures, 1 errors, 0 skips $ ``` Refer to these Ruby issue and pull request for this change: https://bugs.ruby-lang.org/issues/20205 ruby/ruby#10262 Co-authored-by: Rafael Mendonça França <[email protected]>
Hey @casperisfine , I don't have an ruby issue tracker account so this will have to do: This works in Ruby 3.3 but raises on head and results in some test failures for unicorn: require "stringio"
StringIO.new("").write("foo")
#=> 'StringIO#write': not opened for writing (IOError) This is because the chilld string is not considered writeable in this codepath: https://github.com/ruby/stringio/blob/779f71359d4760df49b70cfbcf908bc012e7e4ba/ext/stringio/stringio.c#L156-L165 |
Yes this is known and somewhat expected. But perhaps we could detect this in StringIO and turn this into a warning. |
For the short term, you can set |
Hm, I guess this is something like |
…gainst Ruby 3.4.0dev This commit addresses the following Rails Nightly CI error since ruby/ruby#10262 . https://buildkite.com/rails/rails-nightly/builds/310#018e5929-ff70-4397-b978-9a0a03cd4706/1255-1265 - Without this commit: ```ruby $ ruby -v ruby 3.4.0dev (2024-03-19T08:26:49Z master 12be40ae6b) [x86_64-linux] $ cd actionpack $ RAILS_STRICT_WARNINGS=true bin/test test/controller/renderer_test.rb:37 Running 25 tests in a single process (parallelization threshold is 50) Run options: --seed 14013 /home/yahonda/src/github.com/rails/rails/actionpack/test/fixtures/ruby_template.ruby:2: warning: literal string will be frozen in the future E Error: RendererTest#test_rendering_with_a_class_renderer: RuntimeError: Neutered Exception ActionView::Template::Error: /home/yahonda/src/github.com/rails/rails/actionpack/test/fixtures/ruby_template.ruby:2: warning: literal string will be frozen in the future /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/testing/strict_warnings.rb:33:in 'ActiveSupport::RaiseWarnings#warn' test/fixtures/ruby_template.ruby:2:in '_home_yahonda_src_github_com_rails_rails_actionpack_test_fixtures_ruby_template_ruby__3648742137162546161_6360' /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/base.rb:282:in 'Kernel#public_send' /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/base.rb:282:in 'ActionView::Base#_run' /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/template.rb:275:in 'block in ActionView::Template#render' /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/notifications.rb:212:in 'ActiveSupport::Notifications.instrument' /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/template.rb:567:in 'ActionView::Template#instrument_render_template' /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/template.rb:263:in 'ActionView::Template#render' /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/renderer/template_renderer.rb:66:in 'block (2 levels) in ActionView::TemplateRenderer#render_template' /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/notifications.rb:212:in 'ActiveSupport::Notifications.instrument' /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/renderer/template_renderer.rb:60:in 'block in ActionView::TemplateRenderer#render_template' /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/renderer/template_renderer.rb:80:in 'ActionView::TemplateRenderer#render_with_layout' /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/renderer/template_renderer.rb:59:in 'ActionView::TemplateRenderer#render_template' /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/renderer/template_renderer.rb:11:in 'ActionView::TemplateRenderer#render' /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/renderer/renderer.rb:58:in 'ActionView::Renderer#render_template_to_object' /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/renderer/renderer.rb:31:in 'ActionView::Renderer#render_to_object' /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/rendering.rb:135:in 'block in ActionView::Rendering#_render_template' /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/base.rb:309:in 'ActionView::Base#in_rendering_context' /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/rendering.rb:134:in 'ActionView::Rendering#_render_template' lib/action_controller/metal/streaming.rb:258:in 'ActionController::Streaming#_render_template' /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/rendering.rb:121:in 'ActionView::Rendering#render_to_body' lib/action_controller/metal/rendering.rb:186:in 'ActionController::Rendering#render_to_body' lib/action_controller/metal/renderers.rb:142:in 'ActionController::Renderers#render_to_body' lib/abstract_controller/rendering.rb:47:in 'AbstractController::Rendering#render_to_string' lib/action_controller/metal/rendering.rb:175:in 'ActionController::Rendering#render_to_string' lib/action_controller/renderer.rb:136:in 'ActionController::Renderer#render' test/controller/renderer_test.rb:37:in 'block in <class:RendererTest>' bin/test test/controller/renderer_test.rb:35 Finished in 0.294798s, 3.3921 runs/s, 0.0000 assertions/s. 1 runs, 0 assertions, 0 failures, 1 errors, 0 skips $ ``` Refer to these Ruby issue and pull request for this change: https://bugs.ruby-lang.org/issues/20205 ruby/ruby#10262 Co-authored-by: Rafael Mendonça França <[email protected]>
…gainst Ruby 3.4.0dev This commit addresses the following Rails Nightly CI error since ruby/ruby#10262 . https://buildkite.com/rails/rails-nightly/builds/310#018e5929-ff70-4397-b978-9a0a03cd4706/1255-1265 - Without this commit: ```ruby $ ruby -v ruby 3.4.0dev (2024-03-19T08:26:49Z master 12be40ae6b) [x86_64-linux] $ cd actionpack $ RAILS_STRICT_WARNINGS=true bin/test test/controller/renderer_test.rb:37 Running 25 tests in a single process (parallelization threshold is 50) Run options: --seed 14013 /home/yahonda/src/github.com/rails/rails/actionpack/test/fixtures/ruby_template.ruby:2: warning: literal string will be frozen in the future E Error: RendererTest#test_rendering_with_a_class_renderer: RuntimeError: Neutered Exception ActionView::Template::Error: /home/yahonda/src/github.com/rails/rails/actionpack/test/fixtures/ruby_template.ruby:2: warning: literal string will be frozen in the future /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/testing/strict_warnings.rb:33:in 'ActiveSupport::RaiseWarnings#warn' test/fixtures/ruby_template.ruby:2:in '_home_yahonda_src_github_com_rails_rails_actionpack_test_fixtures_ruby_template_ruby__3648742137162546161_6360' /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/base.rb:282:in 'Kernel#public_send' /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/base.rb:282:in 'ActionView::Base#_run' /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/template.rb:275:in 'block in ActionView::Template#render' /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/notifications.rb:212:in 'ActiveSupport::Notifications.instrument' /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/template.rb:567:in 'ActionView::Template#instrument_render_template' /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/template.rb:263:in 'ActionView::Template#render' /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/renderer/template_renderer.rb:66:in 'block (2 levels) in ActionView::TemplateRenderer#render_template' /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/notifications.rb:212:in 'ActiveSupport::Notifications.instrument' /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/renderer/template_renderer.rb:60:in 'block in ActionView::TemplateRenderer#render_template' /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/renderer/template_renderer.rb:80:in 'ActionView::TemplateRenderer#render_with_layout' /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/renderer/template_renderer.rb:59:in 'ActionView::TemplateRenderer#render_template' /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/renderer/template_renderer.rb:11:in 'ActionView::TemplateRenderer#render' /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/renderer/renderer.rb:58:in 'ActionView::Renderer#render_template_to_object' /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/renderer/renderer.rb:31:in 'ActionView::Renderer#render_to_object' /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/rendering.rb:135:in 'block in ActionView::Rendering#_render_template' /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/base.rb:309:in 'ActionView::Base#in_rendering_context' /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/rendering.rb:134:in 'ActionView::Rendering#_render_template' lib/action_controller/metal/streaming.rb:258:in 'ActionController::Streaming#_render_template' /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/rendering.rb:121:in 'ActionView::Rendering#render_to_body' lib/action_controller/metal/rendering.rb:186:in 'ActionController::Rendering#render_to_body' lib/action_controller/metal/renderers.rb:142:in 'ActionController::Renderers#render_to_body' lib/abstract_controller/rendering.rb:47:in 'AbstractController::Rendering#render_to_string' lib/action_controller/metal/rendering.rb:175:in 'ActionController::Rendering#render_to_string' lib/action_controller/renderer.rb:136:in 'ActionController::Renderer#render' test/controller/renderer_test.rb:37:in 'block in <class:RendererTest>' bin/test test/controller/renderer_test.rb:35 Finished in 0.294798s, 3.3921 runs/s, 0.0000 assertions/s. 1 runs, 0 assertions, 0 failures, 1 errors, 0 skips $ ``` Refer to these Ruby issue and pull request for this change: https://bugs.ruby-lang.org/issues/20205 ruby/ruby#10262 Co-authored-by: Rafael Mendonça França <[email protected]>
…gainst Ruby 3.4.0dev This commit addresses the following Rails Nightly CI error since ruby/ruby#10262 . https://buildkite.com/rails/rails-nightly/builds/310#018e5929-ff70-4397-b978-9a0a03cd4706/1255-1265 - Without this commit: ```ruby $ ruby -v ruby 3.4.0dev (2024-03-19T08:26:49Z master 12be40ae6b) [x86_64-linux] $ cd actionpack $ RAILS_STRICT_WARNINGS=true bin/test test/controller/renderer_test.rb:37 Running 25 tests in a single process (parallelization threshold is 50) Run options: --seed 14013 /home/yahonda/src/github.com/rails/rails/actionpack/test/fixtures/ruby_template.ruby:2: warning: literal string will be frozen in the future E Error: RendererTest#test_rendering_with_a_class_renderer: RuntimeError: Neutered Exception ActionView::Template::Error: /home/yahonda/src/github.com/rails/rails/actionpack/test/fixtures/ruby_template.ruby:2: warning: literal string will be frozen in the future /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/testing/strict_warnings.rb:33:in 'ActiveSupport::RaiseWarnings#warn' test/fixtures/ruby_template.ruby:2:in '_home_yahonda_src_github_com_rails_rails_actionpack_test_fixtures_ruby_template_ruby__3648742137162546161_6360' /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/base.rb:282:in 'Kernel#public_send' /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/base.rb:282:in 'ActionView::Base#_run' /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/template.rb:275:in 'block in ActionView::Template#render' /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/notifications.rb:212:in 'ActiveSupport::Notifications.instrument' /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/template.rb:567:in 'ActionView::Template#instrument_render_template' /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/template.rb:263:in 'ActionView::Template#render' /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/renderer/template_renderer.rb:66:in 'block (2 levels) in ActionView::TemplateRenderer#render_template' /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/notifications.rb:212:in 'ActiveSupport::Notifications.instrument' /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/renderer/template_renderer.rb:60:in 'block in ActionView::TemplateRenderer#render_template' /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/renderer/template_renderer.rb:80:in 'ActionView::TemplateRenderer#render_with_layout' /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/renderer/template_renderer.rb:59:in 'ActionView::TemplateRenderer#render_template' /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/renderer/template_renderer.rb:11:in 'ActionView::TemplateRenderer#render' /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/renderer/renderer.rb:58:in 'ActionView::Renderer#render_template_to_object' /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/renderer/renderer.rb:31:in 'ActionView::Renderer#render_to_object' /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/rendering.rb:135:in 'block in ActionView::Rendering#_render_template' /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/base.rb:309:in 'ActionView::Base#in_rendering_context' /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/rendering.rb:134:in 'ActionView::Rendering#_render_template' lib/action_controller/metal/streaming.rb:258:in 'ActionController::Streaming#_render_template' /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/rendering.rb:121:in 'ActionView::Rendering#render_to_body' lib/action_controller/metal/rendering.rb:186:in 'ActionController::Rendering#render_to_body' lib/action_controller/metal/renderers.rb:142:in 'ActionController::Renderers#render_to_body' lib/abstract_controller/rendering.rb:47:in 'AbstractController::Rendering#render_to_string' lib/action_controller/metal/rendering.rb:175:in 'ActionController::Rendering#render_to_string' lib/action_controller/renderer.rb:136:in 'ActionController::Renderer#render' test/controller/renderer_test.rb:37:in 'block in <class:RendererTest>' bin/test test/controller/renderer_test.rb:35 Finished in 0.294798s, 3.3921 runs/s, 0.0000 assertions/s. 1 runs, 0 assertions, 0 failures, 1 errors, 0 skips $ ``` Refer to these Ruby issue and pull request for this change: https://bugs.ruby-lang.org/issues/20205 ruby/ruby#10262 Co-authored-by: Rafael Mendonça França <[email protected]>
[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 ofenabled/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 toputstring
except it marks the String with theSTR_CHILLED (FL_USER3)
andFL_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.cc @etiennebarrie