@@ -240,6 +240,8 @@ module SymbolicUnitsParse
240
240
import ... DEFAULT_VALUE_TYPE
241
241
import ... DEFAULT_DIM_BASE_TYPE
242
242
243
+ _is_precompiling () = ccall (:jl_generating_output , Cint, ()) == 1
244
+
243
245
# Lazily create unit symbols (since there are so many)
244
246
module Constants
245
247
import .. CONSTANT_SYMBOLS
@@ -249,12 +251,14 @@ module SymbolicUnitsParse
249
251
import .. Quantity
250
252
import .. DEFAULT_VALUE_TYPE
251
253
import .. DEFAULT_DIM_BASE_TYPE
254
+ import .. _is_precompiling
252
255
253
256
import ... Constants as EagerConstants
254
257
255
258
const CONSTANT_SYMBOLS_EXIST = Ref {Bool} (false )
256
259
const CONSTANT_SYMBOLS_LOCK = Threads. SpinLock ()
257
260
function _generate_unit_symbols ()
261
+ _is_precompiling () && return nothing
258
262
CONSTANT_SYMBOLS_EXIST[] || lock (CONSTANT_SYMBOLS_LOCK) do
259
263
CONSTANT_SYMBOLS_EXIST[] && return nothing
260
264
for unit in setdiff (CONSTANT_SYMBOLS, SYMBOL_CONFLICTS)
@@ -273,7 +277,19 @@ module SymbolicUnitsParse
273
277
274
278
const UNIT_SYMBOLS_EXIST = Ref {Bool} (false )
275
279
const UNIT_SYMBOLS_LOCK = Threads. SpinLock ()
276
- function _generate_unit_symbols ()
280
+ function _generate_unit_symbols (; testing= Val (false ))
281
+ if _is_precompiling () || testing === Val (true )
282
+ @warn (
283
+ " Creating SymbolicDimensions objects during precompilation is not allowed, "
284
+ * " as symbolic units are not created until the first runtime call. "
285
+ * " You should use regular `Dimensions` instead for computations, "
286
+ * " and generally use `SymbolicDimensions` for display purposes. "
287
+ * " If needed, you can manually create `SymbolicDimensions` by calling "
288
+ * " the constructor explicitly, such as `Quantity(1.5, SymbolicDimensions; km=1, s=-1)`, "
289
+ * " which is equivalent to `us\" km/s\" `."
290
+ )
291
+ return nothing
292
+ end
277
293
UNIT_SYMBOLS_EXIST[] || lock (UNIT_SYMBOLS_LOCK) do
278
294
UNIT_SYMBOLS_EXIST[] && return nothing
279
295
for unit in UNIT_SYMBOLS
0 commit comments