www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - -vgc Info ok?

reply "Chris" <wendlec tcd.ie> writes:
The following

string[string] myarray = ["key":"value"];
string entry;
entry = myarray["key"]; // => vgc: indexing an associative array 
may cause GC allocation

Why is _accessing_ an assoc treated as indexing it?
May 18 2015
next sibling parent reply ketmar <ketmar ketmar.no-ip.org> writes:
On Mon, 18 May 2015 14:30:42 +0000, Chris wrote:

 The following
=20
 string[string] myarray =3D ["key":"value"];
 string entry;
 entry =3D myarray["key"]; // =3D> vgc: indexing an associative array may
 cause GC allocation
=20
 Why is _accessing_ an assoc treated as indexing it?
it can throw "out of range" error, which is `new`ed.=
May 18 2015
next sibling parent reply "Chris" <wendlec tcd.ie> writes:
On Monday, 18 May 2015 at 14:34:38 UTC, ketmar wrote:
 On Mon, 18 May 2015 14:30:42 +0000, Chris wrote:

 The following
 
 string[string] myarray = ["key":"value"];
 string entry;
 entry = myarray["key"]; // => vgc: indexing an associative 
 array may
 cause GC allocation
 
 Why is _accessing_ an assoc treated as indexing it?
it can throw "out of range" error, which is `new`ed.
But shouldn't it read "accessing an associative array may cause GC allocation"? And maybe a hint to the exception that may be thrown. It's not the same as myarray["key1] = "some value"; myarray["key2] = "some other value"; A bit confusing.
May 18 2015
parent reply ketmar <ketmar ketmar.no-ip.org> writes:
On Mon, 18 May 2015 14:41:19 +0000, Chris wrote:

 On Monday, 18 May 2015 at 14:34:38 UTC, ketmar wrote:
 On Mon, 18 May 2015 14:30:42 +0000, Chris wrote:

 The following
=20
 string[string] myarray =3D ["key":"value"];
 string entry;
 entry =3D myarray["key"]; // =3D> vgc: indexing an associative array ma=
y
 cause GC allocation
=20
 Why is _accessing_ an assoc treated as indexing it?
it can throw "out of range" error, which is `new`ed.
=20 But shouldn't it read "accessing an associative array may cause GC allocation"?
not any access may cause allocation. `auto e =3D "key" in myarray;` will=20 not allocate, for example. yet it's still accessing the array. it's=20 *indexing* which may end in allocation.
 And maybe a hint to the exception that may be thrown.
i believe that such explanation is a work for lint-like tool. burden=20 compiler with special cases can lead too far. ;-)
 It's not the same as
=20
 myarray["key1] =3D "some value";
 myarray["key2] =3D "some other value";
=20
 A bit confusing.
yes, it requires some knowledge of language and libraries. "-vgc" is not=20 a linter, though, it was made with some assumptions about user's=20 knowledge. yet you can open ER in bugzilla, maybe DMD developers will implement it.=20 i'm not a developer, and i can be wrong in reasons behind "-vgc".=
May 18 2015
parent "Chris" <wendlec tcd.ie> writes:
On Monday, 18 May 2015 at 18:40:15 UTC, ketmar wrote:
 On Mon, 18 May 2015 14:41:19 +0000, Chris wrote:

 On Monday, 18 May 2015 at 14:34:38 UTC, ketmar wrote:
 On Mon, 18 May 2015 14:30:42 +0000, Chris wrote:

 The following
 
 string[string] myarray = ["key":"value"];
 string entry;
 entry = myarray["key"]; // => vgc: indexing an associative 
 array may
 cause GC allocation
 
 Why is _accessing_ an assoc treated as indexing it?
it can throw "out of range" error, which is `new`ed.
But shouldn't it read "accessing an associative array may cause GC allocation"?
not any access may cause allocation. `auto e = "key" in myarray;` will not allocate, for example. yet it's still accessing the array. it's *indexing* which may end in allocation.
Yes, that's exactly what was driving at. Accessing is not indexing, and yet I get a warning for _indexing_, while the real reason is that a wrong access can cause an exception (which allocates). I.e. it should be "accessing an associative array may cause GC allocation on error" Maybe the message with "indexing" for accessing is merely reusing the message for indexing, or all assoc array operations are lumped together as "indexing". I dunno. It seems wrong to me, because it's inaccurate.
 And maybe a hint to the exception that may be thrown.
i believe that such explanation is a work for lint-like tool. burden compiler with special cases can lead too far. ;-)
 It's not the same as
 
 myarray["key1] = "some value";
 myarray["key2] = "some other value";
 
 A bit confusing.
yes, it requires some knowledge of language and libraries. "-vgc" is not a linter, though, it was made with some assumptions about user's knowledge. yet you can open ER in bugzilla, maybe DMD developers will implement it. i'm not a developer, and i can be wrong in reasons behind "-vgc".
May 19 2015
prev sibling parent reply "anonymous" <anonymous example.com> writes:
On Monday, 18 May 2015 at 14:34:38 UTC, ketmar wrote:
 it can throw "out of range" error, which is `new`ed.
Array access can also throw RangeError, but -vgc and nogc don't mind that: ---- void main() nogc { int[] a; auto b = a[0]; } ----
May 19 2015
parent ketmar <ketmar ketmar.no-ip.org> writes:
On Tue, 19 May 2015 13:17:15 +0000, anonymous wrote:

 On Monday, 18 May 2015 at 14:34:38 UTC, ketmar wrote:
 it can throw "out of range" error, which is `new`ed.
=20 Array access can also throw RangeError, but -vgc and nogc don't mind that: ---- void main() nogc { int[] a; auto b =3D a[0]; } ----
hm. now either this is bug, or "-vgc" should not warn about AA access.=20 will you fill an issue in bugzilla?=
May 19 2015
prev sibling next sibling parent reply "Namespace" <rswhite4 gmail.com> writes:
On Monday, 18 May 2015 at 14:30:43 UTC, Chris wrote:
 The following

 string[string] myarray = ["key":"value"];
 string entry;
 entry = myarray["key"]; // => vgc: indexing an associative 
 array may cause GC allocation

 Why is _accessing_ an assoc treated as indexing it?
No error if you use myarray.get("key", null); or string* entry = "key" in myarray;
May 19 2015
parent reply "Chris" <wendlec tcd.ie> writes:
On Tuesday, 19 May 2015 at 09:10:50 UTC, Namespace wrote:
 On Monday, 18 May 2015 at 14:30:43 UTC, Chris wrote:
 The following

 string[string] myarray = ["key":"value"];
 string entry;
 entry = myarray["key"]; // => vgc: indexing an associative 
 array may cause GC allocation

 Why is _accessing_ an assoc treated as indexing it?
No error if you use myarray.get("key", null); or string* entry = "key" in myarray;
What are the advantages / disadvantages of the two methods?
May 19 2015
parent "Namespace" <rswhite4 gmail.com> writes:
On Tuesday, 19 May 2015 at 09:43:06 UTC, Chris wrote:
 On Tuesday, 19 May 2015 at 09:10:50 UTC, Namespace wrote:
 On Monday, 18 May 2015 at 14:30:43 UTC, Chris wrote:
 The following

 string[string] myarray = ["key":"value"];
 string entry;
 entry = myarray["key"]; // => vgc: indexing an associative 
 array may cause GC allocation

 Why is _accessing_ an assoc treated as indexing it?
No error if you use myarray.get("key", null); or string* entry = "key" in myarray;
What are the advantages / disadvantages of the two methods?
You could get null with "in" if your key is not there. Besides that, no disadvantages.
May 19 2015
prev sibling parent reply "thedeemon" <dlang thedeemon.com> writes:
On Monday, 18 May 2015 at 14:30:43 UTC, Chris wrote:

 Why is _accessing_ an assoc treated as indexing it?
Are you sure you understand "indexing" as we do? It's not like indexing of databases, it's just "accessing by index" i.e. using myarray[some_index].
May 19 2015
parent reply "Chris" <wendlec tcd.ie> writes:
On Tuesday, 19 May 2015 at 11:08:52 UTC, thedeemon wrote:
 On Monday, 18 May 2015 at 14:30:43 UTC, Chris wrote:

 Why is _accessing_ an assoc treated as indexing it?
Are you sure you understand "indexing" as we do? It's not like indexing of databases, it's just "accessing by index" i.e. using myarray[some_index].
I understood indexing as assigning an index to something myarray["Index1"] = "First Entry"; As in https://en.wiktionary.org/wiki/indexing https://en.wiktionary.org/wiki/index#Verb
May 19 2015
parent reply ketmar <ketmar ketmar.no-ip.org> writes:
On Tue, 19 May 2015 11:36:32 +0000, Chris wrote:

 On Tuesday, 19 May 2015 at 11:08:52 UTC, thedeemon wrote:
 On Monday, 18 May 2015 at 14:30:43 UTC, Chris wrote:

 Why is _accessing_ an assoc treated as indexing it?
Are you sure you understand "indexing" as we do? It's not like indexing of databases, it's just "accessing by index" i.e. using myarray[some_index].
=20 I understood indexing as assigning an index to something =20 myarray["Index1"] =3D "First Entry"; =20 As in =20 https://en.wiktionary.org/wiki/indexing https://en.wiktionary.org/wiki/index#Verb
and that's wrong. ;-) most programmers in this case read "indexing" as=20 "accesing by index". it's a common term for such access. tbh, i didn't even understand you fully until i read the post i'm=20 answering to.=
May 19 2015
parent "Chris" <wendlec tcd.ie> writes:
On Tuesday, 19 May 2015 at 12:41:29 UTC, ketmar wrote:
 On Tue, 19 May 2015 11:36:32 +0000, Chris wrote:

 On Tuesday, 19 May 2015 at 11:08:52 UTC, thedeemon wrote:
 On Monday, 18 May 2015 at 14:30:43 UTC, Chris wrote:

 Why is _accessing_ an assoc treated as indexing it?
Are you sure you understand "indexing" as we do? It's not like indexing of databases, it's just "accessing by index" i.e. using myarray[some_index].
I understood indexing as assigning an index to something myarray["Index1"] = "First Entry"; As in https://en.wiktionary.org/wiki/indexing https://en.wiktionary.org/wiki/index#Verb
and that's wrong. ;-) most programmers in this case read "indexing" as "accesing by index". it's a common term for such access.
Is that so. I don't remember having come across this meaning. It is usually called "access" or "indexing access" (cf. http://dlang.org/hash-map.html). I still think that saying just "indexing" is not correct in -vgc, since it can be both assignment and access.
 tbh, i didn't even understand you fully until i read the post 
 i'm
 answering to.
May 19 2015