| Line | Exclusive | Inclusive | Code |
|---|---|---|---|
| 1 | # This file is a part of Julia. License is MIT: https://julialang.org/license | ||
| 2 | |||
| 3 | # commented-out definitions are implemented in C | ||
| 4 | |||
| 5 | #abstract type Any <: Any end | ||
| 6 | #abstract type Type{T} end | ||
| 7 | |||
| 8 | #abstract type Vararg{T} end | ||
| 9 | |||
| 10 | #mutable struct Symbol | ||
| 11 | # #opaque | ||
| 12 | #end | ||
| 13 | |||
| 14 | #mutable struct TypeName | ||
| 15 | # name::Symbol | ||
| 16 | #end | ||
| 17 | |||
| 18 | #mutable struct DataType <: Type | ||
| 19 | # name::TypeName | ||
| 20 | # super::Type | ||
| 21 | # parameters::Tuple | ||
| 22 | # names::Tuple | ||
| 23 | # types::Tuple | ||
| 24 | # ctor | ||
| 25 | # instance | ||
| 26 | # size::Int32 | ||
| 27 | # abstract::Bool | ||
| 28 | # mutable::Bool | ||
| 29 | # pointerfree::Bool | ||
| 30 | #end | ||
| 31 | |||
| 32 | #struct Union <: Type | ||
| 33 | # a | ||
| 34 | # b | ||
| 35 | #end | ||
| 36 | |||
| 37 | #mutable struct TypeVar | ||
| 38 | # name::Symbol | ||
| 39 | # lb::Type | ||
| 40 | # ub::Type | ||
| 41 | #end | ||
| 42 | |||
| 43 | #struct UnionAll | ||
| 44 | # var::TypeVar | ||
| 45 | # body | ||
| 46 | #end | ||
| 47 | |||
| 48 | #struct Nothing | ||
| 49 | #end | ||
| 50 | #const nothing = Nothing() | ||
| 51 | |||
| 52 | #abstract type AbstractArray{T,N} end | ||
| 53 | #abstract type DenseArray{T,N} <: AbstractArray{T,N} end | ||
| 54 | |||
| 55 | #mutable struct Array{T,N} <: DenseArray{T,N} | ||
| 56 | #end | ||
| 57 | |||
| 58 | #mutable struct Module | ||
| 59 | # name::Symbol | ||
| 60 | #end | ||
| 61 | |||
| 62 | #mutable struct Method | ||
| 63 | #end | ||
| 64 | |||
| 65 | #mutable struct MethodInstance | ||
| 66 | #end | ||
| 67 | |||
| 68 | #mutable struct CodeInstance | ||
| 69 | #end | ||
| 70 | |||
| 71 | #mutable struct CodeInfo | ||
| 72 | #end | ||
| 73 | |||
| 74 | #mutable struct TypeMapLevel | ||
| 75 | #end | ||
| 76 | |||
| 77 | #mutable struct TypeMapEntry | ||
| 78 | #end | ||
| 79 | |||
| 80 | #abstract type Ref{T} end | ||
| 81 | #primitive type Ptr{T} <: Ref{T} {32|64} end | ||
| 82 | |||
| 83 | # types for the front end | ||
| 84 | |||
| 85 | #mutable struct Expr | ||
| 86 | # head::Symbol | ||
| 87 | # args::Array{Any,1} | ||
| 88 | #end | ||
| 89 | |||
| 90 | #struct LineNumberNode | ||
| 91 | # line::Int | ||
| 92 | # file::Union{Symbol,Nothing} | ||
| 93 | #end | ||
| 94 | |||
| 95 | #struct LineInfoNode | ||
| 96 | # method::Any | ||
| 97 | # file::Symbol | ||
| 98 | # line::Int | ||
| 99 | # inlined_at::Int | ||
| 100 | #end | ||
| 101 | |||
| 102 | #struct GotoNode | ||
| 103 | # label::Int | ||
| 104 | #end | ||
| 105 | |||
| 106 | #struct PiNode | ||
| 107 | # val | ||
| 108 | # typ | ||
| 109 | #end | ||
| 110 | |||
| 111 | #struct PhiNode | ||
| 112 | # edges::Vector{Any} | ||
| 113 | # values::Vector{Any} | ||
| 114 | #end | ||
| 115 | |||
| 116 | #struct PhiCNode | ||
| 117 | # values::Vector{Any} | ||
| 118 | #end | ||
| 119 | |||
| 120 | #struct UpsilonNode | ||
| 121 | # val | ||
| 122 | #end | ||
| 123 | |||
| 124 | #struct QuoteNode | ||
| 125 | # value | ||
| 126 | #end | ||
| 127 | |||
| 128 | #struct GlobalRef | ||
| 129 | # mod::Module | ||
| 130 | # name::Symbol | ||
| 131 | #end | ||
| 132 | |||
| 133 | #mutable struct Task | ||
| 134 | # parent::Task | ||
| 135 | # storage::Any | ||
| 136 | # state::Symbol | ||
| 137 | # donenotify::Any | ||
| 138 | # result::Any | ||
| 139 | # exception::Any | ||
| 140 | # backtrace::Any | ||
| 141 | # logstate::Any | ||
| 142 | # code::Any | ||
| 143 | #end | ||
| 144 | |||
| 145 | export | ||
| 146 | # key types | ||
| 147 | Any, DataType, Vararg, NTuple, | ||
| 148 | Tuple, Type, UnionAll, TypeVar, Union, Nothing, Cvoid, | ||
| 149 | AbstractArray, DenseArray, NamedTuple, | ||
| 150 | # special objects | ||
| 151 | Function, Method, | ||
| 152 | Module, Symbol, Task, Array, UndefInitializer, undef, WeakRef, VecElement, | ||
| 153 | # numeric types | ||
| 154 | Number, Real, Integer, Bool, Ref, Ptr, | ||
| 155 | AbstractFloat, Float16, Float32, Float64, | ||
| 156 | Signed, Int, Int8, Int16, Int32, Int64, Int128, | ||
| 157 | Unsigned, UInt, UInt8, UInt16, UInt32, UInt64, UInt128, | ||
| 158 | # string types | ||
| 159 | AbstractChar, Char, AbstractString, String, IO, | ||
| 160 | # errors | ||
| 161 | ErrorException, BoundsError, DivideError, DomainError, Exception, | ||
| 162 | InterruptException, InexactError, OutOfMemoryError, ReadOnlyMemoryError, | ||
| 163 | OverflowError, StackOverflowError, SegmentationFault, UndefRefError, UndefVarError, | ||
| 164 | TypeError, ArgumentError, MethodError, AssertionError, LoadError, InitError, | ||
| 165 | UndefKeywordError, | ||
| 166 | # AST representation | ||
| 167 | Expr, QuoteNode, LineNumberNode, GlobalRef, | ||
| 168 | # object model functions | ||
| 169 | fieldtype, getfield, setfield!, nfields, throw, tuple, ===, isdefined, eval, ifelse, | ||
| 170 | # sizeof # not exported, to avoid conflicting with Base.sizeof | ||
| 171 | # type reflection | ||
| 172 | <:, typeof, isa, typeassert, | ||
| 173 | # method reflection | ||
| 174 | applicable, invoke, | ||
| 175 | # constants | ||
| 176 | nothing, Main | ||
| 177 | |||
| 178 | const getproperty = getfield | ||
| 179 | const setproperty! = setfield! | ||
| 180 | |||
| 181 | abstract type Number end | ||
| 182 | abstract type Real <: Number end | ||
| 183 | abstract type AbstractFloat <: Real end | ||
| 184 | abstract type Integer <: Real end | ||
| 185 | abstract type Signed <: Integer end | ||
| 186 | abstract type Unsigned <: Integer end | ||
| 187 | |||
| 188 | primitive type Float16 <: AbstractFloat 16 end | ||
| 189 | primitive type Float32 <: AbstractFloat 32 end | ||
| 190 | primitive type Float64 <: AbstractFloat 64 end | ||
| 191 | |||
| 192 | #primitive type Bool <: Integer 8 end | ||
| 193 | abstract type AbstractChar end | ||
| 194 | primitive type Char <: AbstractChar 32 end | ||
| 195 | |||
| 196 | primitive type Int8 <: Signed 8 end | ||
| 197 | #primitive type UInt8 <: Unsigned 8 end | ||
| 198 | primitive type Int16 <: Signed 16 end | ||
| 199 | primitive type UInt16 <: Unsigned 16 end | ||
| 200 | #primitive type Int32 <: Signed 32 end | ||
| 201 | #primitive type UInt32 <: Unsigned 32 end | ||
| 202 | #primitive type Int64 <: Signed 64 end | ||
| 203 | #primitive type UInt64 <: Unsigned 64 end | ||
| 204 | primitive type Int128 <: Signed 128 end | ||
| 205 | primitive type UInt128 <: Unsigned 128 end | ||
| 206 | |||
| 207 | if Int === Int64 | ||
| 208 | const UInt = UInt64 | ||
| 209 | else | ||
| 210 | const UInt = UInt32 | ||
| 211 | end | ||
| 212 | |||
| 213 | function iterate end | ||
| 214 | function Typeof end | ||
| 215 | ccall(:jl_toplevel_eval_in, Any, (Any, Any), | ||
| 216 | Core, quote | ||
| 217 | (f::typeof(Typeof))(x) = ($(_expr(:meta,:nospecialize,:x)); isa(x,Type) ? Type{x} : typeof(x)) | ||
| 218 | end) | ||
| 219 | |||
| 220 | macro nospecialize(x) | ||
| 221 | _expr(:meta, :nospecialize, x) | ||
| 222 | end | ||
| 223 | |||
| 224 | Expr(@nospecialize args...) = _expr(args...) | ||
| 225 | |||
| 226 | abstract type Exception end | ||
| 227 | struct ErrorException <: Exception | ||
| 228 | msg::AbstractString | ||
| 229 | end | ||
| 230 | |||
| 231 | macro _inline_meta() | ||
| 232 | Expr(:meta, :inline) | ||
| 233 | end | ||
| 234 | |||
| 235 | macro _noinline_meta() | ||
| 236 | Expr(:meta, :noinline) | ||
| 237 | end | ||
| 238 | |||
| 239 | struct BoundsError <: Exception | ||
| 240 | a::Any | ||
| 241 | i::Any | ||
| 242 | BoundsError() = new() | ||
| 243 | BoundsError(@nospecialize(a)) = (@_noinline_meta; new(a)) | ||
| 244 | BoundsError(@nospecialize(a), i) = (@_noinline_meta; new(a,i)) | ||
| 245 | end | ||
| 246 | struct DivideError <: Exception end | ||
| 247 | struct OutOfMemoryError <: Exception end | ||
| 248 | struct ReadOnlyMemoryError <: Exception end | ||
| 249 | struct SegmentationFault <: Exception end | ||
| 250 | struct StackOverflowError <: Exception end | ||
| 251 | struct UndefRefError <: Exception end | ||
| 252 | struct UndefVarError <: Exception | ||
| 253 | var::Symbol | ||
| 254 | end | ||
| 255 | struct InterruptException <: Exception end | ||
| 256 | struct DomainError <: Exception | ||
| 257 | val | ||
| 258 | msg::AbstractString | ||
| 259 | DomainError(@nospecialize(val)) = (@_noinline_meta; new(val, "")) | ||
| 260 | DomainError(@nospecialize(val), @nospecialize(msg)) = (@_noinline_meta; new(val, msg)) | ||
| 261 | end | ||
| 262 | struct TypeError <: Exception | ||
| 263 | # `func` is the name of the builtin function that encountered a type error, | ||
| 264 | # the name of the type that hit an error in its definition or application, or | ||
| 265 | # some other brief description of where the error happened. | ||
| 266 | # `context` optionally adds extra detail, e.g. the name of the type parameter | ||
| 267 | # that got a bad value. | ||
| 268 | func::Symbol | ||
| 269 | context::Union{AbstractString,Symbol} | ||
| 270 | expected::Type | ||
| 271 | got | ||
| 272 | TypeError(func, context, @nospecialize(expected::Type), @nospecialize(got)) = | ||
| 273 | new(func, context, expected, got) | ||
| 274 | end | ||
| 275 | TypeError(where, @nospecialize(expected::Type), @nospecialize(got)) = | ||
| 276 | TypeError(Symbol(where), "", expected, got) | ||
| 277 | struct InexactError <: Exception | ||
| 278 | func::Symbol | ||
| 279 | T # Type | ||
| 280 | val | ||
| 281 | InexactError(f::Symbol, @nospecialize(T), @nospecialize(val)) = (@_noinline_meta; new(f, T, val)) | ||
| 282 | end | ||
| 283 | struct OverflowError <: Exception | ||
| 284 | msg::AbstractString | ||
| 285 | end | ||
| 286 | |||
| 287 | struct ArgumentError <: Exception | ||
| 288 | msg::AbstractString | ||
| 289 | end | ||
| 290 | struct UndefKeywordError <: Exception | ||
| 291 | var::Symbol | ||
| 292 | end | ||
| 293 | |||
| 294 | struct MethodError <: Exception | ||
| 295 | f | ||
| 296 | args | ||
| 297 | world::UInt | ||
| 298 | MethodError(@nospecialize(f), @nospecialize(args), world::UInt) = new(f, args, world) | ||
| 299 | end | ||
| 300 | const typemax_UInt = ccall(:jl_typemax_uint, Any, (Any,), UInt) | ||
| 301 | MethodError(@nospecialize(f), @nospecialize(args)) = MethodError(f, args, typemax_UInt) | ||
| 302 | |||
| 303 | struct AssertionError <: Exception | ||
| 304 | msg::AbstractString | ||
| 305 | end | ||
| 306 | AssertionError() = AssertionError("") | ||
| 307 | |||
| 308 | abstract type WrappedException <: Exception end | ||
| 309 | |||
| 310 | struct LoadError <: WrappedException | ||
| 311 | file::AbstractString | ||
| 312 | line::Int | ||
| 313 | error | ||
| 314 | end | ||
| 315 | |||
| 316 | struct InitError <: WrappedException | ||
| 317 | mod::Symbol | ||
| 318 | error | ||
| 319 | end | ||
| 320 | |||
| 321 | String(s::String) = s # no constructor yet | ||
| 322 | |||
| 323 | const Cvoid = Nothing | ||
| 324 | Nothing() = nothing | ||
| 325 | |||
| 326 | # This should always be inlined | ||
| 327 | getptls() = ccall(:jl_get_ptls_states, Ptr{Cvoid}, ()) | ||
| 328 | |||
| 329 | include(m::Module, fname::String) = ccall(:jl_load_, Any, (Any, Any), m, fname) | ||
| 330 | |||
| 331 | 833 (100 %) |
833 (100 %)
samples spent calling
literal_pow
eval(m::Module, @nospecialize(e)) = ccall(:jl_toplevel_eval_in, Any, (Any, Any), m, e)
|
|
| 332 | |||
| 333 | kwfunc(@nospecialize(f)) = ccall(:jl_get_keyword_sorter, Any, (Any,), f) | ||
| 334 | |||
| 335 | kwftype(@nospecialize(t)) = typeof(ccall(:jl_get_kwsorter, Any, (Any,), t)) | ||
| 336 | |||
| 337 | mutable struct Box | ||
| 338 | contents::Any | ||
| 339 | Box(@nospecialize(x)) = new(x) | ||
| 340 | Box() = new() | ||
| 341 | end | ||
| 342 | |||
| 343 | # constructors for built-in types | ||
| 344 | |||
| 345 | mutable struct WeakRef | ||
| 346 | value | ||
| 347 | WeakRef() = WeakRef(nothing) | ||
| 348 | WeakRef(@nospecialize(v)) = ccall(:jl_gc_new_weakref_th, Ref{WeakRef}, | ||
| 349 | (Ptr{Cvoid}, Any), getptls(), v) | ||
| 350 | end | ||
| 351 | |||
| 352 | TypeVar(n::Symbol) = _typevar(n, Union{}, Any) | ||
| 353 | TypeVar(n::Symbol, @nospecialize(ub)) = _typevar(n, Union{}, ub) | ||
| 354 | TypeVar(n::Symbol, @nospecialize(lb), @nospecialize(ub)) = _typevar(n, lb, ub) | ||
| 355 | |||
| 356 | UnionAll(v::TypeVar, @nospecialize(t)) = ccall(:jl_type_unionall, Any, (Any, Any), v, t) | ||
| 357 | |||
| 358 | (::Type{Tuple{}})() = () # Tuple{}() | ||
| 359 | |||
| 360 | struct VecElement{T} | ||
| 361 | value::T | ||
| 362 | VecElement{T}(value::T) where {T} = new(value) # disable converting constructor in Core | ||
| 363 | end | ||
| 364 | VecElement(arg::T) where {T} = VecElement{T}(arg) | ||
| 365 | |||
| 366 | _new(typ::Symbol, argty::Symbol) = eval(Core, :($typ(@nospecialize n::$argty) = $(Expr(:new, typ, :n)))) | ||
| 367 | _new(:GotoNode, :Int) | ||
| 368 | _new(:NewvarNode, :SlotNumber) | ||
| 369 | _new(:QuoteNode, :Any) | ||
| 370 | _new(:SSAValue, :Int) | ||
| 371 | eval(Core, :(LineNumberNode(l::Int) = $(Expr(:new, :LineNumberNode, :l, nothing)))) | ||
| 372 | eval(Core, :(LineNumberNode(l::Int, @nospecialize(f)) = $(Expr(:new, :LineNumberNode, :l, :f)))) | ||
| 373 | eval(Core, :(GlobalRef(m::Module, s::Symbol) = $(Expr(:new, :GlobalRef, :m, :s)))) | ||
| 374 | eval(Core, :(SlotNumber(n::Int) = $(Expr(:new, :SlotNumber, :n)))) | ||
| 375 | eval(Core, :(TypedSlot(n::Int, @nospecialize(t)) = $(Expr(:new, :TypedSlot, :n, :t)))) | ||
| 376 | eval(Core, :(PhiNode(edges::Array{Any, 1}, values::Array{Any, 1}) = $(Expr(:new, :PhiNode, :edges, :values)))) | ||
| 377 | eval(Core, :(PiNode(val, typ) = $(Expr(:new, :PiNode, :val, :typ)))) | ||
| 378 | eval(Core, :(PhiCNode(values::Array{Any, 1}) = $(Expr(:new, :PhiCNode, :values)))) | ||
| 379 | eval(Core, :(UpsilonNode(val) = $(Expr(:new, :UpsilonNode, :val)))) | ||
| 380 | eval(Core, :(UpsilonNode() = $(Expr(:new, :UpsilonNode)))) | ||
| 381 | eval(Core, :(LineInfoNode(@nospecialize(method), file::Symbol, line::Int, inlined_at::Int) = | ||
| 382 | $(Expr(:new, :LineInfoNode, :method, :file, :line, :inlined_at)))) | ||
| 383 | |||
| 384 | Module(name::Symbol=:anonymous, std_imports::Bool=true) = ccall(:jl_f_new_module, Ref{Module}, (Any, Bool), name, std_imports) | ||
| 385 | |||
| 386 | function _Task(@nospecialize(f), reserved_stack::Int, completion_future) | ||
| 387 | return ccall(:jl_new_task, Ref{Task}, (Any, Any, Int), f, completion_future, reserved_stack) | ||
| 388 | end | ||
| 389 | |||
| 390 | # simple convert for use by constructors of types in Core | ||
| 391 | # note that there is no actual conversion defined here, | ||
| 392 | # so the methods and ccall's in Core aren't permitted to use convert | ||
| 393 | convert(::Type{Any}, @nospecialize(x)) = x | ||
| 394 | convert(::Type{T}, x::T) where {T} = x | ||
| 395 | cconvert(::Type{T}, x) where {T} = convert(T, x) | ||
| 396 | unsafe_convert(::Type{T}, x::T) where {T} = x | ||
| 397 | |||
| 398 | const NTuple{N,T} = Tuple{Vararg{T,N}} | ||
| 399 | |||
| 400 | |||
| 401 | ## primitive Array constructors | ||
| 402 | struct UndefInitializer end | ||
| 403 | const undef = UndefInitializer() | ||
| 404 | # type and dimensionality specified, accepting dims as series of Ints | ||
| 405 | Array{T,1}(::UndefInitializer, m::Int) where {T} = | ||
| 406 | ccall(:jl_alloc_array_1d, Array{T,1}, (Any, Int), Array{T,1}, m) | ||
| 407 | Array{T,2}(::UndefInitializer, m::Int, n::Int) where {T} = | ||
| 408 | ccall(:jl_alloc_array_2d, Array{T,2}, (Any, Int, Int), Array{T,2}, m, n) | ||
| 409 | Array{T,3}(::UndefInitializer, m::Int, n::Int, o::Int) where {T} = | ||
| 410 | ccall(:jl_alloc_array_3d, Array{T,3}, (Any, Int, Int, Int), Array{T,3}, m, n, o) | ||
| 411 | Array{T,N}(::UndefInitializer, d::Vararg{Int,N}) where {T,N} = | ||
| 412 | ccall(:jl_new_array, Array{T,N}, (Any, Any), Array{T,N}, d) | ||
| 413 | # type and dimensionality specified, accepting dims as tuples of Ints | ||
| 414 | Array{T,1}(::UndefInitializer, d::NTuple{1,Int}) where {T} = Array{T,1}(undef, getfield(d,1)) | ||
| 415 | Array{T,2}(::UndefInitializer, d::NTuple{2,Int}) where {T} = Array{T,2}(undef, getfield(d,1), getfield(d,2)) | ||
| 416 | Array{T,3}(::UndefInitializer, d::NTuple{3,Int}) where {T} = Array{T,3}(undef, getfield(d,1), getfield(d,2), getfield(d,3)) | ||
| 417 | Array{T,N}(::UndefInitializer, d::NTuple{N,Int}) where {T,N} = ccall(:jl_new_array, Array{T,N}, (Any, Any), Array{T,N}, d) | ||
| 418 | # type but not dimensionality specified | ||
| 419 | Array{T}(::UndefInitializer, m::Int) where {T} = Array{T,1}(undef, m) | ||
| 420 | Array{T}(::UndefInitializer, m::Int, n::Int) where {T} = Array{T,2}(undef, m, n) | ||
| 421 | Array{T}(::UndefInitializer, m::Int, n::Int, o::Int) where {T} = Array{T,3}(undef, m, n, o) | ||
| 422 | Array{T}(::UndefInitializer, d::NTuple{N,Int}) where {T,N} = Array{T,N}(undef, d) | ||
| 423 | # empty vector constructor | ||
| 424 | Array{T,1}() where {T} = Array{T,1}(undef, 0) | ||
| 425 | |||
| 426 | |||
| 427 | (::Type{Array{T,N} where T})(x::AbstractArray{S,N}) where {S,N} = Array{S,N}(x) | ||
| 428 | |||
| 429 | Array(A::AbstractArray{T,N}) where {T,N} = Array{T,N}(A) | ||
| 430 | Array{T}(A::AbstractArray{S,N}) where {T,N,S} = Array{T,N}(A) | ||
| 431 | |||
| 432 | AbstractArray{T}(A::AbstractArray{S,N}) where {T,S,N} = AbstractArray{T,N}(A) | ||
| 433 | |||
| 434 | # primitive Symbol constructors | ||
| 435 | eval(Core, :(function Symbol(s::String) | ||
| 436 | $(Expr(:meta, :pure)) | ||
| 437 | return ccall(:jl_symbol_n, Ref{Symbol}, (Ptr{UInt8}, Int), | ||
| 438 | ccall(:jl_string_ptr, Ptr{UInt8}, (Any,), s), | ||
| 439 | sizeof(s)) | ||
| 440 | end)) | ||
| 441 | function Symbol(a::Array{UInt8,1}) | ||
| 442 | return ccall(:jl_symbol_n, Ref{Symbol}, (Ptr{UInt8}, Int), | ||
| 443 | ccall(:jl_array_ptr, Ptr{UInt8}, (Any,), a), | ||
| 444 | Intrinsics.arraylen(a)) | ||
| 445 | end | ||
| 446 | Symbol(s::Symbol) = s | ||
| 447 | |||
| 448 | # module providing the IR object model | ||
| 449 | module IR | ||
| 450 | export CodeInfo, MethodInstance, CodeInstance, GotoNode, | ||
| 451 | NewvarNode, SSAValue, Slot, SlotNumber, TypedSlot, | ||
| 452 | PiNode, PhiNode, PhiCNode, UpsilonNode, LineInfoNode | ||
| 453 | |||
| 454 | import Core: CodeInfo, MethodInstance, CodeInstance, GotoNode, | ||
| 455 | NewvarNode, SSAValue, Slot, SlotNumber, TypedSlot, | ||
| 456 | PiNode, PhiNode, PhiCNode, UpsilonNode, LineInfoNode | ||
| 457 | |||
| 458 | end | ||
| 459 | |||
| 460 | # docsystem basics | ||
| 461 | const unescape = Symbol("hygienic-scope") | ||
| 462 | macro doc(x...) | ||
| 463 | docex = atdoc(__source__, __module__, x...) | ||
| 464 | isa(docex, Expr) && docex.head === :escape && return docex | ||
| 465 | return Expr(:escape, Expr(unescape, docex, typeof(atdoc).name.module)) | ||
| 466 | end | ||
| 467 | macro __doc__(x) | ||
| 468 | return Expr(:escape, Expr(:block, Expr(:meta, :doc), x)) | ||
| 469 | end | ||
| 470 | atdoc = (source, mod, str, expr) -> Expr(:escape, expr) | ||
| 471 | atdoc!(λ) = global atdoc = λ | ||
| 472 | |||
| 473 | # macros for big integer syntax | ||
| 474 | macro int128_str end | ||
| 475 | macro uint128_str end | ||
| 476 | macro big_str end | ||
| 477 | |||
| 478 | # macro for command syntax | ||
| 479 | macro cmd end | ||
| 480 | |||
| 481 | |||
| 482 | # simple stand-alone print definitions for debugging | ||
| 483 | abstract type IO end | ||
| 484 | struct CoreSTDOUT <: IO end | ||
| 485 | struct CoreSTDERR <: IO end | ||
| 486 | const stdout = CoreSTDOUT() | ||
| 487 | const stderr = CoreSTDERR() | ||
| 488 | io_pointer(::CoreSTDOUT) = Intrinsics.pointerref(Intrinsics.cglobal(:jl_uv_stdout, Ptr{Cvoid}), 1, 1) | ||
| 489 | io_pointer(::CoreSTDERR) = Intrinsics.pointerref(Intrinsics.cglobal(:jl_uv_stderr, Ptr{Cvoid}), 1, 1) | ||
| 490 | |||
| 491 | unsafe_write(io::IO, x::Ptr{UInt8}, nb::UInt) = | ||
| 492 | (ccall(:jl_uv_puts, Cvoid, (Ptr{Cvoid}, Ptr{UInt8}, UInt), io_pointer(io), x, nb); nb) | ||
| 493 | unsafe_write(io::IO, x::Ptr{UInt8}, nb::Int) = | ||
| 494 | (ccall(:jl_uv_puts, Cvoid, (Ptr{Cvoid}, Ptr{UInt8}, Int), io_pointer(io), x, nb); nb) | ||
| 495 | write(io::IO, x::UInt8) = | ||
| 496 | (ccall(:jl_uv_putb, Cvoid, (Ptr{Cvoid}, UInt8), io_pointer(io), x); 1) | ||
| 497 | function write(io::IO, x::String) | ||
| 498 | nb = sizeof(x) | ||
| 499 | unsafe_write(io, ccall(:jl_string_ptr, Ptr{UInt8}, (Any,), x), nb) | ||
| 500 | return nb | ||
| 501 | end | ||
| 502 | |||
| 503 | show(io::IO, @nospecialize x) = ccall(:jl_static_show, Cvoid, (Ptr{Cvoid}, Any), io_pointer(io), x) | ||
| 504 | print(io::IO, x::AbstractChar) = ccall(:jl_uv_putc, Cvoid, (Ptr{Cvoid}, Char), io_pointer(io), x) | ||
| 505 | print(io::IO, x::String) = (write(io, x); nothing) | ||
| 506 | print(io::IO, @nospecialize x) = show(io, x) | ||
| 507 | print(io::IO, @nospecialize(x), @nospecialize a...) = (print(io, x); print(io, a...)) | ||
| 508 | println(io::IO) = (write(io, 0x0a); nothing) # 0x0a = '\n' | ||
| 509 | println(io::IO, @nospecialize x...) = (print(io, x...); println(io)) | ||
| 510 | |||
| 511 | show(@nospecialize a) = show(stdout, a) | ||
| 512 | print(@nospecialize a...) = print(stdout, a...) | ||
| 513 | println(@nospecialize a...) = println(stdout, a...) | ||
| 514 | |||
| 515 | struct GeneratedFunctionStub | ||
| 516 | gen | ||
| 517 | argnames::Array{Any,1} | ||
| 518 | spnames::Union{Nothing, Array{Any,1}} | ||
| 519 | line::Int | ||
| 520 | file::Symbol | ||
| 521 | expand_early::Bool | ||
| 522 | end | ||
| 523 | |||
| 524 | # invoke and wrap the results of @generated | ||
| 525 | function (g::GeneratedFunctionStub)(@nospecialize args...) | ||
| 526 | body = g.gen(args...) | ||
| 527 | if body isa CodeInfo | ||
| 528 | return body | ||
| 529 | end | ||
| 530 | lam = Expr(:lambda, g.argnames, | ||
| 531 | Expr(Symbol("scope-block"), | ||
| 532 | Expr(:block, | ||
| 533 | LineNumberNode(g.line, g.file), | ||
| 534 | Expr(:meta, :push_loc, g.file, Symbol("@generated body")), | ||
| 535 | Expr(:return, body), | ||
| 536 | Expr(:meta, :pop_loc)))) | ||
| 537 | if g.spnames === nothing | ||
| 538 | return lam | ||
| 539 | else | ||
| 540 | return Expr(Symbol("with-static-parameters"), lam, g.spnames...) | ||
| 541 | end | ||
| 542 | end | ||
| 543 | |||
| 544 | NamedTuple() = NamedTuple{(),Tuple{}}(()) | ||
| 545 | |||
| 546 | NamedTuple{names}(args::Tuple) where {names} = NamedTuple{names,typeof(args)}(args) | ||
| 547 | |||
| 548 | using .Intrinsics: sle_int, add_int | ||
| 549 | |||
| 550 | eval(Core, :(NamedTuple{names,T}(args::T) where {names, T <: Tuple} = | ||
| 551 | $(Expr(:splatnew, :(NamedTuple{names,T}), :args)))) | ||
| 552 | |||
| 553 | # constructors for built-in types | ||
| 554 | |||
| 555 | import .Intrinsics: eq_int, trunc_int, lshr_int, sub_int, shl_int, bitcast, sext_int, zext_int, and_int | ||
| 556 | |||
| 557 | throw_inexacterror(f::Symbol, ::Type{T}, val) where {T} = (@_noinline_meta; throw(InexactError(f, T, val))) | ||
| 558 | |||
| 559 | function is_top_bit_set(x) | ||
| 560 | @_inline_meta | ||
| 561 | eq_int(trunc_int(UInt8, lshr_int(x, sub_int(shl_int(sizeof(x), 3), 1))), trunc_int(UInt8, 1)) | ||
| 562 | end | ||
| 563 | |||
| 564 | function is_top_bit_set(x::Union{Int8,UInt8}) | ||
| 565 | @_inline_meta | ||
| 566 | eq_int(lshr_int(x, 7), trunc_int(typeof(x), 1)) | ||
| 567 | end | ||
| 568 | |||
| 569 | function check_top_bit(::Type{To}, x) where {To} | ||
| 570 | @_inline_meta | ||
| 571 | is_top_bit_set(x) && throw_inexacterror(:check_top_bit, To, x) | ||
| 572 | x | ||
| 573 | end | ||
| 574 | |||
| 575 | function checked_trunc_sint(::Type{To}, x::From) where {To,From} | ||
| 576 | @_inline_meta | ||
| 577 | y = trunc_int(To, x) | ||
| 578 | back = sext_int(From, y) | ||
| 579 | eq_int(x, back) || throw_inexacterror(:trunc, To, x) | ||
| 580 | y | ||
| 581 | end | ||
| 582 | |||
| 583 | function checked_trunc_uint(::Type{To}, x::From) where {To,From} | ||
| 584 | @_inline_meta | ||
| 585 | y = trunc_int(To, x) | ||
| 586 | back = zext_int(From, y) | ||
| 587 | eq_int(x, back) || throw_inexacterror(:trunc, To, x) | ||
| 588 | y | ||
| 589 | end | ||
| 590 | |||
| 591 | toInt8(x::Int8) = x | ||
| 592 | toInt8(x::Int16) = checked_trunc_sint(Int8, x) | ||
| 593 | toInt8(x::Int32) = checked_trunc_sint(Int8, x) | ||
| 594 | toInt8(x::Int64) = checked_trunc_sint(Int8, x) | ||
| 595 | toInt8(x::Int128) = checked_trunc_sint(Int8, x) | ||
| 596 | toInt8(x::UInt8) = bitcast(Int8, check_top_bit(Int8, x)) | ||
| 597 | toInt8(x::UInt16) = checked_trunc_sint(Int8, check_top_bit(Int8, x)) | ||
| 598 | toInt8(x::UInt32) = checked_trunc_sint(Int8, check_top_bit(Int8, x)) | ||
| 599 | toInt8(x::UInt64) = checked_trunc_sint(Int8, check_top_bit(Int8, x)) | ||
| 600 | toInt8(x::UInt128) = checked_trunc_sint(Int8, check_top_bit(Int8, x)) | ||
| 601 | toInt8(x::Bool) = and_int(bitcast(Int8, x), Int8(1)) | ||
| 602 | toInt16(x::Int8) = sext_int(Int16, x) | ||
| 603 | toInt16(x::Int16) = x | ||
| 604 | toInt16(x::Int32) = checked_trunc_sint(Int16, x) | ||
| 605 | toInt16(x::Int64) = checked_trunc_sint(Int16, x) | ||
| 606 | toInt16(x::Int128) = checked_trunc_sint(Int16, x) | ||
| 607 | toInt16(x::UInt8) = zext_int(Int16, x) | ||
| 608 | toInt16(x::UInt16) = bitcast(Int16, check_top_bit(Int16, x)) | ||
| 609 | toInt16(x::UInt32) = checked_trunc_sint(Int16, check_top_bit(Int16, x)) | ||
| 610 | toInt16(x::UInt64) = checked_trunc_sint(Int16, check_top_bit(Int16, x)) | ||
| 611 | toInt16(x::UInt128) = checked_trunc_sint(Int16, check_top_bit(Int16, x)) | ||
| 612 | toInt16(x::Bool) = and_int(zext_int(Int16, x), Int16(1)) | ||
| 613 | toInt32(x::Int8) = sext_int(Int32, x) | ||
| 614 | toInt32(x::Int16) = sext_int(Int32, x) | ||
| 615 | toInt32(x::Int32) = x | ||
| 616 | toInt32(x::Int64) = checked_trunc_sint(Int32, x) | ||
| 617 | toInt32(x::Int128) = checked_trunc_sint(Int32, x) | ||
| 618 | toInt32(x::UInt8) = zext_int(Int32, x) | ||
| 619 | toInt32(x::UInt16) = zext_int(Int32, x) | ||
| 620 | toInt32(x::UInt32) = bitcast(Int32, check_top_bit(Int32, x)) | ||
| 621 | toInt32(x::UInt64) = checked_trunc_sint(Int32, check_top_bit(Int32, x)) | ||
| 622 | toInt32(x::UInt128) = checked_trunc_sint(Int32, check_top_bit(Int32, x)) | ||
| 623 | toInt32(x::Bool) = and_int(zext_int(Int32, x), Int32(1)) | ||
| 624 | toInt64(x::Int8) = sext_int(Int64, x) | ||
| 625 | toInt64(x::Int16) = sext_int(Int64, x) | ||
| 626 | toInt64(x::Int32) = sext_int(Int64, x) | ||
| 627 | toInt64(x::Int64) = x | ||
| 628 | toInt64(x::Int128) = checked_trunc_sint(Int64, x) | ||
| 629 | toInt64(x::UInt8) = zext_int(Int64, x) | ||
| 630 | toInt64(x::UInt16) = zext_int(Int64, x) | ||
| 631 | toInt64(x::UInt32) = zext_int(Int64, x) | ||
| 632 | toInt64(x::UInt64) = bitcast(Int64, check_top_bit(Int64, x)) | ||
| 633 | toInt64(x::UInt128) = checked_trunc_sint(Int64, check_top_bit(Int64, x)) | ||
| 634 | toInt64(x::Bool) = and_int(zext_int(Int64, x), Int64(1)) | ||
| 635 | toInt128(x::Int8) = sext_int(Int128, x) | ||
| 636 | toInt128(x::Int16) = sext_int(Int128, x) | ||
| 637 | toInt128(x::Int32) = sext_int(Int128, x) | ||
| 638 | toInt128(x::Int64) = sext_int(Int128, x) | ||
| 639 | toInt128(x::Int128) = x | ||
| 640 | toInt128(x::UInt8) = zext_int(Int128, x) | ||
| 641 | toInt128(x::UInt16) = zext_int(Int128, x) | ||
| 642 | toInt128(x::UInt32) = zext_int(Int128, x) | ||
| 643 | toInt128(x::UInt64) = zext_int(Int128, x) | ||
| 644 | toInt128(x::UInt128) = bitcast(Int128, check_top_bit(Int128, x)) | ||
| 645 | toInt128(x::Bool) = and_int(zext_int(Int128, x), Int128(1)) | ||
| 646 | toUInt8(x::Int8) = bitcast(UInt8, check_top_bit(UInt8, x)) | ||
| 647 | toUInt8(x::Int16) = checked_trunc_uint(UInt8, x) | ||
| 648 | toUInt8(x::Int32) = checked_trunc_uint(UInt8, x) | ||
| 649 | toUInt8(x::Int64) = checked_trunc_uint(UInt8, x) | ||
| 650 | toUInt8(x::Int128) = checked_trunc_uint(UInt8, x) | ||
| 651 | toUInt8(x::UInt8) = x | ||
| 652 | toUInt8(x::UInt16) = checked_trunc_uint(UInt8, x) | ||
| 653 | toUInt8(x::UInt32) = checked_trunc_uint(UInt8, x) | ||
| 654 | toUInt8(x::UInt64) = checked_trunc_uint(UInt8, x) | ||
| 655 | toUInt8(x::UInt128) = checked_trunc_uint(UInt8, x) | ||
| 656 | toUInt8(x::Bool) = and_int(bitcast(UInt8, x), UInt8(1)) | ||
| 657 | toUInt16(x::Int8) = sext_int(UInt16, check_top_bit(UInt16, x)) | ||
| 658 | toUInt16(x::Int16) = bitcast(UInt16, check_top_bit(UInt16, x)) | ||
| 659 | toUInt16(x::Int32) = checked_trunc_uint(UInt16, x) | ||
| 660 | toUInt16(x::Int64) = checked_trunc_uint(UInt16, x) | ||
| 661 | toUInt16(x::Int128) = checked_trunc_uint(UInt16, x) | ||
| 662 | toUInt16(x::UInt8) = zext_int(UInt16, x) | ||
| 663 | toUInt16(x::UInt16) = x | ||
| 664 | toUInt16(x::UInt32) = checked_trunc_uint(UInt16, x) | ||
| 665 | toUInt16(x::UInt64) = checked_trunc_uint(UInt16, x) | ||
| 666 | toUInt16(x::UInt128) = checked_trunc_uint(UInt16, x) | ||
| 667 | toUInt16(x::Bool) = and_int(zext_int(UInt16, x), UInt16(1)) | ||
| 668 | toUInt32(x::Int8) = sext_int(UInt32, check_top_bit(UInt32, x)) | ||
| 669 | toUInt32(x::Int16) = sext_int(UInt32, check_top_bit(UInt32, x)) | ||
| 670 | toUInt32(x::Int32) = bitcast(UInt32, check_top_bit(UInt32, x)) | ||
| 671 | toUInt32(x::Int64) = checked_trunc_uint(UInt32, x) | ||
| 672 | toUInt32(x::Int128) = checked_trunc_uint(UInt32, x) | ||
| 673 | toUInt32(x::UInt8) = zext_int(UInt32, x) | ||
| 674 | toUInt32(x::UInt16) = zext_int(UInt32, x) | ||
| 675 | toUInt32(x::UInt32) = x | ||
| 676 | toUInt32(x::UInt64) = checked_trunc_uint(UInt32, x) | ||
| 677 | toUInt32(x::UInt128) = checked_trunc_uint(UInt32, x) | ||
| 678 | toUInt32(x::Bool) = and_int(zext_int(UInt32, x), UInt32(1)) | ||
| 679 | toUInt64(x::Int8) = sext_int(UInt64, check_top_bit(UInt64, x)) | ||
| 680 | toUInt64(x::Int16) = sext_int(UInt64, check_top_bit(UInt64, x)) | ||
| 681 | toUInt64(x::Int32) = sext_int(UInt64, check_top_bit(UInt64, x)) | ||
| 682 | toUInt64(x::Int64) = bitcast(UInt64, check_top_bit(UInt64, x)) | ||
| 683 | toUInt64(x::Int128) = checked_trunc_uint(UInt64, x) | ||
| 684 | toUInt64(x::UInt8) = zext_int(UInt64, x) | ||
| 685 | toUInt64(x::UInt16) = zext_int(UInt64, x) | ||
| 686 | toUInt64(x::UInt32) = zext_int(UInt64, x) | ||
| 687 | toUInt64(x::UInt64) = x | ||
| 688 | toUInt64(x::UInt128) = checked_trunc_uint(UInt64, x) | ||
| 689 | toUInt64(x::Bool) = and_int(zext_int(UInt64, x), UInt64(1)) | ||
| 690 | toUInt128(x::Int8) = sext_int(UInt128, check_top_bit(UInt128, x)) | ||
| 691 | toUInt128(x::Int16) = sext_int(UInt128, check_top_bit(UInt128, x)) | ||
| 692 | toUInt128(x::Int32) = sext_int(UInt128, check_top_bit(UInt128, x)) | ||
| 693 | toUInt128(x::Int64) = sext_int(UInt128, check_top_bit(UInt128, x)) | ||
| 694 | toUInt128(x::Int128) = bitcast(UInt128, check_top_bit(UInt128, x)) | ||
| 695 | toUInt128(x::UInt8) = zext_int(UInt128, x) | ||
| 696 | toUInt128(x::UInt16) = zext_int(UInt128, x) | ||
| 697 | toUInt128(x::UInt32) = zext_int(UInt128, x) | ||
| 698 | toUInt128(x::UInt64) = zext_int(UInt128, x) | ||
| 699 | toUInt128(x::UInt128) = x | ||
| 700 | toUInt128(x::Bool) = and_int(zext_int(UInt128, x), UInt128(1)) | ||
| 701 | |||
| 702 | # TODO: this is here to work around the 4 method limit in inference (#23210). | ||
| 703 | const BuiltinInts = Union{Int128, Int16, Int32, Int64, Int8, UInt128, UInt16, UInt32, UInt64, UInt8, Bool} | ||
| 704 | Int8(x::BuiltinInts) = toInt8(x)::Int8 | ||
| 705 | Int16(x::BuiltinInts) = toInt16(x)::Int16 | ||
| 706 | Int32(x::BuiltinInts) = toInt32(x)::Int32 | ||
| 707 | Int64(x::BuiltinInts) = toInt64(x)::Int64 | ||
| 708 | Int128(x::BuiltinInts) = toInt128(x)::Int128 | ||
| 709 | UInt8(x::BuiltinInts) = toUInt8(x)::UInt8 | ||
| 710 | UInt16(x::BuiltinInts) = toUInt16(x)::UInt16 | ||
| 711 | UInt32(x::BuiltinInts) = toUInt32(x)::UInt32 | ||
| 712 | UInt64(x::BuiltinInts) = toUInt64(x)::UInt64 | ||
| 713 | UInt128(x::BuiltinInts) = toUInt128(x)::UInt128 | ||
| 714 | |||
| 715 | (::Type{T})(x::T) where {T<:Number} = x | ||
| 716 | |||
| 717 | Int(x::Ptr) = bitcast(Int, x) | ||
| 718 | UInt(x::Ptr) = bitcast(UInt, x) | ||
| 719 | if Int === Int32 | ||
| 720 | Int64(x::Ptr) = Int64(UInt32(x)) | ||
| 721 | UInt64(x::Ptr) = UInt64(UInt32(x)) | ||
| 722 | end | ||
| 723 | Ptr{T}(x::Union{Int,UInt,Ptr}) where {T} = bitcast(Ptr{T}, x) | ||
| 724 | Ptr{T}() where {T} = Ptr{T}(0) | ||
| 725 | |||
| 726 | Signed(x::UInt8) = Int8(x) | ||
| 727 | Unsigned(x::Int8) = UInt8(x) | ||
| 728 | Signed(x::UInt16) = Int16(x) | ||
| 729 | Unsigned(x::Int16) = UInt16(x) | ||
| 730 | Signed(x::UInt32) = Int32(x) | ||
| 731 | Unsigned(x::Int32) = UInt32(x) | ||
| 732 | Signed(x::UInt64) = Int64(x) | ||
| 733 | Unsigned(x::Int64) = UInt64(x) | ||
| 734 | Signed(x::UInt128) = Int128(x) | ||
| 735 | Unsigned(x::Int128) = UInt128(x) | ||
| 736 | |||
| 737 | Signed(x::Union{Float32, Float64, Bool}) = Int(x) | ||
| 738 | Unsigned(x::Union{Float32, Float64, Bool}) = UInt(x) | ||
| 739 | |||
| 740 | Integer(x::Integer) = x | ||
| 741 | Integer(x::Union{Float32, Float64}) = Int(x) | ||
| 742 | |||
| 743 | ccall(:jl_set_istopmod, Cvoid, (Any, Bool), Core, true) |