Acknowledged
CIQQA-3320

Make type checker aware of constants inlining and static branches elimination optimizations

The following code can't be built in debug mode with "-l 3 -O 3":

import Toybox.Lang;

(:release)
const CALL_G = true;

(:debug)
const CALL_G = false;

function f() as Number {
    if (CALL_G) {
        return g(); // Undefined symbol ':g' detected.
    } else {
        return 0;
    }
}

(:release)
function g() as Number {
    return 1;
}

The assembler code for release mode has no signs of branching due to compile time optimizations:

globals/f:
    argc 1
    spush globals
    getm
    lputv 0
    getselfv g
    invokemz
    return
globals/f_func_end:

Debug and release annotation are here only for testing purposes. The same happens for custom mutually exclusive annotations.

  • Thank you, that's what I do now, but I'd like to avoid additional "empty" function overhead.

  • I wish this could work! Unfortunately it never did, but maybe Garmin can make it work.

    What I do, is sometimes a bit messy, and you might need to use Prettier Monkey C extension for it to work. But in your case even you could make it work:

    (:debug) function g() as Number {return 0;}
    (:release) function g() as Number {return 1;}

    function f() as Number {return g();}