From d6cf763913efb0376a4f7643eadc0b981f47f483 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Gerardy Date: Tue, 11 Feb 2014 00:05:45 +0100 Subject: [PATCH] setfield -> setfield! --- base/boot.jl | 2 +- base/deprecated.jl | 2 ++ base/inference.jl | 2 +- base/serialize.jl | 2 +- doc/helpdb.jl | 6 +++--- doc/stdlib/base.rst | 6 +++--- src/builtins.c | 10 +++++----- src/dump.c | 2 +- src/julia-syntax.scm | 2 +- test/core.jl | 10 +++++----- 10 files changed, 23 insertions(+), 21 deletions(-) diff --git a/base/boot.jl b/base/boot.jl index 87f7ba8e5cde0..ebba9008482fa 100644 --- a/base/boot.jl +++ b/base/boot.jl @@ -138,7 +138,7 @@ export GetfieldNode, # object model functions apply, arraylen, arrayref, arrayset, arraysize, fieldtype, getfield, - setfield, yieldto, throw, tuple, tuplelen, tupleref, is, ===, isdefined, + setfield!, yieldto, throw, tuple, tuplelen, tupleref, is, ===, isdefined, convert_default, convert_tuple, kwcall, # type reflection issubtype, typeassert, typeof, apply_type, isa, diff --git a/base/deprecated.jl b/base/deprecated.jl index 2d8910d10a35e..8731076532a81 100644 --- a/base/deprecated.jl +++ b/base/deprecated.jl @@ -391,6 +391,8 @@ eval(Sys, :(@deprecate shlib_list dllist)) @deprecate myindexes localindexes +@deprecate setfield setfield! + # 0.3 discontinued functions function nnz(X) diff --git a/base/inference.jl b/base/inference.jl index 563b539f48940..09949c2822193 100644 --- a/base/inference.jl +++ b/base/inference.jl @@ -326,7 +326,7 @@ const getfield_tfunc = function (A, s, name) end end t_func[getfield] = (2, 2, getfield_tfunc) -t_func[setfield] = (3, 3, (o, f, v)->v) +t_func[setfield!] = (3, 3, (o, f, v)->v) const fieldtype_tfunc = function (A, s, name) if !isa(s,DataType) return Type diff --git a/base/serialize.jl b/base/serialize.jl index cd7cdf5fe1cf7..7e1a5cbd2f326 100644 --- a/base/serialize.jl +++ b/base/serialize.jl @@ -505,7 +505,7 @@ function deserialize(s, t::DataType) for i in 1:length(t.names) tag = int32(read(s, Uint8)) if tag==0 || !is(deser_tag[tag], UndefRefTag) - setfield(x, i, handle_deserialize(s, tag)) + setfield!(x, i, handle_deserialize(s, tag)) end end return x diff --git a/doc/helpdb.jl b/doc/helpdb.jl index e4df94b17160e..42bf0abf2bab3 100644 --- a/doc/helpdb.jl +++ b/doc/helpdb.jl @@ -491,11 +491,11 @@ "), -("Types","Base","setfield","setfield(value, name::Symbol, x) +("Types","Base","setfield!","setfield!(value, name::Symbol, x) Assign \"x\" to a named field in \"value\" of composite type. The - syntax \"a.b = c\" calls \"setfield(a, :b, c)\", and the syntax - \"a.(b) = c\" calls \"setfield(a, b, c)\". + syntax \"a.b = c\" calls \"setfield!(a, :b, c)\", and the syntax + \"a.(b) = c\" calls \"setfield!(a, b, c)\". "), diff --git a/doc/stdlib/base.rst b/doc/stdlib/base.rst index 02af58c01f1c2..208162aa7170c 100644 --- a/doc/stdlib/base.rst +++ b/doc/stdlib/base.rst @@ -301,11 +301,11 @@ Types Extract a named field from a value of composite type. The syntax ``a.b`` calls ``getfield(a, :b)``, and the syntax ``a.(b)`` calls ``getfield(a, b)``. -.. function:: setfield(value, name::Symbol, x) +.. function:: setfield!(value, name::Symbol, x) Assign ``x`` to a named field in ``value`` of composite type. - The syntax ``a.b = c`` calls ``setfield(a, :b, c)``, and the syntax ``a.(b) = c`` - calls ``setfield(a, b, c)``. + The syntax ``a.b = c`` calls ``setfield!(a, :b, c)``, and the syntax ``a.(b) = c`` + calls ``setfield!(a, b, c)``. .. function:: fieldoffsets(type) diff --git a/src/builtins.c b/src/builtins.c index 7557b3ef1d6c0..5dd7db6a792e7 100644 --- a/src/builtins.c +++ b/src/builtins.c @@ -500,13 +500,13 @@ JL_CALLABLE(jl_f_get_field) JL_CALLABLE(jl_f_set_field) { - JL_NARGS(setfield, 3, 3); + JL_NARGS(setfield!, 3, 3); jl_value_t *v = args[0]; jl_value_t *vt = (jl_value_t*)jl_typeof(v); if (vt == (jl_value_t*)jl_module_type) jl_error("cannot assign variables in other modules"); if (!jl_is_datatype(vt)) - jl_type_error("setfield", (jl_value_t*)jl_datatype_type, v); + jl_type_error("setfield!", (jl_value_t*)jl_datatype_type, v); jl_datatype_t *st = (jl_datatype_t*)vt; if (!st->mutabl) jl_errorf("type %s is immutable", st->name->name->name); @@ -517,12 +517,12 @@ JL_CALLABLE(jl_f_set_field) jl_throw(jl_bounds_exception); } else { - JL_TYPECHK(setfield, symbol, args[1]); + JL_TYPECHK(setfield!, symbol, args[1]); idx = jl_field_index(st, (jl_sym_t*)args[1], 1); } jl_value_t *ft = jl_tupleref(st->types, idx); if (!jl_subtype(args[2], ft, 1)) { - jl_type_error("setfield", ft, args[2]); + jl_type_error("setfield!", ft, args[2]); } jl_set_nth_field(v, idx, args[2]); return args[2]; @@ -995,7 +995,7 @@ void jl_init_primitives(void) add_builtin_func("tupleref", jl_f_tupleref); add_builtin_func("tuplelen", jl_f_tuplelen); add_builtin_func("getfield", jl_f_get_field); - add_builtin_func("setfield", jl_f_set_field); + add_builtin_func("setfield!", jl_f_set_field); add_builtin_func("fieldtype", jl_f_field_type); add_builtin_func("arraylen", jl_f_arraylen); diff --git a/src/dump.c b/src/dump.c index 03058070ec011..e28cf555b83fc 100644 --- a/src/dump.c +++ b/src/dump.c @@ -1190,7 +1190,7 @@ void jl_init_serializer(void) jl_symbol("arrayset"), jl_symbol("arrayref"), jl_symbol("arraylen"), jl_symbol("boundscheck"), jl_symbol("convert"), jl_symbol("typeassert"), - jl_symbol("getfield"), jl_symbol("setfield"), + jl_symbol("getfield"), jl_symbol("setfield!"), jl_symbol("tupleref"), jl_symbol("tuplelen"), jl_symbol("apply_type"), tuple_sym, diff --git a/src/julia-syntax.scm b/src/julia-syntax.scm index d4d4fb24d05ef..d872ad36d4a94 100644 --- a/src/julia-syntax.scm +++ b/src/julia-syntax.scm @@ -1456,7 +1456,7 @@ `(block ,.(if (eq? aa a) '() `((= ,aa ,(expand-forms a)))) ,.(if (eq? bb b) '() `((= ,bb ,(expand-forms b)))) - (call (top setfield) ,aa ,bb + (call (top setfield!) ,aa ,bb (call (top convert) (call (top fieldtype) ,aa ,bb) ,(expand-forms rhs))))))) diff --git a/test/core.jl b/test/core.jl index 0db56a9eeda79..519b8897a041b 100644 --- a/test/core.jl +++ b/test/core.jl @@ -538,15 +538,15 @@ begin @test_throws getfield(z, 3) strct = LoadError("", 0, "") - setfield(strct, 2, 8) + setfield!(strct, 2, 8) @test strct.line == 8 - setfield(strct, 3, "hi") + setfield!(strct, 3, "hi") @test strct.error == "hi" - setfield(strct, 1, "yo") + setfield!(strct, 1, "yo") @test strct.file == "yo" @test_throws getfield(strct, 10) - @test_throws setfield(strct, 0, "") - @test_throws setfield(strct, 4, "") + @test_throws setfield!(strct, 0, "") + @test_throws setfield!(strct, 4, "") end # allow typevar in Union to match as long as the arguments contain