Skip to content

Commit f7e8f92

Browse files
authored
fix annotations on sym_in (#51573)
This seems to be the right combination of annotations to fix both #50562 and an inference regression in PropertyDicts.jl on the 1.10 release branch. When backported the `@noinline` should be restored for 1.10.
1 parent 9fb67c8 commit f7e8f92

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

base/tuple.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -596,15 +596,15 @@ any(x::Tuple{Bool, Bool}) = x[1]|x[2]
596596
any(x::Tuple{Bool, Bool, Bool}) = x[1]|x[2]|x[3]
597597

598598
# a version of `in` esp. for NamedTuple, to make it pure, and not compiled for each tuple length
599-
function sym_in(x::Symbol, @nospecialize itr::Tuple{Vararg{Symbol}})
599+
function sym_in(x::Symbol, itr::Tuple{Vararg{Symbol}})
600600
@noinline
601601
@_total_meta
602602
for y in itr
603603
y === x && return true
604604
end
605605
return false
606606
end
607-
in(x::Symbol, @nospecialize itr::Tuple{Vararg{Symbol}}) = sym_in(x, itr)
607+
in(x::Symbol, itr::Tuple{Vararg{Symbol}}) = sym_in(x, itr)
608608

609609

610610
"""

test/namedtuple.jl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,3 +406,23 @@ let a = Base.NamedTuple{(:a, :b), Tuple{Any, Any}}((1, 2)), b = Base.NamedTuple{
406406
@test typeof(Base.merge(a, b)) == Base.NamedTuple{(:a, :b), Tuple{Any, Float64}}
407407
@test typeof(Base.structdiff(a, b)) == Base.NamedTuple{(:a,), Tuple{Any}}
408408
end
409+
410+
function mergewith51009(combine, a::NamedTuple{an}, b::NamedTuple{bn}) where {an, bn}
411+
names = Base.merge_names(an, bn)
412+
NamedTuple{names}(ntuple(Val{nfields(names)}()) do i
413+
n = getfield(names, i)
414+
if Base.sym_in(n, an)
415+
if Base.sym_in(n, bn)
416+
combine(getfield(a, n), getfield(b, n))
417+
else
418+
getfield(a, n)
419+
end
420+
else
421+
getfield(b, n)
422+
end
423+
end)
424+
end
425+
let c = (a=1, b=2),
426+
d = (b=3, c=(d=1,))
427+
@test @inferred(mergewith51009((x,y)->y, c, d)) === (a = 1, b = 3, c = (d = 1,))
428+
end

test/tuple.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,12 @@ g42457(a, b) = Base.isequal(a, b) ? 1 : 2.0
763763
# issue #46049: setindex(::Tuple) regression
764764
@inferred Base.setindex((1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16), 42, 1)
765765

766+
# issue #50562
767+
f50562(r) = in(:i_backward, r[])
768+
r50562 = Ref((:b_back, :foofakgka, :i_backw))
769+
f50562(r50562)
770+
@test @allocated(f50562(r50562)) == 0
771+
766772
# issue #47326
767773
function fun1_47326(args...)
768774
head..., tail = args

0 commit comments

Comments
 (0)