DConf 2013 Day 3 Talk 2: Code Analysis for D with AnalyzeD by Stefan Rohe

Jonathan M Davis jmdavisProg at gmx.com
Wed Jun 12 13:41:27 PDT 2013


On Wednesday, June 12, 2013 22:29:15 Adam D. Ruppe wrote:
> On Wednesday, 12 June 2013 at 20:23:43 UTC, Andrej Mitrovic wrote:
> > Are you sure? A compiler can tell whether a function /can/ throw
> > (hence why nothrow works), so I assume it has information on
> > where an exception is thrown.
> 
> Consider this:
> 
> extern(D) void foo();
> void bar() { foo(); }
> 
> 
> That's legal D code, and foo could throw anything, and bar would
> have no idea what it is.

nothrow is like @safe or pure. The compiler knows whether that attribute on 
the function is valid by looking at the signatures of the functions called 
within that function (as well as what the built-in operations used are). The 
bodies of the functions being called never comes into play. At least some of 
the time, it would be theoretically possible for the compiler to go look in 
the bodies of the functions being called, but all of that stuff is based off of 
the function signatures, not their bodies. A function's body is only looked at 
when it's being compiled, not when other functions refer to it. And with the 
C linking model, it really doesn't make sense for the compiler to look at the 
bodies of other functions when compiling a function.

Tools could certainly look at source code and figure out stuff like what 
exceptions could be thrown from a particular function, but that requires 
having all of the source and examining it, and that's not how compilers 
normally work.

- Jonathan M Davis


More information about the Digitalmars-d-announce mailing list