Skip to content

Commit 9eab7cc

Browse files
committed
Merge branch 'master' into fixed-opnorm
2 parents 7164f06 + 100e305 commit 9eab7cc

File tree

197 files changed

+3343
-2233
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

197 files changed

+3343
-2233
lines changed

β€ŽCompiler/LICENSE.mdβ€Ž

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
MIT License
2+
3+
Copyright (c) 2009-2024: Jeff Bezanson, Stefan Karpinski, Viral B. Shah, and other contributors: https://github.com/JuliaLang/julia/contributors
4+
5+
Permission is hereby granted, free of charge, to any person obtaining
6+
a copy of this software and associated documentation files (the
7+
"Software"), to deal in the Software without restriction, including
8+
without limitation the rights to use, copy, modify, merge, publish,
9+
distribute, sublicense, and/or sell copies of the Software, and to
10+
permit persons to whom the Software is furnished to do so, subject to
11+
the following conditions:
12+
13+
The above copyright notice and this permission notice shall be
14+
included in all copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23+
24+
end of terms and conditions
25+
26+
Please see [THIRDPARTY.md](../THIRDPARTY.md) for license information for other software used in this project.

β€ŽCompiler/Project.tomlβ€Ž

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
name = "Compiler"
2+
uuid = "807dbc54-b67e-4c79-8afb-eafe4df6f2e1"
3+
version = "0.0.2"
4+
5+
[compat]
6+
julia = "1.10"

β€ŽCompiler/src/Compiler.jlβ€Ž

Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
# This file is a part of Julia. License is MIT: https://julialang.org/license
2+
3+
if isdefined(Base, :end_base_include) && !isdefined(Base, :Compiler)
4+
5+
# Define a dummy `Compiler` module to make it installable even on Julia versions where
6+
# Compiler.jl is not available as a standard library.
7+
@eval module Compiler
8+
function __init__()
9+
println("""
10+
The `Compiler` standard library is not available for this version of Julia.
11+
Use Julia version `v"1.12.0-DEV.1581"` or later.
12+
""")
13+
end
14+
end
15+
16+
# When generating an incremental precompile file, we first check whether we
17+
# already have a copy of this *exact* code in the system image. If so, we
18+
# simply generates a pkgimage that has the dependency edges we recorded in
19+
# the system image and simply returns that copy of the compiler. If not,
20+
# we proceed to load/precompile this as an ordinary package.
21+
elseif (isdefined(Base, :generating_output) && Base.generating_output(true) &&
22+
Base.samefile(joinpath(Sys.BINDIR, Base.DATAROOTDIR, Base._compiler_require_dependencies[1][2]), @eval @__FILE__) &&
23+
!Base.any_includes_stale(
24+
map(Base.compiler_chi, Base._compiler_require_dependencies),
25+
"sysimg", nothing))
26+
27+
Base.prepare_compiler_stub_image!()
28+
append!(Base._require_dependencies, map(Base.expand_compiler_path, Base._compiler_require_dependencies))
29+
# There isn't much point in precompiling native code - downstream users will
30+
# specialize their own versions of the compiler code and we don't activate
31+
# the compiler by default anyway, so let's save ourselves some disk space.
32+
ccall(:jl_suppress_precompile, Cvoid, (Cint,), 1)
33+
34+
else
35+
36+
@eval baremodule Compiler
37+
38+
# Needs to match UUID defined in Project.toml
39+
ccall(:jl_set_module_uuid, Cvoid, (Any, NTuple{2, UInt64}), Compiler,
40+
(0x807dbc54_b67e_4c79, 0x8afb_eafe4df6f2e1))
41+
42+
using Core.Intrinsics, Core.IR
43+
44+
import Core: print, println, show, write, unsafe_write,
45+
_apply_iterate, svec, apply_type, Builtin, IntrinsicFunction,
46+
MethodInstance, CodeInstance, MethodTable, MethodMatch, PartialOpaque,
47+
TypeofVararg, Core, SimpleVector, donotdelete, compilerbarrier,
48+
memoryref_isassigned, memoryrefnew, memoryrefoffset, memoryrefget,
49+
memoryrefset!, typename
50+
51+
using Base
52+
using Base: Ordering, vect, EffectsOverride, BitVector, @_gc_preserve_begin, @_gc_preserve_end, RefValue,
53+
@nospecializeinfer, @_foldable_meta, fieldindex, is_function_def, indexed_iterate, isexpr, methods,
54+
get_world_counter, JLOptions, _methods_by_ftype, unwrap_unionall, cconvert, unsafe_convert,
55+
issingletontype, isType, rewrap_unionall, has_free_typevars, isvarargtype, hasgenerator,
56+
IteratorSize, SizeUnknown, _array_for, Bottom, generating_output, diff_names,
57+
ismutationfree, NUM_EFFECTS_OVERRIDES, _NAMEDTUPLE_NAME, datatype_fieldtypes,
58+
argument_datatype, isfieldatomic, unwrapva, iskindtype, _bits_findnext, copy_exprargs,
59+
Generator, Filter, ismutabletypename, isvatuple, datatype_fieldcount,
60+
isconcretedispatch, isdispatchelem, datatype_layoutsize,
61+
datatype_arrayelem, unionlen, isidentityfree, _uniontypes, uniontypes, OneTo, Callable,
62+
DataTypeFieldDesc, datatype_nfields, datatype_pointerfree, midpoint, is_valid_intrinsic_elptr,
63+
allocatedinline, isbitsunion, widen_diagonal, unconstrain_vararg_length,
64+
rename_unionall, may_invoke_generator, is_meta_expr_head, is_meta_expr, quoted,
65+
specialize_method, hasintersect, is_nospecializeinfer, is_nospecialized,
66+
get_nospecializeinfer_sig, tls_world_age, uniontype_layout, kwerr,
67+
moduleroot, is_file_tracked, decode_effects_override, lookup_binding_partition,
68+
is_some_imported, binding_kind, is_some_guard, is_some_const_binding, partition_restriction,
69+
BINDING_KIND_GLOBAL, structdiff
70+
using Base.Order
71+
import Base: getindex, setindex!, length, iterate, push!, isempty, first, convert, ==,
72+
copy, popfirst!, in, haskey, resize!, copy!, append!, last, get!, size,
73+
get, iterate, findall, min_world, max_world, _topmod, isready
74+
75+
const getproperty = Core.getfield
76+
const setproperty! = Core.setfield!
77+
const swapproperty! = Core.swapfield!
78+
const modifyproperty! = Core.modifyfield!
79+
const replaceproperty! = Core.replacefield!
80+
const _DOCS_ALIASING_WARNING = ""
81+
82+
ccall(:jl_set_istopmod, Cvoid, (Any, Bool), Compiler, false)
83+
84+
eval(x) = Core.eval(Compiler, x)
85+
eval(m, x) = Core.eval(m, x)
86+
87+
function include(x::String)
88+
if !isdefined(Base, :end_base_include)
89+
# During bootstrap, all includes are relative to `base/`
90+
x = Base.strcat(Base.strcat(Base.BUILDROOT, "../usr/share/julia/Compiler/src/"), x)
91+
end
92+
Base.include(Compiler, x)
93+
end
94+
95+
function include(mod::Module, x::String)
96+
if !isdefined(Base, :end_base_include)
97+
x = Base.strcat(Base.strcat(Base.BUILDROOT, "../usr/share/julia/Compiler/src/"), x)
98+
end
99+
Base.include(mod, x)
100+
end
101+
102+
macro _boundscheck() Expr(:boundscheck) end
103+
104+
function return_type end
105+
function is_return_type(Core.@nospecialize(f))
106+
f === return_type && return true
107+
if isdefined(Base, :Compiler) && Compiler !== Base.Compiler
108+
# Also model the return_type function of the builtin Compiler the same.
109+
# This isn't completely sound. We don't actually have any idea what the
110+
# base compiler will do at runtime. In the fullness of time, we should
111+
# re-work the semantics to make the cache primary and thus avoid having
112+
# to reason about what the compiler may do at runtime, but we're not
113+
# fully there yet.
114+
return f === Base.Compiler.return_type
115+
end
116+
return false
117+
end
118+
119+
include("sort.jl")
120+
121+
# We don't include some.jl, but this definition is still useful.
122+
something(x::Nothing, y...) = something(y...)
123+
something(x::Any, y...) = x
124+
125+
############
126+
# compiler #
127+
############
128+
129+
baremodule BuildSettings
130+
using Core: ARGS, include
131+
using ..Compiler: >, getindex, length
132+
133+
global MAX_METHODS::Int = 3
134+
135+
if length(ARGS) > 2 && ARGS[2] === "--buildsettings"
136+
include(BuildSettings, ARGS[3])
137+
end
138+
end
139+
140+
if false
141+
import Base: Base, @show
142+
else
143+
macro show(ex...)
144+
blk = Expr(:block)
145+
for s in ex
146+
push!(blk.args, :(println(stdout, $(QuoteNode(s)), " = ",
147+
begin local value = $(esc(s)) end)))
148+
end
149+
isempty(ex) || push!(blk.args, :value)
150+
blk
151+
end
152+
end
153+
154+
include("cicache.jl")
155+
include("methodtable.jl")
156+
include("effects.jl")
157+
include("types.jl")
158+
include("utilities.jl")
159+
include("validation.jl")
160+
161+
include("ssair/basicblock.jl")
162+
include("ssair/domtree.jl")
163+
include("ssair/ir.jl")
164+
include("ssair/tarjan.jl")
165+
166+
include("abstractlattice.jl")
167+
include("stmtinfo.jl")
168+
include("inferenceresult.jl")
169+
include("inferencestate.jl")
170+
171+
include("typeutils.jl")
172+
include("typelimits.jl")
173+
include("typelattice.jl")
174+
include("tfuncs.jl")
175+
176+
include("abstractinterpretation.jl")
177+
include("typeinfer.jl")
178+
include("optimize.jl")
179+
180+
include("bootstrap.jl")
181+
include("reflection_interface.jl")
182+
183+
module IRShow end
184+
if !isdefined(Base, :end_base_include)
185+
# During bootstrap, skip including this file and defer it to base/show.jl to include later
186+
else
187+
# When this module is loaded as the standard library, include this file as usual
188+
include(IRShow, "ssair/show.jl")
189+
end
190+
191+
end # baremodule Compiler
192+
193+
end # if isdefined(Base, :generating_output) && ...

β€Žbase/compiler/abstractinterpretation.jlβ€Ž renamed to β€ŽCompiler/src/abstractinterpretation.jlβ€Ž

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -207,15 +207,14 @@ function abstract_call_gf_by_type(interp::AbstractInterpreter, @nospecialize(f),
207207
rettype = from_interprocedural!(interp, rettype, sv, arginfo, conditionals)
208208

209209
# Also considering inferring the compilation signature for this method, so
210-
# it is available to the compiler in case it ends up needing it.
210+
# it is available to the compiler, unless it should not end up needing it (for an invoke).
211211
if (isa(sv, InferenceState) && infer_compilation_signature(interp) &&
212-
(seenall && 1 == napplicable) && rettype !== Any && rettype !== Bottom &&
213-
!is_removable_if_unused(all_effects))
212+
(seenall && 1 == napplicable) && (!is_removable_if_unused(all_effects) || !call_result_unused(si)))
214213
(; match) = applicable[1]
215214
method = match.method
216215
sig = match.spec_types
217216
mi = specialize_method(match; preexisting=true)
218-
if mi !== nothing && !const_prop_methodinstance_heuristic(interp, mi, arginfo, sv)
217+
if mi === nothing || !const_prop_methodinstance_heuristic(interp, mi, arginfo, sv)
219218
csig = get_compileable_sig(method, sig, match.sparams)
220219
if csig !== nothing && csig !== sig
221220
abstract_call_method(interp, method, csig, match.sparams, multiple_matches, StmtInfo(false), sv)::Future
@@ -584,14 +583,6 @@ function abstract_call_method(interp::AbstractInterpreter,
584583
if infmi.specTypes::Type == sig::Type
585584
# avoid widening when detecting self-recursion
586585
# TODO: merge call cycle and return right away
587-
if call_result_unused(si)
588-
add_remark!(interp, sv, RECURSION_UNUSED_MSG)
589-
# since we don't use the result (typically),
590-
# we have a self-cycle in the call-graph, but not in the inference graph (typically):
591-
# break this edge now (before we record it) by returning early
592-
# (non-typically, this means that we lose the ability to detect a guaranteed StackOverflow in some cases)
593-
return Future(MethodCallResult(Any, Any, Effects(), nothing, true, true))
594-
end
595586
topmost = nothing
596587
edgecycle = true
597588
break
@@ -2047,7 +2038,7 @@ function abstract_call_builtin(interp::AbstractInterpreter, f::Builtin, (; fargs
20472038
elsetype = rt === Const(true) ? Bottom : widenslotwrapper(aty)
20482039
return Conditional(a, thentype, elsetype)
20492040
end
2050-
elseif f === Core.Compiler.not_int
2041+
elseif f === Core.Intrinsics.not_int
20512042
aty = argtypes[2]
20522043
if isa(aty, Conditional)
20532044
thentype = rt === Const(false) ? Bottom : aty.elsetype
@@ -2119,7 +2110,7 @@ function form_partially_defined_struct(@nospecialize(obj), @nospecialize(name))
21192110
else
21202111
fldidx > nminfld || return nothing
21212112
end
2122-
return PartialStruct(objt0, Any[obj isa PartialStruct && i≀length(obj.fields) ?
2113+
return PartialStruct(fallback_lattice, objt0, Any[obj isa PartialStruct && i≀length(obj.fields) ?
21232114
obj.fields[i] : fieldtype(objt0,i) for i = 1:fldidx])
21242115
end
21252116

@@ -2200,9 +2191,13 @@ function abstract_invoke(interp::AbstractInterpreter, arginfo::ArgInfo, si::Stmt
22002191
env = tienv[2]::SimpleVector
22012192
mresult = abstract_call_method(interp, method, ti, env, false, si, sv)::Future
22022193
match = MethodMatch(ti, env, method, argtype <: method.sig)
2194+
ft_box = Core.Box(ft)
2195+
ftβ€²_box = Core.Box(ftβ€²)
22032196
return Future{CallMeta}(mresult, interp, sv) do result, interp, sv
22042197
(; rt, exct, effects, edge, volatile_inf_result) = result
2205-
res = nothing
2198+
local argtypes = arginfo.argtypes
2199+
local ft = ft_box.contents
2200+
local ftβ€² = ftβ€²_box.contents
22062201
sig = match.spec_types
22072202
argtypesβ€² = invoke_rewrite(argtypes)
22082203
fargs = arginfo.fargs
@@ -2638,6 +2633,14 @@ function abstract_call_opaque_closure(interp::AbstractInterpreter,
26382633
ocsig = rewrap_unionall(Tuple{Tuple, ocargsigβ€².parameters...}, ocargsig)
26392634
hasintersect(sig, ocsig) || return Future(CallMeta(Union{}, Union{MethodError,TypeError}, EFFECTS_THROWS, NoCallInfo()))
26402635
ocmethod = closure.source::Method
2636+
if !isdefined(ocmethod, :source)
2637+
# This opaque closure was created from optimized source. We cannot infer it further.
2638+
ocrt = rewrap_unionall((unwrap_unionall(tt)::DataType).parameters[2], tt)
2639+
if isa(ocrt, DataType)
2640+
return Future(CallMeta(ocrt, Any, Effects(), NoCallInfo()))
2641+
end
2642+
return Future(CallMeta(Any, Any, Effects(), NoCallInfo()))
2643+
end
26412644
match = MethodMatch(sig, Core.svec(), ocmethod, sig <: ocsig)
26422645
mresult = abstract_call_method(interp, ocmethod, sig, Core.svec(), false, si, sv)
26432646
ocsig_box = Core.Box(ocsig)
@@ -2955,7 +2958,7 @@ function abstract_eval_new(interp::AbstractInterpreter, e::Expr, vtypes::Union{V
29552958
# - any refinement information is available (`anyrefine`), or when
29562959
# - `nargs` is greater than `n_initialized` derived from the struct type
29572960
# information alone
2958-
rt = PartialStruct(rt, ats)
2961+
rt = PartialStruct(𝕃ᡒ, rt, ats)
29592962
end
29602963
else
29612964
rt = refine_partial_type(rt)
@@ -2990,7 +2993,7 @@ function abstract_eval_splatnew(interp::AbstractInterpreter, e::Expr, vtypes::Un
29902993
all(i::Int -> βŠ‘(𝕃ᡒ, (at.fields::Vector{Any})[i], fieldtype(t, i)), 1:n)
29912994
end))
29922995
nothrow = isexact
2993-
rt = PartialStruct(rt, at.fields::Vector{Any})
2996+
rt = PartialStruct(𝕃ᡒ, rt, at.fields::Vector{Any})
29942997
end
29952998
else
29962999
rt = refine_partial_type(rt)
@@ -3524,7 +3527,7 @@ end
35243527
end
35253528
fields[i] = a
35263529
end
3527-
anyrefine && return PartialStruct(rt.typ, fields)
3530+
anyrefine && return PartialStruct(𝕃ᡒ, rt.typ, fields)
35283531
end
35293532
if isa(rt, PartialOpaque)
35303533
return rt # XXX: this case was missed in #39512
File renamed without changes.

0 commit comments

Comments
Β (0)