-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[hot_reload] Add support for row modifications; CustomAttribute updat…
…es (#55445) This fixes #55097 - which allows us to support C# nullability analysis once again in hot reload deltas. Specifically we allow EnC deltas to include modifications of existing rows in the CustomAttribute table as long as the Parent and Type columns stay the same (that is: a custom attribute modification that still applies to the same element - and uses the same custom attribute constructor, but may have a different value). To support this, we add a new BaselineInfo:any_modified_rows array that keeps track for each table whether any rows have been modified (as opposed to added) by any EnC delta. When the runtime calls mono_metadata_decode_row, if there have been any deltas that modified a row in the requested table, we call hot_reload_effective_table_slow which find the latest delta that modified that row. If there have only been additions, we stop at the first delta that added the row we're looking for, if there are modifications, we look through all the deltas and return the latest one. * [hot_reload] Add test for updating custom attribute ctor values Just changing the arguments of a custom attribute constructor should generate an update to the CustomAttributes table with the same parent and .ctor. That kind of change should be allowed by Mono and CoreCLR * [hot_reload] Allow custom attribute row modifications if Parent and Type unchanged. Allows updates to the constructor arguments (or property values) * [hot_reload] Implement table lookup of modified rows Add a bool array on the base image to keep track of whether each table had any row modifications (as opposed to row additions) in any generation. If there was a modification, take the slow path in mono_image_effective_table even if the index we're looking at is in the base image. Update hot_reload_effective_table_slow so that if there was a modified row, we look at all the deltas to see if there's an even later update to that row. (When there are only additions, keep same behavior as before - only look as far as the generation that added the row we wanted to find). Also refine the assertion in hot_reload_relative_delta_index to properly account for EnCMap entries that correspond to modifications - in that case we might stop searching a metadata delta before we hit the end of the table if the EnCmap entries start pointing to rows that are past the one we wanted to look up. * Update the CustomAttributeUpdates test to check attribute value Check that we get the updated custom attribute string property value. * Re-enable nullability for hot reload tests Mono can now deal with the custom attributes modifications that Roslyn emits
- Loading branch information
1 parent
f57b6e7
commit 9fb28c8
Showing
13 changed files
with
270 additions
and
46 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
...ystem.Reflection.Metadata.ApplyUpdate.Test.CustomAttributeUpdate/CustomAttributeUpdate.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
using System; | ||
|
||
|
||
namespace System.Reflection.Metadata.ApplyUpdate.Test | ||
{ | ||
[AttributeUsage (AttributeTargets.Method, AllowMultiple=true)] | ||
public class MyAttribute : Attribute | ||
{ | ||
public MyAttribute (string stringValue) { StringValue = stringValue; } | ||
|
||
public MyAttribute (Type typeValue) { TypeValue = typeValue; } | ||
|
||
public MyAttribute (int x) { IntValue = x; } | ||
|
||
public string StringValue { get; set; } | ||
public Type TypeValue {get; set; } | ||
public int IntValue {get; set; } | ||
} | ||
|
||
public class ClassWithCustomAttributeUpdates | ||
{ | ||
[MyAttribute ("abcd")] | ||
public static string Method1 () => null; | ||
|
||
[MyAttribute (typeof(Exception))] | ||
public static string Method2 () => null; | ||
|
||
[MyAttribute (42, StringValue = "hijkl", TypeValue = typeof(Type))] | ||
[MyAttribute (17, StringValue = "", TypeValue = typeof(object))] | ||
public static string Method3 () => null; | ||
|
||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
...em.Reflection.Metadata.ApplyUpdate.Test.CustomAttributeUpdate/CustomAttributeUpdate_v1.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
using System; | ||
|
||
|
||
namespace System.Reflection.Metadata.ApplyUpdate.Test | ||
{ | ||
[AttributeUsage (AttributeTargets.Method, AllowMultiple=true)] | ||
public class MyAttribute : Attribute | ||
{ | ||
public MyAttribute (string stringValue) { StringValue = stringValue; } | ||
|
||
public MyAttribute (Type typeValue) { TypeValue = typeValue; } | ||
|
||
public MyAttribute (int x) { IntValue = x; } | ||
|
||
public string StringValue { get; set; } | ||
public Type TypeValue {get; set; } | ||
public int IntValue {get; set; } | ||
} | ||
|
||
public class ClassWithCustomAttributeUpdates | ||
{ | ||
[MyAttribute ("rstuv")] | ||
public static string Method1 () => null; | ||
|
||
[MyAttribute (typeof(ArgumentException))] | ||
public static string Method2 () => null; | ||
|
||
[MyAttribute (2042, StringValue = "qwerty", TypeValue = typeof(byte[]))] | ||
[MyAttribute (17, StringValue = "", TypeValue = typeof(object))] | ||
public static string Method3 () => null; | ||
|
||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...mAttributeUpdate/System.Reflection.Metadata.ApplyUpdate.Test.CustomAttributeUpdate.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<RootNamespace>System.Runtime.Loader.Tests</RootNamespace> | ||
<TargetFrameworks>$(NetCoreAppCurrent)</TargetFrameworks> | ||
<TestRuntime>true</TestRuntime> | ||
<DeltaScript>deltascript.json</DeltaScript> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Compile Include="CustomAttributeUpdate.cs" /> | ||
</ItemGroup> | ||
</Project> |
6 changes: 6 additions & 0 deletions
6
...Update/System.Reflection.Metadata.ApplyUpdate.Test.CustomAttributeUpdate/deltascript.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"changes": [ | ||
{"document": "CustomAttributeUpdate.cs", "update": "CustomAttributeUpdate_v1.cs"}, | ||
] | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.