Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Conversation

@JonHanna
Copy link
Contributor

ReduceTypeEqual has a false assumption that if obj is T and typeof(T).IsSealed then obj.GetType() == typeof(T).

It will reduce to Expression.Constant(true) based on this assumption, and as of d5e3d82 will reduce to Expression.Constant(false) based on it too.

Remove the assumption entirely, removing both false positives and false negatives.

Fixes #6258

@JonHanna
Copy link
Contributor Author

I confirmed with a test in System.Dynamic.Runtime based on #6258 which went into an infinite loop that this fixed that loop, but can't add it here as it will fail in CI until the packages are updated with the change this makes.

@stephentoub
Copy link
Member

but can't add it here as it will fail in CI until the packages are updated with the change this makes.

Can you add it but with an [ActiveIssue] flagging the original issue?

@stephentoub
Copy link
Member

cc: @VSadov, @gregg-miskelly

@stephentoub
Copy link
Member

(You added a test based on .NET 4.6 to the issue... could that be added here as well?)

@JonHanna
Copy link
Contributor Author

Good idea. Especially since that test will fail prior to this too, just in a different way.

@JonHanna JonHanna force-pushed the fix_6258 branch 2 times, most recently from 6820e21 to 864c74e Compare February 20, 2016 14:16
@JonHanna
Copy link
Contributor Author

There. The thought "can't commit those tests" led to me not committing any at all, when those in expressions should obviously be there, and as you say we can remove the [ActiveIssue] on the others later.

@JonHanna
Copy link
Contributor Author

@stephentoub is there any case in which the ActiveIssue tests are run? Concerned that these hang rather than fail.

@stephentoub
Copy link
Member

is there any case in which the ActiveIssue tests are run?

In the CI system, no. They can be run explicitly when invoking xunit from the command line, but the CI system always uses -notrait category=failing, which is set by ActiveIssue.

private static int Foo(string s, dynamic d, object o)
{
return s?.Length + d?.ToString()?.Length + o?.ToString()?.Length;
}
Copy link
Member

Choose a reason for hiding this comment

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

C#6 ,
@stephentoub - is it now ok to use yet?
I was holding off using these. Tantalizing though...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is as of #6181,and indeed there's nameof all over the place now. This test is my little act of celebration.

Copy link

Choose a reason for hiding this comment

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

I'm confused about what is this trying to accomplish. If any of the parameters is null, you'll get a RuntimeBindingException about not being able to convert null to int. I get that the parameters are never null, so it doesn't really matter, but in that case, what is the point of using ?. in the first place?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@svick yeah, while it's just do-something-here-don't-care-what test code, there's a limit on how silly even code like that should be. Changed

@VSadov
Copy link
Member

VSadov commented Feb 20, 2016

There is a minor concern about compat since old code could give false positives and we are fixing that.
It seems ok though, since outcome of operation should not be affected by, for example, casting LHS to object.
Consistency with IL semantics is important too.

@VSadov
Copy link
Member

VSadov commented Feb 20, 2016

LGTM.
Check if the C#6 use is ok.
I am not sure about the min requirements of the repo. It may flow into .Net Native or something. And I am not sure what compilers they use. Perhaps keeping it C#5 for now is safer.

@JonHanna
Copy link
Contributor Author

@gregg-miskelly, would you be able to build this branch and check if it does indeed fix your issue, rather than the reproduction only reproducing something similar but separate?

ReduceTypeEqual has a false assumption that if obj is T and
T.IsSealed then typeof(obj) == typeof(T).

It will reduce to Expression.Constant(true) based on this assumption,
and as of d5e3d82 will reduce to Expression.Constant(false) based on it
too.

Remove the assumption entirely, removing both false positives and false
negatives.

Fixes #6258
@JonHanna
Copy link
Contributor Author

@VSadov The C# 6 use is gone due to @svick's point about how silly it was anyway, but there's other use in the project brought in by #6209.

@JonHanna
Copy link
Contributor Author

Test Innerloop Ubuntu Release Build and Test
(hung process during WS-CLEANUP)

@JonHanna
Copy link
Contributor Author

Test Innerloop Ubuntu Release Build and Test (WS-CLEANUP again)

@JonHanna
Copy link
Contributor Author

This talk of C# 6 has made something occur to me, viz that the operation of this whole method could be simpler if it just (perhaps after reducing the value type cases only) compiled TypeEqual as C# 6 would be compiled for obj?.GetType() == type with dup in the CIL to ensure that the expression is evaluated only once. I don't feel particularly eager to change anything here that isn't actually broken, though.

VSadov added a commit that referenced this pull request Feb 22, 2016
Fix false assumption in Expression.TypeEqual
@VSadov VSadov merged commit f139656 into dotnet:master Feb 22, 2016
@JonHanna JonHanna deleted the fix_6258 branch February 22, 2016 21:02
JonHanna added a commit to JonHanna/corefx that referenced this pull request Mar 14, 2016
These tests had to wait for the fix in dotnet#6273 to be available in the feeds
before the [ActiveIssue] attribute could be removed.

Do this now.
@karelz karelz modified the milestone: 1.0.0-rtm Dec 3, 2016
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
Fix false assumption in Expression.TypeEqual

Commit migrated from dotnet/corefx@f139656
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
These tests had to wait for the fix in dotnet/corefx#6273 to be available in the feeds
before the [ActiveIssue] attribute could be removed.

Do this now.


Commit migrated from dotnet/corefx@0e4f668
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants