Skip to content

Conversation

@jjonescz
Copy link
Member

Test plan: #81207

Inspired by RefSafetyRules attribute.

Relevant speclet section: https://github.com/dotnet/csharplang/blob/main/proposals/unsafe-evolution.md#metadata

Inspired by RefSafetyRules attribute.
@jjonescz jjonescz marked this pull request as ready for review November 25, 2025 17:36
@jjonescz jjonescz requested a review from a team as a code owner November 25, 2025 17:36
@jjonescz jjonescz requested review from 333fred and jcouv November 25, 2025 17:36
@jcouv jcouv self-assigned this Nov 25, 2025
@jjonescz
Copy link
Member Author

jjonescz commented Dec 1, 2025

@333fred @jcouv for reviews, thanks #Closed

1 similar comment
@jjonescz
Copy link
Member Author

jjonescz commented Dec 2, 2025

@333fred @jcouv for reviews, thanks #Closed

Copy link
Member

@333fred 333fred left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't fully review the tests, too many questions on the first couple for me to continue.

@jjonescz jjonescz requested a review from 333fred December 3, 2025 12:29
Comment on lines +419 to +420
[assembly: MemorySafetyRules(2)]
[module: MemorySafetyRules(2)]
Copy link
Member

@333fred 333fred Dec 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a version of this test that doesn't manually apply MemorySafetyRules? IE, gets the rules from a reference (as it will from the BCL), and compiles successfully?

It would also be good to have some tests with multiple visible definitions of the attribute:

  1. No definition in the BCL, visible from 1 reference (I would expect this to succeed).
  2. No definition in the BCL, visible from 2 references (I would expect this to error).
  3. No definition in the BCL, visible from 2 references, plus defined in the current compilation (I would expect this to succeed).
  4. Definition in the BCL, visible from 2 references (I would expect this to succeed). #Resolved

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a version of this test that doesn't manually apply MemorySafetyRules? IE, gets the rules from a reference (as it will from the BCL), and compiles successfully?

I'm not sure I understand. A compilation cannot get the rules from a reference, it only gets them if it sets compilationOptions.WithMemorySafetyRules(2). The attribute itself can come from a reference, yes, that's tested in RulesAttribute_FromMetadata.

As for the suggestions, if I understand correctly:

  1. tested in RulesAttribute_FromMetadata,
  2. adding RulesAttribute_FromMetadata_Multiple (it doesn't fail, we synthesize our own attribute, RefSafetyRules behaves in the same way, adding a test for it too),
  3. included in RulesAttribute_FromMetadata_Multiple,
  4. seems equivalent to (1) - compiler doesn't distinguish between BCL and other references in this regard.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm specifically referring to the attribute. I agree 1-3 are covered, but 4 is not equivalent to 1. WellKnownTypes will prefer from the BCL over references.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. Added RulesAttribute_FromMetadata_Multiple_AndCorLib. Thanks.

Copy link
Member

@jcouv jcouv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done with review pass (commit 6)

@jjonescz jjonescz requested review from 333fred and jcouv December 4, 2025 12:58
Copy link
Member

@jcouv jcouv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM Thanks (commit 10) with minor feedback on LINQ usage

@jjonescz
Copy link
Member Author

jjonescz commented Dec 5, 2025

@333fred for another look, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants