forked from JuliaLang/julia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBase.jl
396 lines (318 loc) · 9.23 KB
/
Base.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
# This file is a part of Julia. License is MIT: https://julialang.org/license
baremodule Base
using Core.Intrinsics, Core.IR
const is_primary_base_module = ccall(:jl_module_parent, Ref{Module}, (Any,), Base) === Core.Main
ccall(:jl_set_istopmod, Cvoid, (Any, Bool), Base, is_primary_base_module)
# Try to help prevent users from shooting them-selves in the foot
# with ambiguities by defining a few common and critical operations
# (and these don't need the extra convert code)
getproperty(x::Module, f::Symbol) = getfield(x, f)
setproperty!(x::Module, f::Symbol, v) = setfield!(x, f, v)
getproperty(x::Type, f::Symbol) = getfield(x, f)
setproperty!(x::Type, f::Symbol, v) = setfield!(x, f, v)
getproperty(Core.@nospecialize(x), f::Symbol) = getfield(x, f)
setproperty!(x, f::Symbol, v) = setfield!(x, f, convert(fieldtype(typeof(x), f), v))
function include_relative end
function include(mod::Module, path::AbstractString)
local result
if INCLUDE_STATE === 1
result = _include1(mod, path)
elseif INCLUDE_STATE === 2
result = _include(mod, path)
elseif INCLUDE_STATE === 3
result = include_relative(mod, path)
end
result
end
function include(path::AbstractString)
local result
if INCLUDE_STATE === 1
result = _include1(Base, path)
elseif INCLUDE_STATE === 2
result = _include(Base, path)
else
# to help users avoid error (accidentally evaluating into Base), this is not allowed
error("Base.include(string) is discontinued, use `include(fname)` or `Base.include(@__MODULE__, fname)` instead.")
end
result
end
const _included_files = Array{Tuple{Module,String},1}()
function _include1(mod::Module, path)
Core.Compiler.push!(_included_files, (mod, ccall(:jl_prepend_cwd, Any, (Any,), path)))
Core.include(mod, path)
end
let SOURCE_PATH = ""
# simple, race-y TLS, relative include
global _include
function _include(mod::Module, path)
prev = SOURCE_PATH
path = normpath(joinpath(dirname(prev), path))
push!(_included_files, (mod, abspath(path)))
SOURCE_PATH = path
result = Core.include(mod, path)
SOURCE_PATH = prev
result
end
end
INCLUDE_STATE = 1 # include = Core.include
include("coreio.jl")
eval(x) = Core.eval(Base, x)
eval(m::Module, x) = Core.eval(m, x)
# init core docsystem
import Core: @doc, @__doc__, WrappedException, @int128_str, @uint128_str, @big_str, @cmd
if isdefined(Core, :Compiler)
import Core.Compiler.CoreDocs
Core.atdoc!(CoreDocs.docm)
end
include("exports.jl")
if false
# simple print definitions for debugging. enable these if something
# goes wrong during bootstrap before printing code is available.
# otherwise, they just just eventually get (noisily) overwritten later
global show, print, println
show(io::IO, x) = Core.show(io, x)
print(io::IO, a...) = Core.print(io, a...)
println(io::IO, x...) = Core.println(io, x...)
end
"""
time_ns()
Get the time in nanoseconds. The time corresponding to 0 is undefined, and wraps every 5.8 years.
"""
time_ns() = ccall(:jl_hrtime, UInt64, ())
start_base_include = time_ns()
## Load essential files and libraries
include("essentials.jl")
include("ctypes.jl")
include("gcutils.jl")
include("generator.jl")
include("reflection.jl")
include("options.jl")
# core operations & types
include("promotion.jl")
include("tuple.jl")
include("expr.jl")
include("pair.jl")
include("traits.jl")
include("range.jl")
include("error.jl")
# core numeric operations & types
include("bool.jl")
include("number.jl")
include("int.jl")
include("operators.jl")
include("pointer.jl")
include("refvalue.jl")
include("refpointer.jl")
include("checked.jl")
using .Checked
# array structures
include("indices.jl")
include("array.jl")
include("abstractarray.jl")
include("subarray.jl")
include("views.jl")
include("baseext.jl")
include("ntuple.jl")
include("abstractdict.jl")
include("iterators.jl")
using .Iterators: zip, enumerate
using .Iterators: Flatten, Filter, product # for generators
include("namedtuple.jl")
# numeric operations
include("hashing.jl")
include("rounding.jl")
using .Rounding
include("float.jl")
include("twiceprecision.jl")
include("complex.jl")
include("rational.jl")
include("multinverses.jl")
using .MultiplicativeInverses
include("abstractarraymath.jl")
include("arraymath.jl")
# SIMD loops
include("simdloop.jl")
using .SimdLoop
# map-reduce operators
include("reduce.jl")
## core structures
include("reshapedarray.jl")
include("reinterpretarray.jl")
include("bitarray.jl")
include("bitset.jl")
if !isdefined(Core, :Compiler)
include("docs/core.jl")
Core.atdoc!(CoreDocs.docm)
end
include("multimedia.jl")
using .Multimedia
# Some type
include("some.jl")
include("dict.jl")
include("abstractset.jl")
include("set.jl")
include("char.jl")
include("strings/basic.jl")
include("strings/string.jl")
include("strings/substring.jl")
# For OS specific stuff
include(string((length(Core.ARGS)>=2 ? Core.ARGS[2] : ""), "build_h.jl")) # include($BUILDROOT/base/build_h.jl)
include(string((length(Core.ARGS)>=2 ? Core.ARGS[2] : ""), "version_git.jl")) # include($BUILDROOT/base/version_git.jl)
include("osutils.jl")
include("c.jl")
# Core I/O
include("io.jl")
include("iostream.jl")
include("iobuffer.jl")
# strings & printing
include("intfuncs.jl")
include("strings/strings.jl")
include("parse.jl")
include("shell.jl")
include("regex.jl")
include("show.jl")
include("arrayshow.jl")
# multidimensional arrays
include("cartesian.jl")
using .Cartesian
include("multidimensional.jl")
include("permuteddimsarray.jl")
using .PermutedDimsArrays
include("broadcast.jl")
using .Broadcast
using .Broadcast: broadcasted, broadcasted_kwsyntax, materialize, materialize!
# missing values
include("missing.jl")
# version
include("version.jl")
# system & environment
include("sysinfo.jl")
include("libc.jl")
using .Libc: getpid, gethostname, time
const DL_LOAD_PATH = String[]
if Sys.isapple()
push!(DL_LOAD_PATH, "@loader_path/julia")
push!(DL_LOAD_PATH, "@loader_path")
end
include("env.jl")
# Scheduling
include("libuv.jl")
include("event.jl")
include("task.jl")
include("threads.jl")
include("lock.jl")
include("weakkeydict.jl")
# Logging
include("logging.jl")
using .CoreLogging
# functions defined in Random
function rand end
function randn end
# I/O
include("stream.jl")
include("filesystem.jl")
using .Filesystem
include("process.jl")
include("grisu/grisu.jl")
include("methodshow.jl")
include("secretbuffer.jl")
# core math functions
include("floatfuncs.jl")
include("math.jl")
using .Math
const (√)=sqrt
const (∛)=cbrt
INCLUDE_STATE = 2 # include = _include (from lines above)
# reduction along dims
include("reducedim.jl") # macros in this file relies on string.jl
include("accumulate.jl")
# basic data structures
include("ordering.jl")
using .Order
# Combinatorics
include("sort.jl")
using .Sort
# Fast math
include("fastmath.jl")
using .FastMath
function deepcopy_internal end
# enums
include("Enums.jl")
using .Enums
# BigInts and BigFloats
include("gmp.jl")
using .GMP
include("mpfr.jl")
using .MPFR
include("combinatorics.jl")
# more hashing definitions
include("hashing2.jl")
# irrational mathematical constants
include("irrationals.jl")
include("mathconstants.jl")
using .MathConstants: ℯ, π, pi
# (s)printf macros
include("printf.jl")
# import .Printf
# metaprogramming
include("meta.jl")
# concurrency and parallelism
include("channels.jl")
# utilities
include("deepcopy.jl")
include("download.jl")
include("summarysize.jl")
include("errorshow.jl")
# Stack frames and traces
include("stacktraces.jl")
using .StackTraces
include("initdefs.jl")
# worker threads
include("threadcall.jl")
# code loading
include("uuid.jl")
include("loading.jl")
# misc useful functions & macros
include("util.jl")
include("asyncmap.jl")
# deprecated functions
include("deprecated.jl")
# Some basic documentation
include("docs/basedocs.jl")
include("client.jl")
# Documentation -- should always be included last in sysimg.
include("docs/Docs.jl")
using .Docs
if isdefined(Core, :Compiler) && is_primary_base_module
Docs.loaddocs(Core.Compiler.CoreDocs.DOCS)
end
end_base_include = time_ns()
if is_primary_base_module
function __init__()
# try to ensuremake sure OpenBLAS does not set CPU affinity (#1070, #9639)
if !haskey(ENV, "OPENBLAS_MAIN_FREE") && !haskey(ENV, "GOTOBLAS_MAIN_FREE")
ENV["OPENBLAS_MAIN_FREE"] = "1"
end
# And try to prevent openblas from starting too many threads, unless/until specifically requested
if !haskey(ENV, "OPENBLAS_NUM_THREADS") && !haskey(ENV, "OMP_NUM_THREADS")
cpu_threads = Sys.CPU_THREADS::Int
if cpu_threads > 8 # always at most 8
ENV["OPENBLAS_NUM_THREADS"] = "8"
elseif haskey(ENV, "JULIA_CPU_THREADS") # or exactly as specified
ENV["OPENBLAS_NUM_THREADS"] = cpu_threads
end # otherwise, trust that openblas will pick CPU_THREADS anyways, without any intervention
end
# for the few uses of Libc.rand in Base:
Libc.srand()
# Base library init
reinit_stdio()
Multimedia.reinit_displays() # since Multimedia.displays uses stdout as fallback
# initialize loading
init_depot_path()
init_load_path()
nothing
end
INCLUDE_STATE = 3 # include = include_relative
end
const tot_time_stdlib = RefValue(0.0)
end # baremodule Base