Remove PointerNativeTypeAssignmentRewriter by introducing a separate local with the exact type and assigning to/from it#107219
Merged
jkoritzinsky merged 2 commits intodotnet:mainfrom Sep 4, 2024
Conversation
…local with the exact type and assigning to/from it This removes our syntax rewriting, one of the main blockers for us to move to StringBuilder/string based codegen.
Contributor
|
Tagging subscribers to this area: @dotnet/interop-contrib |
Member
Author
|
This PR is ready for review |
jtschuster
approved these changes
Sep 4, 2024
Comment on lines
-74
to
+94
| // <nativeIdentifier> = <convertToUnmanaged>; | ||
| var assignment = AssignmentExpression( | ||
| SyntaxKind.SimpleAssignmentExpression, | ||
| IdentifierName(nativeIdentifier), | ||
| convertToUnmanaged); | ||
|
|
||
| ExpressionSyntax assignment; | ||
|
|
||
| if (unmanagedType is PointerTypeInfo pointer) | ||
| // For some of our exception marshallers, our marshaller returns nint for pointer types. | ||
| // As a result, we need to insert a cast here in case we're in that scenario (which we can't detect specifically). | ||
| if (unmanagedType is PointerTypeInfo ptrType) | ||
| { | ||
| // <nativeIdentifier> = (<nativeType>)<convertToUnmanaged>; | ||
| assignment = AssignmentExpression(SyntaxKind.SimpleAssignmentExpression, | ||
| IdentifierName(nativeIdentifier), | ||
| CastExpression(ptrType.Syntax, convertToUnmanaged)); | ||
| } | ||
| else | ||
| { | ||
| var rewriter = new PointerNativeTypeAssignmentRewriter(assignment.Right.ToString(), (PointerTypeSyntax)pointer.Syntax); | ||
| assignment = (AssignmentExpressionSyntax)rewriter.Visit(assignment); | ||
| // <nativeIdentifier> = <convertToUnmanaged>; | ||
| assignment = AssignmentExpression( | ||
| SyntaxKind.SimpleAssignmentExpression, | ||
| IdentifierName(nativeIdentifier), | ||
| convertToUnmanaged); | ||
| } | ||
|
|
Member
There was a problem hiding this comment.
Do we need anything like this for native marshalling?
Member
Author
There was a problem hiding this comment.
We only need this for unmarshalling because we only hit it in a specific (due to us artificially resolving the marshaller) scenario. We don't put ourselves into that situation in the native->managed case.
radekdoulik
pushed a commit
to radekdoulik/runtime
that referenced
this pull request
Sep 6, 2024
…local with the exact type and assigning to/from it (dotnet#107219)
jtschuster
pushed a commit
to jtschuster/runtime
that referenced
this pull request
Sep 17, 2024
…local with the exact type and assigning to/from it (dotnet#107219)
sirntar
pushed a commit
to sirntar/runtime
that referenced
this pull request
Sep 30, 2024
…local with the exact type and assigning to/from it (dotnet#107219)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This removes our syntax rewriting, one of the main blockers for us to move to StringBuilder/string based codegen.
Contributes to #95882