DIP1000 questions
Yuxuan Shui via Digitalmars-d
digitalmars-d at puremagic.com
Thu Jan 5 14:47:52 PST 2017
I was trying to read DIP1000, and I've made about half way
through it. I found it confusing/hard to follow, and sometimes
inconsistent. So I want to ask for some clarification. Help would
be appreciated.
> # Abstract
> A garbage collected language is inherently memory safe.
I think in order for this sentence to make sense, we need to
define what is a "garbage collected language". Does any language
that supports GC count? Because there's Boehm GC for C. Does D
count? Because dmd has this compiler switch: -boundscheck=off,
which clearly makes the language not memory safe.
> [...]
> # Description
> ## Definitions
> We also define lifetime for each value, which is the extent
> during which a value can be safely used.
OK.
> * For an unrestricted pointer, [...] lifetime is dictated by
> the lifetime of the data to which the pointer points to.
Why? The pointer itself can be used safely in its lexical scope
just like a value type. It's *pointer which has the lifetime of
the data. Maybe 'using' a pointer means dereferencing it?
> [...]
> ### Algebra of Lifetimes
> expression lifetime notes
> *e ∞ Lifetime is not transitive
Huh? I guess this is true if *e is a value type, since then it
would be copied. But what about:
int a;
int *b = &a;
int **c = &b;
*c = b so lifetime(*c) = lifetime(b), right? And then as per the
example given
> if (...) {
> int x;
> p = &x; // lifetime(p) is now equal to lifetime(x)
> }
lifetime(b) = lifetime(a). So lifetime(*c) = lifetime(a) != ∞.
Maybe that example is poorly written? Because:
> ## Fundamentals of scope
> [...]
> scope int* a = &global_var; // OK per rule 1,
> lifetime(&global_var) > lifetime(a)
> a = &global_var; // OK per rule 1,
> lifetime(&global_var) > lifetime(a)
As per the previous example. lifetime(a) will become
lifetime(&global_var) after first assignment. Would it be better
if we say lifetime(&global_var) > reachability(a)?
BTW, reachability() is defined at the beginning of this DIP, but
never used afterwards. Why bother defining it?
More information about the Digitalmars-d
mailing list