Repository navigation
Conversation
Ruby 4.1 makes Symbol#to_s return the symbol's frozen name string, the same object Symbol#name returns, and makes id2name and name aliases of to_s [Feature #22137]. Since strings returned by Symbol#to_s are no longer chilled, the CHILLED_SYMBOL_TO_S flag and its deprecation warning are removed, as in CRuby commit 2c574ca7e2. Chilled string literals are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Ruby 4.1 makes
Symbol#to_sreturn a frozen string (Feature #22137, CRuby commit 2c574ca7e2). It returns the symbol's own name string, the same object asSymbol#name.id2nameandnameare now aliases ofto_s. JRuby still returned a new chilled string that warns when mutated.:a.to_s.frozen?truefalsetrue:a.to_s.equal?(:a.name)truefalsetrue:a.to_s << "b"FrozenError"ab"(deprecation warning with-W:deprecated)FrozenErrorString(:a).frozen?truefalsetrueSymbol.instance_method(:name)#<UnboundMethod: Symbol#name(to_s)()>#<UnboundMethod: Symbol#name()>#<UnboundMethod: Symbol#name(to_s)()>Symbol.instance_method(:id2name) == Symbol.instance_method(:to_s)truefalsetrue"#{:a}".frozen?falsefalsefalseChanges
RubySymbol#to_sreturns the symbol's frozenfstring, andid2nameandnameare declared as its aliases. The Java methodsname(ThreadContext)andid2name(ThreadContext)are kept and delegate toto_s.Symbol#to_sare no longer chilled, so theCHILLED_SYMBOL_TO_Sflag goes away, as it does in CRuby. This removesStringSupport.CHILLED_SYMBOL_TO_S, the deprecated and unusedObjectFlags.CHILLED_SYMBOL_TO_S_F,RubyString#chill_symbol_string(),RubyString#isChilledLiteral()and the "string returned by :x.to_s will be frozen in the future" warning. Chilled string literals work as before.Testing
spec/ruby/core/symbol/to_s_spec.rb,id2name_spec.rb,name_spec.rbandspec/ruby/core/string/chilled_string_spec.rbalready match CRuby. They pass on JRuby (interpreter and JIT), CRuby 4.1-dev and CRuby 4.0.7.spec/tags/ruby/core/symbol/id2name_tags.txt. Its "is an alias of Symbol#to_s" spec now passes. Its other two entries were for specs that no longer exist.spec/ruby/core/symbolandspec/ruby/core/string: the only change from before is that "Symbol#to_s returns a frozen string" now passes.:fasttarget ofspec/jruby.mspec): no new failures.test/mri/ruby/test_symbol.rbandtest_string.rb: no failures, as before.core/src/main/rubyand the tracked files inlib/ruby/stdlib) does not mutate strings returned bySymbol#to_s. I also checked the Java callers ofRubySymbol#to_sandasString(). They only read the string or copy it first.Not in this PR
RubySymbol#to_s(Ruby)andRubySymbol#asString()now return the shared frozen string too, asrb_sym_to_sdoes in CRuby. Java code that writes to theByteListof that result directly, without a frozen check, would change the symbol's name. I found no such caller incore.🤖 Generated with Claude Code