Repository navigation
Return a frozen string from Symbol#to_s (Feature #22137) - #10117
Conversation
|
@zev There's a few of these PRs still in draft and I'm not sure what your intent is. If they're ready to be reviewed and merged, move out of draft and request a review. These are mostly pretty simple things so I assume it was just an oversight. |
27160cc to
1bc2e4f
Compare
zev
left a comment
There was a problem hiding this comment.
Note on the removed members. CRuby removed the chilled Symbol#to_s state entirely in ruby/ruby@2c574ca7e2 (STR_CHILLED_SYMBOL_TO_S is gone), since Symbol#to_s now returns the frozen name string. Nothing sets these anymore, so I removed them too:
StringSupport.CHILLED_SYMBOL_TO_S(public)ObjectFlags.CHILLED_SYMBOL_TO_S_F(public, already@Deprecated(since = "10.0.3.0"))RubyString#chill_symbol_string()(public) andisChilledLiteral()(protected)
@headius if you'd rather keep them for API compatibility, I can restore them as deprecated no-ops instead.
@headius this is ready for review. I had some in draft because I wanted to review the PRs. |
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>
asString went through to_s(getCurrentContext()) and a cast only to return fstring. to_s(Ruby) has no callers left. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Both are public API, so keep them for now (review on jruby#10117). chill_symbol_string() does nothing, since Symbol#to_s no longer returns a chilled String. ObjectFlags.CHILLED_SYMBOL_TO_S_F stays removed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ef8eacb to
5ca55b2
Compare
|
@headius done: On checking the math: I did the next merge-forward locally (current
|
Go ahead and push a PR removing any now-working excludes or tags. Everything mentioned here is merged. |
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