Skip to content
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

Update for new ref safety rules #169

Open
idg10 opened this issue Mar 3, 2023 · 0 comments
Open

Update for new ref safety rules #169

idg10 opened this issue Mar 3, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@idg10
Copy link
Contributor

idg10 commented Mar 3, 2023

C# 11.0 changes the ref safety rules. These changes are designed to support new scenarios that would previously have required unsafe code. In C# 11.0, we are able to provide the compiler with a more nuanced description of our intentions, and this enables it to recognize certain usage patterns as safe, which it would previously have had to reject as unsafe because its less detailed understanding of our code necessitated a more conservative approach.

Unfortunately, these new safety rules constitute a breaking change for code that makes use of ref struct. The upshot is that the Ais.NET codebase currently does not compile with the .NET 7.0 era SDK.

To participate in the newer, more flexible ref safety rules, it is necessary to provide the compiler with more information. C# 11.0 has introduced a new keyword, scoped for this purpose.

We should add the scoped keyword where necessary to enable the code to compile.

We also need to determine whether doing so causes problems for consumers of our library using pre-C# 11.0 compilation rules. When you build a component that relies on the new rules, the compiler emits a [module: RefSafetyRules(11)] annotation. It's not currently clear to me whether that renders the component unusable by older consumers. There are two possibilities:

  1. older compilers will be unaware of this annotation, and will apply the older, more conservative rules, and that will be OK
  2. libraries compiled under the newer, more flexible ref safety rules cannot be consumed by older compilers that don't know about those rules.

I'm hoping it's 1. If that's the case, we can just add the scoped annotations and make a new release available. But if it's 2, we will need to add a net7.0 target, and use conditional compilation to use these attributes on that target, but not the netstandard2.0 and netstandard2.1 targets.

@idg10 idg10 added the enhancement New feature or request label Mar 3, 2023
RomainDGx added a commit to signature-opensource/CK-Ais-Net that referenced this issue Mar 19, 2024
Some generated code are updated when I ran the tests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant