https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94496

            Bug ID: 94496
           Summary: [D] Use aggressive optimizations in release mode
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: d
          Assignee: ibuclaw at gdcproject dot org
          Reporter: ibuclaw at gdcproject dot org
  Target Milestone: ---

There are a number of attributes in D that on the surface may seem like a good
fit for producing better optimisations, but there's always an escape latch, or
a latent issue that means none of these actually work in practice, for example:

- 'nothrow' code allows throwing Errors.
- 'pure' code allows modifying context state, what's called weakly pure.
- 'in' parameters are documented as const and no escape, but only the const
part was ever enforced.

So to avoid breaking code in ways that are not always immediately obvious,
nothing is really enforced.

When compiling release code however (-frelease), all considerations done to not
break runtime could be thrown out the window.  To take the first example, in
the event of throwing in a 'nothrow' function in release mode, crashing the
run-time at the point of throw is a perfectly valid thing to do, as Errors are
not meant to be caught.

Some of these optimizations could include (repeating some in the list above):

- 'nothrow' attribute sets TREE_NOTHROW
- 'pure' (strongly pure) attribute sets DECL_PURE_P or...
- ...function calls determined to be free of side effects set ECF_PURE if
DECL_PURE_P turns out to be problematic.
- 'const scope' parameters sets (EAF_NOCLOBBER | EAF_NOESCAPE)
- 'asm pure' unsets ASM_VOLATILE_P
- Enable strict aliasing for dynamic arrays.
- 'return' parameters set ERF_RETURNS_ARG.

More may come to mind later.

Reply via email to