Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suboptimal code for non-linear is-pattern expressions compared to switch #59615

Closed
alrz opened this issue Feb 17, 2022 · 1 comment · Fixed by #68694 or #72273
Closed

Suboptimal code for non-linear is-pattern expressions compared to switch #59615

alrz opened this issue Feb 17, 2022 · 1 comment · Fixed by #68694 or #72273
Labels
Area-Compilers Code Gen Quality Room for improvement in the quality of the compiler's generated code
Milestone

Comments

@alrz
Copy link
Member

alrz commented Feb 17, 2022

class C {
    string Worst(object i) {
        // uses a boolean flag for the result and a conditional jump
        return i is 1 or C(2) ? "aaa" : "bbb";
    }
    string Switch(object i) {
        // falls back to switch arms when possible; this info isn't available for `is` expressions
        return i switch { 1 or C(2) => "aaa", _ => "bbb" };
    }
    string Best(object i) {
        // ideally it should be lowered as `||` - still "linear" without using a flag
        return i is 1 || i is C(2) ? "aaa" : "bbb";
    }
    void Deconstruct(out int i) => throw null;
}

Relates to #45679

(sharplab.io)

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels Feb 17, 2022
@jcouv jcouv added Code Gen Quality Room for improvement in the quality of the compiler's generated code and removed untriaged Issues and PRs which have not yet been triaged by a lead labels Feb 18, 2022
@jcouv jcouv added this to the Compiler.Next milestone Feb 18, 2022
@jcouv
Copy link
Member

jcouv commented Aug 17, 2023

Re-opening, as the change had to be reverted in #69582

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers Code Gen Quality Room for improvement in the quality of the compiler's generated code
Projects
None yet
3 participants