Skip to content

Commit 985dfa5

Browse files
authored
Prevent TOML invalidation by pirates of T[elements...] (#39252)
StaticArrays (perhaps among others) semi-pirates this method, although they've worked hard to make it pretty innocuous. Still, there are times when it invalidates the TOML-reading, so best to protect this.
1 parent 344f72e commit 985dfa5

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

base/toml_parser.jl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -657,13 +657,20 @@ end
657657
#########
658658

659659
function push!!(v::Vector, el)
660+
# Since these types are typically non-inferrable, they are a big invalidation risk,
661+
# and since it's used by the package-loading infrastructure the cost of invalidation
662+
# is high. Therefore, this is written to reduce the "exposed surface area": e.g., rather
663+
# than writing `T[el]` we write it as `push!(Vector{T}(undef, 1), el)` so that there
664+
# is no ambiguity about what types of objects will be created.
660665
T = eltype(v)
661666
t = typeof(el)
662667
if el isa T || t === T
663668
push!(v, el::T)
664669
return v
665670
elseif T === Union{}
666-
return t[el]
671+
out = Vector{t}(undef, 1)
672+
out[1] = el
673+
return out
667674
else
668675
if typeof(T) === Union
669676
newT = Any

0 commit comments

Comments
 (0)