|
| 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 | +using Core: ABIOverride, Builtin, CodeInstance, IntrinsicFunction, MethodInstance, MethodMatch, |
| 45 | + MethodTable, PartialOpaque, SimpleVector, TypeofVararg, |
| 46 | + _apply_iterate, apply_type, compilerbarrier, donotdelete, memoryref_isassigned, |
| 47 | + memoryrefget, memoryrefnew, memoryrefoffset, memoryrefset!, print, println, show, svec, |
| 48 | + typename, unsafe_write, write |
| 49 | + |
| 50 | +using Base |
| 51 | +using Base: @_foldable_meta, @_gc_preserve_begin, @_gc_preserve_end, @nospecializeinfer, |
| 52 | + BINDING_KIND_GLOBAL, BINDING_KIND_UNDEF_CONST, BINDING_KIND_BACKDATED_CONST, |
| 53 | + Base, BitVector, Bottom, Callable, DataTypeFieldDesc, |
| 54 | + EffectsOverride, Filter, Generator, IteratorSize, JLOptions, NUM_EFFECTS_OVERRIDES, |
| 55 | + OneTo, Ordering, RefValue, SizeUnknown, _NAMEDTUPLE_NAME, |
| 56 | + _array_for, _bits_findnext, _methods_by_ftype, _uniontypes, all, allocatedinline, any, |
| 57 | + argument_datatype, binding_kind, cconvert, copy_exprargs, datatype_arrayelem, |
| 58 | + datatype_fieldcount, datatype_fieldtypes, datatype_layoutsize, datatype_nfields, |
| 59 | + datatype_pointerfree, decode_effects_override, diff_names, fieldindex, |
| 60 | + generating_output, get_nospecializeinfer_sig, get_world_counter, has_free_typevars, |
| 61 | + hasgenerator, hasintersect, indexed_iterate, isType, is_file_tracked, is_function_def, |
| 62 | + is_meta_expr, is_meta_expr_head, is_nospecialized, is_nospecializeinfer, is_defined_const_binding, |
| 63 | + is_some_const_binding, is_some_guard, is_some_imported, is_valid_intrinsic_elptr, |
| 64 | + isbitsunion, isconcretedispatch, isdispatchelem, isexpr, isfieldatomic, isidentityfree, |
| 65 | + iskindtype, ismutabletypename, ismutationfree, issingletontype, isvarargtype, isvatuple, |
| 66 | + kwerr, lookup_binding_partition, may_invoke_generator, methods, midpoint, moduleroot, |
| 67 | + partition_restriction, quoted, rename_unionall, rewrap_unionall, specialize_method, |
| 68 | + structdiff, tls_world_age, unconstrain_vararg_length, unionlen, uniontype_layout, |
| 69 | + uniontypes, unsafe_convert, unwrap_unionall, unwrapva, vect, widen_diagonal, |
| 70 | + _uncompressed_ir |
| 71 | +using Base.Order |
| 72 | + |
| 73 | +import Base: ==, _topmod, append!, convert, copy, copy!, findall, first, get, get!, |
| 74 | + getindex, haskey, in, isempty, isready, iterate, iterate, last, length, max_world, |
| 75 | + min_world, popfirst!, push!, resize!, setindex!, size |
| 76 | + |
| 77 | +const getproperty = Core.getfield |
| 78 | +const setproperty! = Core.setfield! |
| 79 | +const swapproperty! = Core.swapfield! |
| 80 | +const modifyproperty! = Core.modifyfield! |
| 81 | +const replaceproperty! = Core.replacefield! |
| 82 | +const _DOCS_ALIASING_WARNING = "" |
| 83 | + |
| 84 | +ccall(:jl_set_istopmod, Cvoid, (Any, Bool), Compiler, false) |
| 85 | + |
| 86 | +eval(x) = Core.eval(Compiler, x) |
| 87 | +eval(m, x) = Core.eval(m, x) |
| 88 | + |
| 89 | +function include(x::String) |
| 90 | + if !isdefined(Base, :end_base_include) |
| 91 | + # During bootstrap, all includes are relative to `base/` |
| 92 | + x = Base.strcat(Base.strcat(Base.DATAROOT, "julia/Compiler/src/"), x) |
| 93 | + end |
| 94 | + Base.include(Compiler, x) |
| 95 | +end |
| 96 | + |
| 97 | +function include(mod::Module, x::String) |
| 98 | + if !isdefined(Base, :end_base_include) |
| 99 | + x = Base.strcat(Base.strcat(Base.DATAROOT, "julia/Compiler/src/"), x) |
| 100 | + end |
| 101 | + Base.include(mod, x) |
| 102 | +end |
| 103 | + |
| 104 | +macro _boundscheck() Expr(:boundscheck) end |
| 105 | + |
| 106 | +function return_type end |
| 107 | +function is_return_type(Core.@nospecialize(f)) |
| 108 | + f === return_type && return true |
| 109 | + if isdefined(Base, :Compiler) && Compiler !== Base.Compiler |
| 110 | + # Also model the return_type function of the builtin Compiler the same. |
| 111 | + # This isn't completely sound. We don't actually have any idea what the |
| 112 | + # base compiler will do at runtime. In the fullness of time, we should |
| 113 | + # re-work the semantics to make the cache primary and thus avoid having |
| 114 | + # to reason about what the compiler may do at runtime, but we're not |
| 115 | + # fully there yet. |
| 116 | + return f === Base.Compiler.return_type |
| 117 | + end |
| 118 | + return false |
| 119 | +end |
| 120 | + |
| 121 | +include("sort.jl") |
| 122 | + |
| 123 | +# We don't include some.jl, but this definition is still useful. |
| 124 | +something(x::Nothing, y...) = something(y...) |
| 125 | +something(x::Any, y...) = x |
| 126 | + |
| 127 | +############ |
| 128 | +# compiler # |
| 129 | +############ |
| 130 | + |
| 131 | +baremodule BuildSettings |
| 132 | +using Core: ARGS, include |
| 133 | +using ..Compiler: >, getindex, length |
| 134 | + |
| 135 | +global MAX_METHODS::Int = 3 |
| 136 | + |
| 137 | +if length(ARGS) > 2 && ARGS[2] === "--buildsettings" |
| 138 | + include(BuildSettings, ARGS[3]) |
| 139 | +end |
| 140 | +end |
| 141 | + |
| 142 | +if !isdefined(Base, :end_base_include) |
| 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 | +else |
| 153 | + using Base: @show |
| 154 | +end |
| 155 | + |
| 156 | +include("cicache.jl") |
| 157 | +include("methodtable.jl") |
| 158 | +include("effects.jl") |
| 159 | +include("types.jl") |
| 160 | +include("utilities.jl") |
| 161 | +include("validation.jl") |
| 162 | + |
| 163 | +include("ssair/basicblock.jl") |
| 164 | +include("ssair/domtree.jl") |
| 165 | +include("ssair/ir.jl") |
| 166 | +include("ssair/tarjan.jl") |
| 167 | + |
| 168 | +include("abstractlattice.jl") |
| 169 | +include("stmtinfo.jl") |
| 170 | +include("inferenceresult.jl") |
| 171 | +include("inferencestate.jl") |
| 172 | + |
| 173 | +include("typeutils.jl") |
| 174 | +include("typelimits.jl") |
| 175 | +include("typelattice.jl") |
| 176 | +include("tfuncs.jl") |
| 177 | + |
| 178 | +include("abstractinterpretation.jl") |
| 179 | +include("typeinfer.jl") |
| 180 | +include("optimize.jl") |
| 181 | + |
| 182 | +include("bootstrap.jl") |
| 183 | +include("reflection_interface.jl") |
| 184 | +include("opaque_closure.jl") |
| 185 | + |
| 186 | +macro __SOURCE_FILE__() |
| 187 | + __source__.file === nothing && return nothing |
| 188 | + return QuoteNode(__source__.file::Symbol) |
| 189 | +end |
| 190 | + |
| 191 | +module IRShow end |
| 192 | +function load_irshow!() |
| 193 | + if isdefined(Base, :end_base_include) |
| 194 | + # This code path is exclusively for Revise, which may want to re-run this |
| 195 | + # after bootstrap. |
| 196 | + include(IRShow, Base.joinpath(Base.dirname(Base.String(@__SOURCE_FILE__)), "ssair/show.jl")) |
| 197 | + else |
| 198 | + include(IRShow, "ssair/show.jl") |
| 199 | + end |
| 200 | +end |
| 201 | +if !isdefined(Base, :end_base_include) |
| 202 | + # During bootstrap, skip including this file and defer it to base/show.jl to include later |
| 203 | +else |
| 204 | + # When this module is loaded as the standard library, include this file as usual |
| 205 | + load_irshow!() |
| 206 | +end |
| 207 | + |
| 208 | +end # baremodule Compiler |
| 209 | + |
| 210 | +end # if isdefined(Base, :generating_output) && ... |
0 commit comments