From dec1d2983df549ee033be59397e5ba1e5bf22351 Mon Sep 17 00:00:00 2001 From: Damien Drix Date: Mon, 16 Nov 2015 15:05:00 +0100 Subject: [PATCH 1/3] fixed issue #12620 --- base/inference.jl | 8 ++++++ test/choosetests.jl | 2 +- test/inline.jl | 67 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 test/inline.jl diff --git a/base/inference.jl b/base/inference.jl index b951af1fd9f81..2dad85228e78b 100644 --- a/base/inference.jl +++ b/base/inference.jl @@ -2013,6 +2013,14 @@ function sym_replace(e::ANY, from1, from2, to1, to2) return SymbolNode(e2, e.typ) end end + if isa(e,NewvarNode) + e2 = _sym_repl(e.name::Symbol, from1, from2, to1, to2, e) + if isa(e2, NewvarNode) || !isa(e2, Symbol) + return e2 + else + return NewvarNode(e2) + end + end if !isa(e,Expr) return e end diff --git a/test/choosetests.jl b/test/choosetests.jl index 10ed270e83200..abe3fa6a9fe11 100644 --- a/test/choosetests.jl +++ b/test/choosetests.jl @@ -32,7 +32,7 @@ function choosetests(choices = []) "nullable", "meta", "profile", "libgit2", "docs", "markdown", "base64", "serialize", "functors", "misc", "threads", "enums", "cmdlineargs", "i18n", "workspace", "libdl", "int", - "intset", "floatfuncs", "compile", "parallel" + "intset", "floatfuncs", "compile", "parallel", "inline" ] if Base.USE_GPL_LIBS diff --git a/test/inline.jl b/test/inline.jl new file mode 100644 index 0000000000000..ebc85eb2c1fcd --- /dev/null +++ b/test/inline.jl @@ -0,0 +1,67 @@ + +using Base.Test + +""" +Helper to walk the AST and call a function on every node. +""" +function walk(func, expr) + func(expr) + if isa(expr, Expr) + func(expr.head) + for o in expr.args + walk(func, o) + end + end +end + +""" +Helper to test that every SymbolNode/NewvarNode has a +corresponding varinfo entry after inlining. +""" +function test_inlined_symbols(func, argtypes) + linfo = code_typed(func, argtypes)[1] + locals = linfo.args[2][1] + local_names = Set([name for (name, typ, flag) in locals]) + ast = linfo.args[3] + walk(ast) do e + if isa(e, NewvarNode) || isa(e, SymbolNode) + @test e.name in local_names + end + end +end + +# Test case 1: +# Make sure that all symbols are properly escaped after inlining +# https://github.com/JuliaLang/julia/issues/12620 +@inline function test_inner(count) + x = 1 + i = 0 + while i <= count + y = x + x = x + y + i += 1 + end +end +function test_outer(a) + test_inner(a) +end +#test_inlined_symbols(test_outer, Tuple{Int64}) + +# Test case 2: +# Make sure that an error is thrown for the undeclared +# y in the else branch. +# https://github.com/JuliaLang/julia/issues/12620 +@inline function foo(x) + if x + y = 2 + else + return y + end +end +function bar() + for i = 1:3 + foo(i==1) + end +end +@test_throws UndefVarError bar() + From 65855b0f526d79325bcd531f4a12da0978ee9fd0 Mon Sep 17 00:00:00 2001 From: Damien Drix Date: Mon, 16 Nov 2015 15:09:40 +0100 Subject: [PATCH 2/3] enabled all tests --- test/inline.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/inline.jl b/test/inline.jl index ebc85eb2c1fcd..fb9fb2e913b30 100644 --- a/test/inline.jl +++ b/test/inline.jl @@ -45,7 +45,7 @@ end function test_outer(a) test_inner(a) end -#test_inlined_symbols(test_outer, Tuple{Int64}) +test_inlined_symbols(test_outer, Tuple{Int64}) # Test case 2: # Make sure that an error is thrown for the undeclared From 5f7f559dd8c85eb56c2a4b0f66e2fc1a5b604bc6 Mon Sep 17 00:00:00 2001 From: Damien Drix Date: Mon, 16 Nov 2015 15:13:10 +0100 Subject: [PATCH 3/3] fixed trailing whitespace --- test/inline.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/inline.jl b/test/inline.jl index fb9fb2e913b30..aaeb86002c103 100644 --- a/test/inline.jl +++ b/test/inline.jl @@ -59,7 +59,7 @@ test_inlined_symbols(test_outer, Tuple{Int64}) end end function bar() - for i = 1:3 + for i = 1:3 foo(i==1) end end