-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Consider types with ref fields as managed and Allow pointers of managed types in some contexts #64064
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
Conversation
890cd14 to
d199d64
Compare
44239d5 to
c1b987b
Compare
RikkiGibson
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
approving so we can ship .NET 7. Not thrilled about being able to do var ptr = &managed; but not Managed* ptr = &managed; :)
| InExpressionTree = 1 << 30, | ||
|
|
||
| /// <summary> | ||
| /// The current context allows pointer types to managed types. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
consider indicating that UnsafeRegion is also needed, since absence of that flag means no pointer types are allowed. #Resolved
| // var x = &s; // 1 | ||
| Diagnostic(ErrorCode.WRN_ManagedAddr, "&s").WithArguments("S2").WithLocation(11, 17) | ||
| ); | ||
| var verifier = CompileAndVerify(comp, verify: Verification.Skipped); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't yet found out which unsafe operations are in fact safe from the JIT's perspective...
Since the IL is small and straightforward, I think it's sufficient.
| { | ||
| unsafe void M() | ||
| { | ||
| var x1 = stackalloc S[0]; // 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| // C** y3 = stackalloc C*[0]; // 4 | ||
| Diagnostic(ErrorCode.ERR_ManagedAddr, "C*").WithArguments("C").WithLocation(21, 29) | ||
| ); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| IL_0003: ret | ||
| } | ||
| "); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
Given the change that pointers to managed structs are now allowed and considered a warning instead of an error, could someone pls explain why the warning exists - i.e. why are pointers to managed structs considered unsafe (or "unsafe" unsafe) and why was it originally an error? What issues can I run into if I use pointers to managed structs? There is no documentation for the new warning and I can't find any info on it. |
The first commit reverts commit 76bd0d9.
Spec update for the relaxation: dotnet/csharplang#6453
Some context on EE logic: 02a3854
Note: I've built the runtime libraries locally with this change and some suppressions (as expected).