emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Emacs-diffs] trunk r114593: * lisp.h (eassert): Don't use 'assume'.


From: Eli Zaretskii
Subject: Re: [Emacs-diffs] trunk r114593: * lisp.h (eassert): Don't use 'assume'.
Date: Fri, 11 Oct 2013 12:36:47 +0300

> Date: Fri, 11 Oct 2013 02:18:51 -0700
> From: Daniel Colascione <address@hidden>
> CC: address@hidden, address@hidden
> 
> > That is a hypothetical situation.  In Emacs, the code is already
> > written on the assumption that *b != 0, so it is already "optimized"
> > for that.
> 
> While the programmer may have written her C code under the assumption 
> that an asserted condition holds, the compiler can't know that the 
> asserted condition holds when generating its machine code. The point of 
> the assume mechanism is to provide this information to the compiler.

The compiler will be unable to take advantage of that information,
because there's no source code to apply that information to.

> > In most cases, you won't see any code that can be optimized
> > out using this assumption, as the programmer already did that --
> > that's why she added the assertion in the first place.
> 
> At the C level, not the code generation level.

Code is generated from the C code, not out of thin air.

> > You are obviously thinking about a different reason of using
> > assertions: to assert certain invariants in the code and enforce
> > contracts of certain APIs.  But that is almost never the case in
> > Emacs, because (gasp!) almost every Emacs API has no well-defined
> > contract at all!
> 
> Aren't these two cases actually the same?

No, they are not.  E.g., if the programmer's assumption was wrong, and
there are in fact valid use cases where her assertion doesn't hold,
then in production code (where the assertions are defined away) your
'assume' will degrade the code quality for legitimate use cases.

> >>> , and lumping them
> >>> together into a single construct is likely to continue bumping upon
> >>> problems that stem from basic incompatibility between the use cases,
> >>> which target two different non-overlapping build types.
> >>
> >> Only when we have side effects.
> >
> > For now, yes.  I'm afraid that's just the tip of the iceberg, though.
> 
> What other problems can you imagine?

How should I know?  Does anyone know under which conditions, exactly,
a badly engineered bridge will collapse?

> > The problem is to make sure an assertion obviously _is_ free of side
> > effects.  With Emacs's massive use of macros, which call other macros,
> > which call other macros, which... -- that is extremely hard.  And why
> > should a programmer who just wants to assert something go to such
> > great lengths?  That is just a maintenance burden for which I find no
> > good justification.
> 
> What great lengths? Most common macros --- things like EQ --- are 
> clearly free of side effects.

There are a lot of macros much more complex than EQ.

> The more exotic assertions probably aren't worth assuming anyway.

Not sure I understand what you are saying here.

> If GCC had some builtin that allowed us to determine whether an 
> expression was free of side effects, we could use that to make the 
> decision automatically at compile time. Until we get such a facility, 
> though, providing some kind of eassert_and_assume macro helps people 
> make the best of simple assertions while avoiding the side effect 
> problem for more complicated ones.

I think you are wrong, but I guess I'm unable to convince you.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]