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

Linq: Adds support constant evaluation of Nullable<T>.HasValue #3273

Merged
merged 11 commits into from
Jul 12, 2022

Conversation

ccurrens
Copy link
Contributor

Description

This commit adds support for evaluating Nullable<T>.HasValue when the original nullable constant's HasValue is false.

Nullable<T> is tricky to use with reflection because of it's special runtime behavior. This manually determines if HasValue was false, and in that case returns a constant expression of false.

More details are in #3272.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Closing issues

closes #3272

@ealsur
Copy link
Member

ealsur commented Jun 16, 2022

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 2 pipeline(s).

@ealsur
Copy link
Member

ealsur commented Jun 16, 2022

@khdang Please take a look

Copy link
Member

@FabianMeiswinkel FabianMeiswinkel left a comment

Choose a reason for hiding this comment

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

LGTM - Thanks!

@ealsur ealsur added the LINQ label Jun 21, 2022
@ealsur ealsur changed the title Linq: support constant evaluation of Nullable<T>.HasValue Linq: Adds support constant evaluation of Nullable<T>.HasValue Jun 21, 2022
@ealsur
Copy link
Member

ealsur commented Jul 7, 2022

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 2 pipeline(s).

@leminh98 leminh98 self-requested a review July 7, 2022 17:14
leminh98
leminh98 previously approved these changes Jul 7, 2022
@ealsur ealsur requested a review from adityasa as a code owner July 7, 2022 17:23
@ealsur
Copy link
Member

ealsur commented Jul 7, 2022

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 2 pipeline(s).

@ealsur ealsur enabled auto-merge (squash) July 7, 2022 17:40
@ealsur
Copy link
Member

ealsur commented Jul 7, 2022

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 2 pipeline(s).

ealsur
ealsur previously approved these changes Jul 11, 2022
@ealsur ealsur enabled auto-merge (squash) July 11, 2022 17:22
@ealsur
Copy link
Member

ealsur commented Jul 11, 2022

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 2 pipeline(s).

khdang
khdang previously approved these changes Jul 11, 2022
@ealsur
Copy link
Member

ealsur commented Jul 11, 2022

@ccurrens It looks like the last commit is failing on the LinqTranslationBaselineTests.TestMemberAccess I'll try rerunning everything, but the error is:

Expected: ><![CDATA[SELECTVALUErootFROMrootWHERE(root["NumericField"]=4)]]></SqlQuery></Output></Result><Resul,
Actual:   ><![CDATA[]]></SqlQuery><ErrorMessage><![CDATA[Objectreferencenotsettoaninstanceofanobject.]]></Erro,
OutputPath: BaselineTest\TestOutput\LinqTranslationBaselineTests.TestMemberAccess.xml,
BaselinePath: BaselineTest\TestBaseline\LinqTranslationBaselineTests.TestMemberAccess.xml

@ealsur
Copy link
Member

ealsur commented Jul 11, 2022

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 2 pipeline(s).

@ccurrens
Copy link
Contributor Author

ccurrens commented Jul 12, 2022

@ccurrens It looks like the last commit is failing on the LinqTranslationBaselineTests.TestMemberAccess I'll try rerunning everything, but the error is:

Expected: ><![CDATA[SELECTVALUErootFROMrootWHERE(root["NumericField"]=4)]]></SqlQuery></Output></Result><Resul,
Actual:   ><![CDATA[]]></SqlQuery><ErrorMessage><![CDATA[Objectreferencenotsettoaninstanceofanobject.]]></Erro,
OutputPath: BaselineTest\TestOutput\LinqTranslationBaselineTests.TestMemberAccess.xml,
BaselinePath: BaselineTest\TestBaseline\LinqTranslationBaselineTests.TestMemberAccess.xml

Thanks for the heads up. I messed up the conversion of the first pattern expression back to what it needed to be. I'll post up the fix in just a minute.

targetConstant is { Value: null } was doing a null check on targetConstant and on targetConstant.Value. I only did the latter.

auto-merge was automatically disabled July 12, 2022 01:08

Head branch was pushed to by a user without write access

@ccurrens ccurrens dismissed stale reviews from khdang and ealsur via d01484c July 12, 2022 01:08
@ccurrens
Copy link
Contributor Author

The property pattern for targetConstant is { Value: null } and the new check targetConstant != null && targetConstant.Value == null produce the same assembly (under x64 ryuJit at least), but I've leave it as discrete checks instead of the pattern match. Seemed safer since I don't know about other architectures.

@ealsur
Copy link
Member

ealsur commented Jul 12, 2022

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 2 pipeline(s).

@ealsur
Copy link
Member

ealsur commented Jul 12, 2022

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 2 pipeline(s).

@ealsur
Copy link
Member

ealsur commented Jul 12, 2022

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 2 pipeline(s).

@ealsur ealsur enabled auto-merge (squash) July 12, 2022 16:25
@ealsur ealsur merged commit be8814f into Azure:master Jul 12, 2022
sourabh1007 added a commit that referenced this pull request Jul 13, 2022
sourabh1007 added a commit that referenced this pull request Jul 13, 2022
sourabh1007 added a commit that referenced this pull request Jul 13, 2022
sourabh1007 added a commit that referenced this pull request Jul 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
5 participants