Skip to content

Commit 46c2708

Browse files
stevengjStefanKarpinski
authored andcommitted
inline string literals in dot calls (#19829)
1 parent 84057ee commit 46c2708

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

src/ast.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,15 +200,14 @@ value_t fl_invoke_julia_macro(fl_context_t *fl_ctx, value_t *args, uint32_t narg
200200
// Check whether v is a scalar for purposes of inlining fused-broadcast
201201
// arguments when lowering; should agree with broadcast.jl on what is a
202202
// scalar. When in doubt, return false, since this is only an optimization.
203-
// (TODO: update after #16966 is resolved.)
204203
value_t fl_julia_scalar(fl_context_t *fl_ctx, value_t *args, uint32_t nargs)
205204
{
206205
argcount(fl_ctx, "julia-scalar?", nargs, 1);
207-
if (fl_isnumber(fl_ctx, args[0]))
206+
if (fl_isnumber(fl_ctx, args[0]) || fl_isstring(fl_ctx, args[0]))
208207
return fl_ctx->T;
209208
else if (iscvalue(args[0]) && fl_ctx->jl_sym == cv_type((cvalue_t*)ptr(args[0]))) {
210209
jl_value_t *v = *(jl_value_t**)cptr(args[0]);
211-
if (jl_subtype(v,(jl_value_t*)jl_number_type,1))
210+
if (jl_subtype(v,(jl_value_t*)jl_number_type,1) || jl_is_string(v))
212211
return fl_ctx->T;
213212
}
214213
return fl_ctx->F;

test/broadcast.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,8 @@ import Base.Meta: isexpr
291291
@test isexpr(expand(:(f.(x,1))), :thunk)
292292
@test isexpr(expand(:(f.(x,1.0))), :thunk)
293293
@test isexpr(expand(:(f.(x,$π))), :thunk)
294+
@test isexpr(expand(:(f.(x,"hello"))), :thunk)
295+
@test isexpr(expand(:(f.(x,$("hello")))), :thunk)
294296

295297
# PR #17623: Fused binary operators
296298
@test [true] .* [true] == [true]
@@ -339,6 +341,9 @@ end
339341
@test broadcast(+, 1.0, (0, -2.0)) == (1.0,-1.0)
340342
@test broadcast(+, 1.0, (0, -2.0), [1]) == [2.0, 0.0]
341343
@test broadcast(*, ["Hello"], ", ", ["World"], "!") == ["Hello, World!"]
344+
let s = "foo"
345+
@test s .* ["bar", "baz"] == ["foobar", "foobaz"] == "foo" .* ["bar", "baz"]
346+
end
342347

343348
# Ensure that even strange constructors that break `T(x)::T` work with broadcast
344349
immutable StrangeType18623 end

test/replcompletions.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,11 +316,14 @@ c, r, res = test_complete(s)
316316
@test length(c) == 1
317317
@test s[r] == "CompletionFoo.test4"
318318

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

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

0 commit comments

Comments
 (0)