Skip to content
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

eval in Rack::Builder prints "warning: `frozen_string_literal' is ignored after any tokens" #5128

Closed
perlun opened this issue Apr 4, 2018 · 2 comments

Comments

@perlun
Copy link
Contributor

perlun commented Apr 4, 2018

Environment

  • JRuby version: 9.1.16.0
  • Operating system and platform: Darwin ecvaawplun6.local 17.4.0 Darwin Kernel Version 17.4.0: Sun Dec 17 09:19:54 PST 2017; root:xnu-4570.41.2~1/RELEASE_X86_64 x86_64 i386 MacBookPro14,3 Darwin

Expected Behavior

When using this config.ru:

# frozen_string_literal: true

run Proc.new { |env| ['200', {'Content-Type' => 'text/html'}, ['get rack\'d']] }

I should be able to run rackup without any warnings.

Actual Behavior

With JRuby, I get a warning; with MRI 2.5.1 (and 2.3.6) I do not:

$ rackup
/Users/plundberg/.rvm/gems/jruby-9.1.16.0/gems/rack-2.0.4/lib/rack/builder.rb:49: warning: `frozen_string_literal' is ignored after any tokens
Puma starting in single mode...
* Version 3.11.3 (jruby 9.1.16.0 - ruby 2.3.3), codename: Love Song
* Min threads: 0, max threads: 16
* Environment: development
* Listening on tcp://localhost:9292
Use Ctrl-C to stop
^C- Gracefully stopping, waiting for requests to finish
=== puma shutdown: 2018-04-04 10:59:46 +0300 ===
- Goodbye!
$ rvm use 2.5.1
Using /Users/plundberg/.rvm/gems/ruby-2.5.1
$ rackup
Puma starting in single mode...
* Version 3.11.3 (ruby 2.5.1-p57), codename: Love Song
* Min threads: 0, max threads: 16
* Environment: development
* Listening on tcp://localhost:9292
Use Ctrl-C to stop
^C- Gracefully stopping, waiting for requests to finish
=== puma shutdown: 2018-04-04 11:00:04 +0300 ===
- Goodbye!

I analyzed this down to https://github.com/rack/rack/blob/master/lib/rack/builder.rb#L49, where the failing code looks like this:

    def self.new_from_string(builder_script, file="(rackup)")
      eval "Rack::Builder.new {\n" + builder_script + "\n}.to_app",
        TOPLEVEL_BINDING, file, 0
    end

So it seems, JRuby prints this warning if it encounters a frozen_string_literal comment in the middle of an eval statement, whereas MRI does not.


I wonder how MRI actually handles the frozen_string_literal setting in that case - does it use unfrozen string literals for the code before that comment, and frozen string literals for anything that comes after it?

Anyway, this is a semantic difference between MRI and JRuby that deserves to be documented, and potentially discussed.

@enebo
Copy link
Member

enebo commented Apr 4, 2018

@perlun We did not intend to not match MRI here so this is a bug. I am guessing they probably pass the frozen string lteral state to any evals which lexically occur with the source file or perhaps the strings somehow get annotated somehow on that first parse as being frozen.

@perlun
Copy link
Contributor Author

perlun commented Apr 9, 2018

@enebo OK, great to get that confirmed. Let me know if you want some more help from me in nailing this one down.

@enebo enebo added this to the JRuby 9.1.17.0 milestone Apr 17, 2018
enebo added a commit that referenced this issue Apr 19, 2018
…ral' is ignored after any tokens".

Silliest of the silly inverted logic.
@enebo enebo closed this as completed Apr 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants