|
| 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.DATAROOT, "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.DATAROOT, "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 !isdefined(Base, :end_base_include) |
| 141 | + macro show(ex...) |
| 142 | + blk = Expr(:block) |
| 143 | + for s in ex |
| 144 | + push!(blk.args, :(println(stdout, $(QuoteNode(s)), " = ", |
| 145 | + begin local value = $(esc(s)) end))) |
| 146 | + end |
| 147 | + isempty(ex) || push!(blk.args, :value) |
| 148 | + blk |
| 149 | + end |
| 150 | +else |
| 151 | + using Base: @show |
| 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 | +include("opaque_closure.jl") |
| 183 | + |
| 184 | +module IRShow end |
| 185 | +if !isdefined(Base, :end_base_include) |
| 186 | + # During bootstrap, skip including this file and defer it to base/show.jl to include later |
| 187 | +else |
| 188 | + # When this module is loaded as the standard library, include this file as usual |
| 189 | + include(IRShow, "ssair/show.jl") |
| 190 | +end |
| 191 | + |
| 192 | +end # baremodule Compiler |
| 193 | + |
| 194 | +end # if isdefined(Base, :generating_output) && ... |
0 commit comments