mazeppa-dev / mazeppa

A modern supercompiler for call-by-value functional languages
MIT License
366 stars 6 forks source link

Propagate positive information for inequality (`!=`) tests #7

Closed Hirrolot closed 1 month ago

Hirrolot commented 1 month ago

We already propagate positive information for equality tests (=). So the following code:

main(x) := match =(x, 0i32) {
    T() -> match =(x, 5i32) {
        T() -> Panic("impossible"),
        F() -> "Good 1"
    },
    F() -> match !=(x, 10i32) {
        T() -> "Good 2",
        F() -> match =(x, 10i32) {
            T() -> "Good 3",
            F() -> Panic("impossible")
        }
    }
};

Supercompiles to:

main(x) := match =(x, 0i32) {
    F() -> match !=(x, 10i32) {
        F() -> match =(x, 10i32) {
            F() -> Panic("impossible"),
            T() -> "Good 3"
        },
        T() -> "Good 2"
    },
    T() -> "Good 1"
};

However, the =(x, 10i32) test should be also eliminated, resulting in:

main(x) := match =(x, 0i32) {
    F() -> match !=(x, 10i32) {
        F() -> "Good 3",
        T() -> "Good 2"
    },
    T() -> "Good 1"
};