Skip to content

Commit

Permalink
release-1.10: Backports for 1.10-alpha2 (#50508)
Browse files Browse the repository at this point in the history
Backported PRs:
- [x] #50411 <!-- Fix weird dispatch of * with zero arguments -->
- [x] #50202 <!-- Remove dynamic dispatch from _wait/wait2 -->
- [x] #50064 <!-- Fix numbered prompt with input only with comment -->
- [x] #50026 <!-- Store heapsnapshot files in tempdir() instead of
current directory -->
- [x] #50402 <!-- Add CPU feature helper function -->
- [x] #50387 <!-- update newpages pointer after actually sweeping pages
-->
- [x] #50424 <!-- avoid potential type-instability in _replace_(str,
...) -->
- [x] #50444 <!-- Optimize getfield lowering to avoid boxing in some
cases -->
- [x] #50474 <!-- docs: Fix a `!!! note` which was miscapitalized -->
- [x] #50466 <!-- relax assertion involving pg->nold to reflect that it
may be a bit in… -->
- [x] #50490 <!-- Fix compat annotation for italic printstyled -->
- [x] #50488 <!-- fix typo in `Base.isassigned` with `Tridiagonal` -->
- [x] #50476 <!-- Profile: Add specifying dir for `take_heap_snapshot`
and handling if current dir is unwritable -->
- [x] #50461 <!-- fix typo in the --gcthreads argument description -->
- [x] #50528 <!-- ssair: Correctly handle stmt insertion at end of basic
block -->
- [x] #50533 <!-- ensure internal_obj_base_ptr checks whether objects
past freelist pointer are in freelist -->
- [x] #49322 <!-- improve cat design / performance -->
- [x] #50540 <!-- gc: remove over-eager assertion -->
- [x] #50542 <!-- gf: remove unnecessary assert cycle==depth -->
- [x] #50559 <!-- Expand kwcall lowering positional default check to
vararg -->
- [x] #50058 <!-- Add unwrapping mechanism for triangular mul and solves
-->
- [x] #50551 <!-- typeintersect: also record chained `innervars` -->
- [x] #50552 <!-- read(io, Char): fix read with too many leading ones
-->
- [x] #50541 <!-- precompile: ensure globals are not accidentally
created where disallowed -->
- [x] #50576 <!-- use atomic compare exchange when setting the GC
mark-bit -->
- [x] #50578 <!-- gf: make method overwrite/delete an error during
precompile -->
- [x] #50516 <!-- Fix visibility of assert on GCC12/13 -->
- [x] #50597 <!-- Fix memory corruption if task is launched inside
finalizer -->
- [x] #50591 <!-- build: fix various makefile bugs -->
- [x] #50599 <!-- faster invalid object lookup in conservative gc -->
- [x] #50634 <!-- 🤖 [master] Bump the SparseArrays stdlib from b4b0e72
to 99c99b4 -->
- [x] #50639 <!-- Backport LLVM patches to fix various issues. -->
- [x] #50546 <!-- Revert storage of method instance in LineInfoNode -->
- [x] #50631 <!-- Shift DCE pass to optimize imaging mode code better
-->
- [x] #50525 <!-- only check that values are finite in `generic_lufact`
when `check=true` -->
- [x] #50587 <!-- isassigned for ranges with BigInt indices -->
- [x] #50144 <!-- Page based heap size heuristics -->


Need manual backport:
- [ ] #50595 <!-- Rename ENV variable `JULIA_USE_NEW_PARSER` ->
`JULIA_USE_FLISP_PARSER` -->



Non-merged PRs with backport label:
- [ ] #50637 <!-- Remove SparseArrays legacy code -->
- [ ] #50618 <!-- inference: continue const-prop' when concrete-eval
returns non-inlineable -->
- [ ] #50598 <!-- only limit types in stack traces in the REPL -->
- [ ] #50594 <!-- Disallow non-index Integer types in isassigned -->
- [ ] #50568 <!-- `Array(::AbstractRange)` should return an `Array` -->
- [ ] #50523 <!-- Avoid generic call in most cases for getproperty -->
- [ ] #50172 <!-- print feature flags used for matching pkgimage -->
  • Loading branch information
KristofferC authored Jul 24, 2023
2 parents bda3e09 + 152f0e9 commit f9b2614
Show file tree
Hide file tree
Showing 100 changed files with 2,039 additions and 1,486 deletions.
6 changes: 3 additions & 3 deletions Make.inc
Original file line number Diff line number Diff line change
Expand Up @@ -603,15 +603,15 @@ endif

ifeq ($(OS),WINNT)
define versioned_libname
$$(if $(2),$(1)-$(2).$(SHLIB_EXT),$(1).$(SHLIB_EXT))
$(if $(2),$(1)-$(2).$(SHLIB_EXT),$(1).$(SHLIB_EXT))
endef
else ifeq ($(OS),Darwin)
define versioned_libname
$$(if $(2),$(1).$(2).$(SHLIB_EXT),$(1).$(SHLIB_EXT))
$(if $(2),$(1).$(2).$(SHLIB_EXT),$(1).$(SHLIB_EXT))
endef
else
define versioned_libname
$$(if $(2),$(1).$(SHLIB_EXT).$(2),$(1).$(SHLIB_EXT))
$(if $(2),$(1).$(SHLIB_EXT).$(2),$(1).$(SHLIB_EXT))
endef
endif

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ else ifeq ($(JULIA_BUILD_MODE),debug)
JL_PRIVATE_LIBS-0 += libjulia-internal-debug libjulia-codegen-debug
endif
ifeq ($(USE_GPL_LIBS), 1)
JL_PRIVATE_LIBS-$(USE_SYSTEM_LIBSUITESPARSE) += libamd libbtf libcamd libccolamd libcholmod libcolamd libklu libldl librbio libspqr libsuitesparseconfig libumfpack
JL_PRIVATE_LIBS-$(USE_SYSTEM_LIBSUITESPARSE) += libamd libbtf libcamd libccolamd libcholmod libcholmod_cuda libcolamd libklu libldl librbio libspqr libspqr_cuda libsuitesparseconfig libumfpack
endif
JL_PRIVATE_LIBS-$(USE_SYSTEM_LIBBLASTRAMPOLINE) += libblastrampoline
JL_PRIVATE_LIBS-$(USE_SYSTEM_PCRE) += libpcre2-8
Expand Down
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Language changes

Compiler/Runtime improvements
-----------------------------
* Updated GC heuristics to count allocated pages instead of individual objects ([#50144]).

* The `@pure` macro is now deprecated. Use `Base.@assume_effects :foldable` instead ([#48682]).
* The mark phase of the Garbage Collector is now multi-threaded ([#48600]).
Expand Down Expand Up @@ -67,6 +68,8 @@ New library features
* A `CartesianIndex` is now treated as a "scalar" for broadcasting ([#47044]).
* `printstyled` now supports italic output ([#45164]).
* `parent` and `parentindices` support `SubString`s
* `replace(string, pattern...)` now supports an optional `IO` argument to
write the output to a stream rather than returning a string ([#48625]).

Standard library changes
------------------------
Expand Down
2 changes: 2 additions & 0 deletions base/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -269,9 +269,11 @@ $(eval $(call symlink_system_library,LIBSUITESPARSE,libamd))
$(eval $(call symlink_system_library,LIBSUITESPARSE,libcamd))
$(eval $(call symlink_system_library,LIBSUITESPARSE,libccolamd))
$(eval $(call symlink_system_library,LIBSUITESPARSE,libcholmod))
$(eval $(call symlink_system_library,LIBSUITESPARSE,libcholmod_cuda))
$(eval $(call symlink_system_library,LIBSUITESPARSE,libcolamd))
$(eval $(call symlink_system_library,LIBSUITESPARSE,libumfpack))
$(eval $(call symlink_system_library,LIBSUITESPARSE,libspqr))
$(eval $(call symlink_system_library,LIBSUITESPARSE,libspqr_cuda))
$(eval $(call symlink_system_library,LIBSUITESPARSE,libsuitesparseconfig))
# EXCLUDED LIBRARIES (installed/used, but not vendored for use with dlopen):
# libunwind
Expand Down
50 changes: 24 additions & 26 deletions base/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1651,7 +1651,7 @@ function _typed_hcat(::Type{T}, A::AbstractVecOrTuple{AbstractVecOrMat}) where T
for j = 1:nargs
Aj = A[j]
if size(Aj, 1) != nrows
throw(ArgumentError("number of rows of each array must match (got $(map(x->size(x,1), A)))"))
throw(DimensionMismatch("number of rows of each array must match (got $(map(x->size(x,1), A)))"))
end
dense &= isa(Aj,Array)
nd = ndims(Aj)
Expand Down Expand Up @@ -1686,7 +1686,7 @@ function _typed_vcat(::Type{T}, A::AbstractVecOrTuple{AbstractVecOrMat}) where T
ncols = size(A[1], 2)
for j = 2:nargs
if size(A[j], 2) != ncols
throw(ArgumentError("number of columns of each array must match (got $(map(x->size(x,2), A)))"))
throw(DimensionMismatch("number of columns of each array must match (got $(map(x->size(x,2), A)))"))
end
end
B = similar(A[1], T, nrows, ncols)
Expand Down Expand Up @@ -1984,16 +1984,14 @@ julia> cat(1, [2], [3;;]; dims=Val(2))

# The specializations for 1 and 2 inputs are important
# especially when running with --inline=no, see #11158
# The specializations for Union{AbstractVecOrMat,Number} are necessary
# to have more specialized methods here than in LinearAlgebra/uniformscaling.jl
vcat(A::AbstractArray) = cat(A; dims=Val(1))
vcat(A::AbstractArray, B::AbstractArray) = cat(A, B; dims=Val(1))
vcat(A::AbstractArray...) = cat(A...; dims=Val(1))
vcat(A::Union{AbstractVecOrMat,Number}...) = cat(A...; dims=Val(1))
vcat(A::Union{AbstractArray,Number}...) = cat(A...; dims=Val(1))
hcat(A::AbstractArray) = cat(A; dims=Val(2))
hcat(A::AbstractArray, B::AbstractArray) = cat(A, B; dims=Val(2))
hcat(A::AbstractArray...) = cat(A...; dims=Val(2))
hcat(A::Union{AbstractVecOrMat,Number}...) = cat(A...; dims=Val(2))
hcat(A::Union{AbstractArray,Number}...) = cat(A...; dims=Val(2))

typed_vcat(T::Type, A::AbstractArray) = _cat_t(Val(1), T, A)
typed_vcat(T::Type, A::AbstractArray, B::AbstractArray) = _cat_t(Val(1), T, A, B)
Expand Down Expand Up @@ -2055,8 +2053,8 @@ julia> hvcat((2,2,2), a,b,c,d,e,f) == hvcat(2, a,b,c,d,e,f)
true
```
"""
hvcat(rows::Tuple{Vararg{Int}}, xs::AbstractVecOrMat...) = typed_hvcat(promote_eltype(xs...), rows, xs...)
hvcat(rows::Tuple{Vararg{Int}}, xs::AbstractVecOrMat{T}...) where {T} = typed_hvcat(T, rows, xs...)
hvcat(rows::Tuple{Vararg{Int}}, xs::AbstractArray...) = typed_hvcat(promote_eltype(xs...), rows, xs...)
hvcat(rows::Tuple{Vararg{Int}}, xs::AbstractArray{T}...) where {T} = typed_hvcat(T, rows, xs...)

function typed_hvcat(::Type{T}, rows::Tuple{Vararg{Int}}, as::AbstractVecOrMat...) where T
nbr = length(rows) # number of block rows
Expand Down Expand Up @@ -2084,16 +2082,16 @@ function typed_hvcat(::Type{T}, rows::Tuple{Vararg{Int}}, as::AbstractVecOrMat..
Aj = as[a+j-1]
szj = size(Aj,2)
if size(Aj,1) != szi
throw(ArgumentError("mismatched height in block row $(i) (expected $szi, got $(size(Aj,1)))"))
throw(DimensionMismatch("mismatched height in block row $(i) (expected $szi, got $(size(Aj,1)))"))
end
if c-1+szj > nc
throw(ArgumentError("block row $(i) has mismatched number of columns (expected $nc, got $(c-1+szj))"))
throw(DimensionMismatch("block row $(i) has mismatched number of columns (expected $nc, got $(c-1+szj))"))
end
out[r:r-1+szi, c:c-1+szj] = Aj
c += szj
end
if c != nc+1
throw(ArgumentError("block row $(i) has mismatched number of columns (expected $nc, got $(c-1))"))
throw(DimensionMismatch("block row $(i) has mismatched number of columns (expected $nc, got $(c-1))"))
end
r += szi
a += rows[i]
Expand All @@ -2115,7 +2113,7 @@ function hvcat(rows::Tuple{Vararg{Int}}, xs::T...) where T<:Number
k = 1
@inbounds for i=1:nr
if nc != rows[i]
throw(ArgumentError("row $(i) has mismatched number of columns (expected $nc, got $(rows[i]))"))
throw(DimensionMismatch("row $(i) has mismatched number of columns (expected $nc, got $(rows[i]))"))
end
for j=1:nc
a[i,j] = xs[k]
Expand Down Expand Up @@ -2144,14 +2142,14 @@ end
hvcat(rows::Tuple{Vararg{Int}}, xs::Number...) = typed_hvcat(promote_typeof(xs...), rows, xs...)
hvcat(rows::Tuple{Vararg{Int}}, xs...) = typed_hvcat(promote_eltypeof(xs...), rows, xs...)
# the following method is needed to provide a more specific one compared to LinearAlgebra/uniformscaling.jl
hvcat(rows::Tuple{Vararg{Int}}, xs::Union{AbstractVecOrMat,Number}...) = typed_hvcat(promote_eltypeof(xs...), rows, xs...)
hvcat(rows::Tuple{Vararg{Int}}, xs::Union{AbstractArray,Number}...) = typed_hvcat(promote_eltypeof(xs...), rows, xs...)

function typed_hvcat(::Type{T}, rows::Tuple{Vararg{Int}}, xs::Number...) where T
nr = length(rows)
nc = rows[1]
for i = 2:nr
if nc != rows[i]
throw(ArgumentError("row $(i) has mismatched number of columns (expected $nc, got $(rows[i]))"))
throw(DimensionMismatch("row $(i) has mismatched number of columns (expected $nc, got $(rows[i]))"))
end
end
hvcat_fill!(Matrix{T}(undef, nr, nc), xs)
Expand Down Expand Up @@ -2319,7 +2317,7 @@ function _typed_hvncat(::Type{T}, ::Val{N}, as::AbstractArray...) where {T, N}
Ndim += cat_size(as[i], N)
nd = max(nd, cat_ndims(as[i]))
for d 1:N - 1
cat_size(as[1], d) == cat_size(as[i], d) || throw(ArgumentError("mismatched size along axis $d in element $i"))
cat_size(as[1], d) == cat_size(as[i], d) || throw(DimensionMismatch("mismatched size along axis $d in element $i"))
end
end

Expand All @@ -2346,7 +2344,7 @@ function _typed_hvncat(::Type{T}, ::Val{N}, as...) where {T, N}
nd = max(nd, cat_ndims(as[i]))
for d 1:N-1
cat_size(as[i], d) == 1 ||
throw(ArgumentError("all dimensions of element $i other than $N must be of length 1"))
throw(DimensionMismatch("all dimensions of element $i other than $N must be of length 1"))
end
end

Expand Down Expand Up @@ -2463,7 +2461,7 @@ function _typed_hvncat_dims(::Type{T}, dims::NTuple{N, Int}, row_first::Bool, as
for dd 1:N
dd == d && continue
if cat_size(as[startelementi], dd) != cat_size(as[i], dd)
throw(ArgumentError("incompatible shape in element $i"))
throw(DimensionMismatch("incompatible shape in element $i"))
end
end
end
Expand Down Expand Up @@ -2500,18 +2498,18 @@ function _typed_hvncat_dims(::Type{T}, dims::NTuple{N, Int}, row_first::Bool, as
elseif currentdims[d] < outdims[d] # dimension in progress
break
else # exceeded dimension
throw(ArgumentError("argument $i has too many elements along axis $d"))
throw(DimensionMismatch("argument $i has too many elements along axis $d"))
end
end
end
elseif currentdims[d1] > outdims[d1] # exceeded dimension
throw(ArgumentError("argument $i has too many elements along axis $d1"))
throw(DimensionMismatch("argument $i has too many elements along axis $d1"))
end
end

outlen = prod(outdims)
elementcount == outlen ||
throw(ArgumentError("mismatched number of elements; expected $(outlen), got $(elementcount)"))
throw(DimensionMismatch("mismatched number of elements; expected $(outlen), got $(elementcount)"))

# copy into final array
A = cat_similar(as[1], T, outdims)
Expand Down Expand Up @@ -2572,8 +2570,8 @@ function _typed_hvncat_shape(::Type{T}, shape::NTuple{N, Tuple}, row_first, as::
if d == 1 || i == 1 || wasstartblock
currentdims[d] += dsize
elseif dsize != cat_size(as[i - 1], ad)
throw(ArgumentError("argument $i has a mismatched number of elements along axis $ad; \
expected $(cat_size(as[i - 1], ad)), got $dsize"))
throw(DimensionMismatch("argument $i has a mismatched number of elements along axis $ad; \
expected $(cat_size(as[i - 1], ad)), got $dsize"))
end

wasstartblock = blockcounts[d] == 1 # remember for next dimension
Expand All @@ -2583,15 +2581,15 @@ function _typed_hvncat_shape(::Type{T}, shape::NTuple{N, Tuple}, row_first, as::
if outdims[d] == -1
outdims[d] = currentdims[d]
elseif outdims[d] != currentdims[d]
throw(ArgumentError("argument $i has a mismatched number of elements along axis $ad; \
expected $(abs(outdims[d] - (currentdims[d] - dsize))), got $dsize"))
throw(DimensionMismatch("argument $i has a mismatched number of elements along axis $ad; \
expected $(abs(outdims[d] - (currentdims[d] - dsize))), got $dsize"))
end
currentdims[d] = 0
blockcounts[d] = 0
shapepos[d] += 1
d > 1 && (blockcounts[d - 1] == 0 ||
throw(ArgumentError("shape in level $d is inconsistent; level counts must nest \
evenly into each other")))
throw(DimensionMismatch("shape in level $d is inconsistent; level counts must nest \
evenly into each other")))
end
end
end
Expand Down
12 changes: 0 additions & 12 deletions base/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2041,18 +2041,6 @@ function vcat(arrays::Vector{T}...) where T
end
vcat(A::Vector...) = cat(A...; dims=Val(1)) # more special than SparseArrays's vcat

# disambiguation with LinAlg/special.jl
# Union{Number,Vector,Matrix} is for LinearAlgebra._DenseConcatGroup
# VecOrMat{T} is for LinearAlgebra._TypedDenseConcatGroup
hcat(A::Union{Number,Vector,Matrix}...) = cat(A...; dims=Val(2))
hcat(A::VecOrMat{T}...) where {T} = typed_hcat(T, A...)
vcat(A::Union{Number,Vector,Matrix}...) = cat(A...; dims=Val(1))
vcat(A::VecOrMat{T}...) where {T} = typed_vcat(T, A...)
hvcat(rows::Tuple{Vararg{Int}}, xs::Union{Number,Vector,Matrix}...) =
typed_hvcat(promote_eltypeof(xs...), rows, xs...)
hvcat(rows::Tuple{Vararg{Int}}, xs::VecOrMat{T}...) where {T} =
typed_hvcat(T, rows, xs...)

_cat(n::Integer, x::Integer...) = reshape([x...], (ntuple(Returns(1), n-1)..., length(x)))

## find ##
Expand Down
4 changes: 2 additions & 2 deletions base/compiler/ssair/inlining.jl
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ function ir_inline_linetable!(linetable::Vector{LineInfoNode}, inlinee_ir::IRCod
# Append the linetable of the inlined function to our line table
topline::Int32 = linetable_offset + Int32(1)
coverage_by_path = JLOptions().code_coverage == 3
push!(linetable, LineInfoNode(inlinee_def.module, inlinee, inlinee_def.file, inlinee_def.line, inlined_at))
push!(linetable, LineInfoNode(inlinee_def.module, inlinee_def.name, inlinee_def.file, inlinee_def.line, inlined_at))
oldlinetable = inlinee_ir.linetable
extra_coverage_line = zero(Int32)
for oldline in eachindex(oldlinetable)
Expand Down Expand Up @@ -1817,7 +1817,7 @@ end

function insert_spval!(insert_node!::Inserter, spvals_ssa::SSAValue, spidx::Int, do_isdefined::Bool)
ret = insert_node!(
effect_free_and_nothrow(NewInstruction(Expr(:call, Core._svec_ref, false, spvals_ssa, spidx), Any)))
effect_free_and_nothrow(NewInstruction(Expr(:call, Core._svec_ref, spvals_ssa, spidx), Any)))
tcheck_not = nothing
if do_isdefined
tcheck = insert_node!(
Expand Down
22 changes: 16 additions & 6 deletions base/compiler/ssair/ir.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1508,10 +1508,20 @@ function finish_current_bb!(compact::IncrementalCompact, active_bb::Int,
return skipped
end

function attach_after_stmt_after(compact::IncrementalCompact, idx::Int)
compact.new_nodes_idx > length(compact.perm) && return false
entry = compact.ir.new_nodes.info[compact.perm[compact.new_nodes_idx]]
return entry.pos == idx && entry.attach_after
"""
stmts_awaiting_insertion(compact::IncrementalCompact, idx::Int)
Returns true if there are new/pending instructions enqueued for insertion into
`compact` on any instruction in the range `1:idx`. Otherwise, returns false.
"""
function stmts_awaiting_insertion(compact::IncrementalCompact, idx::Int)

new_node_waiting = compact.new_nodes_idx <= length(compact.perm) &&
compact.ir.new_nodes.info[compact.perm[compact.new_nodes_idx]].pos <= idx
pending_node_waiting = !isempty(compact.pending_perm) &&
compact.pending_nodes.info[compact.pending_perm[1]].pos <= idx

return new_node_waiting || pending_node_waiting
end

function process_newnode!(compact::IncrementalCompact, new_idx::Int, new_node_entry::Instruction, new_node_info::NewNodeInfo, idx::Int, active_bb::Int, do_rename_ssa::Bool)
Expand All @@ -1523,7 +1533,7 @@ function process_newnode!(compact::IncrementalCompact, new_idx::Int, new_node_en
compact.result_idx = result_idx
# If this instruction has reverse affinity and we were at the end of a basic block,
# finish it now.
if new_node_info.attach_after && idx == last(bb.stmts)+1 && !attach_after_stmt_after(compact, idx-1)
if new_node_info.attach_after && idx == last(bb.stmts)+1 && !stmts_awaiting_insertion(compact, idx-1)
active_bb += 1
finish_current_bb!(compact, active_bb, old_result_idx)
end
Expand Down Expand Up @@ -1653,7 +1663,7 @@ function iterate_compact(compact::IncrementalCompact)
compact.result[old_result_idx] = compact.ir.stmts[idx]
result_idx = process_node!(compact, old_result_idx, compact.ir.stmts[idx], idx, idx, active_bb, true)
compact.result_idx = result_idx
if idx == last(bb.stmts) && !attach_after_stmt_after(compact, idx)
if idx == last(bb.stmts) && !stmts_awaiting_insertion(compact, idx)
finish_current_bb!(compact, active_bb, old_result_idx)
active_bb += 1
end
Expand Down
6 changes: 3 additions & 3 deletions base/compiler/ssair/passes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -810,10 +810,10 @@ function perform_lifting!(compact::IncrementalCompact,
end

function lift_svec_ref!(compact::IncrementalCompact, idx::Int, stmt::Expr)
length(stmt.args) != 4 && return
length(stmt.args) != 3 && return

vec = stmt.args[3]
val = stmt.args[4]
vec = stmt.args[2]
val = stmt.args[3]
valT = argextype(val, compact)
(isa(valT, Const) && isa(valT.val, Int)) || return
valI = valT.val::Int
Expand Down
2 changes: 1 addition & 1 deletion base/compiler/typeinfer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1015,7 +1015,7 @@ function typeinf_ext(interp::AbstractInterpreter, mi::MethodInstance)
tree.slotflags = fill(IR_FLAG_NULL, nargs)
tree.ssavaluetypes = 1
tree.codelocs = Int32[1]
tree.linetable = LineInfoNode[LineInfoNode(method.module, mi, method.file, method.line, Int32(0))]
tree.linetable = LineInfoNode[LineInfoNode(method.module, method.name, method.file, method.line, Int32(0))]
tree.ssaflags = UInt8[0]
set_inlineable!(tree, true)
tree.parent = mi
Expand Down
34 changes: 27 additions & 7 deletions base/essentials.jl
Original file line number Diff line number Diff line change
Expand Up @@ -543,21 +543,41 @@ unsafe_convert(::Type{T}, x::T) where {T<:Ptr} = x # to resolve ambiguity with
unsafe_convert(::Type{P}, x::Ptr) where {P<:Ptr} = convert(P, x)

"""
reinterpret(type, x)
reinterpret(::Type{Out}, x::In)
Change the type-interpretation of the binary data in the primitive value `x`
to that of the primitive type `type`.
The size of `type` has to be the same as that of the type of `x`.
Change the type-interpretation of the binary data in the isbits value `x`
to that of the isbits type `Out`.
The size (ignoring padding) of `Out` has to be the same as that of the type of `x`.
For example, `reinterpret(Float32, UInt32(7))` interprets the 4 bytes corresponding to `UInt32(7)` as a
[`Float32`](@ref).
# Examples
```jldoctest
julia> reinterpret(Float32, UInt32(7))
1.0f-44
julia> reinterpret(NTuple{2, UInt8}, 0x1234)
(0x34, 0x12)
julia> reinterpret(UInt16, (0x34, 0x12))
0x1234
julia> reinterpret(Tuple{UInt16, UInt8}, (0x01, 0x0203))
(0x0301, 0x02)
```
!!! warning
Use caution if some combinations of bits in `Out` are not considered valid and would
otherwise be prevented by the type's constructors and methods. Unexpected behavior
may result without additional validation.
"""
reinterpret(::Type{T}, x) where {T} = bitcast(T, x)
function reinterpret(Out::Type, x::In) where {In}
if isprimitivetype(Out) && isprimitivetype(In)
return bitcast(Out, x)
end
# only available when Base is fully loaded.
return _reinterpret(Out, x)
end

"""
sizeof(T::DataType)
Expand Down Expand Up @@ -741,7 +761,7 @@ end

# SimpleVector

@eval getindex(v::SimpleVector, i::Int) = (@_foldable_meta; Core._svec_ref($(Expr(:boundscheck)), v, i))
getindex(v::SimpleVector, i::Int) = (@_foldable_meta; Core._svec_ref(v, i))
function length(v::SimpleVector)
@_total_meta
t = @_gc_preserve_begin v
Expand Down
Loading

0 comments on commit f9b2614

Please sign in to comment.