Skip to content

Commit 258f06f

Browse files
committed
update text
1 parent fe4c222 commit 258f06f

File tree

6 files changed

+34
-30
lines changed

6 files changed

+34
-30
lines changed

base/expr.jl

+8-4
Original file line numberDiff line numberDiff line change
@@ -453,16 +453,20 @@ end
453453
"""
454454
@atomic ex
455455
456-
Mark `ex` as being performed atomically.
456+
Mark `ex` as being performed atomically, if `ex` is a supported expression.
457457
458458
```julia
459459
mutable struct Atomic{T}; @atomic x::T; end
460460
a = Atomic(1)
461461
@atomic a.x = 2 # set field x of a
462462
@atomic a.x # fetch field x or a
463-
# TODO: @atomic a.x += 1 # increment field x of a
464-
# TODO: @atomic +!(a.x, 1) # increment field x of a
465-
# TODO: @atomic a.x, z = y, a.x # swap field x of a with y and put the old value in z
463+
```
464+
465+
The following forms are also planned, but not yet implemented:
466+
```
467+
# @atomic a.x += 1 # increment field x of a
468+
# @atomic +!(a.x, 1) # increment field x of a
469+
# @atomic a.x, z = y, a.x # swap field x of a with y and put the old value in z
466470
```
467471
"""
468472
macro atomic(ex)

src/builtins.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -850,9 +850,9 @@ JL_CALLABLE(jl_f_getfield)
850850
}
851851
int isatomic = jl_field_isatomic(st, idx);
852852
if (!isatomic && order != jl_memory_order_notatomic && order != jl_memory_order_unspecified)
853-
jl_atomic_error("getfield non-atomic field cannot be accessed atomically");
853+
jl_atomic_error("getfield: non-atomic field cannot be accessed atomically");
854854
if (isatomic && order == jl_memory_order_notatomic)
855-
jl_atomic_error("getfield atomic field cannot be accessed non-atomically");
855+
jl_atomic_error("getfield: atomic field cannot be accessed non-atomically");
856856
v = jl_get_nth_field_checked(v, idx);
857857
if (order >= jl_memory_order_acq_rel || order == jl_memory_order_acquire)
858858
jl_fence(); // `v` already had at least consume ordering
@@ -875,7 +875,7 @@ JL_CALLABLE(jl_f_setfield)
875875
if (st == jl_module_type)
876876
jl_error("cannot assign variables in other modules");
877877
if (!st->mutabl)
878-
jl_errorf("setfield! immutable struct of type %s cannot be changed", jl_symbol_name(st->name->name));
878+
jl_errorf("setfield!: immutable struct of type %s cannot be changed", jl_symbol_name(st->name->name));
879879
size_t idx;
880880
if (jl_is_long(args[1])) {
881881
idx = jl_unbox_long(args[1]) - 1;
@@ -892,8 +892,8 @@ JL_CALLABLE(jl_f_setfield)
892892
}
893893
int isatomic = !!jl_field_isatomic(st, idx);
894894
if (isatomic == (order == jl_memory_order_notatomic))
895-
jl_atomic_error(isatomic ? "setfield! atomic field cannot be written non-atomically"
896-
: "setfield! non-atomic field cannot be written atomically");
895+
jl_atomic_error(isatomic ? "setfield!: atomic field cannot be written non-atomically"
896+
: "setfield!: non-atomic field cannot be written atomically");
897897
if (order >= jl_memory_order_acq_rel || order == jl_memory_order_release)
898898
jl_fence(); // `st->[idx]` will be have at least relaxed ordering
899899
set_nth_field(st, v, idx, args[2], isatomic);

src/cgutils.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -1725,7 +1725,7 @@ static bool emit_getfield_unknownidx(jl_codectx_t &ctx,
17251725
bool maybeatomic = stt->name->atomicfields != NULL;
17261726
if (strct.ispointer() && !maybeatomic) { // boxed or stack
17271727
if (order != jl_memory_order_notatomic && order != jl_memory_order_unspecified) {
1728-
emit_atomic_error(ctx, "getfield non-atomic field cannot be accessed atomically");
1728+
emit_atomic_error(ctx, "getfield: non-atomic field cannot be accessed atomically");
17291729
*ret = jl_cgval_t(); // unreachable
17301730
return true;
17311731
}
@@ -1800,11 +1800,11 @@ static jl_cgval_t emit_getfield_knownidx(jl_codectx_t &ctx, const jl_cgval_t &st
18001800
bool isatomic = jl_field_isatomic(jt, idx);
18011801
bool needlock = isatomic && !jl_field_isptr(jt, idx) && jl_datatype_size(jfty) > MAX_ATOMIC_SIZE;
18021802
if (!isatomic && order != jl_memory_order_notatomic && order != jl_memory_order_unspecified) {
1803-
emit_atomic_error(ctx, "getfield non-atomic field cannot be accessed atomically");
1803+
emit_atomic_error(ctx, "getfield: non-atomic field cannot be accessed atomically");
18041804
return jl_cgval_t(); // unreachable
18051805
}
18061806
if (isatomic && order == jl_memory_order_notatomic) {
1807-
emit_atomic_error(ctx, "getfield atomic field cannot be accessed non-atomically");
1807+
emit_atomic_error(ctx, "getfield: atomic field cannot be accessed non-atomically");
18081808
return jl_cgval_t(); // unreachable
18091809
}
18101810
if (jfty == jl_bottom_type) {
@@ -2926,7 +2926,7 @@ static void emit_setfield(jl_codectx_t &ctx,
29262926
}
29272927
}
29282928
else {
2929-
std::string msg = "setfield! immutable struct of type "
2929+
std::string msg = "setfield!: immutable struct of type "
29302930
+ std::string(jl_symbol_name(sty->name->name))
29312931
+ " cannot be changed";
29322932
emit_error(ctx, msg);

src/rtutils.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ JL_DLLEXPORT void jl_set_nth_field(jl_value_t *v, size_t idx0, jl_value_t *rhs)
363363
{
364364
jl_datatype_t *st = (jl_datatype_t*)jl_typeof(v);
365365
if (!st->mutabl)
366-
jl_errorf("setfield! immutable struct of type %s cannot be changed", jl_symbol_name(st->name->name));
366+
jl_errorf("setfield!: immutable struct of type %s cannot be changed", jl_symbol_name(st->name->name));
367367
if (idx0 >= jl_datatype_nfields(st))
368368
jl_bounds_error_int(v, idx0 + 1);
369369
//jl_value_t *ft = jl_field_type(st, idx0);

test/core.jl

+4-4
Original file line numberDiff line numberDiff line change
@@ -1099,9 +1099,9 @@ end
10991099
let strct = LoadError("yofile", 0, "bad")
11001100
@test nfields(strct) == 3 # sanity test
11011101
@test_throws BoundsError(strct, 10) getfield(strct, 10)
1102-
@test_throws ErrorException("setfield! immutable struct of type LoadError cannot be changed") setfield!(strct, 0, "")
1103-
@test_throws ErrorException("setfield! immutable struct of type LoadError cannot be changed") setfield!(strct, 4, "")
1104-
@test_throws ErrorException("setfield! immutable struct of type LoadError cannot be changed") setfield!(strct, :line, 0)
1102+
@test_throws ErrorException("setfield!: immutable struct of type LoadError cannot be changed") setfield!(strct, 0, "")
1103+
@test_throws ErrorException("setfield!: immutable struct of type LoadError cannot be changed") setfield!(strct, 4, "")
1104+
@test_throws ErrorException("setfield!: immutable struct of type LoadError cannot be changed") setfield!(strct, :line, 0)
11051105
@test strct.file == "yofile"
11061106
@test strct.line === 0
11071107
@test strct.error == "bad"
@@ -1123,7 +1123,7 @@ let mstrct = TestMutable("melm", 1, nothing)
11231123
@test_throws BoundsError(mstrct, 4) setfield!(mstrct, 4, "")
11241124
end
11251125
let strct = LoadError("yofile", 0, "bad")
1126-
@test_throws(ErrorException("setfield! immutable struct of type LoadError cannot be changed"),
1126+
@test_throws(ErrorException("setfield!: immutable struct of type LoadError cannot be changed"),
11271127
ccall(:jl_set_nth_field, Cvoid, (Any, Csize_t, Any), strct, 0, ""))
11281128
end
11291129
let mstrct = TestMutable("melm", 1, nothing)

test/intrinsics.jl

+12-12
Original file line numberDiff line numberDiff line change
@@ -153,20 +153,20 @@ end
153153
@test_intrinsic Core.Intrinsics.fptoui UInt Float16(3.3) UInt(3)
154154
end
155155

156-
@test Core.Intrinsics.atomics_fence(:sequentially_consistent) === nothing
157-
@test Core.Intrinsics.atomics_pointerref(C_NULL, :sequentially_consistent) == nothing
156+
@test Core.Intrinsics.atomic_fence(:sequentially_consistent) === nothing
157+
@test Core.Intrinsics.atomic_pointerref(C_NULL, :sequentially_consistent) == nothing
158158
let r = Ref{Int}(10)
159159
p = Base.unsafe_convert(Ptr{Int}, r)
160160
GC.@preserve r begin
161-
@test Core.Intrinsics.atomics_pointerref(p, :sequentially_consistent) === 10
162-
@test Core.Intrinsics.atomics_pointerset(p, 1, :sequentially_consistent) === p
163-
@test Core.Intrinsics.atomics_pointerref(p, :sequentially_consistent) === 1
164-
@test Core.Intrinsics.atomics_pointercmpswap(p, 100, 1, :sequentially_consistent, :sequentially_consistent) === true
165-
@test Core.Intrinsics.atomics_pointerref(p, :sequentially_consistent) === 100
166-
@test Core.Intrinsics.atomics_pointercmpswap(p, 1, 1, :sequentially_consistent, :sequentially_consistent) === false
167-
@test Core.Intrinsics.atomics_pointerref(p, :sequentially_consistent) === 100
168-
@test Core.Intrinsics.atomics_pointermodify(p, +, 1, :sequentially_consistent) == 100
169-
@test Core.Intrinsics.atomics_pointermodify(p, +, 1, :sequentially_consistent) == 101
170-
@test Core.Intrinsics.atomics_pointerref(p, :sequentially_consistent) == 102
161+
@test Core.Intrinsics.atomic_pointerref(p, :sequentially_consistent) === 10
162+
@test Core.Intrinsics.atomic_pointerset(p, 1, :sequentially_consistent) === p
163+
@test Core.Intrinsics.atomic_pointerref(p, :sequentially_consistent) === 1
164+
@test Core.Intrinsics.atomic_pointercmpswap(p, 100, 1, :sequentially_consistent, :sequentially_consistent) === true
165+
@test Core.Intrinsics.atomic_pointerref(p, :sequentially_consistent) === 100
166+
@test Core.Intrinsics.atomic_pointercmpswap(p, 1, 1, :sequentially_consistent, :sequentially_consistent) === false
167+
@test Core.Intrinsics.atomic_pointerref(p, :sequentially_consistent) === 100
168+
@test Core.Intrinsics.atomic_pointermodify(p, +, 1, :sequentially_consistent) == 100
169+
@test Core.Intrinsics.atomic_pointermodify(p, +, 1, :sequentially_consistent) == 101
170+
@test Core.Intrinsics.atomic_pointerref(p, :sequentially_consistent) == 102
171171
end
172172
end

0 commit comments

Comments
 (0)