On 10/02/2015 08:15 AM, Per Nordlöw wrote:
On Friday, 2 October 2015 at 11:19:51 UTC, Andrei Alexandrescu wrote:
assert(e1 == e2)

could be lowered into:

{
  auto a = e1, b = e2;
  if (a == b) return;
  onAssertFailed!"=="(a, b, __FILE__, __LINE__, __FUNCTION__,
__MODULE__);
}()

So lowering is kind of like macro expansion for AST-nodes, then?

Not sure what you mean. The code up there will be replaced with the code down there :o).

Is DMD clever enough to avoid trigger postblits for

  auto a = e1, b = e2;
  if (a == b) return;

? Or is that part of the question whether this will work?

Ah, interesting. There is a means in the compiler to generate ref variables, which is not accessible for user code. But perhaps that's not necessary if we do the lowering as such:

(auto ref a, auto ref b) {
  if (a == b) return;
  onAssertFailed!"=="(a, b, __FILE__, __LINE__, __FUNCTION__, __MODULE__);
}(e1, e2)

So that evaluates the two expressions and avoids creating copies for lvalues.

I guess we only need on symbol name for `onAssertFailed` then instead of
`assertBinOp` and `assertUnOp`, right?

Probably a judgment call. I'd start with one and see what happens.


Andrei

Reply via email to