-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
Inefficient implementation of PartialEq for nested (fieldless) enums #132628
Copy link
Copy link
Open
Labels
A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.A-codegenArea: Code generationArea: Code generationA-enumArea: Enums (discriminated unions, or more generally ADTs (algebraic data types))Area: Enums (discriminated unions, or more generally ADTs (algebraic data types))C-optimizationCategory: An issue highlighting optimization opportunities or PRs implementing suchCategory: An issue highlighting optimization opportunities or PRs implementing suchE-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.I-heavyIssue: Problems and improvements with respect to binary size of generated code.Issue: Problems and improvements with respect to binary size of generated code.I-slowIssue: Problems and improvements with respect to performance of generated code.Issue: Problems and improvements with respect to performance of generated code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Metadata
Metadata
Assignees
Labels
A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.A-codegenArea: Code generationArea: Code generationA-enumArea: Enums (discriminated unions, or more generally ADTs (algebraic data types))Area: Enums (discriminated unions, or more generally ADTs (algebraic data types))C-optimizationCategory: An issue highlighting optimization opportunities or PRs implementing suchCategory: An issue highlighting optimization opportunities or PRs implementing suchE-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.I-heavyIssue: Problems and improvements with respect to binary size of generated code.Issue: Problems and improvements with respect to binary size of generated code.I-slowIssue: Problems and improvements with respect to performance of generated code.Issue: Problems and improvements with respect to performance of generated code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Type
Fields
Give feedbackNo fields configured for issues without a type.
I'm not sure if this is the right place for this (might be LLVM to blame), just a bit of inefficient code that I noticed.
https://godbolt.org/z/K57orYj5h
The only difference between the two functions
eqandmatchesis the use of==andmatches!for the enum comparison. The generated code foreqincludes two calls toPartialEqforOuter, whereas the code formatcheshas a much simpler (inline) comparison.Also, the generated code for
PartialEqseems very inefficient, given the enum is just a two-byte value that can be directly compared.If you tinker with the enum definitions it's not hard to cause
eqto optimise exactly likematches.Example copied here