Emit RVA fields for constant collection expressions with spreads of `u8` literals.
- Dominant language
- C#
- Stars
- 20.7k
- Forks
- 4.3k
- PR merge metrics
- PR metrics pending
Description
Expressions like `(ReadOnlySpan)[.."Hello"u8, 1, 2, 3, 4, .."World"u8]` are emitted by constructing a `List`, adding its elements, calling `ToArray()`, and getting a span from it. However, the compiler can statically determine the expression's content, and should be able to directly emit an RVA blob.
This is an extension of #60896, and can help in expressions where text interleaves with binary content, or the expression does not entirely contain valid UTF-8 text. Without this, people have to write `[(byte)'H', (byte)'e', (byte)'l', (byte)'l', (byte)'o', …]` to get an optimized RVA blob (an analyzer and fixer could be added in the future).
Contributor guide
Research direction
Start by tracing the compiler implementation and tests for constant collection expressions, using the behavior described here and the related issue #60896 as entry points. Verify how spreads of u8 literals are currently emitted, then add coverage for the mixed "Hello"u8 and "World"u8 example and confirm that the completed expression emits an RVA blob rather than the current collection-building path.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 50/100