Skip to content

Commit 03eebcc

Browse files
committed
Don't introduce scope in at-allowscalar.
1 parent cd237a4 commit 03eebcc

File tree

4 files changed

+20
-5
lines changed

4 files changed

+20
-5
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
1515

1616
[compat]
1717
Adapt = "2.0, 3.0"
18-
GPUArraysCore = "= 0.1.4"
18+
GPUArraysCore = "= 0.1.5"
1919
LLVM = "3.9, 4, 5"
2020
Reexport = "1"
2121
julia = "1.6"

lib/GPUArraysCore/Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "GPUArraysCore"
22
uuid = "46192b85-c4d5-4398-a991-12ede77f4527"
33
authors = ["Tim Besard <tim.besard@gmail.com>"]
4-
version = "0.1.4"
4+
version = "0.1.5"
55

66
[deps]
77
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"

lib/GPUArraysCore/src/GPUArraysCore.jl

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,16 @@ function assertscalar(op = "operation")
110110
return
111111
end
112112

113+
# Like a try-finally block, except without introducing the try scope
114+
# NOTE: This is deprecated and should not be used from user logic. A proper solution to
115+
# this problem will be introduced in https://github.com/JuliaLang/julia/pull/39217
116+
macro __tryfinally(ex, fin)
117+
Expr(:tryfinally,
118+
:($(esc(ex))),
119+
:($(esc(fin)))
120+
)
121+
end
122+
113123
"""
114124
@allowscalar() begin
115125
# code that can use scalar indexing
@@ -121,9 +131,11 @@ See also: [`allowscalar`](@ref).
121131
"""
122132
macro allowscalar(ex)
123133
quote
124-
task_local_storage(:ScalarIndexing, ScalarAllowed) do
125-
$(esc(ex))
126-
end
134+
local tls_value = get(task_local_storage(), :ScalarIndexing, nothing)
135+
task_local_storage(:ScalarIndexing, ScalarAllowed)
136+
@__tryfinally($(esc(ex)),
137+
isnothing(tls_value) ? delete!(task_local_storage(), :ScalarIndexing)
138+
: task_local_storage(:ScalarIndexing, tls_value))
127139
end
128140
end
129141

test/testsuite/indexing.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
end
1818

1919
@test_throws ErrorException x[]
20+
21+
@allowscalar y = 42
22+
@test y == 42
2023
end
2124

2225
@allowscalar @testset "getindex with $T" for T in eltypes

0 commit comments

Comments
 (0)