Skip to content

Commit 71ee9ea

Browse files
authored
[hot reload][mono] Implement support for adding static and instance fields to generic classes (#87285)
Fixes #86111 * new test adding a generic field * workaround roslyn issue to generate generic static field test dotnet/roslyn#68293 we get an error if we add a generic field and try to use it during the same edit. workaround is to do two separate edits * implement hot reload for static fields in generics ldsflda seems to be working * Add a generic instance add instance field test * add reflection testing to the generic instance added field test * fixup valuetype loads * add non-generic valuetype ldflda test * Mark failing tests for CoreCLR * light up GenericAddFieldToExistingType capability * use interp_emit_ldobj for metadata-update; add barrier if volatile
1 parent 10335b8 commit 71ee9ea

File tree

19 files changed

+402
-51
lines changed

19 files changed

+402
-51
lines changed

src/libraries/System.Runtime.Loader/tests/ApplyUpdate/System.Reflection.Metadata.ApplyUpdate.Test.AddInstanceField/AddInstanceField.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,7 @@ public double FireEvents() {
4747

4848
return Accumulator;
4949
}
50+
51+
public DateTime GetDateTime() => default(DateTime);
5052
}
5153
}

src/libraries/System.Runtime.Loader/tests/ApplyUpdate/System.Reflection.Metadata.ApplyUpdate.Test.AddInstanceField/AddInstanceField_v1.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ public double FireEvents() {
8585
return Accumulator;
8686
}
8787

88+
public DateTime GetDateTime() => default(DateTime);
89+
8890
public double AddedFirstProp {get => 0.0; set { Console.WriteLine (value); } }
91+
92+
public DateTime AddedDateTime;
93+
8994
}
9095
}

src/libraries/System.Runtime.Loader/tests/ApplyUpdate/System.Reflection.Metadata.ApplyUpdate.Test.AddInstanceField/AddInstanceField_v2.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,12 @@ public double FireEvents() {
8585
return Accumulator;
8686
}
8787

88+
public DateTime GetDateTime() => AddedDateTime;
89+
8890
public double AddedFirstProp {get => 0.0; set { Console.WriteLine (value+value); } }
8991
public short AddedSecondProp {get; set; }
92+
93+
public DateTime AddedDateTime;
94+
9095
}
9196
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
using System;
4+
5+
6+
namespace System.Reflection.Metadata.ApplyUpdate.Test
7+
{
8+
public class GenericAddInstanceField<T>
9+
{
10+
public GenericAddInstanceField (T p) {
11+
}
12+
13+
public T GetIt()
14+
{
15+
return default(T);
16+
}
17+
}
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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+
using System;
4+
5+
6+
namespace System.Reflection.Metadata.ApplyUpdate.Test
7+
{
8+
public class GenericAddInstanceField<T>
9+
{
10+
public GenericAddInstanceField (T p) {
11+
}
12+
13+
T myAddedField;
14+
15+
public T GetIt()
16+
{
17+
return default(T);
18+
}
19+
}
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
using System;
4+
5+
6+
namespace System.Reflection.Metadata.ApplyUpdate.Test
7+
{
8+
public class GenericAddInstanceField<T>
9+
{
10+
public GenericAddInstanceField (T p) {
11+
myAddedField = p;
12+
}
13+
14+
T myAddedField;
15+
16+
public T GetIt()
17+
{
18+
return myAddedField;
19+
}
20+
}
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<RootNamespace>System.Runtime.Loader.Tests</RootNamespace>
4+
<TargetFramework>$(NetCoreAppCurrent)</TargetFramework>
5+
<TestRuntime>true</TestRuntime>
6+
<DeltaScript>deltascript.json</DeltaScript>
7+
</PropertyGroup>
8+
<ItemGroup>
9+
<Compile Include="GenericAddInstanceField.cs" />
10+
</ItemGroup>
11+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"changes": [
3+
{"document": "GenericAddInstanceField.cs", "update": "GenericAddInstanceField_v1.cs"},
4+
{"document": "GenericAddInstanceField.cs", "update": "GenericAddInstanceField_v2.cs"},
5+
]
6+
}
7+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
using System;
4+
5+
6+
namespace System.Reflection.Metadata.ApplyUpdate.Test
7+
{
8+
public class GenericAddStaticField<T>
9+
{
10+
public GenericAddStaticField () {
11+
}
12+
13+
public T GetField () => s_field;
14+
15+
private static T s_field;
16+
17+
public void TestMethod () {
18+
s_field = (T)(object)"abcd";
19+
}
20+
21+
}
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
using System;
4+
5+
6+
namespace System.Reflection.Metadata.ApplyUpdate.Test
7+
{
8+
public class GenericAddStaticField<T>
9+
{
10+
public GenericAddStaticField () {
11+
}
12+
13+
public T GetField () => s_field;
14+
15+
private static T s_field;
16+
17+
public static T s_field2;
18+
19+
public void TestMethod () {
20+
s_field = (T)(object)"spqr";
21+
//s_field2 = (T)(object)"4567";
22+
}
23+
24+
}
25+
}

0 commit comments

Comments
 (0)