-
Notifications
You must be signed in to change notification settings - Fork 122
Emit full "Impl" types for delegates in 'cswinrtgen' #2161
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
Draft
Sergio0694
wants to merge
14
commits into
user/sergiopedri/dictionary-collection-ccw
Choose a base branch
from
user/sergiopedri/delegate-codegen
base: user/sergiopedri/dictionary-collection-ccw
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
5d30c24
Add type mismatch validation for interop method return values
Sergio0694 b6215ec
Add type and exception checks to marshaller selection
Sergio0694 5f8dd62
Add ManagedParameter marshalling logic
Sergio0694 bf95f24
Refactor method rewrite info classes for return values
Sergio0694 acdec2c
Add ManagedParameter support to method rewrite info
Sergio0694 89908bc
Refactor delegate Invoke method to use ABI parameter types
Sergio0694 f927d7d
Add IEnumerable, IEnumerator, and IList to type checks
Sergio0694 4388a51
Add type mappings for IEnumerator and IBindableIterator
Sergio0694 e93df6a
Add XAML IBindable interface mappings and adjust GUIDs
Sergio0694 f334d90
Track IMapChangedEventArgs1 type for MapChangedEventHandler
Sergio0694 3068206
Refactor marshaller creation to centralize logic
Sergio0694 e0c0199
Fix method import for marshaller calls
Sergio0694 6b22963
Refactor delegate invoke method parameter handling
Sergio0694 704c268
Add marshalling support for Type parameters
Sergio0694 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -8,8 +8,9 @@ | |||||||||||||||||||||||||||||
| using AsmResolver.PE.DotNet.Cil; | ||||||||||||||||||||||||||||||
| using AsmResolver.PE.DotNet.Metadata.Tables; | ||||||||||||||||||||||||||||||
| using WindowsRuntime.InteropGenerator.Factories; | ||||||||||||||||||||||||||||||
| using WindowsRuntime.InteropGenerator.References; | ||||||||||||||||||||||||||||||
| using WindowsRuntime.InteropGenerator.Generation; | ||||||||||||||||||||||||||||||
| using WindowsRuntime.InteropGenerator.Helpers; | ||||||||||||||||||||||||||||||
| using WindowsRuntime.InteropGenerator.References; | ||||||||||||||||||||||||||||||
| using static AsmResolver.PE.DotNet.Cil.CilOpCodes; | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| namespace WindowsRuntime.InteropGenerator.Builders; | ||||||||||||||||||||||||||||||
|
|
@@ -71,28 +72,37 @@ public static void IIDs( | |||||||||||||||||||||||||||||
| /// <param name="delegateType">The <see cref="TypeSignature"/> for the <see cref="Delegate"/> type.</param> | ||||||||||||||||||||||||||||||
| /// <param name="interopDefinitions">The <see cref="InteropDefinitions"/> instance to use.</param> | ||||||||||||||||||||||||||||||
| /// <param name="interopReferences">The <see cref="InteropReferences"/> instance to use.</param> | ||||||||||||||||||||||||||||||
| /// <param name="emitState">The emit state for this invocation.</param> | ||||||||||||||||||||||||||||||
| /// <param name="module">The interop module being built.</param> | ||||||||||||||||||||||||||||||
| /// <param name="implType">The resulting implementation type.</param> | ||||||||||||||||||||||||||||||
| public static void ImplType( | ||||||||||||||||||||||||||||||
| GenericInstanceTypeSignature delegateType, | ||||||||||||||||||||||||||||||
| InteropDefinitions interopDefinitions, | ||||||||||||||||||||||||||||||
| InteropReferences interopReferences, | ||||||||||||||||||||||||||||||
| InteropGeneratorEmitState emitState, | ||||||||||||||||||||||||||||||
| ModuleDefinition module, | ||||||||||||||||||||||||||||||
| out TypeDefinition implType) | ||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||
| MemberReference delegateInvokeMethod = interopReferences.DelegateInvoke(delegateType, module); | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| // Prepare the sender and arguments types. This path is only ever reached for valid | ||||||||||||||||||||||||||||||
| // generic Windows Runtime delegate types, and they all have exactly two type arguments. | ||||||||||||||||||||||||||||||
| TypeSignature senderType = ((MethodSignature)delegateInvokeMethod.Signature!).ParameterTypes[0]; | ||||||||||||||||||||||||||||||
| TypeSignature argsType = ((MethodSignature)delegateInvokeMethod.Signature!).ParameterTypes[1]; | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| // Define the 'Invoke' method as follows: | ||||||||||||||||||||||||||||||
| // | ||||||||||||||||||||||||||||||
| // [UnmanagedCallersOnly(CallConvs = [typeof(CallConvMemberFunction)])] | ||||||||||||||||||||||||||||||
| // private static int Invoke(void* thisPtr, void* sender, void* e) | ||||||||||||||||||||||||||||||
| // private static int Invoke(void* thisPtr, <ABI_SENDER_TYPE> sender, <ABI_ARGS_TYPE> e) | ||||||||||||||||||||||||||||||
| MethodDefinition invokeMethod = new( | ||||||||||||||||||||||||||||||
| name: "Invoke"u8, | ||||||||||||||||||||||||||||||
| attributes: MethodAttributes.Private | MethodAttributes.HideBySig | MethodAttributes.Static, | ||||||||||||||||||||||||||||||
| signature: MethodSignature.CreateStatic( | ||||||||||||||||||||||||||||||
| returnType: module.CorLibTypeFactory.Int32, | ||||||||||||||||||||||||||||||
| parameterTypes: [ | ||||||||||||||||||||||||||||||
| module.CorLibTypeFactory.Void.MakePointerType(), | ||||||||||||||||||||||||||||||
| module.CorLibTypeFactory.Void.MakePointerType(), | ||||||||||||||||||||||||||||||
| module.CorLibTypeFactory.Void.MakePointerType()])) | ||||||||||||||||||||||||||||||
| senderType.GetAbiType(interopReferences).Import(module), | ||||||||||||||||||||||||||||||
| argsType.GetAbiType(interopReferences).Import(module)])) | ||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||
| CustomAttributes = { InteropCustomAttributeFactory.UnmanagedCallersOnly(interopReferences, module) } | ||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||
|
|
@@ -101,6 +111,8 @@ public static void ImplType( | |||||||||||||||||||||||||||||
| CilInstruction ldloc_0_returnHResult = new(Ldloc_0); | ||||||||||||||||||||||||||||||
| CilInstruction ldarg_0_tryStart = new(Ldarg_0); | ||||||||||||||||||||||||||||||
| CilInstruction call_catchStartMarshalException = new(Call, interopReferences.RestrictedErrorInfoExceptionMarshallerConvertToUnmanaged.Import(module)); | ||||||||||||||||||||||||||||||
| CilInstruction nop_parameter1Rewrite = new(Nop); | ||||||||||||||||||||||||||||||
| CilInstruction nop_parameter2Rewrite = new(Nop); | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| // Create a method body for the 'Invoke' method | ||||||||||||||||||||||||||||||
| invokeMethod.CilMethodBody = new CilMethodBody() | ||||||||||||||||||||||||||||||
|
|
@@ -113,11 +125,9 @@ public static void ImplType( | |||||||||||||||||||||||||||||
| // '.try' code | ||||||||||||||||||||||||||||||
| { ldarg_0_tryStart }, | ||||||||||||||||||||||||||||||
| { Call, interopReferences.ComInterfaceDispatchGetInstance.MakeGenericInstanceMethod(delegateType).Import(module) }, | ||||||||||||||||||||||||||||||
| { Ldarg_1 }, | ||||||||||||||||||||||||||||||
| { Call, interopReferences.WindowsRuntimeObjectMarshallerConvertToManaged.Import(module) }, | ||||||||||||||||||||||||||||||
| { Ldarg_2 }, | ||||||||||||||||||||||||||||||
| { Call, interopReferences.WindowsRuntimeObjectMarshallerConvertToManaged.Import(module) }, | ||||||||||||||||||||||||||||||
| { Callvirt, interopReferences.DelegateInvoke(delegateType, module).Import(module) }, | ||||||||||||||||||||||||||||||
| { nop_parameter1Rewrite }, | ||||||||||||||||||||||||||||||
| { nop_parameter2Rewrite }, | ||||||||||||||||||||||||||||||
| { Callvirt, delegateInvokeMethod.Import(module) }, | ||||||||||||||||||||||||||||||
| { Ldc_I4_0 }, | ||||||||||||||||||||||||||||||
| { Stloc_0 }, | ||||||||||||||||||||||||||||||
| { Leave_S, ldloc_0_returnHResult.CreateLabel() }, | ||||||||||||||||||||||||||||||
|
|
@@ -145,6 +155,19 @@ public static void ImplType( | |||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| // Track rewriting the two parameters for this method | ||||||||||||||||||||||||||||||
| emitState.TrackManagedParameterMethodRewrite( | ||||||||||||||||||||||||||||||
| paraneterType: senderType, | ||||||||||||||||||||||||||||||
| method: invokeMethod, | ||||||||||||||||||||||||||||||
| marker: nop_parameter1Rewrite, | ||||||||||||||||||||||||||||||
| parameterIndex: 1); | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| emitState.TrackManagedParameterMethodRewrite( | ||||||||||||||||||||||||||||||
| paraneterType: argsType, | ||||||||||||||||||||||||||||||
|
Comment on lines
+160
to
+166
|
||||||||||||||||||||||||||||||
| paraneterType: senderType, | |
| method: invokeMethod, | |
| marker: nop_parameter1Rewrite, | |
| parameterIndex: 1); | |
| emitState.TrackManagedParameterMethodRewrite( | |
| paraneterType: argsType, | |
| parameterType: senderType, | |
| method: invokeMethod, | |
| marker: nop_parameter1Rewrite, | |
| parameterIndex: 1); | |
| emitState.TrackManagedParameterMethodRewrite( | |
| parameterType: argsType, |
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
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
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.
Corrected spelling of 'paraneterType' to 'parameterType'.