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

Feat - extending decompilation to referenced queries #215

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

magicmoux
Copy link
Contributor

@magicmoux magicmoux commented Oct 25, 2022

@hazzik
here's PR #209 merged directly into OtpimzeExpressionVisitor.cs

Once again, I committed the unit tests first for demonstration.

@magicmoux magicmoux changed the title Feat - extending decompilation for referenced queries Feat - extending decompilation to referenced queries Oct 25, 2022
@hazzik
Copy link
Owner

hazzik commented Oct 26, 2022

@magicmoux please rebase.

{
IQueryable<int> query = Enumerable.Empty<int>().AsQueryable().Where(i => i >= 0);
Test<Func<IQueryable<int>, IQueryable<int>>>(
ints => Enumerable.Empty<int>().AsQueryable().Where(i => i >= 0),
Copy link
Owner

Choose a reason for hiding this comment

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

I think this test is incorrect. It should be ints => query

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The test is correct when based on the assumption that every nested IQueryable reference encountered should be also decompiled (I suppose that is the issue you raised by your comment that decompilation may go to far ?)

The test will fail anyway because of different outputs, but the difference would be acceptable (System.Int32[] instead of the expected Empty().AsQueryable())

public void TestQueryableRefFromField()
{
Test<Func<IQueryable<int>, IQueryable<int>>>(
ints => Enumerable.Empty<int>().AsQueryable().Where(i => i >= 0),
Copy link
Owner

Choose a reason for hiding this comment

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

I think this test is incorrect. It should be ints => fQref1.Where(i => i >= 0)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

see previous answer

public void TestQueryableRefFromStaticField()
{
Test<Func<IQueryable<int>, IQueryable<int>>>(
ints => Enumerable.Empty<int>().AsQueryable().Where(i => i >= 0),
Copy link
Owner

Choose a reason for hiding this comment

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

Same here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

same also

@hazzik
Copy link
Owner

hazzik commented Oct 26, 2022

I've fixed majority of the cases except EF tests. Also, it seems that decompilation here is going too far and maybe undesirable for some users.

@magicmoux
Copy link
Contributor Author

The nesting handling is so simple that I did not see it sitting right in front of me

Also, it seems that decompilation here is going too far and maybe undesirable for some users.

I suppose you're talking about the fact that the solution provided here assumes that any IQueryable referenced by fields or local variables would be forcibly decompiled ?

@magicmoux
Copy link
Contributor Author

magicmoux commented Oct 26, 2022

@hazzik rebased and I restricted dereferencing queryables only to explicitly decompiled instances (also applied this to the EF tests)
This helps reflect the DecompileAttribute usage (which is not applicable in those cases) for local variables and class fields.

@hazzik
Copy link
Owner

hazzik commented Oct 26, 2022

I suppose you're talking about the fact that the solution provided here assumes that any IQueryable referenced by fields or local variables would be forcibly decompiled ?

yes

//ATTEMPT
env.AboutToUseDelegateDecompiler();

var referencedQuery = env.Db.Set<Animal>().Where(it => it.Species == "Canis lupus").Decompile();
Copy link
Owner

Choose a reason for hiding this comment

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

Can you add test where the query would not be decompiled

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @hazzik, got a bit sidetracked.
I'm not sure I understand what test you want added here, so I added one failing test to expose the issue and refactored the other to compare materialized results

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