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

Expression trees support for tuples. #12897

Open
VSadov opened this issue Aug 3, 2016 · 11 comments
Open

Expression trees support for tuples. #12897

VSadov opened this issue Aug 3, 2016 · 11 comments

Comments

@VSadov
Copy link
Member

VSadov commented Aug 3, 2016

We should consider supporting expressions with tuples in expression tree lambdas.

It can be done either by

  1. Introducing new nodes that represent tuple creation/conversion/field accesses or
  2. Use lowered form

Option 1 is more desirable since it is more expressive, but will require introducing new nodes, possibly as a reducible layer on top of the standard ET nodes.

Option 2 could run into problems where tuple conversions require temporaries and in the ET version (1.0) those are not available.
It may be possible to use member bindings to avoid this problem, but it is not completely clear if that is possible and it will require that tuple conversion lowering in a context of expression trees to be significantly different.

Option 1 seems more attractive to me at the moment.

@a-a-k
Copy link

a-a-k commented May 13, 2020

which status on this?

@evilguest
Copy link

evilguest commented Aug 9, 2020

@VBAndCs
Copy link

VBAndCs commented Sep 11, 2020

Any news about this 4 years old proposal?

@CyrusNajmabadi
Copy link
Member

Any news about this 4 years old proposal?

Nope. No news.

@sjd2021
Copy link

sjd2021 commented May 24, 2021

Is this being worked on?

@CyrusNajmabadi
Copy link
Member

No. It is not being worked on. See #12897 (comment)

@jnm2
Copy link
Contributor

jnm2 commented May 24, 2021

@CyrusNajmabadi Are you sure? dotnet/csharplang#4727 links this very thread.

@qsdfplkj
Copy link

qsdfplkj commented May 23, 2023

This seems to be working:

Expression<Func<int, int, object>> f = (x, y) => Tuple.Create(x, y);
Expression<Func<int, int, object>> f = (x, y) => ValueTuple.Create(x, y);

@poke
Copy link

poke commented May 24, 2023

@qsdfplkj Those are standard method invocations though. This issue proposes tuples on a language level within expression trees.

@qsdfplkj
Copy link

qsdfplkj commented May 24, 2023

So using the valuetuple is a good alternative?

@evilguest
Copy link

evilguest commented May 29, 2023

Yes, if you want to construct a tuple within the available Expression Trees (as of C# 10). creating a tuple via a method call is a good alternative to Expression<Func<int, int, object>> f = (x, y) => (x, y); that just doesn't work.
I am frustrated, since the option #1 mentioned at the start of this thread seems to be a perfect solution.
Any existing code that would break with tuples will break with tuples, regardless of the way those are constructed. (See also npgsql/efcore.pg#2458).
A code that can process (x, y) => Tuple.Create(x, y); (or any shorthand one can sketch, like 𝜏(x, y) defined as a static method on a class imported via a using statement) would work just the same way with an expression tree that uses (x, y) => (x, y);. Especially if the new node would properly implement the .Reduce() method.
I can't imagine a scenario where a node refererncing the new tuple creation syntax would break the code that is capable of handling the Tuple.Create() syntax.

@jaredpar jaredpar modified the milestones: Compiler.Next, Backlog Sep 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests