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

1.6 bug: nested string interpolation is broken #40258

Closed
NHDaly opened this issue Mar 29, 2021 · 4 comments · Fixed by #40261
Closed

1.6 bug: nested string interpolation is broken #40258

NHDaly opened this issue Mar 29, 2021 · 4 comments · Fixed by #40261
Labels
compiler:lowering Syntax lowering (compiler front end, 2nd stage) domain:strings "Strings!" kind:bug Indicates an unexpected problem or unintended behavior kind:regression Regression in behavior compared to a previous version

Comments

@NHDaly
Copy link
Member

NHDaly commented Mar 29, 2021

Hello. :) I believe we have encountered a bug in the 1.6 release: nested string interpolation appears to be broken.

Consider this simple example:

julia> VERSION
v"1.6.0"

julia> v = "a $("b $("c")")"
"a b "

julia> length(v)
4

Where the inner nested string is dropped. Compare this with the prior release which produces the correct answer:

julia> VERSION
v"1.5.4"

julia> v = "a $("b $("c")")"
"a b c"

julia> length(v)
5

I am running on macOS:

julia> versioninfo()
Julia Version 1.6.0
Commit f9720dc2eb (2021-03-24 12:55 UTC)
Platform Info:
  OS: macOS (x86_64-apple-darwin19.6.0)
  CPU: Intel(R) Core(TM) i9-8950HK CPU @ 2.90GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-11.0.1 (ORCJIT, skylake)

In case this is relevant, we came across this when a macro that includes string interpolation broke. As a very simple example, consider something like this:

macro pstring(str)
    @info str
    return quote
        println("str1:", $(str))
        println("str2: $($(str))")
    end
end

Interestingly, the @macroexpand is different between 1.5 and 1.6, but as far as I can tell, both are equally valid expansions, so I don't think anything is wrong with the new expansion in 1.6. However, the 1.6 expansion creates nested string interpolation, which doesn't work in 1.6, even though it did work in 1.5:

julia> VERSION
v"1.6.0"

julia> @pstring "hello $("nathan")"
[ Info: "hello $("nathan")"
str1:hello nathan
str2: hello 

julia> @macroexpand @pstring "hello $("nathan")"
[ Info: "hello $("nathan")"
quote
    #= /Users/nathandaly/work/Delve/test/compilation_times/lib.jl:7 =#
    Main.println("str1:", "hello $("nathan")")
    #= /Users/nathandaly/work/Delve/test/compilation_times/lib.jl:8 =#
    Main.println("str2: $("hello $("nathan")")")
end
julia> VERSION
v"1.5.4"

julia> @pstring "hello $("nathan")"
[ Info: "hello nathan"
str1:hello nathan
str2: hello nathan

julia> @macroexpand @pstring "hello $("nathan")"
[ Info: "hello nathan"
quote
    #= /Users/nathandaly/work/Delve/test/compilation_times/lib.jl:7 =#
    Main.println("str1:", "hello nathan")
    #= /Users/nathandaly/work/Delve/test/compilation_times/lib.jl:8 =#
    Main.println("str2: $("hello nathan")")
end
@NHDaly
Copy link
Member Author

NHDaly commented Mar 29, 2021

And just to confirm, the above is all true on master as well:

julia> VERSION
v"1.7.0-DEV.717"

julia> v = "a $("b $("c")")"
"a b "

julia> length(v)
4

julia> macro pstring(str)
           @info str
           return quote
               println("str1:", $(str))
               println("str2: $($(str))")
           end
       end
@pstring (macro with 1 method)

julia> VERSION
v"1.7.0-DEV.717"

julia> @pstring "hello $("nathan")"
[ Info: "hello $("nathan")"
str1:hello nathan
str2: hello

julia> @macroexpand @pstring "hello $("nathan")"
[ Info: "hello $("nathan")"
quote
    #= REPL[4]:4 =#
    Main.println("str1:", "hello $("nathan")")
    #= REPL[4]:5 =#
    Main.println("str2: $("hello $("nathan")")")
end

@simeonschaub simeonschaub added parser Language parsing and surface syntax kind:bug Indicates an unexpected problem or unintended behavior labels Mar 29, 2021
@vtjnash vtjnash added the kind:regression Regression in behavior compared to a previous version label Mar 29, 2021
@NHDaly
Copy link
Member Author

NHDaly commented Mar 29, 2021

added parser bug labels

FWIW I'm not sure if this is indeed related to the parser, since it seems to parse correctly (EDIT: or at least, reasonably), and rather it fails during the eval:

julia> e = Meta.parse(raw""" "str2: $("hello $("nathan")")" """)
:("str2: $("hello $("nathan")")")

julia> dump(e)
Expr
  head: Symbol string
  args: Array{Any}((2,))
    1: String "str2: "
    2: Expr
      head: Symbol string
      args: Array{Any}((2,))
        1: String "hello "
        2: Expr
          head: Symbol string
          args: Array{Any}((1,))
            1: String "nathan"

julia> eval(e)
"str2: hello "

@NHDaly NHDaly added the domain:strings "Strings!" label Mar 29, 2021
@NHDaly
Copy link
Member Author

NHDaly commented Mar 29, 2021

Although I take that back, since it parses differently on 1.5, so the parser might indeed be the problem:

julia> e = Meta.parse(raw""" "str2: $("hello $("nathan")")" """)
:("str2: $("hello nathan")")

julia> dump(e)
Expr
  head: Symbol string
  args: Array{Any}((2,))
    1: String "str2: "
    2: Expr
      head: Symbol string
      args: Array{Any}((2,))
        1: String "hello "
        2: String "nathan"

julia> VERSION
v"1.5.4"

@KristofferC
Copy link
Sponsor Member

KristofferC commented Mar 29, 2021

It is completel gone after lowering:

julia> f() = "a $("b $("c")")"
f (generic function with 1 method)

julia> @code_lowered f()
CodeInfo(
1%1 = Base.string("a ", "b ")
└──      return %1
)

@simeonschaub simeonschaub added compiler:lowering Syntax lowering (compiler front end, 2nd stage) and removed parser Language parsing and surface syntax labels Mar 29, 2021
simeonschaub added a commit that referenced this issue Mar 29, 2021
simeonschaub added a commit that referenced this issue Mar 31, 2021
* fix #40258: nested string interpolation

fixes #40258

* fix interpolation with varargs

* add additional test case

* add additional test cases

Co-authored-by: Nathan Daly <[email protected]>

* keep previous behavior, don't try to be too smart

Co-authored-by: Nathan Daly <[email protected]>
Co-authored-by: Jeff Bezanson <[email protected]>
KristofferC pushed a commit that referenced this issue Apr 4, 2021
* fix #40258: nested string interpolation

fixes #40258

* fix interpolation with varargs

* add additional test case

* add additional test cases

Co-authored-by: Nathan Daly <[email protected]>

* keep previous behavior, don't try to be too smart

Co-authored-by: Nathan Daly <[email protected]>
Co-authored-by: Jeff Bezanson <[email protected]>
(cherry picked from commit 637f52b)
KristofferC pushed a commit that referenced this issue Apr 4, 2021
* fix #40258: nested string interpolation

fixes #40258

* fix interpolation with varargs

* add additional test case

* add additional test cases

Co-authored-by: Nathan Daly <[email protected]>

* keep previous behavior, don't try to be too smart

Co-authored-by: Nathan Daly <[email protected]>
Co-authored-by: Jeff Bezanson <[email protected]>
(cherry picked from commit 637f52b)
KristofferC pushed a commit that referenced this issue Apr 4, 2021
* fix #40258: nested string interpolation

fixes #40258

* fix interpolation with varargs

* add additional test case

* add additional test cases

Co-authored-by: Nathan Daly <[email protected]>

* keep previous behavior, don't try to be too smart

Co-authored-by: Nathan Daly <[email protected]>
Co-authored-by: Jeff Bezanson <[email protected]>
(cherry picked from commit 637f52b)
ElOceanografo pushed a commit to ElOceanografo/julia that referenced this issue May 4, 2021
* fix JuliaLang#40258: nested string interpolation

fixes JuliaLang#40258

* fix interpolation with varargs

* add additional test case

* add additional test cases

Co-authored-by: Nathan Daly <[email protected]>

* keep previous behavior, don't try to be too smart

Co-authored-by: Nathan Daly <[email protected]>
Co-authored-by: Jeff Bezanson <[email protected]>
antoine-levitt pushed a commit to antoine-levitt/julia that referenced this issue May 9, 2021
* fix JuliaLang#40258: nested string interpolation

fixes JuliaLang#40258

* fix interpolation with varargs

* add additional test case

* add additional test cases

Co-authored-by: Nathan Daly <[email protected]>

* keep previous behavior, don't try to be too smart

Co-authored-by: Nathan Daly <[email protected]>
Co-authored-by: Jeff Bezanson <[email protected]>
johanmon pushed a commit to johanmon/julia that referenced this issue Jul 5, 2021
* fix JuliaLang#40258: nested string interpolation

fixes JuliaLang#40258

* fix interpolation with varargs

* add additional test case

* add additional test cases

Co-authored-by: Nathan Daly <[email protected]>

* keep previous behavior, don't try to be too smart

Co-authored-by: Nathan Daly <[email protected]>
Co-authored-by: Jeff Bezanson <[email protected]>
staticfloat pushed a commit that referenced this issue Dec 23, 2022
* fix #40258: nested string interpolation

fixes #40258

* fix interpolation with varargs

* add additional test case

* add additional test cases

Co-authored-by: Nathan Daly <[email protected]>

* keep previous behavior, don't try to be too smart

Co-authored-by: Nathan Daly <[email protected]>
Co-authored-by: Jeff Bezanson <[email protected]>
(cherry picked from commit 637f52b)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler:lowering Syntax lowering (compiler front end, 2nd stage) domain:strings "Strings!" kind:bug Indicates an unexpected problem or unintended behavior kind:regression Regression in behavior compared to a previous version
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants