1
+ # This file is a part of Julia. License is MIT: https://julialang.org/license
2
+
1
3
# Script to run in the process that generates juliac's object file output
2
4
3
5
# Run the verifier in the current world (before modifications), so that error
@@ -21,164 +23,8 @@ if Base.get_bool_env("JULIA_USE_FLISP_PARSER", false) === false
21
23
Base. JuliaSyntax. enable_in_core! ()
22
24
end
23
25
24
- # Patch methods in Core and Base
25
-
26
- @eval Core begin
27
- DomainError (@nospecialize (val), @nospecialize (msg:: AbstractString )) = (@noinline ; $ (Expr (:new , :DomainError , :val , :msg )))
28
- end
29
-
30
- (f:: Base.RedirectStdStream )(io:: Core.CoreSTDOUT ) = Base. _redirect_io_global (io, f. unix_fd)
31
-
32
- @eval Base begin
33
- depwarn (msg, funcsym; force:: Bool = false ) = nothing
34
- _assert_tostring (msg) = " "
35
- reinit_stdio () = nothing
36
- JuliaSyntax. enable_in_core! () = nothing
37
- init_active_project () = ACTIVE_PROJECT[] = nothing
38
- set_active_project (projfile:: Union{AbstractString,Nothing} ) = ACTIVE_PROJECT[] = projfile
39
- disable_library_threading () = nothing
40
- start_profile_listener () = nothing
41
- invokelatest_trimmed (f, args... ; kwargs... ) = f (args... ; kwargs... )
42
- const invokelatest = invokelatest_trimmed
43
- function sprint (f:: F , args:: Vararg{Any,N} ; context= nothing , sizehint:: Integer = 0 ) where {F<: Function ,N}
44
- s = IOBuffer (sizehint= sizehint)
45
- if context isa Tuple
46
- f (IOContext (s, context... ), args... )
47
- elseif context != = nothing
48
- f (IOContext (s, context), args... )
49
- else
50
- f (s, args... )
51
- end
52
- String (_unsafe_take! (s))
53
- end
54
- function show_typeish (io:: IO , @nospecialize (T))
55
- if T isa Type
56
- show (io, T)
57
- elseif T isa TypeVar
58
- print (io, (T:: TypeVar ). name)
59
- else
60
- print (io, " ?" )
61
- end
62
- end
63
- function show (io:: IO , T:: Type )
64
- if T isa DataType
65
- print (io, T. name. name)
66
- if T != = T. name. wrapper && length (T. parameters) > 0
67
- print (io, " {" )
68
- first = true
69
- for p in T. parameters
70
- if ! first
71
- print (io, " , " )
72
- end
73
- first = false
74
- if p isa Int
75
- show (io, p)
76
- elseif p isa Type
77
- show (io, p)
78
- elseif p isa Symbol
79
- print (io, " :" )
80
- print (io, p)
81
- elseif p isa TypeVar
82
- print (io, p. name)
83
- else
84
- print (io, " ?" )
85
- end
86
- end
87
- print (io, " }" )
88
- end
89
- elseif T isa Union
90
- print (io, " Union{" )
91
- show_typeish (io, T. a)
92
- print (io, " , " )
93
- show_typeish (io, T. b)
94
- print (io, " }" )
95
- elseif T isa UnionAll
96
- print (io, T. body:: Type )
97
- print (io, " where " )
98
- print (io, T. var. name)
99
- end
100
- end
101
- show_type_name (io:: IO , tn:: Core.TypeName ) = print (io, tn. name)
102
-
103
- mapreduce (f:: F , op:: F2 , A:: AbstractArrayOrBroadcasted ; dims= :, init= _InitialValue ()) where {F, F2} =
104
- _mapreduce_dim (f, op, init, A, dims)
105
- mapreduce (f:: F , op:: F2 , A:: AbstractArrayOrBroadcasted... ; kw... ) where {F, F2} =
106
- reduce (op, map (f, A... ); kw... )
107
-
108
- _mapreduce_dim (f:: F , op:: F2 , nt, A:: AbstractArrayOrBroadcasted , :: Colon ) where {F, F2} =
109
- mapfoldl_impl (f, op, nt, A)
110
-
111
- _mapreduce_dim (f:: F , op:: F2 , :: _InitialValue , A:: AbstractArrayOrBroadcasted , :: Colon ) where {F, F2} =
112
- _mapreduce (f, op, IndexStyle (A), A)
113
-
114
- _mapreduce_dim (f:: F , op:: F2 , nt, A:: AbstractArrayOrBroadcasted , dims) where {F, F2} =
115
- mapreducedim! (f, op, reducedim_initarray (A, dims, nt), A)
116
-
117
- _mapreduce_dim (f:: F , op:: F2 , :: _InitialValue , A:: AbstractArrayOrBroadcasted , dims) where {F,F2} =
118
- mapreducedim! (f, op, reducedim_init (f, op, A, dims), A)
119
-
120
- mapreduce_empty_iter (f:: F , op:: F2 , itr, ItrEltype) where {F, F2} =
121
- reduce_empty_iter (MappingRF (f, op), itr, ItrEltype)
122
- mapreduce_first (f:: F , op:: F2 , x) where {F,F2} = reduce_first (op, f (x))
123
-
124
- _mapreduce (f:: F , op:: F2 , A:: AbstractArrayOrBroadcasted ) where {F,F2} = _mapreduce (f, op, IndexStyle (A), A)
125
- mapreduce_empty (:: typeof (identity), op:: F , T) where {F} = reduce_empty (op, T)
126
- mapreduce_empty (:: typeof (abs), op:: F , T) where {F} = abs (reduce_empty (op, T))
127
- mapreduce_empty (:: typeof (abs2), op:: F , T) where {F} = abs2 (reduce_empty (op, T))
128
- end
129
- @eval Base. Sys begin
130
- __init_build () = nothing
131
- end
132
- @eval Base. GMP begin
133
- function __init__ ()
134
- try
135
- ccall ((:__gmp_set_memory_functions , libgmp), Cvoid,
136
- (Ptr{Cvoid},Ptr{Cvoid},Ptr{Cvoid}),
137
- cglobal (:jl_gc_counted_malloc ),
138
- cglobal (:jl_gc_counted_realloc_with_old_size ),
139
- cglobal (:jl_gc_counted_free_with_size ))
140
- ZERO. alloc, ZERO. size, ZERO. d = 0 , 0 , C_NULL
141
- ONE. alloc, ONE. size, ONE. d = 1 , 1 , pointer (_ONE)
142
- catch ex
143
- Base. showerror_nostdio (ex, " WARNING: Error during initialization of module GMP" )
144
- end
145
- # This only works with a patched version of GMP, ignore otherwise
146
- try
147
- ccall ((:__gmp_set_alloc_overflow_function , libgmp), Cvoid,
148
- (Ptr{Cvoid},),
149
- cglobal (:jl_throw_out_of_memory_error ))
150
- ALLOC_OVERFLOW_FUNCTION[] = true
151
- catch ex
152
- # ErrorException("ccall: could not find function...")
153
- if typeof (ex) != ErrorException
154
- rethrow ()
155
- end
156
- end
157
- end
158
- end
159
- @eval Base. Sort begin
160
- issorted (itr;
161
- lt:: T = isless, by:: F = identity, rev:: Union{Bool,Nothing} = nothing , order:: Ordering = Forward) where {T,F} =
162
- issorted (itr, ord (lt,by,rev,order))
163
- end
164
- @eval Base. TOML begin
165
- function try_return_datetime (p, year, month, day, h, m, s, ms)
166
- return DateTime (year, month, day, h, m, s, ms)
167
- end
168
- function try_return_date (p, year, month, day)
169
- return Date (year, month, day)
170
- end
171
- function parse_local_time (l:: Parser )
172
- h = @try parse_int (l, false )
173
- h in 0 : 23 || return ParserError (ErrParsingDateTime)
174
- _, m, s, ms = @try _parse_local_time (l, true )
175
- # TODO : Could potentially parse greater accuracy for the
176
- # fractional seconds here.
177
- return try_return_time (l, h, m, s, ms)
178
- end
179
- function try_return_time (p, h, m, s, ms)
180
- return Time (h, m, s, ms)
181
- end
26
+ if Base. JLOptions (). trim != 0
27
+ include (joinpath (@__DIR__ , " juliac-trim-base.jl" ))
182
28
end
183
29
184
30
# Load user code
@@ -229,85 +75,8 @@ let mod = Base.include(Main, ARGS[1])
229
75
end
230
76
end
231
77
232
- # Additional method patches depending on whether user code loads certain stdlibs
233
- let
234
- find_loaded_root_module (key:: Base.PkgId ) = Base. maybe_root_module (key)
235
-
236
- SparseArrays = find_loaded_root_module (Base. PkgId (
237
- Base. UUID (" 2f01184e-e22b-5df5-ae63-d93ebab69eaf" ), " SparseArrays" ))
238
- if SparseArrays != = nothing
239
- @eval SparseArrays. CHOLMOD begin
240
- function __init__ ()
241
- ccall ((:SuiteSparse_config_malloc_func_set , :libsuitesparseconfig ),
242
- Cvoid, (Ptr{Cvoid},), cglobal (:jl_malloc , Ptr{Cvoid}))
243
- ccall ((:SuiteSparse_config_calloc_func_set , :libsuitesparseconfig ),
244
- Cvoid, (Ptr{Cvoid},), cglobal (:jl_calloc , Ptr{Cvoid}))
245
- ccall ((:SuiteSparse_config_realloc_func_set , :libsuitesparseconfig ),
246
- Cvoid, (Ptr{Cvoid},), cglobal (:jl_realloc , Ptr{Cvoid}))
247
- ccall ((:SuiteSparse_config_free_func_set , :libsuitesparseconfig ),
248
- Cvoid, (Ptr{Cvoid},), cglobal (:jl_free , Ptr{Cvoid}))
249
- end
250
- end
251
- end
252
-
253
- Artifacts = find_loaded_root_module (Base. PkgId (
254
- Base. UUID (" 56f22d72-fd6d-98f1-02f0-08ddc0907c33" ), " Artifacts" ))
255
- if Artifacts != = nothing
256
- @eval Artifacts begin
257
- function _artifact_str (
258
- __module__,
259
- artifacts_toml,
260
- name,
261
- path_tail,
262
- artifact_dict,
263
- hash,
264
- platform,
265
- _:: Val{LazyArtifacts}
266
- ) where LazyArtifacts
267
- # If the artifact exists, we're in the happy path and we can immediately
268
- # return the path to the artifact:
269
- dirs = artifacts_dirs (bytes2hex (hash. bytes))
270
- for dir in dirs
271
- if isdir (dir)
272
- return jointail (dir, path_tail)
273
- end
274
- end
275
- error (" Artifact not found" )
276
- end
277
- end
278
- end
279
-
280
- Pkg = find_loaded_root_module (Base. PkgId (
281
- Base. UUID (" 44cfe95a-1eb2-52ea-b672-e2afdf69b78f" ), " Pkg" ))
282
- if Pkg != = nothing
283
- @eval Pkg begin
284
- __init__ () = rand () # TODO , methods that do nothing don't get codegened
285
- end
286
- end
287
-
288
- StyledStrings = find_loaded_root_module (Base. PkgId (
289
- Base. UUID (" f489334b-da3d-4c2e-b8f0-e476e12c162b" ), " StyledStrings" ))
290
- if StyledStrings != = nothing
291
- @eval StyledStrings begin
292
- __init__ () = rand ()
293
- end
294
- end
295
-
296
- Markdown = find_loaded_root_module (Base. PkgId (
297
- Base. UUID (" d6f4376e-aef5-505a-96c1-9c027394607a" ), " Markdown" ))
298
- if Markdown != = nothing
299
- @eval Markdown begin
300
- __init__ () = rand ()
301
- end
302
- end
303
-
304
- JuliaSyntaxHighlighting = find_loaded_root_module (Base. PkgId (
305
- Base. UUID (" ac6e5ff7-fb65-4e79-a425-ec3bc9c03011" ), " JuliaSyntaxHighlighting" ))
306
- if JuliaSyntaxHighlighting != = nothing
307
- @eval JuliaSyntaxHighlighting begin
308
- __init__ () = rand ()
309
- end
310
- end
78
+ if Base. JLOptions (). trim != 0
79
+ include (joinpath (@__DIR__ , " juliac-trim-stdlib.jl" ))
311
80
end
312
81
313
82
empty! (Core. ARGS )
0 commit comments