Skip to content

Commit eb44451

Browse files
authored
Merge branch 'master' into rationalize_irrational
2 parents 7609e3c + 79ce168 commit eb44451

File tree

32 files changed

+420
-202
lines changed

32 files changed

+420
-202
lines changed

Compiler/src/ssair/passes.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1511,6 +1511,10 @@ function sroa_pass!(ir::IRCode, inlining::Union{Nothing,InliningState}=nothing)
15111511
used_ssas[x.id] -= 1
15121512
end
15131513
ir = complete(compact)
1514+
# remove any use that has been optimized away by the DCE
1515+
for (intermediaries, defuse) in values(defuses)
1516+
filter!(x -> ir[SSAValue(x.idx)][:stmt] !== nothing, defuse.uses)
1517+
end
15141518
sroa_mutables!(ir, defuses, used_ssas, lazydomtree, inlining)
15151519
return ir
15161520
else

Compiler/src/tfuncs.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2454,6 +2454,9 @@ const _SPECIAL_BUILTINS = Any[
24542454
Core._apply_iterate,
24552455
]
24562456

2457+
# Types compatible with fpext/fptrunc
2458+
const CORE_FLOAT_TYPES = Union{Core.BFloat16, Float16, Float32, Float64}
2459+
24572460
function isdefined_effects(𝕃::AbstractLattice, argtypes::Vector{Any})
24582461
# consistent if the first arg is immutable
24592462
na = length(argtypes)
@@ -2867,6 +2870,17 @@ function intrinsic_exct(𝕃::AbstractLattice, f::IntrinsicFunction, argtypes::V
28672870
if !(isprimitivetype(ty) && isprimitivetype(xty))
28682871
return ErrorException
28692872
end
2873+
2874+
# fpext and fptrunc have further restrictions on the allowed types.
2875+
if f === Intrinsics.fpext &&
2876+
!(ty <: CORE_FLOAT_TYPES && xty <: CORE_FLOAT_TYPES && Core.sizeof(ty) > Core.sizeof(xty))
2877+
return ErrorException
2878+
end
2879+
if f === Intrinsics.fptrunc &&
2880+
!(ty <: CORE_FLOAT_TYPES && xty <: CORE_FLOAT_TYPES && Core.sizeof(ty) < Core.sizeof(xty))
2881+
return ErrorException
2882+
end
2883+
28702884
return Union{}
28712885
end
28722886

Compiler/test/effects.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1384,3 +1384,14 @@ end |> Compiler.is_nothrow
13841384
@test Base.infer_effects() do
13851385
@ccall unsafecall()::Cvoid
13861386
end == Compiler.EFFECTS_UNKNOWN
1387+
1388+
# fpext
1389+
@test Compiler.intrinsic_nothrow(Core.Intrinsics.fpext, Any[Type{Float32}, Float16])
1390+
@test Compiler.intrinsic_nothrow(Core.Intrinsics.fpext, Any[Type{Float64}, Float16])
1391+
@test Compiler.intrinsic_nothrow(Core.Intrinsics.fpext, Any[Type{Float64}, Float32])
1392+
@test !Compiler.intrinsic_nothrow(Core.Intrinsics.fpext, Any[Type{Float16}, Float16])
1393+
@test !Compiler.intrinsic_nothrow(Core.Intrinsics.fpext, Any[Type{Float16}, Float32])
1394+
@test !Compiler.intrinsic_nothrow(Core.Intrinsics.fpext, Any[Type{Float32}, Float32])
1395+
@test !Compiler.intrinsic_nothrow(Core.Intrinsics.fpext, Any[Type{Float32}, Float64])
1396+
@test !Compiler.intrinsic_nothrow(Core.Intrinsics.fpext, Any[Type{Int32}, Float16])
1397+
@test !Compiler.intrinsic_nothrow(Core.Intrinsics.fpext, Any[Type{Float32}, Int16])

Compiler/test/irpasses.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2030,3 +2030,15 @@ let code = Any[
20302030
ir = Compiler.domsort_ssa!(ir, domtree)
20312031
Compiler.verify_ir(ir)
20322032
end
2033+
2034+
# https://github.com/JuliaLang/julia/issues/57141
2035+
# don't eliminate `setfield!` when the field is to be used
2036+
let src = code_typed1(()) do
2037+
ref = Ref{Any}()
2038+
ref[] = 0
2039+
@assert isdefined(ref, :x)
2040+
inner() = ref[] + 1
2041+
(inner(), ref[])
2042+
end
2043+
@test count(iscall((src, setfield!)), src.code) == 1
2044+
end

NEWS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Language changes
5656
behavior. Infinite loops that actually do things (e.g. have side effects
5757
or sleep) were never and are still not undefined behavior. ([#52999])
5858

59-
- It is now an error to mark a symbol as both `public` and `export`ed.
59+
- It is now an error to mark a binding as both `public` and `export`ed.
6060
([#53664])
6161

6262
Compiler/Runtime improvements

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.12.0-DEV
1+
1.13.0-DEV

base/Base_compiler.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,13 +234,13 @@ include("abstractarray.jl")
234234
include("baseext.jl")
235235

236236
include("c.jl")
237-
include("ntuple.jl")
238237
include("abstractset.jl")
239238
include("bitarray.jl")
240239
include("bitset.jl")
241240
include("abstractdict.jl")
242241
include("iddict.jl")
243242
include("idset.jl")
243+
include("ntuple.jl")
244244
include("iterators.jl")
245245
using .Iterators: zip, enumerate, only
246246
using .Iterators: Flatten, Filter, product # for generators

base/boot.jl

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -777,27 +777,6 @@ struct GeneratedFunctionStub
777777
spnames::SimpleVector
778778
end
779779

780-
# invoke and wrap the results of @generated expression
781-
function (g::GeneratedFunctionStub)(world::UInt, source::LineNumberNode, @nospecialize args...)
782-
# args is (spvals..., argtypes...)
783-
body = g.gen(args...)
784-
file = source.file
785-
file isa Symbol || (file = :none)
786-
lam = Expr(:lambda, Expr(:argnames, g.argnames...).args,
787-
Expr(:var"scope-block",
788-
Expr(:block,
789-
source,
790-
Expr(:meta, :push_loc, file, :var"@generated body"),
791-
Expr(:return, body),
792-
Expr(:meta, :pop_loc))))
793-
spnames = g.spnames
794-
if spnames === svec()
795-
return lam
796-
else
797-
return Expr(Symbol("with-static-parameters"), lam, spnames...)
798-
end
799-
end
800-
801780
# If the generator is a subtype of this trait, inference caches the generated unoptimized
802781
# code, sacrificing memory space to improve the performance of subsequent inferences.
803782
# This tradeoff is not appropriate in general cases (e.g., for `GeneratedFunctionStub`s

base/expr.jl

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1654,3 +1654,46 @@ end
16541654
function quoted(@nospecialize(x))
16551655
return is_self_quoting(x) ? x : QuoteNode(x)
16561656
end
1657+
1658+
# Implementation of generated functions
1659+
function generated_body_to_codeinfo(ex::Expr, defmod::Module, isva::Bool)
1660+
ci = ccall(:jl_expand, Any, (Any, Any), ex, defmod)
1661+
if !isa(ci, CodeInfo)
1662+
if isa(ci, Expr) && ci.head === :error
1663+
error("syntax: $(ci.args[1])")
1664+
end
1665+
error("The function body AST defined by this @generated function is not pure. This likely means it contains a closure, a comprehension or a generator.")
1666+
end
1667+
ci.isva = isva
1668+
code = ci.code
1669+
bindings = IdSet{Core.Binding}()
1670+
for i = 1:length(code)
1671+
stmt = code[i]
1672+
if isa(stmt, GlobalRef)
1673+
push!(bindings, convert(Core.Binding, stmt))
1674+
end
1675+
end
1676+
if !isempty(bindings)
1677+
ci.edges = Core.svec(bindings...)
1678+
end
1679+
return ci
1680+
end
1681+
1682+
# invoke and wrap the results of @generated expression
1683+
function (g::Core.GeneratedFunctionStub)(world::UInt, source::Method, @nospecialize args...)
1684+
# args is (spvals..., argtypes...)
1685+
body = g.gen(args...)
1686+
file = source.file
1687+
file isa Symbol || (file = :none)
1688+
lam = Expr(:lambda, Expr(:argnames, g.argnames...).args,
1689+
Expr(:var"scope-block",
1690+
Expr(:block,
1691+
LineNumberNode(Int(source.line), source.file),
1692+
Expr(:meta, :push_loc, file, :var"@generated body"),
1693+
Expr(:return, body),
1694+
Expr(:meta, :pop_loc))))
1695+
spnames = g.spnames
1696+
return generated_body_to_codeinfo(spnames === Core.svec() ? lam : Expr(Symbol("with-static-parameters"), lam, spnames...),
1697+
typename(typeof(g.gen)).module,
1698+
source.isva)
1699+
end

base/invalidation.jl

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -93,26 +93,28 @@ function scan_edge_list(ci::Core.CodeInstance, binding::Core.Binding)
9393
end
9494

9595
function invalidate_method_for_globalref!(gr::GlobalRef, method::Method, invalidated_bpart::Core.BindingPartition, new_max_world::UInt)
96+
invalidate_all = false
97+
binding = convert(Core.Binding, gr)
9698
if isdefined(method, :source)
9799
src = _uncompressed_ir(method)
98-
binding = convert(Core.Binding, gr)
99100
old_stmts = src.code
100101
invalidate_all = should_invalidate_code_for_globalref(gr, src)
101-
for mi in specializations(method)
102-
isdefined(mi, :cache) || continue
103-
ci = mi.cache
104-
while true
105-
if ci.max_world > new_max_world && (invalidate_all || scan_edge_list(ci, binding))
106-
ccall(:jl_invalidate_code_instance, Cvoid, (Any, UInt), ci, new_max_world)
107-
end
108-
isdefined(ci, :next) || break
109-
ci = ci.next
102+
end
103+
for mi in specializations(method)
104+
isdefined(mi, :cache) || continue
105+
ci = mi.cache
106+
while true
107+
if ci.max_world > new_max_world && (invalidate_all || scan_edge_list(ci, binding))
108+
ccall(:jl_invalidate_code_instance, Cvoid, (Any, UInt), ci, new_max_world)
110109
end
110+
isdefined(ci, :next) || break
111+
ci = ci.next
111112
end
112113
end
113114
end
114115

115116
function invalidate_code_for_globalref!(gr::GlobalRef, invalidated_bpart::Core.BindingPartition, new_max_world::UInt)
117+
b = convert(Core.Binding, gr)
116118
try
117119
valid_in_valuepos = false
118120
foreach_module_mtable(gr.mod, new_max_world) do mt::Core.MethodTable

0 commit comments

Comments
 (0)