beardgame / utilities

General C# (game) utilities library, containing a variety of useful types and algorithms
MIT License
28 stars 14 forks source link

⬇️ Downgrade System.Collections.Immutable #382

Closed tomrijnbeek closed 6 months ago

tomrijnbeek commented 6 months ago

✨ What's this?

This PR downgrades the System.Collections.Immutable reference to 6.0.0.

It also replaces some references to ImmutableList to ImmutableArray which is a more appropriate data structures in our use cases.

🔍 Why do we want this?

System.Collections.Immutable isn't a "true" NuGet package. Rather it is part of the .NET runtime. Therefore, as long as we support .NET 6, we should stick with the current version.

Now... why not drop .NET 6 support you might ask? Well, because the Roslyn Source Generators in Rider completely break down if you target a runtime newer than .NET 6. If we want to be able to keep using types from Bearded.Utilities in binaries referenced by source generators (for example, in TD we use Id<T>) we will want to stick with .NET 6 for now.

One change to consider is to split the complex types, such as the algorithms and data structures, from the simpler stuff, so that it becomes easier to access some of the more atomic types (which could target a relatively low .NET version because we use no advanced features) without needing to pull in the bigger dependencies needed for complex code.

The change from ImmutableList to ImmutableArray is to ensure that access by index is a constant time operation.

🏗 How is it done?

Manual replacement in VS Code.

💥 Breaking changes

There is only one case where the public API used ImmutableList, that is the return type of CoffmanGraham. If you only rely on that being a collection anyway, code should remain compatible when recompiling (less likely to be binary compatible).