@@ -4,6 +4,16 @@ baremodule Base
4
4
5
5
using Core. Intrinsics, Core. IR
6
6
7
+ const _included_files = Array {Tuple{Module,String},1} ()
8
+ function include (mod:: Module , path:: String )
9
+ ccall (:jl_array_grow_end , Cvoid, (Any, UInt), _included_files, UInt (1 ))
10
+ Core. arrayset (true , _included_files, (mod, ccall (:jl_prepend_cwd , Any, (Any,), path)), arraylen (_included_files))
11
+ Core. println (path)
12
+ ccall (:jl_uv_flush , Nothing, (Ptr{Nothing},), Core. io_pointer (Core. stdout ))
13
+ Core. include (mod, path)
14
+ end
15
+ include (path:: String ) = include (Base, path)
16
+
7
17
const is_primary_base_module = ccall (:jl_module_parent , Ref{Module}, (Any,), Base) === Core. Main
8
18
ccall (:jl_set_istopmod , Cvoid, (Any, Bool), Base, is_primary_base_module)
9
19
@@ -20,50 +30,6 @@ setproperty!(x::Tuple, f::Int, v) = setfield!(x, f, v) # to get a decent error
20
30
getproperty (Core. @nospecialize (x), f:: Symbol ) = getfield (x, f)
21
31
setproperty! (x, f:: Symbol , v) = setfield! (x, f, convert (fieldtype (typeof (x), f), v))
22
32
23
- function include_relative end
24
- function include (mod:: Module , path:: AbstractString )
25
- local result
26
- if INCLUDE_STATE === 1
27
- result = _include1 (mod, path)
28
- elseif INCLUDE_STATE === 2
29
- result = _include (mod, path)
30
- elseif INCLUDE_STATE === 3
31
- result = include_relative (mod, path)
32
- end
33
- result
34
- end
35
- function include (path:: AbstractString )
36
- local result
37
- if INCLUDE_STATE === 1
38
- result = _include1 (Base, path)
39
- elseif INCLUDE_STATE === 2
40
- result = _include (Base, path)
41
- else
42
- # to help users avoid error (accidentally evaluating into Base), this is not allowed
43
- error (" Base.include(string) is discontinued, use `include(fname)` or `Base.include(@__MODULE__, fname)` instead." )
44
- end
45
- result
46
- end
47
- const _included_files = Array {Tuple{Module,String},1} ()
48
- function _include1 (mod:: Module , path)
49
- Core. Compiler. push! (_included_files, (mod, ccall (:jl_prepend_cwd , Any, (Any,), path)))
50
- Core. include (mod, path)
51
- end
52
- let SOURCE_PATH = " "
53
- # simple, race-y TLS, relative include
54
- global _include
55
- function _include (mod:: Module , path)
56
- prev = SOURCE_PATH
57
- path = normpath (joinpath (dirname (prev), path))
58
- push! (_included_files, (mod, abspath (path)))
59
- SOURCE_PATH = path
60
- result = Core. include (mod, path)
61
- SOURCE_PATH = prev
62
- result
63
- end
64
- end
65
- INCLUDE_STATE = 1 # include = Core.include
66
-
67
33
include (" coreio.jl" )
68
34
69
35
eval (x) = Core. eval (Base, x)
@@ -279,7 +245,21 @@ using .Math
279
245
const (√ )= sqrt
280
246
const (∛ )= cbrt
281
247
282
- INCLUDE_STATE = 2 # include = _include (from lines above)
248
+ # now switch to a simple, race-y TLS, relative include for the rest of Base
249
+ delete_method (which (include, (Module, String)))
250
+ let SOURCE_PATH = " "
251
+ global function include (mod:: Module , path:: String )
252
+ prev = SOURCE_PATH
253
+ path = normpath (joinpath (dirname (prev), path))
254
+ Core. println (path)
255
+ ccall (:jl_uv_flush , Nothing, (Ptr{Nothing},), Core. io_pointer (Core. stdout ))
256
+ push! (_included_files, (mod, abspath (path)))
257
+ SOURCE_PATH = path
258
+ result = Core. include (mod, path)
259
+ SOURCE_PATH = prev
260
+ return result
261
+ end
262
+ end
283
263
284
264
# reduction along dims
285
265
include (" reducedim.jl" ) # macros in this file relies on string.jl
@@ -377,6 +357,34 @@ if isdefined(Core, :Compiler) && is_primary_base_module
377
357
Docs. loaddocs (Core. Compiler. CoreDocs. DOCS)
378
358
end
379
359
360
+ # finally, now make `include` point to the full version
361
+ for m in methods (include)
362
+ delete_method (m)
363
+ end
364
+ # These functions are duplicated in client.jl/include(::String) for
365
+ # nicer stacktraces. Modifications here have to be backported there
366
+ include (mod:: Module , path:: AbstractString ) = include (mod, convert (String, path))
367
+ function include (mod:: Module , _path:: String )
368
+ path, prev = _include_dependency (mod, _path)
369
+ for callback in include_callbacks # to preserve order, must come before Core.include
370
+ invokelatest (callback, mod, path)
371
+ end
372
+ tls = task_local_storage ()
373
+ tls[:SOURCE_PATH ] = path
374
+ local result
375
+ try
376
+ # result = Core.include(mod, path)
377
+ result = ccall (:jl_load_ , Any, (Any, Any), mod, path)
378
+ finally
379
+ if prev === nothing
380
+ delete! (tls, :SOURCE_PATH )
381
+ else
382
+ tls[:SOURCE_PATH ] = prev
383
+ end
384
+ end
385
+ return result
386
+ end
387
+
380
388
end_base_include = time_ns ()
381
389
382
390
if is_primary_base_module
@@ -405,7 +413,7 @@ function __init__()
405
413
nothing
406
414
end
407
415
408
- INCLUDE_STATE = 3 # include = include_relative
416
+
409
417
end
410
418
411
419
const tot_time_stdlib = RefValue (0.0 )
0 commit comments