Exception handling

H. S. Teoh via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Jul 14 16:35:45 PDT 2017


On Fri, Jul 14, 2017 at 11:09:23PM +0000, Stefan Koch via Digitalmars-d-learn wrote:
> On Friday, 14 July 2017 at 23:02:24 UTC, Moritz Maxeiner wrote:
> > On Friday, 14 July 2017 at 21:20:29 UTC, Jonathan M Davis wrote:
> > > Basically, the  compiler _never_ looks at the bodies of other
> > > functions when determining which attributes apply. It always
> > > [...].
> > 
> > I'm well aware of that, but it doesn't mean that it can't be
> > enhanced to do so (i.e. what it can do, not what it does do).
> 
> "Enhancing" the compiler to do so comes at a very very high cost.
> Which would force the compiler to look at every body it can look at to
> maybe discover a closed set of execptions. This would kill fast
> compile-times!

The compiler could internally keep track of which exceptions are thrown
by a function when it does a semantic pass on the function body. This
doesn't need to be represented in the language itself.

Also, when the function body is available and the compiler is compiling
code that calls this function, we're going to need to run semantic on
that function anyway, so it doesn't hurt to run semantic right then to
extract the list of exceptions. Later on semantic will just be no-op for
functions that have already gotten semantic triggered by exception
scanning. If that function already has semantic run, then the exception
list is already available so you just read it.

This won't slow the compiler down -- you're still doing the same work,
just in a different order.


T

-- 
Computers are like a jungle: they have monitor lizards, rams, mice, c-moss, binary trees... and bugs.


More information about the Digitalmars-d-learn mailing list