Skip to content

Commit

Permalink
inline string literals in dot calls (#19829)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevengj authored and StefanKarpinski committed Jan 12, 2017
1 parent 84057ee commit 46c2708
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
5 changes: 2 additions & 3 deletions src/ast.c
Original file line number Diff line number Diff line change
Expand Up @@ -200,15 +200,14 @@ value_t fl_invoke_julia_macro(fl_context_t *fl_ctx, value_t *args, uint32_t narg
// Check whether v is a scalar for purposes of inlining fused-broadcast
// arguments when lowering; should agree with broadcast.jl on what is a
// scalar. When in doubt, return false, since this is only an optimization.
// (TODO: update after #16966 is resolved.)
value_t fl_julia_scalar(fl_context_t *fl_ctx, value_t *args, uint32_t nargs)
{
argcount(fl_ctx, "julia-scalar?", nargs, 1);
if (fl_isnumber(fl_ctx, args[0]))
if (fl_isnumber(fl_ctx, args[0]) || fl_isstring(fl_ctx, args[0]))
return fl_ctx->T;
else if (iscvalue(args[0]) && fl_ctx->jl_sym == cv_type((cvalue_t*)ptr(args[0]))) {
jl_value_t *v = *(jl_value_t**)cptr(args[0]);
if (jl_subtype(v,(jl_value_t*)jl_number_type,1))
if (jl_subtype(v,(jl_value_t*)jl_number_type,1) || jl_is_string(v))
return fl_ctx->T;
}
return fl_ctx->F;
Expand Down
5 changes: 5 additions & 0 deletions test/broadcast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,8 @@ import Base.Meta: isexpr
@test isexpr(expand(:(f.(x,1))), :thunk)
@test isexpr(expand(:(f.(x,1.0))), :thunk)
@test isexpr(expand(:(f.(x,$π))), :thunk)
@test isexpr(expand(:(f.(x,"hello"))), :thunk)
@test isexpr(expand(:(f.(x,$("hello")))), :thunk)

# PR #17623: Fused binary operators
@test [true] .* [true] == [true]
Expand Down Expand Up @@ -339,6 +341,9 @@ end
@test broadcast(+, 1.0, (0, -2.0)) == (1.0,-1.0)
@test broadcast(+, 1.0, (0, -2.0), [1]) == [2.0, 0.0]
@test broadcast(*, ["Hello"], ", ", ["World"], "!") == ["Hello, World!"]
let s = "foo"
@test s .* ["bar", "baz"] == ["foobar", "foobaz"] == "foo" .* ["bar", "baz"]
end

# Ensure that even strange constructors that break `T(x)::T` work with broadcast
immutable StrangeType18623 end
Expand Down
7 changes: 5 additions & 2 deletions test/replcompletions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -316,11 +316,14 @@ c, r, res = test_complete(s)
@test length(c) == 1
@test s[r] == "CompletionFoo.test4"

# (As discussed in #19829, the Base.REPLCompletions.get_type function isn't
# powerful enough to analyze general dot calls because it can't handle
# anonymous-function evaluation.)
s = "CompletionFoo.test5(push!(Base.split(\"\",' '),\"\",\"\").==\"\","
c, r, res = test_complete(s)
@test !res
@test length(c) == 1
@test c[1] == string(first(methods(Main.CompletionFoo.test5, Tuple{BitArray{1}})))
@test_broken length(c) == 1
@test_broken c[1] == string(first(methods(Main.CompletionFoo.test5, Tuple{BitArray{1}})))

s = "CompletionFoo.test4(CompletionFoo.test_y_array[1]()[1], CompletionFoo.test_y_array[1]()[2], "
c, r, res = test_complete(s)
Expand Down

0 comments on commit 46c2708

Please sign in to comment.