21 Star 49 Fork 0

Gitee 极速下载/julia-language

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
.devcontainer
.github
Compiler
base
cli
contrib
deps
doc
etc
src
stdlib
test
RelocationTestPkg1
RelocationTestPkg2
RelocationTestPkg3
RelocationTestPkg4
TestPkg
clangsa
depot/packages
embedding
gc
gcext
llvmpasses
manifest
netload
project
strings
testhelpers
trimming
unicode
.gitignore
Makefile
abstractarray.jl
ambiguous.jl
arrayops.jl
asyncmap.jl
atexit.jl
atomics.jl
backtrace.jl
binaryplatforms.jl
bitarray.jl
bitset.jl
boundscheck.jl
boundscheck_exec.jl
broadcast.jl
buildkitetestjson.jl
cartesian.jl
ccall.jl
channel_threadpool.jl
channels.jl
char.jl
checked.jl
choosetests.jl
client.jl
cmdlineargs.jl
combinatorics.jl
compileall.jl
complex.jl
copy.jl
core.jl
corelogging.jl
deprecation_exec.jl
dict.jl
docs.jl
download.jl
download_exec.jl
enums.jl
env.jl
error.jl
errorshow.jl
euler.jl
exceptions.jl
fastmath.jl
file.jl
filesystem.jl
float16.jl
floatapprox.jl
floatfuncs.jl
functional.jl
gc.jl
generic_map_tests.jl
gmp.jl
goto.jl
hashing.jl
int.jl
interpreter.jl
intfuncs.jl
intrinsics.jl
iobuffer.jl
iostream.jl
iterators.jl
keywordargs.jl
llvmcall.jl
llvmcall2.jl
loading.jl
math.jl
meta.jl
misc.jl
missing.jl
mod2pi.jl
mpfr.jl
namedtuple.jl
numbers.jl
offsetarray.jl
opaque_closure.jl
operators.jl
ordering.jl
osutils.jl
parse.jl
path.jl
precompile.jl
precompile_absint1.jl
precompile_absint2.jl
precompile_utils.jl
print_process_affinity.jl
profile_spawnmany_exec.jl
ranges.jl
rational.jl
read.jl
rebinding.jl
reduce.jl
reducedim.jl
reflection.jl
regex.jl
reinterpretarray.jl
relocatedepot.jl
rounding.jl
runtests.jl
ryu.jl
scopedvalues.jl
secretbuffer.jl
sets.jl
show.jl
simdloop.jl
smallarrayshrink.jl
some.jl
sorting.jl
spawn.jl
specificity.jl
stack_overflow.jl
stacktraces.jl
staged.jl
stdlib_dependencies.jl
stress.jl
stress_fd_exec.jl
subarray.jl
subtype.jl
syntax.jl
sysinfo.jl
terminfo.jl
test_exec.jl
test_sourcepath.jl
testdefs.jl
testenv.jl
threadpool_latency.jl
threadpool_use.jl
threads.jl
threads_exec.jl
triplequote.jl
tuple.jl
vecelement.jl
version.jl
worlds.jl
.buildkite-external-version
.clang-format
.clangd
.codecov.yml
.git-blame-ignore-revs
.gitattributes
.gitignore
.mailmap
AGENTS.md
CITATION.bib
CITATION.cff
CLAUDE.md
CONTRIBUTING.md
HISTORY.md
LICENSE.md
Make.inc
Makefile
NEWS.md
README.md
THIRDPARTY.md
VERSION
julia.spdx.json
pkgimage.mk
sysimage.mk
typos.toml
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/JuliaLang/julia
克隆/下载
scopedvalues.jl 4.52 KB
一键复制 编辑 原始数据 按行查看 历史
# This file is a part of Julia. License is MIT: https://julialang.org/license
using Base.ScopedValues
include(joinpath(@__DIR__,"../Compiler/test/irutils.jl"))
@testset "errors" begin
@test ScopedValue{Float64}(1)[] == 1.0
@test_throws InexactError ScopedValue{Int}(1.5)
let val = ScopedValue(1)
@test_throws MethodError val[] = 2
with() do
@test_throws MethodError val[] = 2
end
end
let val = ScopedValue{String}()
@test_throws KeyError val[]
end
let val = ScopedValue{Int}()
@test_throws KeyError val[]
end
@test_throws MethodError ScopedValue()
end
const sval = ScopedValue(1)
@testset "inheritance" begin
@test sval[] == 1
with() do
@test sval[] == 1
with() do
@test sval[] == 1
end
with(sval => 2) do
@test sval[] == 2
end
@test sval[] == 1
end
@test sval[] == 1
end
const sval_float = ScopedValue(1.0)
@testset "multiple scoped values" begin
with(sval => 2, sval_float => 2.0) do
@test sval[] == 2
@test sval_float[] == 2.0
end
with(sval => 2, sval => 3) do
@test sval[] == 3
end
end
emptyf() = nothing
@testset "conversion" begin
with(emptyf, sval_float=>2)
@test_throws MethodError with(emptyf, sval_float=>"hello")
a = ScopedValue(1)
with(a => 2.0) do
@test a[] == 2
@test a[] isa Int
end
a = ScopedValue(1.0)
with(a => 2) do
@test a[] == 2.0
@test a[] isa Float64
end
end
import Base.Threads: @spawn
@testset "tasks" begin
@test fetch(@spawn begin
sval[]
end) == 1
with(sval => 2) do
@test fetch(@spawn begin
sval[]
end) == 2
end
end
@testset "show" begin
@test sprint(show, ScopedValue{Int}()) == "Base.ScopedValues.ScopedValue{$Int}(undefined)"
@test sprint(show, sval) == "Base.ScopedValues.ScopedValue{$Int}(1)"
@test sprint(show, Core.current_scope()) == "nothing"
with(sval => 2.0) do
@test sprint(show, sval) == "Base.ScopedValues.ScopedValue{$Int}(2)"
objid = sprint(show, Base.objectid(sval))
@test sprint(show, Core.current_scope()) == "Base.ScopedValues.Scope(Base.ScopedValues.ScopedValue{$Int}@$objid => 2)"
end
end
const depth = ScopedValue(0)
function nth_with(f, n)
if n <= 0
f()
else
with(depth => n) do
nth_with(f, n-1)
end
end
end
@testset "nested with" begin
@testset for depth in 1:16
nth_with(depth) do
@test sval_float[] == 1.0
end
with(sval_float=>2.0) do
nth_with(depth) do
@test sval_float[] == 2.0
end
end
nth_with(depth) do
with(sval_float=>2.0) do
@test sval_float[] == 2.0
end
end
end
with(sval_float=>2.0) do
nth_with(15) do
@test sval_float[] == 2.0
with(sval_float => 3.0) do
@test sval_float[] == 3.0
end
end
end
end
@testset "macro" begin
@with sval=>2 sval_float=>2.0 begin
@test sval[] == 2
@test sval_float[] == 2.0
end
# Doesn't do much...
@with begin
@test sval[] == 1
@test sval_float[] == 1.0
end
@with sval=>2 sval_float=>2.0 begin
@with begin
@test sval[] == 2
@test sval_float[] == 2.0
end
end
end
@testset "isassigned" begin
sv = ScopedValue(1)
@test isassigned(sv)
sv = ScopedValue{Int}()
@test !isassigned(sv)
with(sv => 2) do
@test isassigned(sv)
end
end
# Test that the `@with` macro doesn't introduce unnecessary PhiC nodes
# (which can be hard for the optimizer to remove).
function with_macro_slot_cross()
a = 1
@with sval=>1 begin
a = sval_float[]
end
return a
end
let code = code_typed(with_macro_slot_cross)[1][1].code
@test !any(x->isa(x, Core.PhiCNode), code)
end
# inline constant scoped values
const inlineable_const_sv = ScopedValue(1)
@test fully_eliminated(; retval=(inlineable_const_sv => 1)) do
inlineable_const_sv => 1
end
# Handle nothrow scope bodies correctly (#56609)
@eval function nothrow_scope()
$(Expr(:tryfinally, :(), nothing, 1))
@test Core.current_scope() === nothing
end
nothrow_scope()
# https://github.com/JuliaLang/julia/issues/56062
@testset "issue #56062" begin
ts = Int[]
try
@with begin
return
end
catch err
finally
push!(ts, 2)
end
end
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/mirrors/julia-language.git
git@gitee.com:mirrors/julia-language.git
mirrors
julia-language
julia-language
master

搜索帮助