Maybe igored CTFE

bearophile bearophileHUGS at lycos.com
Sun Apr 4 11:03:57 PDT 2010


This is a small benchmark I've adapted from the old Shootout code, it tests the performance of exceptions (on dmd they are very slow). This code can be used at compile time too.
It contains a printf and exceptions that can't be used in CTFE, but if you compile this with -version=ctfe or if you add another enum in the main, this program compiles and prints 0/0. So I presume there's a bug, the ctfe code is not even compiled. Are you able to find reduce the case, so I can file a bug report?


import std.c.stdio: printf;

class LoException : Exception {
    this() {
        super(null);
    }
}

class HiException : Exception {
    this() {
        super(null);
    }
}

struct HiLo { int hi, lo; }

struct App {
    int hi, lo, count;

    void someFunction() {
        try {
            hiFunction();
        } catch (Exception e) {
            printf("We shouldn't get here\n");
        }
    }

    void hiFunction() {
        try {
            loFunction();
        } catch (HiException) {
            hi++;
        }
    }

    void loFunction() {
        try {
            blowUp();
        } catch (LoException) {
            lo++;
        }
    }

    void blowUp() {
        if (count & 1)
            throw new HiException();
        else
            throw new LoException();
    }

    auto go(int n) {
        for (count = 0; count < n; count++)
            someFunction();
        return HiLo(hi, lo);
    }
}

void main() {
    enum int n = 1000;
    App app;

    version (ctfe)
        enum HiLo result = app.go(n);
    else
        HiLo result = app.go(n);

    printf("excepts(%d) hi|lo = %d | %d\n", n, result.hi, result.lo);
}


Bye,
bearophile


More information about the Digitalmars-d-learn mailing list