Skip to content

Commit 6335386

Browse files
Unexport with, at_with, and ScopedValue from Base (JuliaLang#53004)
fixes JuliaLang#52535 --------- Co-authored-by: Kristoffer Carlsson <kcarlsson89@gmail.com>
1 parent 90d84d4 commit 6335386

File tree

6 files changed

+34
-17
lines changed

6 files changed

+34
-17
lines changed

base/exports.jl

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -653,11 +653,6 @@ export
653653
sprint,
654654
summary,
655655

656-
# ScopedValue
657-
with,
658-
@with,
659-
ScopedValue,
660-
661656
# logging
662657
@debug,
663658
@info,

base/logging.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
module CoreLogging
44

55
import Base: isless, +, -, convert, show
6+
import Base: ScopedValue, with, @with
67

78
export
89
AbstractLogger,

base/mpfr.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,9 @@ end
109109
tie_breaker_is_to_even(::MPFRRoundingMode) = true
110110

111111
const ROUNDING_MODE = Ref{MPFRRoundingMode}(MPFRRoundNearest)
112-
const CURRENT_ROUNDING_MODE = ScopedValue{MPFRRoundingMode}()
112+
const CURRENT_ROUNDING_MODE = Base.ScopedValue{MPFRRoundingMode}()
113113
const DEFAULT_PRECISION = Ref{Clong}(256)
114-
const CURRENT_PRECISION = ScopedValue{Clong}()
114+
const CURRENT_PRECISION = Base.ScopedValue{Clong}()
115115
# Basic type and initialization definitions
116116

117117
# Warning: the constants are MPFR implementation details from
@@ -162,7 +162,7 @@ significand_limb_count(x::BigFloat) = div(sizeof(x._d), sizeof(Limb), RoundToZer
162162
rounding_raw(::Type{BigFloat}) = something(Base.ScopedValues.get(CURRENT_ROUNDING_MODE), ROUNDING_MODE[])
163163
setrounding_raw(::Type{BigFloat}, r::MPFRRoundingMode) = ROUNDING_MODE[]=r
164164
function setrounding_raw(f::Function, ::Type{BigFloat}, r::MPFRRoundingMode)
165-
@with(CURRENT_ROUNDING_MODE => r, f())
165+
Base.@with(CURRENT_ROUNDING_MODE => r, f())
166166
end
167167

168168

@@ -1109,7 +1109,7 @@ Note: `nextfloat()`, `prevfloat()` do not use the precision mentioned by
11091109
The `base` keyword requires at least Julia 1.8.
11101110
"""
11111111
function setprecision(f::Function, ::Type{BigFloat}, prec::Integer; base::Integer=2)
1112-
@with(CURRENT_PRECISION => _convert_precision_from_base(prec, base), f())
1112+
Base.@with(CURRENT_PRECISION => _convert_precision_from_base(prec, base), f())
11131113
end
11141114

11151115
setprecision(f::Function, prec::Integer; base::Integer=2) = setprecision(f, BigFloat, prec; base)

base/scopedvalues.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ Dynamic scopes are propagated across tasks.
1919
# Examples
2020
2121
```jldoctest
22+
julia> using Base.ScopedValues;
23+
2224
julia> const sval = ScopedValue(1);
2325
2426
julia> sval[]

doc/src/base/scopedvalues.md

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ concurrently.
1717
Scoped values were introduced in Julia 1.11. In Julia 1.8+ a compatible
1818
implementation is available from the package ScopedValues.jl.
1919

20-
In its simplest form you can create a [`ScopedValue`](@ref) with a
21-
default value and then use [`with`](@ref Base.with) or [`@with`](@ref) to
20+
In its simplest form you can create a [`Base.ScopedValue`](@ref) with a
21+
default value and then use [`Base.with`](@ref with) or [`Base.@with`](@ref) to
2222
enter a new dynamic scope.
2323

2424
The new scope will inherit all values from the parent scope
@@ -54,6 +54,8 @@ f() # 1
5454
Now using a `ScopedValue` we can use **dynamic** scoping.
5555

5656
```julia
57+
using Base.ScopedValues
58+
5759
x = ScopedValue(1)
5860
f() = @show x[]
5961
with(x=>5) do
@@ -70,6 +72,8 @@ and you can set the value of multiple `ScopedValue`s with one call to `with`.
7072

7173

7274
```julia
75+
using Base.ScopedValues
76+
7377
const scoped_val = ScopedValue(1)
7478
const scoped_val2 = ScopedValue(0)
7579

@@ -94,6 +98,8 @@ Since `with` requires a closure or a function and creates another call-frame,
9498
it can sometimes be beneficial to use the macro form.
9599

96100
```julia
101+
using Base.ScopedValues
102+
97103
const STATE = ScopedValue{State}()
98104
with_state(f, state::State) = @with(STATE => state, f())
99105
```
@@ -106,7 +112,9 @@ The parent task and the two child tasks observe independent values of the
106112
same scoped value at the same time.
107113

108114
```julia
115+
using Base.ScopedValues
109116
import Base.Threads: @spawn
117+
110118
const scoped_val = ScopedValue(1)
111119
@sync begin
112120
with(scoped_val => 2)
@@ -128,7 +136,9 @@ values. You might want to explicitly [unshare mutable state](@ref unshare_mutabl
128136
when entering a new dynamic scope.
129137

130138
```julia
139+
using Base.ScopedValues
131140
import Base.Threads: @spawn
141+
132142
const sval_dict = ScopedValue(Dict())
133143

134144
# Example of using a mutable value wrongly
@@ -161,6 +171,8 @@ are not well suited for this kind of propagation; our only alternative would hav
161171
been to thread a value through the entire call-chain.
162172

163173
```julia
174+
using Base.ScopedValues
175+
164176
const LEVEL = ScopedValue(:GUEST)
165177

166178
function serve(request, response)
@@ -189,7 +201,9 @@ end
189201
### [Unshare mutable state](@id unshare_mutable_state)
190202

191203
```julia
204+
using Base.ScopedValues
192205
import Base.Threads: @spawn
206+
193207
const sval_dict = ScopedValue(Dict())
194208

195209
# If you want to add new values to the dict, instead of replacing
@@ -210,6 +224,7 @@ be in (lexical) scope. This means most often you likely want to use scoped value
210224
as constant globals.
211225

212226
```julia
227+
using Base.ScopedValues
213228
const sval = ScopedValue(1)
214229
```
215230

@@ -218,7 +233,9 @@ Indeed one can think of scoped values as hidden function arguments.
218233
This does not preclude their use as non-globals.
219234

220235
```julia
236+
using Base.ScopedValues
221237
import Base.Threads: @spawn
238+
222239
function main()
223240
role = ScopedValue(:client)
224241

@@ -241,6 +258,8 @@ If you find yourself creating many `ScopedValue`'s for one given module,
241258
it may be better to use a dedicated struct to hold them.
242259

243260
```julia
261+
using Base.ScopedValues
262+
244263
Base.@kwdef struct Configuration
245264
color::Bool = false
246265
verbose::Bool = false
@@ -260,7 +279,7 @@ end
260279
Base.ScopedValues.ScopedValue
261280
Base.ScopedValues.with
262281
Base.ScopedValues.@with
263-
Base.isassigned(::ScopedValue)
282+
Base.isassigned(::Base.ScopedValues.ScopedValue)
264283
Base.ScopedValues.get
265284
```
266285

test/scopedvalues.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# This file is a part of Julia. License is MIT: https://julialang.org/license
2-
import Base: ScopedValues
2+
using Base.ScopedValues
33

44
@testset "errors" begin
55
@test ScopedValue{Float64}(1)[] == 1.0
@@ -67,13 +67,13 @@ import Base.Threads: @spawn
6767
end
6868

6969
@testset "show" begin
70-
@test sprint(show, ScopedValue{Int}()) == "ScopedValue{$Int}(undefined)"
71-
@test sprint(show, sval) == "ScopedValue{$Int}(1)"
70+
@test sprint(show, ScopedValue{Int}()) == "Base.ScopedValues.ScopedValue{$Int}(undefined)"
71+
@test sprint(show, sval) == "Base.ScopedValues.ScopedValue{$Int}(1)"
7272
@test sprint(show, Core.current_scope()) == "nothing"
7373
with(sval => 2.0) do
74-
@test sprint(show, sval) == "ScopedValue{$Int}(2)"
74+
@test sprint(show, sval) == "Base.ScopedValues.ScopedValue{$Int}(2)"
7575
objid = sprint(show, Base.objectid(sval))
76-
@test sprint(show, Core.current_scope()) == "Base.ScopedValues.Scope(ScopedValue{$Int}@$objid => 2)"
76+
@test sprint(show, Core.current_scope()) == "Base.ScopedValues.Scope(Base.ScopedValues.ScopedValue{$Int}@$objid => 2)"
7777
end
7878
end
7979

0 commit comments

Comments
 (0)