Skip to content

Remove outdated sections that don't belong in the Collection Expressions proposal #9088

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 0 additions & 78 deletions proposals/csharp-12.0/collection-expressions.md
Original file line number Diff line number Diff line change
Expand Up @@ -1275,81 +1275,3 @@ such types are valid `params` types when these APIs are declared public and are
#### Conclusion

Approved with modifications [LDM-2024-01-10](https://github.com/dotnet/csharplang/blob/main/meetings/2024/LDM-2024-01-10.md)

## Design meetings
[design-meetings]: #design-meetings

https://github.com/dotnet/csharplang/blob/main/meetings/2021/LDM-2021-11-01.md#collection-literals
https://github.com/dotnet/csharplang/blob/main/meetings/2022/LDM-2022-03-09.md#ambiguity-of--in-collection-expressions
https://github.com/dotnet/csharplang/blob/main/meetings/2022/LDM-2022-09-28.md#collection-literals
https://github.com/dotnet/csharplang/blob/main/meetings/2024/LDM-2024-01-08.md
https://github.com/dotnet/csharplang/blob/main/meetings/2024/LDM-2024-01-10.md

## Working group meetings
[working-group-meetings]: #working-group-meetings

https://github.com/dotnet/csharplang/blob/main/meetings/working-groups/collection-literals/CL-2022-10-06.md
https://github.com/dotnet/csharplang/blob/main/meetings/working-groups/collection-literals/CL-2022-10-14.md
https://github.com/dotnet/csharplang/blob/main/meetings/working-groups/collection-literals/CL-2022-10-21.md
https://github.com/dotnet/csharplang/blob/main/meetings/working-groups/collection-literals/CL-2023-04-05.md
https://github.com/dotnet/csharplang/blob/main/meetings/working-groups/collection-literals/CL-2023-04-28.md
https://github.com/dotnet/csharplang/blob/main/meetings/working-groups/collection-literals/CL-2023-05-26.md
https://github.com/dotnet/csharplang/blob/main/meetings/working-groups/collection-literals/CL-2023-06-12.md
https://github.com/dotnet/csharplang/blob/main/meetings/working-groups/collection-literals/CL-2023-06-26.md
https://github.com/dotnet/csharplang/blob/main/meetings/working-groups/collection-literals/CL-2023-08-03.md
https://github.com/dotnet/csharplang/blob/main/meetings/working-groups/collection-literals/CL-2023-08-10.md

## Upcoming agenda items

* Stack allocations for huge collections might blow the stack. Should the compiler have a heuristic for placing this data on the heap? Should the language be unspecified to allow for this flexibility? We should follow what the spec/impl does for [`params Span<T>`](https://github.com/dotnet/csharplang/issues/1757). Options are:

* Always stackalloc. Teach people to be careful with Span. This allows things like `Span<T> span = [1, 2, ..s]` to work, and be fine as long as `s` is small. If this could blow the stack, users could always create an array instead, and then get a span around this. This seems like the most in line with what people might want, but with extreme danger.
* Only stackalloc when the literal has a *fixed* number of elements (i.e. no spread elements). This then likely makes things always safe, with fixed stack usage, and the compiler (hopefully) able to reuse that fixed buffer. However, it means things like `[1, 2, ..s]` would never be possible, even if the user knows it is completely safe at runtime.

* How does overload resolution work? If an API has:

```C#
public void M(T[] values);
public void M(List<T> values);
```

What happens with `M([1, 2, 3])`? We likely need to define 'betterness' for these conversions.

* Should we expand on collection initializers to look for the very common `AddRange` method? It could be used by the underlying constructed type to perform adding of spread elements potentially more efficiently. We might also want to look for things like `.CopyTo` as well. There may be drawbacks here as those methods might end up causing excess allocations/dispatches versus directly enumerating in the translated code.
* Generic type inference should be updated to flow type information to/from collection literals. For example:

```C#
void M<T>(T[] values);
M([1, 2, 3]);
```

It seems natural that this should be something the inference algorithm can be made aware of. Once this is supported for the 'base' constructible collection type cases (`T[]`, `I<T>`, `Span<T>` `new T()`), then it should also fall out of the `Collect(constructible_type)` case. For example:

```C#
void M<T>(ImmutableArray<T> values);
M([1, 2, 3]);
```

Here, `Immutable<T>` is constructible through an `init void Construct(T[] values)` method. So the `T[] values` type would be used with inference against `[1, 2, 3]` leading to an inference of `int` for `T`.

* Cast/Index ambiguity.

Today the following is an expression that is indexed into

```c#
var v = (Expr)[1, 2, 3];
```

But it would be nice to be able to do things like:

```c#
var v = (ImmutableArray<int>)[1, 2, 3];
```

Can/should we take a break here?

* Syntactic ambiguities with `?[`.

It might be worthwhile to change the rules for `nullable index access` to state that no space can occur between `?` and `[`. That would be a breaking change (but likely minor as VS already forces those together if you type them with a space). If we do this, then we can have `x?[y]` be parsed differently than `x ? [y]`.

A similar thing occurs if we want to go with https://github.com/dotnet/csharplang/issues/2926. In that world `x?.y` is ambiguous with `x ? .y`. If we require the `?.` to abut, we can syntactically distinguish the two cases trivially.