-
Notifications
You must be signed in to change notification settings - Fork 2.6k
JIT: test case showing inexact type for this in constructors #16239
Conversation
@briansull PTAL [Edit: results below are for a now-abandoned invalid opt, so please disregard] jit-diffs results:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Is the following still going to print "Child" with this optimization? using System;
using System.Threading;
using System.Threading.Tasks;
class Test {
public Test() {
Console.WriteLine(ToString());
}
static void Main() {
new Child();
}
}
class Child : Test {
public override string ToString() {
return "Child";
}
} |
Yes, it does. That particular call was already being devirtualized because of inlining into In cases where we don't inline the constructor, this change kicks in. [edited to fix a few typos...] |
@jkotas thought about it some more and you were right. We also need to check that the constructor type is final. Relevant example. using System;
using System.Runtime.CompilerServices;
class Test {
public override string ToString() {
return "Test";
}
[MethodImpl(MethodImplOptions.NoInlining)]
public Test() {
Console.WriteLine(ToString()); // we don't know type of "this" exactly here
}
static void Main() {
new Child();
}
}
class Child : Test {
[MethodImpl(MethodImplOptions.NoInlining)]
public Child() { }
public override string ToString() {
return "Child";
}
} Looks like I should add a test in addition to a fix. |
And since we already know about final classes the upshot is this now doesn't tell us anything we don't already know. So I'll update this to just add a test case as we don't seem to have any basic tests that would catch this. |
See #16198 for discussion.
1464a16
to
94e802c
Compare
Tizen failure unrelated, will ignore. |
…lr#16239) See dotnet/coreclr#16198 for discussion. Commit migrated from dotnet/coreclr@ff1da90
Add test case showing that in constructors the exact type of
this
is not generally known. To devirtualize we need to rely on type propagation from thenewobj
.Related discussion in #16198.