Skip to content

Added support for Linker.DefineFunction with generic tuples#285

Merged
peterhuene merged 1 commit into
bytecodealliance:mainfrom
martindevans:linker_define_generic_tuple
Nov 7, 2023
Merged

Added support for Linker.DefineFunction with generic tuples#285
peterhuene merged 1 commit into
bytecodealliance:mainfrom
martindevans:linker_define_generic_tuple

Conversation

@martindevans
Copy link
Copy Markdown
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
Copy Markdown
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
@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