More efficient constant conversion
- Dominant language
- C#
- Stars
- 451
- Forks
- 49
- Avg merge
- 13h 59m
- Merged PRs (30d)
- 6
Description
From #157:
> Current implementation is inefficient for constants. For example, `1 + 'b'` gives the following:
>
> ```
> IL_0000: ldc.i4 1
> IL_0005: ldc.i4 98
> IL_000a: conv.u1
> IL_000b: conv.i4
> IL_000c: add
> IL_000d: stloc V_0
> ```
>
> As you see, the char is first converted from int to byte, and then back to int. This could be removed if we implement lowering to implicit casts - the cast expression would see that the operand is a constant and emit it immediately. But this would require a lot of refactoring. so I left it for another day.
Contributor guide
Research direction
Start by tracing the compiler path that emits conversions for constant expressions, focusing on the proposed lowering to implicit casts and the cast expression's handling of constants. Confirm the redundant int-to-byte-to-int instructions in the reported `1 + 'b'` example, then define tests showing that constant conversions are emitted directly without changing the result.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- compilers
- Issue type
- Refactor
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100