From 18e0f50d0cae0084e01848acaa1a336f341d5597 Mon Sep 17 00:00:00 2001 From: Arnav Kapoor Date: Wed, 28 May 2025 12:23:38 +0530 Subject: [PATCH 01/18] Add default MethodError handler for --trim mode --- base/client.jl | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/base/client.jl b/base/client.jl index 5bf658bead437..ea4e148f8053d 100644 --- a/base/client.jl +++ b/base/client.jl @@ -668,3 +668,14 @@ macro main(args...) esc(:main) end end + +try + Base._start() # or whatever the main function is +catch e + if Base.JLOptions().trim > 0 && isa(e, MethodError) + println("MethodError: no method matching ", e.f, " with argument types ", e.args) + exit(1) + end + Base.display_error(e, catch_backtrace()) + exit(1) +end From 4281f0ffd3578e12d132c607793f03c15933ca21 Mon Sep 17 00:00:00 2001 From: Arnav Kapoor Date: Thu, 29 May 2025 11:43:49 +0530 Subject: [PATCH 02/18] reviewed changes --- base/client.jl | 11 ----------- contrib/juliac-buildscript.jl | 10 ++++++++++ 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/base/client.jl b/base/client.jl index ea4e148f8053d..5bf658bead437 100644 --- a/base/client.jl +++ b/base/client.jl @@ -668,14 +668,3 @@ macro main(args...) esc(:main) end end - -try - Base._start() # or whatever the main function is -catch e - if Base.JLOptions().trim > 0 && isa(e, MethodError) - println("MethodError: no method matching ", e.f, " with argument types ", e.args) - exit(1) - end - Base.display_error(e, catch_backtrace()) - exit(1) -end diff --git a/contrib/juliac-buildscript.jl b/contrib/juliac-buildscript.jl index 1697ed3fd1f03..b37fccae08929 100644 --- a/contrib/juliac-buildscript.jl +++ b/contrib/juliac-buildscript.jl @@ -189,6 +189,16 @@ import Base.Experimental.entrypoint function _main(argc::Cint, argv::Ptr{Ptr{Cchar}})::Cint args = ccall(:jl_set_ARGS, Any, (Cint, Ptr{Ptr{Cchar}}), argc, argv)::Vector{String} return Main.main(args) + try + argc::Cint, argv::Ptr{Ptr{Cchar}} # existing main execution code + catch e + # generic error handling, mimic default exception behavior + Base.show_backtrace(stderr, catch_backtrace()) + println(stderr, "Error: ", e) + # exit or handle as needed + exit(1) + end + end end let mod = Base.include(Main, ARGS[1]) From e586a8b8524468cd84d41ce9af551a04403bf637 Mon Sep 17 00:00:00 2001 From: Arnav Kapoor Date: Fri, 30 May 2025 12:00:30 +0530 Subject: [PATCH 03/18] reviewed changes --- contrib/juliac-buildscript.jl | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/contrib/juliac-buildscript.jl b/contrib/juliac-buildscript.jl index b37fccae08929..32ab0545587e2 100644 --- a/contrib/juliac-buildscript.jl +++ b/contrib/juliac-buildscript.jl @@ -188,16 +188,12 @@ import Base.Experimental.entrypoint # for use as C main if needed function _main(argc::Cint, argv::Ptr{Ptr{Cchar}})::Cint args = ccall(:jl_set_ARGS, Any, (Cint, Ptr{Ptr{Cchar}}), argc, argv)::Vector{String} - return Main.main(args) try - argc::Cint, argv::Ptr{Ptr{Cchar}} # existing main execution code + return Main.main(args) catch e - # generic error handling, mimic default exception behavior Base.show_backtrace(stderr, catch_backtrace()) println(stderr, "Error: ", e) - # exit or handle as needed - exit(1) - end + return 1 # Or `exit(1)` if appropriate in context end end From 13dc7468791db6a491458a0b4f1ca4ff9d6dd979 Mon Sep 17 00:00:00 2001 From: Arnav Kapoor Date: Fri, 30 May 2025 14:38:23 +0530 Subject: [PATCH 04/18] Serialization doc changes --- stdlib/Serialization/docs/src/index.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/stdlib/Serialization/docs/src/index.md b/stdlib/Serialization/docs/src/index.md index 0d00e47ed84ce..eefdc80913cab 100644 --- a/stdlib/Serialization/docs/src/index.md +++ b/stdlib/Serialization/docs/src/index.md @@ -11,3 +11,19 @@ Serialization.serialize Serialization.deserialize Serialization.writeheader ``` +## File Format and Conventions + +!!! note + Julia's binary serialization format is not guaranteed to be stable across Julia versions or platforms. + It is best suited for temporary storage of data within the same Julia version. + +### Recommended File Extension + +While the Serialization module does not mandate a specific file extension, the Julia community commonly uses the `.jls` extension for serialized Julia files. + +Example: + +```julia +open("model.jls", "w") do io + serialize(io, my_model) +end \ No newline at end of file From 8f64f14b5d6ed7a5009a00a4537dde31be518ae2 Mon Sep 17 00:00:00 2001 From: Arnav Kapoor Date: Fri, 30 May 2025 14:41:15 +0530 Subject: [PATCH 05/18] Fix: Add trailing newline to pass whitespace --- stdlib/Serialization/docs/src/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/Serialization/docs/src/index.md b/stdlib/Serialization/docs/src/index.md index eefdc80913cab..83e4e28dd6436 100644 --- a/stdlib/Serialization/docs/src/index.md +++ b/stdlib/Serialization/docs/src/index.md @@ -26,4 +26,4 @@ Example: ```julia open("model.jls", "w") do io serialize(io, my_model) -end \ No newline at end of file +end From 29779ff96296f511537e67e60016c7c404ae46fa Mon Sep 17 00:00:00 2001 From: Arnav Kapoor Date: Mon, 2 Jun 2025 15:42:20 +0530 Subject: [PATCH 06/18] updating NEWS.md --- NEWS.md | 1 + base/mpfr.jl | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/NEWS.md b/NEWS.md index 92514cff37390..4b48669d29a97 100644 --- a/NEWS.md +++ b/NEWS.md @@ -15,6 +15,7 @@ Language changes is considered a bug fix ([#47102]) - The `hash` algorithm and its values have changed. Most `hash` specializations will remain correct and require no action. Types that reimplement the core hashing logic independently, such as some third-party string packages do, may require a migration to the new algorithm. ([#57509]) + - `setprecision` now utilizes `ScopedValue`, enhancing thread safety when setting precision levels. This change allows for safer precision adjustments in multi-threaded environments. ([#51362]) Compiler/Runtime improvements ----------------------------- diff --git a/base/mpfr.jl b/base/mpfr.jl index 25b7f0abe4b98..e2532deefd60f 100644 --- a/base/mpfr.jl +++ b/base/mpfr.jl @@ -1054,6 +1054,14 @@ Set the precision (in bits, by default) to be used for `T` arithmetic. If `base` is specified, then the precision is the minimum required to give at least `precision` digits in the given `base`. +!!! note + Temporarily sets the precision for BigFloat operations to `precision` bits within the scope of function `f`. This function is now thread-safe due to the use of `ScopedValue`, ensuring that precision settings do not interfere across threads. + +Example: + setprecision(256) do + # Operations here use 256-bit precision + end + !!! warning This function is not thread-safe. It will affect code running on all threads, but From 45ae40b4d648f0331ffc8933a1bd5eb4745d377e Mon Sep 17 00:00:00 2001 From: Arnav Kapoor Date: Mon, 2 Jun 2025 15:43:58 +0530 Subject: [PATCH 07/18] Update juliac-buildscript.jl --- contrib/juliac-buildscript.jl | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/contrib/juliac-buildscript.jl b/contrib/juliac-buildscript.jl index 32ab0545587e2..1697ed3fd1f03 100644 --- a/contrib/juliac-buildscript.jl +++ b/contrib/juliac-buildscript.jl @@ -188,13 +188,7 @@ import Base.Experimental.entrypoint # for use as C main if needed function _main(argc::Cint, argv::Ptr{Ptr{Cchar}})::Cint args = ccall(:jl_set_ARGS, Any, (Cint, Ptr{Ptr{Cchar}}), argc, argv)::Vector{String} - try - return Main.main(args) - catch e - Base.show_backtrace(stderr, catch_backtrace()) - println(stderr, "Error: ", e) - return 1 # Or `exit(1)` if appropriate in context - end + return Main.main(args) end let mod = Base.include(Main, ARGS[1]) From 4151c07dd4d5b9964b8c7aa2f65374fe84dd5ac1 Mon Sep 17 00:00:00 2001 From: Arnav Kapoor Date: Mon, 2 Jun 2025 15:44:16 +0530 Subject: [PATCH 08/18] Update index.md --- stdlib/Serialization/docs/src/index.md | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/stdlib/Serialization/docs/src/index.md b/stdlib/Serialization/docs/src/index.md index 83e4e28dd6436..0d00e47ed84ce 100644 --- a/stdlib/Serialization/docs/src/index.md +++ b/stdlib/Serialization/docs/src/index.md @@ -11,19 +11,3 @@ Serialization.serialize Serialization.deserialize Serialization.writeheader ``` -## File Format and Conventions - -!!! note - Julia's binary serialization format is not guaranteed to be stable across Julia versions or platforms. - It is best suited for temporary storage of data within the same Julia version. - -### Recommended File Extension - -While the Serialization module does not mandate a specific file extension, the Julia community commonly uses the `.jls` extension for serialized Julia files. - -Example: - -```julia -open("model.jls", "w") do io - serialize(io, my_model) -end From 69092642aebcd1d9003e7ed46b2e49558cc4acc9 Mon Sep 17 00:00:00 2001 From: Arnav Kapoor Date: Mon, 2 Jun 2025 15:49:22 +0530 Subject: [PATCH 09/18] Update mpfr.jl --- base/mpfr.jl | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/base/mpfr.jl b/base/mpfr.jl index e2532deefd60f..54b411da8fdb3 100644 --- a/base/mpfr.jl +++ b/base/mpfr.jl @@ -1055,19 +1055,15 @@ If `base` is specified, then the precision is the minimum required to give at least `precision` digits in the given `base`. !!! note - Temporarily sets the precision for BigFloat operations to `precision` bits within the scope of function `f`. This function is now thread-safe due to the use of `ScopedValue`, ensuring that precision settings do not interfere across threads. +Temporarily sets the precision for BigFloat operations to `precision` bits within the +scope of function `f`. This function is now thread-safe due to the use of `ScopedValue`, +ensuring that precision settings do not interfere across threads. Example: setprecision(256) do # Operations here use 256-bit precision end -!!! warning - - This function is not thread-safe. It will affect code running on all threads, but - its behavior is undefined if called concurrently with computations that use the - setting. - !!! compat "Julia 1.8" The `base` keyword requires at least Julia 1.8. """ From 1abdfb98a0aa804644a655e69d413ba8452e39d5 Mon Sep 17 00:00:00 2001 From: Arnav Kapoor Date: Mon, 2 Jun 2025 16:18:59 +0530 Subject: [PATCH 10/18] Update mpfr.jl --- base/mpfr.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/base/mpfr.jl b/base/mpfr.jl index 54b411da8fdb3..07d7bfaea3748 100644 --- a/base/mpfr.jl +++ b/base/mpfr.jl @@ -1055,9 +1055,9 @@ If `base` is specified, then the precision is the minimum required to give at least `precision` digits in the given `base`. !!! note -Temporarily sets the precision for BigFloat operations to `precision` bits within the -scope of function `f`. This function is now thread-safe due to the use of `ScopedValue`, -ensuring that precision settings do not interfere across threads. + Temporarily sets the precision for BigFloat operations to `precision` bits within the + scope of function `f`. This function is now thread-safe due to the use of `ScopedValue`, + ensuring that precision settings do not interfere across threads. Example: setprecision(256) do From d4881d1e5fe63121b2b8ad6ad292d50971d9c96c Mon Sep 17 00:00:00 2001 From: Arnav Kapoor Date: Mon, 2 Jun 2025 16:24:56 +0530 Subject: [PATCH 11/18] Update mpfr.jl --- base/mpfr.jl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/base/mpfr.jl b/base/mpfr.jl index 07d7bfaea3748..cc12ce31414ac 100644 --- a/base/mpfr.jl +++ b/base/mpfr.jl @@ -1060,9 +1060,11 @@ at least `precision` digits in the given `base`. ensuring that precision settings do not interfere across threads. Example: + ```julia setprecision(256) do # Operations here use 256-bit precision end +``` !!! compat "Julia 1.8" The `base` keyword requires at least Julia 1.8. From 68ebd6a18ddaa9a5aa18a3424582cafe48db5140 Mon Sep 17 00:00:00 2001 From: Arnav Kapoor Date: Mon, 2 Jun 2025 16:28:04 +0530 Subject: [PATCH 12/18] Update mpfr.jl --- base/mpfr.jl | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/base/mpfr.jl b/base/mpfr.jl index cc12ce31414ac..756c06de990ce 100644 --- a/base/mpfr.jl +++ b/base/mpfr.jl @@ -1061,9 +1061,7 @@ at least `precision` digits in the given `base`. Example: ```julia - setprecision(256) do - # Operations here use 256-bit precision - end + setprecision(256) ``` !!! compat "Julia 1.8" From eb591ec48c5c41346cb31a0241032935f9bc8ca9 Mon Sep 17 00:00:00 2001 From: Arnav Kapoor Date: Mon, 2 Jun 2025 16:29:30 +0530 Subject: [PATCH 13/18] Update mpfr.jl --- base/mpfr.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/base/mpfr.jl b/base/mpfr.jl index 756c06de990ce..5a24732d9c1d3 100644 --- a/base/mpfr.jl +++ b/base/mpfr.jl @@ -1061,7 +1061,7 @@ at least `precision` digits in the given `base`. Example: ```julia - setprecision(256) + setprecision(256) ``` !!! compat "Julia 1.8" From d0a7c3e52248cdd7a1ba22e7e539457e03014a46 Mon Sep 17 00:00:00 2001 From: Arnav Kapoor Date: Tue, 3 Jun 2025 10:06:23 +0530 Subject: [PATCH 14/18] Update mpfr.jl --- base/mpfr.jl | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/base/mpfr.jl b/base/mpfr.jl index 5a24732d9c1d3..f8de6144c5440 100644 --- a/base/mpfr.jl +++ b/base/mpfr.jl @@ -1050,20 +1050,23 @@ _precision_with_base_2(::Type{BigFloat}) = """ setprecision([T=BigFloat,] precision::Int; base=2) -Set the precision (in bits, by default) to be used for `T` arithmetic. +Set the global precision (in bits, by default) to be used for `T` arithmetic. If `base` is specified, then the precision is the minimum required to give at least `precision` digits in the given `base`. -!!! note - Temporarily sets the precision for BigFloat operations to `precision` bits within the - scope of function `f`. This function is now thread-safe due to the use of `ScopedValue`, - ensuring that precision settings do not interfere across threads. - Example: - ```julia +```julia setprecision(256) ``` +!!! note + Temporarily sets the precision for BigFloat operations to `precision` bits within the + scope of function `f`. This method is thread-safe due to the use of ScopedValue, ensuring + that precision settings do not interfere across threads. + +!!! compat "Julia 1.12" + Thread safety via ScopedValue is guaranteed starting with Julia 1.12. ([#51362]) + !!! compat "Julia 1.8" The `base` keyword requires at least Julia 1.8. """ From 9af09283e9fdb05816c1432ac0f07cf065581e5d Mon Sep 17 00:00:00 2001 From: Arnav Kapoor Date: Tue, 3 Jun 2025 10:08:51 +0530 Subject: [PATCH 15/18] Update NEWS.md --- NEWS.md | 1 - 1 file changed, 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index 4b48669d29a97..92514cff37390 100644 --- a/NEWS.md +++ b/NEWS.md @@ -15,7 +15,6 @@ Language changes is considered a bug fix ([#47102]) - The `hash` algorithm and its values have changed. Most `hash` specializations will remain correct and require no action. Types that reimplement the core hashing logic independently, such as some third-party string packages do, may require a migration to the new algorithm. ([#57509]) - - `setprecision` now utilizes `ScopedValue`, enhancing thread safety when setting precision levels. This change allows for safer precision adjustments in multi-threaded environments. ([#51362]) Compiler/Runtime improvements ----------------------------- From 7ccd0ef723fd64ea16e8e111d2299d9765441c6b Mon Sep 17 00:00:00 2001 From: Arnav Kapoor Date: Tue, 3 Jun 2025 10:13:25 +0530 Subject: [PATCH 16/18] v1.12 history --- HISTORY.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/HISTORY.md b/HISTORY.md index 6c2ca03662233..62d805e0047bb 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -91,6 +91,8 @@ Multi-threading changes the first time it is called, and then always return the same result value of type `T` every subsequent time afterwards. There are also `OncePerThread{T}` and `OncePerTask{T}` types for similar usage with threads or tasks ([#55793]). +* `setprecision` utilizes `ScopedValue` for enhancing thread safety when setting precision levels. + This change allows for safer precision adjustments in multi-threaded environments. ([#51362]) Build system changes -------------------- From ccb6cd962082e6daae16928673d29befebbfa749 Mon Sep 17 00:00:00 2001 From: Arnav Kapoor Date: Tue, 3 Jun 2025 10:16:03 +0530 Subject: [PATCH 17/18] Update HISTORY.md --- HISTORY.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/HISTORY.md b/HISTORY.md index 62d805e0047bb..b4c7064339276 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -91,7 +91,7 @@ Multi-threading changes the first time it is called, and then always return the same result value of type `T` every subsequent time afterwards. There are also `OncePerThread{T}` and `OncePerTask{T}` types for similar usage with threads or tasks ([#55793]). -* `setprecision` utilizes `ScopedValue` for enhancing thread safety when setting precision levels. +* `setprecision` utilizes `ScopedValue` for enhancing thread safety when setting precision levels. This change allows for safer precision adjustments in multi-threaded environments. ([#51362]) Build system changes From c97122cd0f0e5859c6d2969650523a9adf8c4e7b Mon Sep 17 00:00:00 2001 From: Arnav Kapoor Date: Tue, 3 Jun 2025 13:40:00 +0530 Subject: [PATCH 18/18] Update mpfr.jl --- base/mpfr.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/base/mpfr.jl b/base/mpfr.jl index f8de6144c5440..cd87dc2461e6e 100644 --- a/base/mpfr.jl +++ b/base/mpfr.jl @@ -1065,7 +1065,7 @@ Example: that precision settings do not interfere across threads. !!! compat "Julia 1.12" - Thread safety via ScopedValue is guaranteed starting with Julia 1.12. ([#51362]) + Thread safety via ScopedValue is guaranteed starting with Julia 1.12. !!! compat "Julia 1.8" The `base` keyword requires at least Julia 1.8.