Skip to content

Commit 20fae6a

Browse files
authored
Merge pull request #55 from SebastianM-C/claude/multi-threading-review-9hat4i
Fix laser equality/hashing and actually run the thread-safety test
2 parents bdb676b + 1ac3ccb commit 20fae6a

4 files changed

Lines changed: 33 additions & 33 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ on:
99

1010
jobs:
1111
test:
12-
name: Julia ${{ matrix.julia-version }} - ${{ matrix.os }} - ${{ matrix.julia-arch }} - threads ${{ matrix.julia-threads }}
12+
name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.julia-arch }} - threads ${{ matrix.julia-threads }}
1313
runs-on: ${{ matrix.os }}
1414
env:
1515
JULIA_NUM_THREADS: ${{ matrix.julia-threads }}

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "LaserTypes"
22
uuid = "e07c0bfa-524c-4f35-a151-c3dd916fa2f0"
3-
version = "0.2.1"
3+
version = "0.2.2"
44
authors = ["Sebastian Micluța-Câmpeanu <m.c.sebastian95@gmail.com>", "Petru-Vlad Toma <tomapv@gmail.com>"]
55

66
[deps]
@@ -27,7 +27,7 @@ TaskLocalValues = "0.1.3"
2727
UnPack = "1.0"
2828
Unitful = "1.0"
2929
UnitfulAtomic = "0.3, 1.0"
30-
julia = "1"
30+
julia = "1.10"
3131

3232
[extras]
3333
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"

src/utils.jl

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -23,40 +23,32 @@ end
2323
@inline inv_rotate(R, r) = R \ r
2424
@inline inv_rotate(::UniformScaling, r) = r
2525

26+
# The cache field is excluded from equality and hashing: it holds transient
27+
# task-local scratch state, so including it would make the results depend on
28+
# the evaluation history of the current task.
2629
function Base.:(==)(a::AbstractLaser, b::AbstractLaser)
27-
typeof(a) == typeof(b) &&
28-
fundamental_constants(a) == fundamental_constants(b) &&
29-
immutable_cache(a) == immutable_cache(b) &&
30-
mutable_cache(a) == mutable_cache(b) &&
31-
geometry(a) == geometry(b) &&
32-
polarization(a) == polarization(b) &&
33-
profile(a) == profile(b) &&
34-
true
30+
typeof(a) == typeof(b) || return false
31+
for f in fieldnames(typeof(a))
32+
f === :cache && continue
33+
getfield(a, f) == getfield(b, f) || return false
34+
end
35+
return true
3536
end
3637

3738
function Base.isequal(a::AbstractLaser, b::AbstractLaser)
38-
t1 = typeof(a)
39-
t2 = typeof(b)
40-
41-
isequal(t1, t2) &&
42-
fundamental_constants(a) == fundamental_constants(b) &&
43-
immutable_cache(a) == immutable_cache(b) &&
44-
mutable_cache(a) == mutable_cache(b) &&
45-
geometry(a) == mutable_cache(b) &&
46-
polarization(a) == polarization(b) &&
47-
profile(a) == profile(b) &&
48-
true
39+
typeof(a) == typeof(b) || return false
40+
for f in fieldnames(typeof(a))
41+
f === :cache && continue
42+
isequal(getfield(a, f), getfield(b, f)) || return false
43+
end
44+
return true
4945
end
5046

5147
function Base.hash(l::AbstractLaser, h::UInt)
52-
constants = fundamental_constants(l)
53-
derived = immutable_cache(l)
54-
cache = mutable_cache(l)
55-
geo = geometry(l)
56-
pol = polarization(l)
57-
prof = profile(l)
58-
59-
typename = Symbol(typeof(l))
60-
hash(prof, hash(pol, hash(geo, hash(cache, hash(derived, hash(constants,
61-
hash(typename, h)))))))
48+
h = hash(Symbol(typeof(l)), h)
49+
for f in fieldnames(typeof(l))
50+
f === :cache && continue
51+
h = hash(getfield(l, f), h)
52+
end
53+
return h
6254
end

test/runtests.jl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ using Test, SafeTestsets
88
@safetestset "Laguerre-Gauss" begin include("Laguerre-Gauss/laguerre-gauss.jl") end
99
@safetestset "Fμν" begin include("faraday.jl") end
1010
@safetestset "Derived" begin include("derived.jl") end
11+
@safetestset "Threads" begin include("threads.jl") end
1112
@safetestset "Show" begin include("show.jl") end
12-
@safetestset "QA" begin include("qa.jl") end
13+
# JET reports upstream runtime dispatch on Julia pre-releases (e.g. Base
14+
# printing internals and StaticArrays construction on 1.13-DEV), so only
15+
# run the QA tests on release versions.
16+
if isempty(VERSION.prerelease)
17+
@safetestset "QA" begin include("qa.jl") end
18+
else
19+
@info "Skipping JET QA tests on pre-release Julia" VERSION
20+
end
1321
end

0 commit comments

Comments
 (0)