Feature Proposal: Const Generics
# Const Generics "Const Generics" stands for allowing constant value to be used in a type parameter. A fully working MVP implementation for CoreCLR can be found here: https://github.com/dotnet/runtime/pull/89636 And an implementation including the managed part can be found here: https://github.com/hez2010/runtime/tree/feature/const-generics-managed Link to the language proposal: https://github.com/dotnet/csharplang/discussions/7508 ## Background and Use Cases "Const Generics" enables the use cases where developers need to pass a const value through a type parameter. Typical use cases are templating for things like shuffle (its basically a guaranteed constant) as well as for numerics, tensors, matrices and etc. For example, fixed buffer and vector types [1], jagged arrays/spans [2], constrained shape of arrays [3], numeric types and multiplier types especially in graphics programming [4], expression abstractions [5], and value specialization [6]. For [1], we can have a type `struct ValueArray<T, int N>` to define a type of array of `T` with `N` elements. This can also be useful in variadic parameters. For example, a `params ValueArray<int, 5>` can represent a variadic parameter that receives only 5 int arguments. Beside, we can also leverage the `ValueArray<T, int N>` type to implement `params {ReadOnly}Span<T>`. For [2], we can use the const type parameter to define a `Span<T, int Dim>`, so we can use `Span` for multi-dimension arrays as well. For [3], we can const
Posted by hez2010 on Jul 31, 2023, 5:13 PM
Tags
Related issues
- [Meta] Feedback on granular control over Copilot changes
- unexpected status 401 Unauthorized issue
- [MODEL] Measurable quality regression in Claude generation 5 (Fable 5 / Opus 5 / Sonnet 5): worse nonsense detection, ~2x verbosity, under-disclosed model fallb
- [CRITICAL] Subagent spawning and subagent pattern bugs trigger infinite recursion, infinite token usage, grossly inefficient token usage, and lost accumulated s
- Video stops playing after some minutes
- [MODEL] Claude verbose code comments by default — ignores instructions to stop.
Raise real-world problems, find people facing the same issue, and discuss solutions.2,000 issues0 comments
github (Software)
[Meta] Feedback on granular control over Copilot changes
unexpected status 401 Unauthorized issue
[MODEL] Measurable quality regression in Claude generation 5 (Fable 5 / Opus 5 / Sonnet 5): worse nonsense detection, ~2x verbosity, under-disclosed model fallb
[CRITICAL] Subagent spawning and subagent pattern bugs trigger infinite recursion, infinite token usage, grossly inefficient token usage, and lost accumulated s
Video stops playing after some minutes
[MODEL] Claude verbose code comments by default — ignores instructions to stop.
Scope Codex VS Code chats to the current workspace/project
Update on "Co-authored-by: Copilot" in commit messages
Feature Proposal: Const Generics
# Const Generics "Const Generics" stands for allowing constant value to be used in a type parameter. A fully working MVP implementation for CoreCLR can be found here: https://github.com/dotnet/runtime/pull/89636 And an implementation including the managed part can be found here: https://github.com/hez2010/runtime/tree/feature/const-generics-managed Link to the language proposal: https://github.com/dotnet/csharplang/discussions/7508 ## Background and Use Cases "Const Generics" enables the use cases where developers need to pass a const value through a type parameter. Typical use cases are templating for things like shuffle (its basically a guaranteed constant) as well as for numerics, tensors, matrices and etc. For example, fixed buffer and vector types [1], jagged arrays/spans [2], constrained shape of arrays [3], numeric types and multiplier types especially in graphics programming [4], expression abstractions [5], and value specialization [6]. For [1], we can have a type `struct ValueArray<T, int N>` to define a type of array of `T` with `N` elements. This can also be useful in variadic parameters. For example, a `params ValueArray<int, 5>` can represent a variadic parameter that receives only 5 int arguments. Beside, we can also leverage the `ValueArray<T, int N>` type to implement `params {ReadOnly}Span<T>`. For [2], we can use the const type parameter to define a `Span<T, int Dim>`, so we can use `Span` for multi-dimension arrays as well. For [3], we can const
Comments (0)
No comments yet. Start the discussion.