From: sam.saffron@... Date: 2018-02-14T22:27:51+00:00 Subject: [ruby-core:85560] [Ruby trunk Bug#14475] String de-duplication is broken in files with frozen_string_literal: true Issue #14475 has been updated by sam.saffron (Sam Saffron). "If the string is frozen, then return the string itself." Yeah I do not agree with this documentation, I think it should be changed. Trouble is that there is no simple way to de-duplicate unconditionally without either inefficiency or side effects: Say `x` is an arbitrary string (either frozen or unfrozen) : ``` x = -x # may return a non fstring x = -+x # will return fstring, but makes an unneeded copy x = -x.dup # fstring again, uneeded copy x = x.frozen? ? -+x : -x # too verbose ``` Instead why not change it so `-` deduped unconditionally? ---------------------------------------- Bug #14475: String de-duplication is broken in files with frozen_string_literal: true https://bugs.ruby-lang.org/issues/14475#change-70352 * Author: sam.saffron (Sam Saffron) * Status: Open * Priority: Normal * Assignee: * Target version: * ruby -v: 2.5.0, 2.6.0 * Backport: 2.3: UNKNOWN, 2.4: UNKNOWN, 2.5: UNKNOWN ---------------------------------------- Create 2 files: test.rb ``` $LOAD_PATH.unshift(File.dirname(__FILE__)) require 'frozen' puts frozen.object_id puts frozen.object_id ``` frozen.rb ``` # frozen_string_literal: true A = "a" def frozen -"#{A}" end ``` Run `test.rb` ``` % ruby test.rb 70189973179400 70189973179260 ``` Change to `# frozen_string_literal: false` And you get ``` 70189973181360 70189973181360 ``` So something is over-optimising here, fix should be backported to 2.5.0 imo. -- https://bugs.ruby-lang.org/ Unsubscribe: