-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Description
In #111584, the alignment of ref struct
types was relaxed if the type didn't contained object or byref fields. The previous behavior was that a ref struct
was always pointer aligned. This change resulted in the following question:
Do we need to add this to breaking-change-rules.md? Would we consider it a breaking change to add a ref field to a ref struct that didn't previously have a ref field?
_Originally posted by @MichalStrehovsky in #111584 (review)
Initially this was accepted but then reverted due to pushback about the layout of types was an implementation details unless specifically documented.
If the libraries folks agree, I think it would be fine to explicitly match the current Roslyn behavior and say that adding first field of a new kind to an existing value type is disallowed change. Kind can be any of objref, byref or generic type argument, and the rule applies recursively.
Introducing new significant state in existing value types is close to impossible to do in compatible way for other reasons (e.g. it is why we have both DateTime and DateTimeOffset), so these situations do not come up in practice. I guess it is the reason why nobody bothered to mention it in the breaking changes doc up until now.
Originally posted by @jkotas in #111584 (comment)
The question now goes to the Libraries team, @stephentoub, and perhaps the .NET API review team, @bartonjs, to help us decide if adding a new kind of field (that is, objref, byref or generic type argument), to an existing value type should be considered a change that should result in a breaking change announcement.