|
23 | 23 | @inline inv_rotate(R, r) = R \ r |
24 | 24 | @inline inv_rotate(::UniformScaling, r) = r |
25 | 25 |
|
| 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. |
26 | 29 | 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 |
35 | 36 | end |
36 | 37 |
|
37 | 38 | 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 |
49 | 45 | end |
50 | 46 |
|
51 | 47 | 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 |
62 | 54 | end |
0 commit comments