Bug 13970 – Simple flow analysis should eliminate null uses statically

Status
NEW
Severity
enhancement
Priority
P4
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Mac OS X
Creation time
2015-01-12T16:24:10Z
Last change time
2024-12-13T18:38:49Z
Assigned to
No Owner
Creator
Andrei Alexandrescu
Moved to GitHub: dmd#18927 →

Comments

Comment #0 by andrei — 2015-01-12T16:24:10Z
See the first snippet in http://maikklein.github.io/2015/01/11/Evaluating-D-for-games/. We should do the same amount of flow analysis we do in class constructors (regarding the call to super()) to emit a compile-time error for using null references.
Comment #1 by bearophile_hugs — 2015-01-12T16:41:15Z
I suggest to not put in Bugzilla links to code located elsewhere, because it can vanish. The example: import std.stdio; import std.typecons; class Foo(T){ public: T i; } class Bar{ public: int hello = 0; } void main() { Foo!(Bar) f; int i = f.i.hello; }
Comment #2 by destructionator — 2015-01-12T18:43:24Z
I believe this is done in dmd -O builds already void main() { Object o; o.toString(); } $ dmd n -O n.d(3): Error: null dereference in function _Dmain So the backend already does it, maybe the frontend can borrow that too.
Comment #3 by andrei — 2015-01-12T19:21:40Z
@Adam Discussions with Walter suggest the mechanism used by the optimizer is unsuitable here. The closest thing we have is the analysis that makes sure super() is called exactly once in derived constructors. That is well understood, covers a bunch of cases, and IIRC is used in Java as well. So using the same analysis for this purpose seem fit.
Comment #4 by robert.schadek — 2024-12-13T18:38:49Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/18927 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB