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

Added support for Linker.DefineFunction with generic tuples #285

Merged

Conversation

martindevans
Copy link
Contributor

@martindevans martindevans commented Nov 3, 2023

Added support for defining functions which have a tuple as a generic parameter.

Previously defining like this would work:

Linker.DefineFunction<int, int, int>("module", "name", (int a) => (a, a));

But doing this would not work:

void DefineWrapper<TIn, TOut>(Func<TIn, TOut> func)
{
    Linker.DefineFunction<TIn, TOut>("module", "name", func);
}

DefineWrapper<int, (int, int)>((int a) => (a, a));

Even though they're ultimately doing the same thing, just with one more level of generic typing.

This PR detects that case and adds limited support for tuples (only up to 4 elements).

I have not added support for ValueRaw unboxing of tuples. As far as I can tell it's not required anywhere.

…parameter.

Previously defining this would work:

```csharp
Linker.DefineFunction<int, (int, int)>("module", "name", (int a) => (a, a));
```

But doing this would not work:

```csharp
void DefineWrapper<TIn, TOut>(Func<TIn, TOut> func)
{
    Linker.DefineFunction<TIn, TOut>("module", "name", func);
}

DefineWrapper<int, (int, int)>((int a) => (a, a));
```

Even though they're ultimately doing the same thing, just with one more level of generic typing.
Copy link
Member

@peterhuene peterhuene left a comment

Choose a reason for hiding this comment

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

Thanks for the PR!

@peterhuene peterhuene merged commit 9c97eac into bytecodealliance:main Nov 7, 2023
6 checks passed
@martindevans martindevans deleted the linker_define_generic_tuple branch November 7, 2023 19:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants