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

Commit 913795e

Browse files
committed
Add some test cases
1 parent d6c5086 commit 913795e

File tree

10 files changed

+432
-0
lines changed

10 files changed

+432
-0
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System;
6+
7+
public sealed class X: IComparable<X>
8+
{
9+
int ival;
10+
11+
public X(int i)
12+
{
13+
ival = i;
14+
}
15+
16+
public int CompareTo(X x)
17+
{
18+
return ival - x.ival;
19+
}
20+
21+
public bool Equals(X x)
22+
{
23+
return ival == x.ival;
24+
}
25+
}
26+
27+
public class Y<T> where T : IComparable<T>
28+
{
29+
public static int C(T x, T y)
30+
{
31+
// IL here is
32+
// ldarga 0
33+
// ldarg 1
34+
// constrained ... callvirt ...
35+
//
36+
// The ldarga blocks both caller-arg direct sub and type
37+
// propagation since the jit thinks arg0 might be redefined.
38+
//
39+
// For ref types the ldarga is undone in codegen just before
40+
// the call so we end up with *(&arg0) and we know this is
41+
// arg0. Ideally we'd also understand that this pattern can't
42+
// lead to reassignment, but our view of the callee and what
43+
// it does with address-taken args is quite limited.
44+
//
45+
// Even if we can't propagate the caller's value or type, we
46+
// might be able to retype the generic __Canon for arg0 as the
47+
// more specific type that the caller is using (here, X).
48+
//
49+
// An interesting variant on this would be to derive from X
50+
// (say with XD) and have the caller pass instances of XD
51+
// instead of instances of X. We'd need to make sure we retype
52+
// arg0 as X and not XD.
53+
return x.CompareTo(y);
54+
}
55+
}
56+
57+
public class Z
58+
{
59+
public static int Main()
60+
{
61+
// Ideally inlining Y.C would enable the interface call in Y
62+
// to be devirtualized, since we know the exact type of the
63+
// first argument. We can't get this yet.
64+
int result = Y<X>.C(new X(103), new X(3));
65+
return result;
66+
}
67+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<AssemblyName>$(MSBuildProjectName)</AssemblyName>
8+
<SchemaVersion>2.0</SchemaVersion>
9+
<ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
10+
<OutputType>Exe</OutputType>
11+
<AppDesignerFolder>Properties</AppDesignerFolder>
12+
<FileAlignment>512</FileAlignment>
13+
<ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
14+
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT .0\UITestExtensionPackages</ReferencePath>
15+
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
16+
<NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
17+
</PropertyGroup>
18+
<!-- Default configurations to help VS understand the configurations -->
19+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
20+
</PropertyGroup>
21+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
22+
</PropertyGroup>
23+
<ItemGroup>
24+
<CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
25+
<Visible>False</Visible>
26+
</CodeAnalysisDependentAssemblyPaths>
27+
</ItemGroup>
28+
<PropertyGroup>
29+
<DebugType>PdbOnly</DebugType>
30+
<Optimize>True</Optimize>
31+
</PropertyGroup>
32+
<ItemGroup>
33+
<Compile Include="comparable.cs" />
34+
</ItemGroup>
35+
<ItemGroup>
36+
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
37+
</ItemGroup>
38+
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
39+
<PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
40+
</PropertyGroup>
41+
</Project>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System;
6+
7+
interface I<out T>
8+
{
9+
T A();
10+
}
11+
12+
class X<T> : I<T> where T: class
13+
{
14+
T I<T>.A()
15+
{
16+
return (T)(object)"X";
17+
}
18+
}
19+
20+
class T
21+
{
22+
static object F(I<object> i)
23+
{
24+
return i.A();
25+
}
26+
27+
public static int Main()
28+
{
29+
// Jit should inline F and then devirtualize the call to A.
30+
// (inlining A blocked by runtime lookup)
31+
object j = F(new X<string>());
32+
if (j is string)
33+
{
34+
return ((string)j)[0] + 12;
35+
}
36+
return -1;
37+
}
38+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<AssemblyName>$(MSBuildProjectName)</AssemblyName>
8+
<SchemaVersion>2.0</SchemaVersion>
9+
<ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
10+
<OutputType>Exe</OutputType>
11+
<AppDesignerFolder>Properties</AppDesignerFolder>
12+
<FileAlignment>512</FileAlignment>
13+
<ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
14+
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT .0\UITestExtensionPackages</ReferencePath>
15+
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
16+
<NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
17+
</PropertyGroup>
18+
<!-- Default configurations to help VS understand the configurations -->
19+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
20+
</PropertyGroup>
21+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
22+
</PropertyGroup>
23+
<ItemGroup>
24+
<CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
25+
<Visible>False</Visible>
26+
</CodeAnalysisDependentAssemblyPaths>
27+
</ItemGroup>
28+
<PropertyGroup>
29+
<DebugType>PdbOnly</DebugType>
30+
<Optimize>True</Optimize>
31+
</PropertyGroup>
32+
<ItemGroup>
33+
<Compile Include="contravariance.cs" />
34+
</ItemGroup>
35+
<ItemGroup>
36+
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
37+
</ItemGroup>
38+
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
39+
<PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
40+
</PropertyGroup>
41+
</Project>
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System;
6+
7+
interface I<in T>
8+
{
9+
int A(T t);
10+
}
11+
12+
class X<T> : I<T>
13+
{
14+
int c = 0;
15+
int I<T>.A(T t)
16+
{
17+
return ++c;
18+
}
19+
}
20+
21+
class T
22+
{
23+
static int F(I<string> i)
24+
{
25+
return i.A("A");
26+
}
27+
28+
public static int Main()
29+
{
30+
// Jit should inline F and then devirtualize
31+
// and inline the call to A.
32+
int j = F(new X<object>());
33+
return j + 99;
34+
}
35+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<AssemblyName>$(MSBuildProjectName)</AssemblyName>
8+
<SchemaVersion>2.0</SchemaVersion>
9+
<ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
10+
<OutputType>Exe</OutputType>
11+
<AppDesignerFolder>Properties</AppDesignerFolder>
12+
<FileAlignment>512</FileAlignment>
13+
<ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
14+
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT .0\UITestExtensionPackages</ReferencePath>
15+
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
16+
<NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
17+
</PropertyGroup>
18+
<!-- Default configurations to help VS understand the configurations -->
19+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
20+
</PropertyGroup>
21+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
22+
</PropertyGroup>
23+
<ItemGroup>
24+
<CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
25+
<Visible>False</Visible>
26+
</CodeAnalysisDependentAssemblyPaths>
27+
</ItemGroup>
28+
<PropertyGroup>
29+
<DebugType>PdbOnly</DebugType>
30+
<Optimize>True</Optimize>
31+
</PropertyGroup>
32+
<ItemGroup>
33+
<Compile Include="covariance.cs" />
34+
</ItemGroup>
35+
<ItemGroup>
36+
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
37+
</ItemGroup>
38+
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
39+
<PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
40+
</PropertyGroup>
41+
</Project>
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System;
6+
7+
interface Ix<T> where T : class
8+
{
9+
T F();
10+
}
11+
12+
class Base : Ix<string>
13+
{
14+
public virtual string F() { return "B"; }
15+
}
16+
17+
class Derived : Base
18+
{
19+
public override string F() { return "D"; }
20+
}
21+
22+
class Bx
23+
{
24+
public Ix<string> Get() { return new Derived(); }
25+
}
26+
27+
public class Z
28+
{
29+
static string X(Base b)
30+
{
31+
return b.F();
32+
}
33+
34+
public static int Main()
35+
{
36+
// Would like to be able to late devirtualize the call to F
37+
// here after inlining Get exposes the exact type of the
38+
// object, but since the return type of Get is a (shared)
39+
// interface type, we need the exact context for F to do so
40+
// safely.
41+
//
42+
// Unfortunately we lose track of that context, because when
43+
// we import the call to F, it is not an inline candidate.
44+
string s = new Bx().Get().F();
45+
return (int) s[0] + 32;
46+
}
47+
}
48+
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<AssemblyName>$(MSBuildProjectName)</AssemblyName>
8+
<SchemaVersion>2.0</SchemaVersion>
9+
<ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
10+
<OutputType>Exe</OutputType>
11+
<AppDesignerFolder>Properties</AppDesignerFolder>
12+
<FileAlignment>512</FileAlignment>
13+
<ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
14+
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT .0\UITestExtensionPackages</ReferencePath>
15+
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
16+
<NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
17+
</PropertyGroup>
18+
<!-- Default configurations to help VS understand the configurations -->
19+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
20+
</PropertyGroup>
21+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
22+
</PropertyGroup>
23+
<ItemGroup>
24+
<CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
25+
<Visible>False</Visible>
26+
</CodeAnalysisDependentAssemblyPaths>
27+
</ItemGroup>
28+
<PropertyGroup>
29+
<DebugType>PdbOnly</DebugType>
30+
<Optimize>True</Optimize>
31+
</PropertyGroup>
32+
<ItemGroup>
33+
<Compile Include="late.cs" />
34+
</ItemGroup>
35+
<ItemGroup>
36+
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
37+
</ItemGroup>
38+
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
39+
<PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
40+
</PropertyGroup>
41+
</Project>
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System;
6+
7+
// Some simple interface call devirtualization cases
8+
9+
interface Ix
10+
{
11+
int F();
12+
}
13+
14+
interface Iy
15+
{
16+
int G();
17+
}
18+
19+
public class B : Iy, Ix
20+
{
21+
public int F() { return 44; }
22+
virtual public int G() { return 55; }
23+
}
24+
25+
public class Z : B
26+
{
27+
new public int F() { return 33; }
28+
override public int G() { return 22; }
29+
30+
static int Fx(Ix x) { return x.F(); }
31+
static int Gy(Iy y) { return y.G(); }
32+
33+
public static int Main()
34+
{
35+
// B:F Z:G B:F B:G
36+
return Fx(new Z()) + Gy(new Z()) + Fx(new B()) + Gy(new B()) - 65;
37+
}
38+
}
39+

0 commit comments

Comments
 (0)