Slightly inefficient codegen for is check against sealed type
- Dominant language
- C#
- Stars
- 18.3k
- Forks
- 5.6k
- PR merge metrics
- PR metrics pending
Description
### Description
Given:
```cs
internal class Program
{
public static bool A1(object o) => o is Sealed;
public static bool A2(object o) => o is not null && o.GetType() == typeof(Sealed);
}
public sealed class Sealed {}
```
All 2 variants currently emit different codegen, with A2 being the most efficient one. Ideally all 3 would use the A2 codegen.
### Configuration
n/a
### Regression?
no
### Data
https://compiler-explorer.com/z/Mae9oYbPf
https://compiler-explorer.com/z/31vdf49Yr
Contributor guide
Research direction
Start by comparing the two C# examples in the linked Compiler Explorer reproductions and inspect the generated code for A1 and A2. Trace the compiler code-generation path for sealed-type is checks; done means the variants produce the equivalent more efficient code shown for A2, with appropriate validation added where the relevant tests are found.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- compilers, performance
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100