Skip to content
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

Add awaiter implementation #133

Open
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

extraes
Copy link

@extraes extraes commented Jun 17, 2024

Adds Pass61ImplementAwaiters
Looks for types implementing INotifyCompletion and generates new methods that allow the interop types to implement that interface, calling the Il2CppSystem.Action -> System.Action implicit conversion before calling the original method.

This makes originally-awaitable types (e.g. UniTasks, if the game has them) awaitable again.

I previously did this in a much less automated way with Cecil in another project, but the runtime didn't like what I was doing, so I figured I'd make it less janky and add it to Il2CppInterop, and sure enough the runtime no longer rejects the type.

@ds5678 ds5678 added generation Related to assembly generation enhancement New feature or request labels Jul 15, 2024
@ds5678

This comment was marked as outdated.

@ds5678
Copy link
Collaborator

ds5678 commented Dec 22, 2024

I investigated this pull request and what it's attempting to solve. I discovered that the type system improvements I mentioned above will not automatically fix the issue.

As I understand it, the issue is that even if proper interface support is implemented with system interface support, only the Il2Cpp INotifyCompletion interface will be implemented since the generated OnCompleted method uses Il2CppSystem.Action instead of System.Action. Your pull request generates a helper method to avoid this.

For the rewrite, I could see a generic implementation where all Il2Cpp Action and Func delegates in method signatures are converted to their System counterparts, but I can also see your narrow implementation persisting into the rewrite if the generic implementation proves difficult or has some undesirable outcomes.

I am willing to review this pull request once it has been ported to AsmResolver.

Reference: https://source.dot.net/#System.Private.CoreLib/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/INotifyCompletion.cs

- Use CorLibTypeFactory.Void for void reference
- Added a couple more early-outs before LINQ
- Use .Single
- Use MemberCloner (and define a nested type for that)
- Check method signature & forward to methods that may have been wonkily unhollowed
@ds5678
Copy link
Collaborator

ds5678 commented Dec 25, 2024

Whenever you're ready for another review, let me know.

@extraes
Copy link
Author

extraes commented Dec 26, 2024

Ah yeah, if you can review again that'd be great

Copy link
Collaborator

@ds5678 ds5678 left a comment

Choose a reason for hiding this comment

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

I gave it another pass. 👍

- Use .Single for action conversion
- Match interface using namespace (in addition to name)
- Match method using .OriginalMethod.Name
- Use SignatureComparer & change comment to reflect that
- Make sure method is instanced
- Remove nop opcodes
@extraes
Copy link
Author

extraes commented Feb 11, 2025

Apologies for the month of absence, it's ready for review again. I'm not too familiar with PRs, so if it needs to be brought up to date with main again, let me know.

Copy link
Collaborator

@ds5678 ds5678 left a comment

Choose a reason for hiding this comment

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

Hello! I gave your PR another review. In addition to the changes I wrote comments about, I also noticed that the continuous integration is indicating a code format problem. That'll need resolved too.

@extraes
Copy link
Author

extraes commented Feb 12, 2025

Ready for review again! :octocat:

Copy link
Collaborator

@ds5678 ds5678 left a comment

Choose a reason for hiding this comment

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

Just one more thing to change.

Comment on lines +34 to +36
// Used later for MemberCloner, just putting up here as an early exit in case .Module is ever null
if (typeContext.NewType.Module is null)
continue;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This can be removed.

@ds5678
Copy link
Collaborator

ds5678 commented Feb 12, 2025

@js6pak Do you have any feedback for this PR before I merge it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request generation Related to assembly generation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants