diff --git a/Assets/Tests/Editor/HotReload/HotReloadExplicitInterfaceE2ETests.cs b/Assets/Tests/Editor/HotReload/HotReloadExplicitInterfaceE2ETests.cs
index 22f1235ef..e672d43d2 100644
--- a/Assets/Tests/Editor/HotReload/HotReloadExplicitInterfaceE2ETests.cs
+++ b/Assets/Tests/Editor/HotReload/HotReloadExplicitInterfaceE2ETests.cs
@@ -22,6 +22,7 @@ namespace io.github.hatayama.UnityCliLoop.Tests.Editor.HotReload
public class HotReloadExplicitInterfaceE2ETests
{
private const string FixtureFileName = "HotReloadExplicitInterfaceFixtures.cs";
+ private const string HiddenFixtureFileName = "HotReloadHiddenExplicitInterfaceFixtures.cs";
private HotReloadDomainTestScope _scope;
@@ -203,7 +204,7 @@ await ApplyEditAsync(
"IHotReloadExplicitBaseCaller.Value(");
Assert.That(caller.Value(1), Is.EqualTo(1 + 100 + 9108));
- string fixturePath = ResolveFixturePath();
+ string fixturePath = ResolveFixturePath(FixtureFileName);
string onDisk = File.ReadAllText(fixturePath);
string skippedEdit = onDisk.Replace(
original,
@@ -310,7 +311,7 @@ await ApplyEditAsync(
public async Task Run_ExplicitPropertyRespelledWithGlobal_ApplyAndRevert_RunsTheEditedGetter()
{
IHotReloadExplicitValue value = new HotReloadExplicitValueFixture();
- string fixturePath = ResolveFixturePath();
+ string fixturePath = ResolveFixturePath(FixtureFileName);
string onDisk = File.ReadAllText(fixturePath);
string edited = onDisk
.Replace(
@@ -339,7 +340,7 @@ public async Task Run_ExplicitPropertyRespelledWithGlobal_ApplyAndRevert_RunsThe
public async Task Run_GetterAddedToOrdinarySetOnlyProperty_IsSkippedAndTheFileStillApplies()
{
IHotReloadExplicitRunner runner = new HotReloadExplicitRunnerFixture();
- string fixturePath = ResolveFixturePath();
+ string fixturePath = ResolveFixturePath(FixtureFileName);
string onDisk = File.ReadAllText(fixturePath);
string edited = onDisk
.Replace(
@@ -365,13 +366,193 @@ public async Task Run_GetterAddedToOrdinarySetOnlyProperty_IsSkippedAndTheFileSt
HotReloadCompositionRoot.Services.Patcher.RevertAll();
}
+ ///
+ /// What: an edited explicit method of an internal interface declared in a file the reload is
+ /// not given is Patched, a call through the interface runs the edited body, and RevertAll
+ /// restores the compiled body.
+ ///
+ [Test]
+ public async Task Run_EditedExplicitImplementationOfHiddenInterface_ApplyAndRevert_RunsTheEditedBody()
+ {
+ IHotReloadHiddenRunner runner = new HotReloadHiddenRunnerFixture();
+ Assert.That(runner.Run(), Is.EqualTo(8301));
+
+ await ApplyEditOfAsync(HiddenFixtureFileName, "HiddenE2ERunner.cs", "8301", "9301", "IHotReloadHiddenRunner.Run(");
+
+ Assert.That(runner.Run(), Is.EqualTo(9301));
+ HotReloadCompositionRoot.Services.Patcher.RevertAll();
+ Assert.That(runner.Run(), Is.EqualTo(8301), "RevertAll must restore the compiled body.");
+ }
+
+ ///
+ /// What: an edited explicit property of an internal interface declared in a file the reload is
+ /// not given is Patched under its getter's compiled name and a read through the interface
+ /// returns the edited value until RevertAll.
+ ///
+ [Test]
+ public async Task Run_EditedExplicitPropertyOfHiddenInterface_ApplyAndRevert_ReturnsTheEditedValue()
+ {
+ IHotReloadHiddenValue value = new HotReloadHiddenValueFixture();
+ Assert.That(value.Value, Is.EqualTo(8305));
+
+ await ApplyEditOfAsync(HiddenFixtureFileName, "HiddenE2EValue.cs", "8305", "9305", "IHotReloadHiddenValue.get_Value(");
+
+ Assert.That(value.Value, Is.EqualTo(9305));
+ HotReloadCompositionRoot.Services.Patcher.RevertAll();
+ Assert.That(value.Value, Is.EqualTo(8305), "RevertAll must restore the compiled getter.");
+ }
+
+ ///
+ /// What: an edited explicit method of an internal interface declared in a file the reload is
+ /// not given, whose signature names the reloaded type itself, is Patched and a call through
+ /// the interface runs the edited body until RevertAll.
+ ///
+ [Test]
+ public async Task Run_EditedExplicitImplementationOfHiddenInterfaceNamingTheReloadedType_RunsTheEditedBody()
+ {
+ HotReloadHiddenCopierFixture copier = new HotReloadHiddenCopierFixture();
+ IHotReloadHiddenCopier viaInterface = copier;
+
+ await ApplyEditOfAsync(HiddenFixtureFileName, "HiddenE2ECopier.cs", "8311", "9311", "IHotReloadHiddenCopier.Copy(");
+
+ int count = 0;
+ HotReloadHiddenCopierFixture returned = viaInterface.Copy(copier, ref count);
+ HotReloadCompositionRoot.Services.Patcher.RevertAll();
+ Assert.That(count, Is.EqualTo(9311));
+ Assert.That(returned, Is.SameAs(copier));
+ }
+
+ ///
+ /// What: editing one of two same-signature explicit members of an internal interface declared
+ /// in a file the reload is not given patches that member only; the sibling keeps its body.
+ /// Both orders are covered so a pick of the first same-shape member cannot pass by luck.
+ ///
+ [TestCase("8314", "9314", "IHotReloadHiddenSiblings.Run(", 9314, 8315)]
+ [TestCase("8315", "9315", "IHotReloadHiddenSiblings.Stop(", 8314, 9315)]
+ public async Task Run_EditedOneOfSameSignatureSiblingsOfHiddenInterface_PatchesOnlyThatMember(
+ string token,
+ string replacement,
+ string patchedMethodFragment,
+ int expectedRun,
+ int expectedStop)
+ {
+ IHotReloadHiddenSiblings siblings = new HotReloadHiddenSiblingsFixture();
+
+ await ApplyEditOfAsync(HiddenFixtureFileName, "HiddenE2ESiblings.cs", token, replacement, patchedMethodFragment);
+
+ int run = siblings.Run();
+ int stop = siblings.Stop();
+ HotReloadCompositionRoot.Services.Patcher.RevertAll();
+ Assert.That(run, Is.EqualTo(expectedRun));
+ Assert.That(stop, Is.EqualTo(expectedStop));
+ }
+
+ ///
+ /// What: editing one of two explicit overloads of an internal interface declared in a file the
+ /// reload is not given, which differ by parameter type only, patches that overload only.
+ ///
+ [TestCase("8316", "9316", "Take(System.Int32)", 1 + 9316, 3 + 8317)]
+ [TestCase("8317", "9317", "Take(System.String)", 1 + 8316, 3 + 9317)]
+ public async Task Run_EditedOneOverloadOfHiddenInterface_PatchesOnlyThatOverload(
+ string token,
+ string replacement,
+ string patchedMethodFragment,
+ int expectedIntTake,
+ int expectedStringTake)
+ {
+ IHotReloadHiddenOverloads overloads = new HotReloadHiddenOverloadsFixture();
+
+ await ApplyEditOfAsync(HiddenFixtureFileName, "HiddenE2EOverloads.cs", token, replacement, patchedMethodFragment);
+
+ int intTake = overloads.Take(1);
+ int stringTake = overloads.Take("abc");
+ HotReloadCompositionRoot.Services.Patcher.RevertAll();
+ Assert.That(intTake, Is.EqualTo(expectedIntTake));
+ Assert.That(stringTake, Is.EqualTo(expectedStringTake));
+ }
+
+ ///
+ /// What: an explicit method or property of an internal interface declared in a file the reload
+ /// is not given, whose edited signature matches no member of that interface, is Skipped rather
+ /// than Failed, and the compiled member keeps running.
+ ///
+ [TestCase("int IHotReloadHiddenOverloads.Take(int value) { return value + 8316; }", "int IHotReloadHiddenOverloads.Take(long value) { return (int)value + 9316; }", "Take(")]
+ [TestCase("int IHotReloadHiddenValue.Value => 8305;", "long IHotReloadHiddenValue.Value => 9305;", "Value")]
+ public async Task Run_EditedHiddenInterfaceImplementationMatchingNoMember_IsSkippedAndKeepsTheCompiledMember(
+ string token,
+ string replacement,
+ string skippedFragment)
+ {
+ IHotReloadHiddenOverloads overloads = new HotReloadHiddenOverloadsFixture();
+ IHotReloadHiddenValue value = new HotReloadHiddenValueFixture();
+
+ HotReloadOrchestratorResult result = await RunEditOfAsync(HiddenFixtureFileName, "HiddenE2ENoMatch.cs", token, replacement);
+
+ int intTake = overloads.Take(1);
+ int read = value.Value;
+ HotReloadCompositionRoot.Services.Patcher.RevertAll();
+ Assert.That(result.Methods.Where(outcome => outcome.Kind == HotReloadMethodOutcomeKind.Failed), Is.Empty, FormatOutcomes(result));
+ Assert.That(
+ result.Methods.Any(outcome => outcome.Kind == HotReloadMethodOutcomeKind.Skipped
+ && outcome.Method.Contains(skippedFragment, StringComparison.Ordinal)),
+ Is.True,
+ FormatOutcomes(result));
+ Assert.That(intTake, Is.EqualTo(1 + 8316));
+ Assert.That(read, Is.EqualTo(8305));
+ }
+
+ ///
+ /// What: an edited method whose body relies on its class implementing an internal interface
+ /// declared in a file the reload is not given (a conversion to it, an extension on it, an
+ /// indexer taking it) is Patched and returns the edited value.
+ ///
+ [TestCase("8306", "9306", "RunThroughInterface(", 8301 + 9306)]
+ [TestCase("8307", "9307", "RunThroughExtension(", 8301 * 2 + 9307)]
+ [TestCase("8308", "9308", "RunThroughIndexer(", 8301 + 1 + 9308)]
+ public async Task Run_EditedBodyRelyingOnTheHiddenInterface_IsPatchedAndReturnsTheEditedValue(
+ string token,
+ string replacement,
+ string patchedMethodFragment,
+ int expected)
+ {
+ HotReloadHiddenRunnerFixture runner = new HotReloadHiddenRunnerFixture();
+
+ await ApplyEditOfAsync(HiddenFixtureFileName, "HiddenE2ERelation.cs", token, replacement, patchedMethodFragment);
+
+ int actual = patchedMethodFragment == "RunThroughInterface("
+ ? runner.RunThroughInterface()
+ : patchedMethodFragment == "RunThroughExtension(" ? runner.RunThroughExtension() : runner.RunThroughIndexer();
+ HotReloadCompositionRoot.Services.Patcher.RevertAll();
+ Assert.That(actual, Is.EqualTo(expected));
+ }
+
private static async Task ApplyEditAsync(
string editedFileName,
string token,
string replacement,
string patchedMethodFragment)
{
- string fixturePath = ResolveFixturePath();
+ await ApplyEditOfAsync(FixtureFileName, editedFileName, token, replacement, patchedMethodFragment);
+ }
+
+ private static async Task ApplyEditOfAsync(
+ string fixtureFileName,
+ string editedFileName,
+ string token,
+ string replacement,
+ string patchedMethodFragment)
+ {
+ HotReloadOrchestratorResult result = await RunEditOfAsync(fixtureFileName, editedFileName, token, replacement);
+ AssertHasPatched(result, patchedMethodFragment);
+ }
+
+ private static async Task RunEditOfAsync(
+ string fixtureFileName,
+ string editedFileName,
+ string token,
+ string replacement)
+ {
+ string fixturePath = ResolveFixturePath(fixtureFileName);
string onDisk = File.ReadAllText(fixturePath);
int index = onDisk.IndexOf(token, StringComparison.Ordinal);
Assert.That(index, Is.GreaterThanOrEqualTo(0), "Precondition: the fixture must hold " + token);
@@ -383,12 +564,10 @@ private static async Task ApplyEditAsync(
editedFileName,
onDisk.Replace(token, replacement, StringComparison.Ordinal));
- HotReloadOrchestratorResult result = await HotReloadCompositionRoot.Services.Orchestrator.RunAsync(
+ return await HotReloadCompositionRoot.Services.Orchestrator.RunAsync(
new[] { fixturePath },
editedPath,
CancellationToken.None);
-
- AssertHasPatched(result, patchedMethodFragment);
}
private static void AssertHasPatched(HotReloadOrchestratorResult result, string methodFragment)
@@ -416,9 +595,9 @@ private static string FormatOutcomes(HotReloadOrchestratorResult result)
return string.Join("\n", lines);
}
- private static string ResolveFixturePath()
+ private static string ResolveFixturePath(string fixtureFileName)
{
- string path = Path.Combine(Application.dataPath, "Tests", "Editor", "HotReload", FixtureFileName);
+ string path = Path.Combine(Application.dataPath, "Tests", "Editor", "HotReload", fixtureFileName);
Assert.That(File.Exists(path), Is.True, "Explicit-interface fixture source missing: " + path);
return Path.GetFullPath(path);
}
diff --git a/Assets/Tests/Editor/HotReload/HotReloadHiddenExplicitInterfaceDeclarations.cs b/Assets/Tests/Editor/HotReload/HotReloadHiddenExplicitInterfaceDeclarations.cs
new file mode 100644
index 000000000..153fe97bf
--- /dev/null
+++ b/Assets/Tests/Editor/HotReload/HotReloadHiddenExplicitInterfaceDeclarations.cs
@@ -0,0 +1,87 @@
+using System;
+
+namespace io.github.hatayama.UnityCliLoop.Tests.Editor.HotReload
+{
+ ///
+ /// Internal interface declared apart from its implementers, so a reload given only the
+ /// implementers' file sees it through the compiled assembly alone.
+ ///
+ internal interface IHotReloadHiddenRunner
+ {
+ int Run();
+ }
+
+ /// Internal interface with a property, declared apart from its implementer.
+ internal interface IHotReloadHiddenValue
+ {
+ int Value { get; }
+ }
+
+ /// Internal interface with an indexer, declared apart from its implementer.
+ internal interface IHotReloadHiddenIndexed
+ {
+ int this[int index] { get; set; }
+ }
+
+ /// Internal interface with an init-only property, declared apart from its implementer.
+ internal interface IHotReloadHiddenInitValue
+ {
+ int Value { get; init; }
+ }
+
+ /// Internal interface with an event, declared apart from its implementer.
+ internal interface IHotReloadHiddenNotifier
+ {
+ event Action Changed;
+ }
+
+ ///
+ /// Internal interface whose method takes and returns a type the reloaded file declares, so its
+ /// signature names the compiled copy of that type.
+ ///
+ internal interface IHotReloadHiddenCopier
+ {
+ HotReloadHiddenCopierFixture Copy(HotReloadHiddenCopierFixture value, ref int count);
+ }
+
+ /// Internal interface with two members of one signature, so a match must use the name.
+ internal interface IHotReloadHiddenSiblings
+ {
+ int Run();
+
+ int Stop();
+ }
+
+ /// Internal interface with overloads that differ by parameter type only.
+ internal interface IHotReloadHiddenOverloads
+ {
+ int Take(int value);
+
+ int Take(string value);
+ }
+
+ /// Extension on an internal interface, so a call on an implementer needs the conversion.
+ internal static class HotReloadHiddenRunnerExtensions
+ {
+ internal static int Doubled(this IHotReloadHiddenRunner runner)
+ {
+ return runner.Run() * 2;
+ }
+ }
+
+ /// Indexer that takes an internal interface, so an implementer as the index needs the conversion.
+ internal class HotReloadHiddenRunnerIndexed
+ {
+ internal int this[IHotReloadHiddenRunner runner] => runner.Run() + 1;
+ }
+
+ /// Declares an internal interface nested in a type, apart from its implementers.
+ internal class HotReloadHiddenOuter
+ {
+ /// Internal interface nested in a type.
+ internal interface IInner
+ {
+ int Run();
+ }
+ }
+}
diff --git a/Assets/Tests/Editor/HotReload/HotReloadHiddenExplicitInterfaceDeclarations.cs.meta b/Assets/Tests/Editor/HotReload/HotReloadHiddenExplicitInterfaceDeclarations.cs.meta
new file mode 100644
index 000000000..3d9430278
--- /dev/null
+++ b/Assets/Tests/Editor/HotReload/HotReloadHiddenExplicitInterfaceDeclarations.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 8f79517b9941141c9a505cd1142d9fef
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Tests/Editor/HotReload/HotReloadHiddenExplicitInterfaceFixtures.cs b/Assets/Tests/Editor/HotReload/HotReloadHiddenExplicitInterfaceFixtures.cs
new file mode 100644
index 000000000..6f69353c6
--- /dev/null
+++ b/Assets/Tests/Editor/HotReload/HotReloadHiddenExplicitInterfaceFixtures.cs
@@ -0,0 +1,120 @@
+using System;
+
+namespace io.github.hatayama.UnityCliLoop.Tests.Editor.HotReload
+{
+ /// Implements an internal interface from another file explicitly.
+ public class HotReloadHiddenRunnerFixture : IHotReloadHiddenRunner
+ {
+ int IHotReloadHiddenRunner.Run() { return 8301; }
+
+ public int RunThroughInterface()
+ {
+ IHotReloadHiddenRunner runner = this;
+ return runner.Run() + 8306;
+ }
+
+ public int RunThroughExtension()
+ {
+ return this.Doubled() + 8307;
+ }
+
+ public int RunThroughIndexer()
+ {
+ return new HotReloadHiddenRunnerIndexed()[this] + 8308;
+ }
+ }
+
+ /// Implements an internal interface nested in a type from another file explicitly.
+ public class HotReloadHiddenNestedInterfaceFixture : HotReloadHiddenOuter.IInner
+ {
+ int HotReloadHiddenOuter.IInner.Run() { return 8302; }
+ }
+
+ /// Holds a nested type that implements an internal interface from another file explicitly.
+ public class HotReloadHiddenImplementerHolder
+ {
+ /// Nested implementer of the internal interface.
+ internal class Nested : IHotReloadHiddenRunner
+ {
+ int IHotReloadHiddenRunner.Run() { return 8303; }
+ }
+ }
+
+ /// Implements a property of an internal interface from another file explicitly.
+ public class HotReloadHiddenValueFixture : IHotReloadHiddenValue
+ {
+ int IHotReloadHiddenValue.Value => 8305;
+ }
+
+ /// Implements an indexer of an internal interface from another file explicitly.
+ public class HotReloadHiddenIndexedFixture : IHotReloadHiddenIndexed
+ {
+ private int _lastWritten;
+
+ int IHotReloadHiddenIndexed.this[int index]
+ {
+ get { return index + 8309; }
+ set { _lastWritten = value + 8312; }
+ }
+ }
+
+ /// Implements an init-only property of an internal interface from another file explicitly.
+ public class HotReloadHiddenInitValueFixture : IHotReloadHiddenInitValue
+ {
+ private int _stored;
+
+ int IHotReloadHiddenInitValue.Value
+ {
+ get { return _stored; }
+ init { _stored = value + 8313; }
+ }
+ }
+
+ /// Implements an event of an internal interface from another file explicitly.
+ public class HotReloadHiddenNotifierFixture : IHotReloadHiddenNotifier
+ {
+ private Action _changed;
+
+ event Action IHotReloadHiddenNotifier.Changed
+ {
+ add { _changed += value; Touched = 8310; }
+ remove { _changed -= value; }
+ }
+
+ public int Touched { get; private set; }
+ }
+
+ /// Implements a method whose signature names this type itself, of an internal interface from another file.
+ public class HotReloadHiddenCopierFixture : IHotReloadHiddenCopier
+ {
+ public int Mark { get; set; }
+
+ HotReloadHiddenCopierFixture IHotReloadHiddenCopier.Copy(HotReloadHiddenCopierFixture value, ref int count)
+ {
+ count += 8311;
+ return value;
+ }
+ }
+
+ /// Implements two same-signature members of an internal interface from another file.
+ public class HotReloadHiddenSiblingsFixture : IHotReloadHiddenSiblings
+ {
+ int IHotReloadHiddenSiblings.Run() { return 8314; }
+
+ int IHotReloadHiddenSiblings.Stop() { return 8315; }
+ }
+
+ /// Implements overloads of an internal interface from another file that differ by parameter type.
+ public class HotReloadHiddenOverloadsFixture : IHotReloadHiddenOverloads
+ {
+ int IHotReloadHiddenOverloads.Take(int value) { return value + 8316; }
+
+ int IHotReloadHiddenOverloads.Take(string value) { return value.Length + 8317; }
+ }
+
+ /// Class beside the implementers whose edit leaves them unedited.
+ public class HotReloadHiddenNeighborFixture
+ {
+ public int Value() { return 8304; }
+ }
+}
diff --git a/Assets/Tests/Editor/HotReload/HotReloadHiddenExplicitInterfaceFixtures.cs.meta b/Assets/Tests/Editor/HotReload/HotReloadHiddenExplicitInterfaceFixtures.cs.meta
new file mode 100644
index 000000000..ae2a9708e
--- /dev/null
+++ b/Assets/Tests/Editor/HotReload/HotReloadHiddenExplicitInterfaceFixtures.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: c496a76c2dfa646a4baa350a4a4cd2f6
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Tests/Editor/HotReload/TransformWorkerExplicitInterfaceTests.cs b/Assets/Tests/Editor/HotReload/TransformWorkerExplicitInterfaceTests.cs
index cd2109994..8d95e4ce4 100644
--- a/Assets/Tests/Editor/HotReload/TransformWorkerExplicitInterfaceTests.cs
+++ b/Assets/Tests/Editor/HotReload/TransformWorkerExplicitInterfaceTests.cs
@@ -29,6 +29,8 @@ public class TransformWorkerExplicitInterfaceTests
private const string Namespace = "io.github.hatayama.UnityCliLoop.Tests.Editor.HotReload";
private const string RunnerBody = "int IHotReloadExplicitRunner.Run() { return 8101; }";
private const string ValueSpecifier = "int IHotReloadExplicitValue.Value";
+ private const string HiddenFixtureProjectRelativePath =
+ "Assets/Tests/Editor/HotReload/HotReloadHiddenExplicitInterfaceFixtures.cs";
///
/// What: an edited explicit implementation of a namespaced interface is an entry named by the
@@ -710,6 +712,209 @@ public async Task Run_EditedExplicitIndexerAccessor_StaysSkipped()
HotReloadWorkerReasonCode.MethodTransformExplicitInterfaceImplementation);
}
+ ///
+ /// What: editing only a class beside explicit implementations of internal interfaces that the
+ /// reload was not given leaves those implementations out of the result, with no skipped row
+ /// and no edit-outside-method-bodies warning, because none of them was edited.
+ ///
+ [Test]
+ public async Task Run_EditOfNeighborOfHiddenInterfaceImplementations_LeavesThemOutWithoutWarnings()
+ {
+ TransformWorkerClientResult result = await RunWorkerOnEditedHiddenFixtureAsync(
+ "HiddenNeighbor.cs",
+ source => ReplaceUniqueFragment(source, "8304", "9304"));
+
+ AssertEntry(result, typeof(HotReloadHiddenNeighborFixture), "Value", "Value");
+ AssertNoEntryFor(result, typeof(HotReloadHiddenRunnerFixture));
+ AssertNoEntryFor(result, typeof(HotReloadHiddenNestedInterfaceFixture));
+ AssertNoEntryFor(result, typeof(HotReloadHiddenImplementerHolder.Nested));
+ AssertNoEntryFor(result, typeof(HotReloadHiddenValueFixture));
+ AssertNoEntryFor(result, typeof(HotReloadHiddenIndexedFixture));
+ AssertNoEntryFor(result, typeof(HotReloadHiddenNotifierFixture));
+ AssertNoEntryFor(result, typeof(HotReloadHiddenCopierFixture));
+ AssertNoEntryFor(result, typeof(HotReloadHiddenInitValueFixture));
+ Assert.That(FormatSkipped(result), Is.EqualTo("(none)"), "No unedited implementation may be skipped.");
+ AssertNoDriftOrRemovedMember(result);
+ }
+
+ ///
+ /// What: an edited explicit implementation of an internal interface that the reload was not
+ /// given is an entry named by the compiled metadata name, as it is for a public interface.
+ ///
+ [Test]
+ public async Task Run_EditedExplicitImplementationOfHiddenInterface_EmitsEntryWithCompiledName()
+ {
+ TransformWorkerClientResult result = await RunWorkerOnEditedHiddenFixtureAsync(
+ "HiddenRunner.cs",
+ source => ReplaceUniqueFragment(source, "8301", "9301"));
+
+ AssertEntry(result, typeof(HotReloadHiddenRunnerFixture), Namespace + ".IHotReloadHiddenRunner.Run", "Run");
+ AssertNoDriftOrRemovedMember(result);
+ }
+
+ ///
+ /// What: an edited explicit implementation of an internal interface that the reload was not
+ /// given, whose signature names the type the reloaded file declares (as a parameter, a ref
+ /// parameter's neighbor and the return type), is an entry named by the compiled metadata name.
+ ///
+ [Test]
+ public async Task Run_EditedExplicitImplementationOfHiddenInterfaceNamingTheReloadedType_EmitsEntryWithCompiledName()
+ {
+ TransformWorkerClientResult result = await RunWorkerOnEditedHiddenFixtureAsync(
+ "HiddenCopier.cs",
+ source => ReplaceUniqueFragment(source, "8311", "9311"));
+
+ AssertEntry(result, typeof(HotReloadHiddenCopierFixture), Namespace + ".IHotReloadHiddenCopier.Copy", "Copy");
+ AssertNoDriftOrRemovedMember(result);
+ }
+
+ ///
+ /// What: an edited explicit implementation of an internal interface nested in a type, declared
+ /// in a file the reload was not given, is an entry whose name joins the outer and nested type
+ /// with a dot.
+ ///
+ [Test]
+ public async Task Run_EditedExplicitImplementationOfNestedHiddenInterface_EmitsEntryWithCompiledName()
+ {
+ TransformWorkerClientResult result = await RunWorkerOnEditedHiddenFixtureAsync(
+ "HiddenNestedInterface.cs",
+ source => ReplaceUniqueFragment(source, "8302", "9302"));
+
+ AssertEntry(
+ result,
+ typeof(HotReloadHiddenNestedInterfaceFixture),
+ Namespace + ".HotReloadHiddenOuter.IInner.Run",
+ "Run");
+ AssertNoDriftOrRemovedMember(result);
+ }
+
+ ///
+ /// What: a nested type's edited explicit implementation of an internal interface that the
+ /// reload was not given is an entry on the nested type, named by the compiled metadata name.
+ ///
+ [Test]
+ public async Task Run_EditedExplicitImplementationOnNestedImplementerOfHiddenInterface_EmitsEntryWithCompiledName()
+ {
+ TransformWorkerClientResult result = await RunWorkerOnEditedHiddenFixtureAsync(
+ "HiddenNestedImplementer.cs",
+ source => ReplaceUniqueFragment(source, "8303", "9303"));
+
+ AssertEntry(
+ result,
+ typeof(HotReloadHiddenImplementerHolder.Nested),
+ Namespace + ".IHotReloadHiddenRunner.Run",
+ "Run");
+ AssertNoDriftOrRemovedMember(result);
+ }
+
+ ///
+ /// What: an edited explicit property implementation of an internal interface that the reload
+ /// was not given is an entry for its getter under the compiled metadata name, not under a
+ /// name built as if the property were an ordinary one.
+ ///
+ [Test]
+ public async Task Run_EditedExplicitPropertyOfHiddenInterface_EmitsGetterEntryWithCompiledName()
+ {
+ TransformWorkerClientResult result = await RunWorkerOnEditedHiddenFixtureAsync(
+ "HiddenValue.cs",
+ source => ReplaceUniqueFragment(source, "8305", "9305"));
+
+ AssertEntry(
+ result,
+ typeof(HotReloadHiddenValueFixture),
+ Namespace + ".IHotReloadHiddenValue.get_Value",
+ "get_Value");
+ AssertNoDriftOrRemovedMember(result);
+ }
+
+ ///
+ /// What: an edited accessor of an explicit indexer, event or init-only property of an internal interface that the
+ /// reload was not given stays Skipped as it does for a public interface, under the name the
+ /// compiled assembly gives the accessor, with no edit-outside-method-bodies warning.
+ ///
+ [TestCase("8309", "9309", "IHotReloadHiddenIndexed.get_Item(System.Int32)", "MethodTransformExplicitInterfaceImplementation")]
+ [TestCase("8310", "9310", "IHotReloadHiddenNotifier.add_Changed(System.Action)", "UnsupportedMemberUnsupportedKind")]
+ [TestCase("8312", "9312", "IHotReloadHiddenIndexed.set_Item(System.Int32,System.Int32)", "MethodTransformExplicitInterfaceImplementation")]
+ [TestCase("8313", "9313", "IHotReloadHiddenInitValue.set_Value(System.Int32)", "UnsupportedMemberExplicitAccessor")]
+ public async Task Run_EditedExplicitIndexerOrEventAccessorOfHiddenInterface_StaysSkippedUnderTheCompiledName(
+ string token,
+ string replacement,
+ string accessorLabelEnd,
+ string codeName)
+ {
+ TransformWorkerClientResult result = await RunWorkerOnEditedHiddenFixtureAsync(
+ "HiddenIndexerOrEvent.cs",
+ source => ReplaceUniqueFragment(source, token, replacement));
+
+ Assert.That(
+ result.Output.skipped.Select(skipped => skipped.method + " :: " + skipped.reason?.code),
+ Is.EqualTo(new[] { Namespace + "." + FixtureTypeOf(token) + "." + Namespace + "." + accessorLabelEnd + " :: " + codeName }));
+ AssertNoDriftOrRemovedMember(result);
+ }
+
+ ///
+ /// What: an edited method of an implementer whose body relies on the class implementing an
+ /// internal interface that the reload was not given (a conversion to it, an extension on it,
+ /// an indexer taking it) is an entry, with no row for the implementer's explicit method.
+ ///
+ [TestCase("8306", "9306", "RunThroughInterface")]
+ [TestCase("8307", "9307", "RunThroughExtension")]
+ [TestCase("8308", "9308", "RunThroughIndexer")]
+ public async Task Run_EditedBodyRelyingOnTheHiddenInterface_EmitsOnlyThatEntry(
+ string token,
+ string replacement,
+ string methodName)
+ {
+ TransformWorkerClientResult result = await RunWorkerOnEditedHiddenFixtureAsync(
+ "HiddenRelation.cs",
+ source => ReplaceUniqueFragment(source, token, replacement));
+
+ Assert.That(
+ result.Output.entries.Select(entry => entry.typeMetadataName + "::" + entry.methodName),
+ Is.EqualTo(new[] { typeof(HotReloadHiddenRunnerFixture).FullName + "::" + methodName }));
+ Assert.That(FormatSkipped(result), Is.EqualTo("(none)"));
+ AssertNoDriftOrRemovedMember(result);
+ }
+
+ ///
+ /// What: an explicit implementation of an internal interface that the reload was not given,
+ /// whose edit only respells the interface with global::, is reported unchanged under the
+ /// compiled name with no entry and no warning, as it is for a public interface.
+ ///
+ [Test]
+ public async Task Run_HiddenInterfaceImplementationOnlyRespelledWithGlobal_IsUnchangedWithoutWarnings()
+ {
+ TransformWorkerClientResult result = await RunWorkerOnEditedHiddenFixtureAsync(
+ "HiddenGlobalOnlyRespelled.cs",
+ source => ReplaceUniqueFragment(
+ source,
+ "int IHotReloadHiddenRunner.Run() { return 8301; }",
+ "int global::" + Namespace + ".IHotReloadHiddenRunner.Run() { return 8301; }"));
+
+ AssertNoEntryFor(result, typeof(HotReloadHiddenRunnerFixture));
+ Assert.That(
+ result.Output.unchangedMethods
+ .Where(row => row.typeMetadataName == typeof(HotReloadHiddenRunnerFixture).FullName)
+ .Select(row => row.methodName),
+ Does.Contain(Namespace + ".IHotReloadHiddenRunner.Run"));
+ Assert.That(FormatSkipped(result), Is.EqualTo("(none)"));
+ AssertNoDriftOrRemovedMember(result);
+ }
+
+ private static string FixtureTypeOf(string token)
+ {
+ switch (token)
+ {
+ case "8309":
+ case "8312":
+ return nameof(HotReloadHiddenIndexedFixture);
+ case "8313":
+ return nameof(HotReloadHiddenInitValueFixture);
+ default:
+ return nameof(HotReloadHiddenNotifierFixture);
+ }
+ }
+
private static void AssertNoDriftOrRemovedMember(TransformWorkerClientResult result)
{
Assert.That(
@@ -729,7 +934,7 @@ private static IEnumerable RemovedMemberLabels(TransformWorkerClientResu
private static void AssertNoEntryFor(TransformWorkerClientResult result, Type fixtureType)
{
Assert.That(
- result.Output.entries.Where(entry => entry.typeMetadataName == fixtureType.FullName).Select(entry => entry.methodName),
+ result.Output.entries.Where(entry => entry.typeMetadataName == MetadataNameOf(fixtureType)).Select(entry => entry.methodName),
Is.Empty,
"No entry expected for " + fixtureType.Name);
}
@@ -750,7 +955,7 @@ private static TransformWorkerEntryDto AssertEntry(
string memberName)
{
TransformWorkerEntryDto entry = result.Output.entries.FirstOrDefault(candidate =>
- candidate.typeMetadataName == fixtureType.FullName);
+ candidate.typeMetadataName == MetadataNameOf(fixtureType));
Assert.That(entry, Is.Not.Null, "Expected an entry for " + fixtureType.Name + ". Skipped=" + FormatSkipped(result));
Assert.That(entry.methodName, Is.EqualTo(expectedMethodName));
Assert.That(
@@ -761,6 +966,12 @@ private static TransformWorkerEntryDto AssertEntry(
return entry;
}
+ // Why: the worker names a nested type with '/', as metadata does, and reflection with '+'.
+ private static string MetadataNameOf(Type fixtureType)
+ {
+ return fixtureType.FullName.Replace('+', '/');
+ }
+
private static string FormatSkipped(TransformWorkerClientResult result)
{
if (result.Output.skipped == null || result.Output.skipped.Length == 0)
@@ -786,11 +997,29 @@ private static async Task RunWorkerOnEditedFixtureA
string fileName,
Func edit,
string[] excludedMethodKeys = null)
+ {
+ return await RunWorkerOnEditedFileAsync(FixtureProjectRelativePath, fileName, edit, excludedMethodKeys);
+ }
+
+ // Why a separate file: its internal interfaces live in a file the reload is not given, so
+ // the worker sees them only through the compiled assembly.
+ private static async Task RunWorkerOnEditedHiddenFixtureAsync(
+ string fileName,
+ Func edit)
+ {
+ return await RunWorkerOnEditedFileAsync(HiddenFixtureProjectRelativePath, fileName, edit, null);
+ }
+
+ private static async Task RunWorkerOnEditedFileAsync(
+ string fixtureProjectRelativePath,
+ string fileName,
+ Func edit,
+ string[] excludedMethodKeys)
{
string projectRoot = Path.GetFullPath(Path.Combine(Application.dataPath, ".."));
string fixturePath = Path.Combine(
projectRoot,
- FixtureProjectRelativePath.Replace('/', Path.DirectorySeparatorChar));
+ fixtureProjectRelativePath.Replace('/', Path.DirectorySeparatorChar));
string onDisk = File.ReadAllText(fixturePath);
string editedSource = edit(onDisk);
Assert.That(editedSource, Is.Not.EqualTo(onDisk), "Precondition: snapshot must differ.");
@@ -800,7 +1029,11 @@ private static async Task RunWorkerOnEditedFixtureA
string sourcePath = Path.Combine(directory, fileName);
File.WriteAllText(sourcePath, editedSource);
- TransformWorkerClientResult result = await RunWorkerOnSourceAsync(sourcePath, onDisk, excludedMethodKeys);
+ TransformWorkerClientResult result = await RunWorkerOnSourceAsync(
+ sourcePath,
+ onDisk,
+ excludedMethodKeys,
+ fixtureProjectRelativePath);
Assert.That(result.Success, Is.True, result.ErrorMessage);
return result;
}
@@ -808,7 +1041,8 @@ private static async Task RunWorkerOnEditedFixtureA
private static async Task RunWorkerOnSourceAsync(
string sourcePath,
string snapshotSource,
- string[] excludedMethodKeys = null)
+ string[] excludedMethodKeys = null,
+ string projectRelativePath = FixtureProjectRelativePath)
{
string projectRoot = Path.GetFullPath(Path.Combine(Application.dataPath, ".."));
string targetDllPath = Path.Combine(projectRoot, "Library", "ScriptAssemblies", TestAssemblyName + ".dll");
@@ -854,7 +1088,7 @@ private static async Task RunWorkerOnSourceAsync(
new TransformWorkerSourceDto
{
sourcePath = sourcePath,
- projectRelativePath = FixtureProjectRelativePath,
+ projectRelativePath = projectRelativePath,
snapshotSource = snapshotSource
}
},
diff --git a/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/AddedFieldSkippedWriterWarnings.cs b/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/AddedFieldSkippedWriterWarnings.cs
index 14121c06e..93452475b 100644
--- a/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/AddedFieldSkippedWriterWarnings.cs
+++ b/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/AddedFieldSkippedWriterWarnings.cs
@@ -76,7 +76,8 @@ public static void AppendWarnings(
new HashSet(
allTypeEmitStates.SelectMany(state => state.QueuedMethods).Select(queued => queued.MethodDeclaration)),
addedPropertyCatalog,
- BuildCompiledTypeBySourceType(allTypeEmitStates));
+ BuildCompiledTypeBySourceType(allTypeEmitStates),
+ unit.ExplicitImplementations);
foreach (WorkerSourceUnit scannedUnit in transformUnits)
{
RecordUses(scannedUnit, candidates, classifier);
diff --git a/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/AddedPropertyClassifier.cs b/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/AddedPropertyClassifier.cs
index c939212f4..c2ea3eb4b 100644
--- a/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/AddedPropertyClassifier.cs
+++ b/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/AddedPropertyClassifier.cs
@@ -148,7 +148,7 @@ private static AddedPropertyCandidate CreateCandidateOrNull(
AddedMethodCatalog addedMethodCatalog)
{
IPropertySymbol symbol = semanticModel.GetDeclaredSymbol(declaration);
- if (symbol == null || AddedPropertySkipEvaluator.HasCompiledProperty(compiledType, symbol))
+ if (symbol == null || AddedPropertySkipEvaluator.HasCompiledProperty(typeState.SourceUnit.ExplicitImplementations, compiledType, symbol))
{
return null;
}
diff --git a/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/AddedPropertySkipEvaluator.cs b/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/AddedPropertySkipEvaluator.cs
index 90caf47fb..adb242e46 100644
--- a/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/AddedPropertySkipEvaluator.cs
+++ b/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/AddedPropertySkipEvaluator.cs
@@ -32,13 +32,13 @@ internal static WorkerReason EvaluateCompiledMemberKindChangeReason(
return null;
}
- internal static bool HasCompiledProperty(INamedTypeSymbol compiledType, IPropertySymbol property)
+ internal static bool HasCompiledProperty(ExplicitImplementationMatcher explicitImplementations, INamedTypeSymbol compiledType, IPropertySymbol property)
{
// Why the matcher for an explicit property: a respelled specifier changes its name, and the
// property would otherwise be read as added.
- if (property.ExplicitInterfaceImplementations.Length > 0)
+ if (explicitImplementations.IsExplicitImplementation(property))
{
- return ExplicitImplementationMatcher.FindCompiledPropertyImplementation(compiledType, property) != null;
+ return explicitImplementations.FindCompiledPropertyImplementation(compiledType, property) != null;
}
foreach (ISymbol member in compiledType.GetMembers(property.Name))
diff --git a/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/CompiledMemberKindChangeWarnings.cs b/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/CompiledMemberKindChangeWarnings.cs
index 1b48cee26..c2b22a9d3 100644
--- a/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/CompiledMemberKindChangeWarnings.cs
+++ b/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/CompiledMemberKindChangeWarnings.cs
@@ -34,6 +34,7 @@ internal sealed class SyntaxKeys
/// redeclared as another member kind, even when no method body changed.
///
internal static SyntaxKeys AppendCompiledPropertyOrEventKindChangeWarnings(
+ ExplicitImplementationMatcher explicitImplementations,
CompilationUnitSyntax root,
SemanticModel semanticModel,
WorkerTypeHome home,
@@ -79,6 +80,7 @@ in root.DescendantNodes().OfType())
}
AppendMissingCompiledPropertyOrEventWarnings(
+ explicitImplementations,
compiledType,
sourceType,
typeMetadataName,
@@ -90,6 +92,7 @@ in root.DescendantNodes().OfType())
}
internal static void AppendMissingCompiledPropertyOrEventWarnings(
+ ExplicitImplementationMatcher explicitImplementations,
INamedTypeSymbol compiledType,
INamedTypeSymbol sourceType,
string typeMetadataName,
@@ -98,7 +101,7 @@ internal static void AppendMissingCompiledPropertyOrEventWarnings(
{
foreach (ISymbol compiledMember in compiledType.GetMembers())
{
- string warning = TryFormatMissingCompiledPropertyOrEventWarning(compiledMember, sourceType);
+ string warning = TryFormatMissingCompiledPropertyOrEventWarning(explicitImplementations, compiledMember, sourceType);
if (warning == null)
{
continue;
@@ -122,6 +125,7 @@ internal static void AppendMissingCompiledPropertyOrEventWarnings(
}
internal static string TryFormatMissingCompiledPropertyOrEventWarning(
+ ExplicitImplementationMatcher explicitImplementations,
ISymbol compiledMember,
INamedTypeSymbol sourceType)
{
@@ -136,7 +140,7 @@ internal static string TryFormatMissingCompiledPropertyOrEventWarning(
&& property.Parameters.Length == 0
&& !property.IsImplicitlyDeclared
&& !SourceDeclaresProperty(sourceType, property.Name)
- && !ExplicitImplementationMatcher.SourceImplementsSameInterfaceMember(sourceType, property))
+ && !explicitImplementations.SourceImplementsSameInterfaceMember(sourceType, property))
{
return string.Format(
CultureInfo.InvariantCulture,
@@ -147,7 +151,7 @@ internal static string TryFormatMissingCompiledPropertyOrEventWarning(
if (compiledMember is IEventSymbol compiledEvent
&& !compiledEvent.IsImplicitlyDeclared
&& !SourceDeclaresEvent(sourceType, compiledEvent.Name)
- && !ExplicitImplementationMatcher.SourceImplementsSameInterfaceMember(sourceType, compiledEvent))
+ && !explicitImplementations.SourceImplementsSameInterfaceMember(sourceType, compiledEvent))
{
return string.Format(
CultureInfo.InvariantCulture,
diff --git a/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/EventAccessorSkipCollector.cs b/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/EventAccessorSkipCollector.cs
index 1edd4f573..8e135364a 100644
--- a/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/EventAccessorSkipCollector.cs
+++ b/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/EventAccessorSkipCollector.cs
@@ -10,6 +10,7 @@
internal static class EventAccessorSkipCollector
{
internal static void AppendEventAccessorSkips(
+ ExplicitImplementationMatcher explicitImplementations,
TypeDeclarationSyntax typeDeclaration,
string typeMetadataNameFromSyntax,
SemanticModel semanticModel,
@@ -42,6 +43,7 @@ internal static void AppendEventAccessorSkips(
EventDeclarationSyntax currentEvent = hasSnapshotPeer ? plainEvent : eventDeclaration;
EventDeclarationSyntax snapshotForCompare = hasSnapshotPeer ? snapshotEvent : null;
AppendEventAccessorSkipForKind(
+ explicitImplementations,
skipped,
eventDeclaration,
snapshotForCompare,
@@ -49,6 +51,7 @@ internal static void AppendEventAccessorSkips(
SyntaxKind.AddAccessorDeclaration,
eventSymbol.AddMethod);
AppendEventAccessorSkipForKind(
+ explicitImplementations,
skipped,
eventDeclaration,
snapshotForCompare,
@@ -61,6 +64,7 @@ internal static void AppendEventAccessorSkips(
// Why per accessor: an add-only edit used to skip remove as well because the
// collector compared the whole event declaration.
private static void AppendEventAccessorSkipForKind(
+ ExplicitImplementationMatcher explicitImplementations,
List skipped,
EventDeclarationSyntax eventDeclaration,
EventDeclarationSyntax snapshotEvent,
@@ -74,7 +78,7 @@ private static void AppendEventAccessorSkipForKind(
return;
}
- AppendEventAccessorSkipIfExplicit(skipped, eventDeclaration, accessorKind, accessorMethod);
+ AppendEventAccessorSkipIfExplicit(explicitImplementations, skipped, eventDeclaration, accessorKind, accessorMethod);
}
private static bool EventAccessorUnchanged(
@@ -110,6 +114,7 @@ private static AccessorDeclarationSyntax FindEventAccessor(
}
private static void AppendEventAccessorSkipIfExplicit(
+ ExplicitImplementationMatcher explicitImplementations,
List skipped,
EventDeclarationSyntax eventDeclaration,
SyntaxKind accessorKind,
@@ -132,7 +137,10 @@ private static void AppendEventAccessorSkipIfExplicit(
return;
}
- UnsupportedMemberSkipCollector.AppendUnsupportedKindSkip(skipped, accessorMethod);
+ UnsupportedMemberSkipCollector.AppendUnsupportedKindSkip(
+ skipped,
+ accessorMethod,
+ WorkerMethodKeys.FormatSourceLabel(explicitImplementations, accessorMethod));
return;
}
}
diff --git a/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/ExplicitImplementationMatcher.cs b/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/ExplicitImplementationMatcher.cs
index f5f18b604..9e76aedf0 100644
--- a/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/ExplicitImplementationMatcher.cs
+++ b/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/ExplicitImplementationMatcher.cs
@@ -1,5 +1,7 @@
+using System.Collections.Generic;
using System.Linq;
using Microsoft.CodeAnalysis;
+using Microsoft.CodeAnalysis.CSharp.Syntax;
///
/// Finds the compiled counterpart of a source explicit interface implementation by the interface
@@ -11,22 +13,87 @@
/// implementation. The fully qualified display of the interface is the same for a source symbol
/// and a metadata symbol whatever the spelling (alias, global::, int or
/// System.Int32).
+/// Why one object for the run and not the symbols alone: the compilation binds a declaration's
+/// interfaces with accessibility enforced, so an explicit implementation of an internal interface
+/// of the compiled assembly reports no implemented member. The run resolves those once through the
+/// accessibility-ignoring binding (see ), and every
+/// question about an explicit implementation is asked here so that each sees the same answer.
///
-internal static class ExplicitImplementationMatcher
+internal sealed class ExplicitImplementationMatcher
{
+ private readonly IReadOnlyDictionary _resolvedImplementedMembers;
+
+ ///
+ /// The interface member of each source explicit implementation the compilation left
+ /// implementing nothing, accessors included; empty when the run resolved none.
+ ///
+ internal ExplicitImplementationMatcher(IReadOnlyDictionary resolvedImplementedMembers)
+ {
+ _resolvedImplementedMembers = resolvedImplementedMembers;
+ }
+
+ ///
+ /// The interface member explicitly implements; null when it is
+ /// not an explicit implementation or its interface member could not be resolved.
+ ///
+ internal ISymbol ImplementedMemberOrNull(ISymbol sourceMember)
+ {
+ ISymbol declared = DeclaredImplementedMemberOrNull(sourceMember);
+ if (declared != null)
+ {
+ return declared;
+ }
+
+ return sourceMember != null && _resolvedImplementedMembers.TryGetValue(sourceMember, out ISymbol resolved)
+ ? resolved
+ : null;
+ }
+
+ ///
+ /// Whether , or the property or event an accessor belongs to, is
+ /// declared as an explicit interface implementation, whether or not its interface member resolves.
+ ///
+ ///
+ /// Why the declaration too: an explicit implementation whose member cannot be resolved is still
+ /// no ordinary member, and reading it as one names it after its dotted declaration.
+ ///
+ internal bool IsExplicitImplementation(ISymbol sourceMember)
+ {
+ if (ImplementedMemberOrNull(sourceMember) != null)
+ {
+ return true;
+ }
+
+ ISymbol declared = sourceMember is IMethodSymbol { AssociatedSymbol: { } associated } ? associated : sourceMember;
+ return declared != null && declared.DeclaringSyntaxReferences.Any(reference => HasSpecifier(reference.GetSyntax()));
+ }
+
+ private static bool HasSpecifier(SyntaxNode declaration)
+ {
+ switch (declaration)
+ {
+ case MethodDeclarationSyntax method:
+ return method.ExplicitInterfaceSpecifier != null;
+ // Why one case: an event declaration is a BasePropertyDeclarationSyntax too.
+ case BasePropertyDeclarationSyntax property:
+ return property.ExplicitInterfaceSpecifier != null;
+ default:
+ return false;
+ }
+ }
+
///
/// The compiled method that explicitly implements the same interface member with the same
/// parameters and return type as ; null when the compiled type
/// has none, that is when the implementation was added since the last compile.
///
- internal static IMethodSymbol FindCompiledImplementation(INamedTypeSymbol compiledType, IMethodSymbol sourceMethod)
+ internal IMethodSymbol FindCompiledImplementation(INamedTypeSymbol compiledType, IMethodSymbol sourceMethod)
{
- if (compiledType == null || sourceMethod.ExplicitInterfaceImplementations.Length == 0)
+ if (compiledType == null || !(ImplementedMemberOrNull(sourceMethod) is IMethodSymbol sourceMember))
{
return null;
}
- IMethodSymbol sourceMember = sourceMethod.ExplicitInterfaceImplementations[0];
foreach (IMethodSymbol compiledMethod in compiledType.GetMembers().OfType())
{
if (ImplementsSameMember(compiledMethod, sourceMember)
@@ -47,11 +114,11 @@ internal static IMethodSymbol FindCompiledImplementation(INamedTypeSymbol compil
/// Why: the Editor resolves and reverts patches by the compiled name, and a source spelled
/// global::Ns.IFoo.Run has a different name from the compiled Ns.IFoo.Run.
///
- internal static string RowMethodName(INamedTypeSymbol compiledType, IMethodSymbol sourceMethod)
+ internal string RowMethodName(INamedTypeSymbol compiledType, IMethodSymbol sourceMethod)
{
// Why not MethodKind: an accessor of an explicit property is PropertyGet or PropertySet,
// yet carries the compiled metadata name all the same.
- if (sourceMethod.ExplicitInterfaceImplementations.Length == 0)
+ if (!IsExplicitImplementation(sourceMethod))
{
return sourceMethod.Name;
}
@@ -64,14 +131,13 @@ internal static string RowMethodName(INamedTypeSymbol compiledType, IMethodSymbo
/// The compiled property that explicitly implements the same interface property, with the same
/// type, as ; null when the compiled type has none.
///
- internal static IPropertySymbol FindCompiledPropertyImplementation(INamedTypeSymbol compiledType, IPropertySymbol sourceProperty)
+ internal IPropertySymbol FindCompiledPropertyImplementation(INamedTypeSymbol compiledType, IPropertySymbol sourceProperty)
{
- if (compiledType == null || sourceProperty.ExplicitInterfaceImplementations.Length == 0)
+ if (compiledType == null || !(ImplementedMemberOrNull(sourceProperty) is IPropertySymbol sourceMember))
{
return null;
}
- IPropertySymbol sourceMember = sourceProperty.ExplicitInterfaceImplementations[0];
string sourceInterface = sourceMember.ContainingType.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat);
string sourceType = CecilTypeNames.ToCecilFullName(sourceProperty.Type);
foreach (IPropertySymbol compiledProperty in compiledType.GetMembers().OfType())
@@ -97,9 +163,9 @@ internal static IPropertySymbol FindCompiledPropertyImplementation(INamedTypeSym
/// Why: a source implementation respelled with global:: is named after the new spelling,
/// so looking it up by the compiled name finds nothing.
///
- internal static bool SourceImplementsSameInterfaceMember(INamedTypeSymbol sourceType, ISymbol compiledMember)
+ internal bool SourceImplementsSameInterfaceMember(INamedTypeSymbol sourceType, ISymbol compiledMember)
{
- ISymbol compiledImplemented = ExplicitlyImplementedPropertyOrEventOrNull(compiledMember);
+ ISymbol compiledImplemented = DeclaredPropertyOrEventOrNull(compiledMember);
if (compiledImplemented == null)
{
return false;
@@ -108,7 +174,7 @@ internal static bool SourceImplementsSameInterfaceMember(INamedTypeSymbol source
string compiledInterface = compiledImplemented.ContainingType.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat);
foreach (ISymbol sourceMember in sourceType.GetMembers())
{
- ISymbol implemented = ExplicitlyImplementedPropertyOrEventOrNull(sourceMember);
+ ISymbol implemented = ImplementedPropertyOrEventOrNull(sourceMember);
if (implemented != null
&& implemented.Kind == compiledImplemented.Kind
&& implemented.Name == compiledImplemented.Name
@@ -121,16 +187,55 @@ internal static bool SourceImplementsSameInterfaceMember(INamedTypeSymbol source
return false;
}
+ ///
+ /// The name the compiler gives when its interface member is
+ /// accessible to the declaration: an accessor of an explicit property, indexer or event this run
+ /// resolved is named after the interface accessor (Ns.IFoo.get_Item), not after its property
+ /// (get_Ns.IFoo.Item).
+ ///
+ internal string SourceMethodName(IMethodSymbol sourceMethod)
+ {
+ if (DeclaredImplementedMemberOrNull(sourceMethod) != null
+ || sourceMethod.AssociatedSymbol == null
+ || !(ImplementedMemberOrNull(sourceMethod) is IMethodSymbol implemented))
+ {
+ return sourceMethod.Name;
+ }
+
+ string associatedName = sourceMethod.AssociatedSymbol.Name;
+ int lastDot = associatedName.LastIndexOf('.');
+ return lastDot < 0 ? sourceMethod.Name : associatedName.Substring(0, lastDot + 1) + implemented.Name;
+ }
+
/// The name of the interface member a source explicit implementation implements.
- internal static string ImplementedMemberName(IMethodSymbol sourceMethod)
+ internal string ImplementedMemberName(IMethodSymbol sourceMethod)
+ {
+ // Why the last segment as a fallback: an unresolved one is named after its dotted declaration.
+ ISymbol implemented = ImplementedMemberOrNull(sourceMethod);
+ return implemented != null ? implemented.Name : sourceMethod.Name.Substring(sourceMethod.Name.LastIndexOf('.') + 1);
+ }
+
+ // Why only properties and events: a compiled method is matched through FindCompiledImplementation.
+ private static ISymbol DeclaredPropertyOrEventOrNull(ISymbol member)
+ {
+ ISymbol implemented = DeclaredImplementedMemberOrNull(member);
+ return implemented is IPropertySymbol || implemented is IEventSymbol ? implemented : null;
+ }
+
+ private ISymbol ImplementedPropertyOrEventOrNull(ISymbol member)
{
- return sourceMethod.ExplicitInterfaceImplementations[0].Name;
+ ISymbol implemented = ImplementedMemberOrNull(member);
+ return implemented is IPropertySymbol || implemented is IEventSymbol ? implemented : null;
}
- private static ISymbol ExplicitlyImplementedPropertyOrEventOrNull(ISymbol member)
+ // What the compiler recorded for the member: a metadata member always has it, and a source
+ // member has it when its interface was accessible to the declaration.
+ private static ISymbol DeclaredImplementedMemberOrNull(ISymbol member)
{
switch (member)
{
+ case IMethodSymbol method when method.ExplicitInterfaceImplementations.Length > 0:
+ return method.ExplicitInterfaceImplementations[0];
case IPropertySymbol property when property.ExplicitInterfaceImplementations.Length > 0:
return property.ExplicitInterfaceImplementations[0];
case IEventSymbol eventSymbol when eventSymbol.ExplicitInterfaceImplementations.Length > 0:
diff --git a/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/ExplicitInterfaceMemberResolver.cs b/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/ExplicitInterfaceMemberResolver.cs
new file mode 100644
index 000000000..87a62645d
--- /dev/null
+++ b/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/ExplicitInterfaceMemberResolver.cs
@@ -0,0 +1,208 @@
+using System.Collections.Generic;
+using System.Linq;
+using Microsoft.CodeAnalysis;
+using Microsoft.CodeAnalysis.CSharp.Syntax;
+
+// What: the interface member of each explicit implementation in the given trees that the
+// compilation left implementing nothing, resolved by binding its specifier with accessibility
+// ignored. That happens when the interface is internal to the compiled assembly and declared in a
+// file the run was not given: the worker sees that assembly only through its reference, and the
+// compilation binds a declaration's interfaces with accessibility enforced.
+// Why not let the compilation ignore accessibility instead: that switches off every binding the
+// run's guards enforce accessibility with, and lets a body reach a member the running code cannot.
+internal static class ExplicitInterfaceMemberResolver
+{
+ ///
+ /// Source member (and each of its accessors) to the interface member it implements, for the
+ /// explicit implementations whose implemented member the compiler did not record. An
+ /// implementation whose specifier binds to no interface, or to an interface with no member or
+ /// several members of the same shape, is left out, so it stays an implementation of nothing.
+ ///
+ /// Accessibility-ignoring models of the trees to scan.
+ internal static Dictionary Resolve(IEnumerable semanticModels)
+ {
+ Dictionary resolved = new Dictionary(SymbolEqualityComparer.Default);
+ foreach (SemanticModel semanticModel in semanticModels)
+ {
+ foreach (MemberDeclarationSyntax declaration in semanticModel.SyntaxTree.GetRoot()
+ .DescendantNodes()
+ .OfType())
+ {
+ AddResolved(semanticModel, declaration, resolved);
+ }
+ }
+
+ return resolved;
+ }
+
+ private static void AddResolved(
+ SemanticModel semanticModel,
+ MemberDeclarationSyntax declaration,
+ Dictionary resolved)
+ {
+ ExplicitInterfaceSpecifierSyntax specifier = SpecifierOrNull(declaration);
+ if (specifier == null)
+ {
+ return;
+ }
+
+ ISymbol sourceMember = semanticModel.GetDeclaredSymbol(declaration);
+ if (sourceMember == null || ImplementsAMember(sourceMember))
+ {
+ return;
+ }
+
+ if (!(semanticModel.GetSymbolInfo(specifier.Name).Symbol is INamedTypeSymbol interfaceType)
+ || interfaceType.TypeKind != TypeKind.Interface)
+ {
+ return;
+ }
+
+ List matches = interfaceType.GetMembers()
+ .Where(candidate => !candidate.IsStatic && SameShape(candidate, sourceMember))
+ .ToList();
+ if (matches.Count != 1)
+ {
+ return;
+ }
+
+ resolved[sourceMember] = matches[0];
+ AddAccessors(sourceMember, matches[0], resolved);
+ }
+
+ private static ExplicitInterfaceSpecifierSyntax SpecifierOrNull(MemberDeclarationSyntax declaration)
+ {
+ switch (declaration)
+ {
+ case MethodDeclarationSyntax method:
+ return method.ExplicitInterfaceSpecifier;
+ // Why one case: an event declaration is a BasePropertyDeclarationSyntax too.
+ case BasePropertyDeclarationSyntax property:
+ return property.ExplicitInterfaceSpecifier;
+ default:
+ return null;
+ }
+ }
+
+ private static bool ImplementsAMember(ISymbol sourceMember)
+ {
+ switch (sourceMember)
+ {
+ case IMethodSymbol method:
+ return method.ExplicitInterfaceImplementations.Length > 0;
+ case IPropertySymbol property:
+ return property.ExplicitInterfaceImplementations.Length > 0;
+ case IEventSymbol eventSymbol:
+ return eventSymbol.ExplicitInterfaceImplementations.Length > 0;
+ default:
+ return true;
+ }
+ }
+
+ // Why the implemented member's name and not the source member's: the source name is the
+ // dotted explicit name (Ns.IFoo.Run), the interface member is named Run.
+ private static bool SameShape(ISymbol candidate, ISymbol sourceMember)
+ {
+ switch (sourceMember)
+ {
+ case IMethodSymbol method:
+ return candidate is IMethodSymbol interfaceMethod && SameMethodShape(interfaceMethod, method);
+ case IPropertySymbol property:
+ return candidate is IPropertySymbol interfaceProperty && SamePropertyShape(interfaceProperty, property);
+ case IEventSymbol eventSymbol:
+ return candidate is IEventSymbol interfaceEvent
+ && interfaceEvent.Name == ExplicitMemberName(eventSymbol.Name)
+ && SameType(interfaceEvent.Type, eventSymbol.Type);
+ default:
+ return false;
+ }
+ }
+
+ private static bool SameMethodShape(IMethodSymbol interfaceMethod, IMethodSymbol sourceMethod)
+ {
+ if (interfaceMethod.MethodKind != MethodKind.Ordinary
+ || interfaceMethod.Name != ExplicitMemberName(sourceMethod.Name)
+ || interfaceMethod.Arity != sourceMethod.Arity)
+ {
+ return false;
+ }
+
+ // Why construct with the source's type parameters: the interface's own method type
+ // parameters are different symbols, so M(T) would never equal the source's M(T).
+ IMethodSymbol comparable = interfaceMethod.Arity == 0
+ ? interfaceMethod
+ : interfaceMethod.Construct(sourceMethod.TypeParameters.Cast().ToArray());
+ return comparable.RefKind == sourceMethod.RefKind
+ && SameType(comparable.ReturnType, sourceMethod.ReturnType)
+ && SameParameters(comparable.Parameters, sourceMethod.Parameters);
+ }
+
+ private static bool SamePropertyShape(IPropertySymbol interfaceProperty, IPropertySymbol sourceProperty)
+ {
+ bool sameName = sourceProperty.IsIndexer
+ ? interfaceProperty.IsIndexer
+ : !interfaceProperty.IsIndexer && interfaceProperty.Name == ExplicitMemberName(sourceProperty.Name);
+ return sameName
+ && interfaceProperty.RefKind == sourceProperty.RefKind
+ && SameType(interfaceProperty.Type, sourceProperty.Type)
+ && SameParameters(interfaceProperty.Parameters, sourceProperty.Parameters);
+ }
+
+ private static bool SameParameters(
+ IReadOnlyList interfaceParameters,
+ IReadOnlyList sourceParameters)
+ {
+ if (interfaceParameters.Count != sourceParameters.Count)
+ {
+ return false;
+ }
+
+ for (int index = 0; index < sourceParameters.Count; index++)
+ {
+ if (interfaceParameters[index].RefKind != sourceParameters[index].RefKind
+ || !SameType(interfaceParameters[index].Type, sourceParameters[index].Type))
+ {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ // Why by metadata name and not by symbol: a type the reloaded file declares has two copies, the
+ // compiled one the interface's signature names and the source one the implementation names.
+ private static bool SameType(ITypeSymbol interfaceType, ITypeSymbol sourceType)
+ {
+ return CecilTypeNames.ToCecilFullName(interfaceType) == CecilTypeNames.ToCecilFullName(sourceType);
+ }
+
+ // The member name after the specifier: 'Ns.IFoo.Run' declares 'Run'.
+ private static string ExplicitMemberName(string sourceName)
+ {
+ int lastDot = sourceName.LastIndexOf('.');
+ return lastDot < 0 ? sourceName : sourceName.Substring(lastDot + 1);
+ }
+
+ private static void AddAccessors(ISymbol sourceMember, ISymbol interfaceMember, Dictionary resolved)
+ {
+ switch (sourceMember)
+ {
+ case IPropertySymbol property when interfaceMember is IPropertySymbol interfaceProperty:
+ AddAccessor(property.GetMethod, interfaceProperty.GetMethod, resolved);
+ AddAccessor(property.SetMethod, interfaceProperty.SetMethod, resolved);
+ break;
+ case IEventSymbol eventSymbol when interfaceMember is IEventSymbol interfaceEvent:
+ AddAccessor(eventSymbol.AddMethod, interfaceEvent.AddMethod, resolved);
+ AddAccessor(eventSymbol.RemoveMethod, interfaceEvent.RemoveMethod, resolved);
+ break;
+ }
+ }
+
+ private static void AddAccessor(IMethodSymbol sourceAccessor, IMethodSymbol interfaceAccessor, Dictionary resolved)
+ {
+ if (sourceAccessor != null && interfaceAccessor != null)
+ {
+ resolved[sourceAccessor] = interfaceAccessor;
+ }
+ }
+}
diff --git a/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/IndexerAccessorEmitter.cs b/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/IndexerAccessorEmitter.cs
index 4df4122d1..822815823 100644
--- a/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/IndexerAccessorEmitter.cs
+++ b/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/IndexerAccessorEmitter.cs
@@ -121,7 +121,7 @@ private static void EmitAccessor(
if (target.Indexer.ExplicitInterfaceSpecifier != null)
{
- AddSkip(skipped, sourceProjectRelativePath, accessorSymbol, WorkerReason.Of(HotReloadWorkerReasonCode.MethodTransformExplicitInterfaceImplementation));
+ AddSkip(skipped, sourceProjectRelativePath, typeState.SourceUnit.ExplicitImplementations, accessorSymbol, WorkerReason.Of(HotReloadWorkerReasonCode.MethodTransformExplicitInterfaceImplementation));
return;
}
@@ -202,6 +202,7 @@ private static MethodTransformDecision DecideOrSkip(
{
string sourceProjectRelativePath = typeState.SourceUnit.Input.ProjectRelativePath;
(bool skipAccessor, MethodTransformDecision decision) = PropertyGetterClassifier.TrySkipPropertyAccessorByDecision(
+ typeState.SourceUnit.ExplicitImplementations,
sourceProjectRelativePath,
typeState.TypeDeclaration,
typeState.TypeSymbol,
@@ -241,7 +242,7 @@ private static MethodTransformDecision DecideOrSkip(
return decision;
}
- AddSkip(skipped, sourceProjectRelativePath, accessorSymbol, siblingSkip);
+ AddSkip(skipped, sourceProjectRelativePath, typeState.SourceUnit.ExplicitImplementations, accessorSymbol, siblingSkip);
return null;
}
@@ -334,13 +335,14 @@ private static MethodDeclarationSyntax ApplyBody(
private static void AddSkip(
List skipped,
string sourceProjectRelativePath,
+ ExplicitImplementationMatcher explicitImplementations,
IMethodSymbol accessorSymbol,
WorkerReason reason)
{
skipped.Add(new WorkerSkipped
{
SourceProjectRelativePath = sourceProjectRelativePath,
- Method = WorkerMethodKeys.FormatMethodLabel(accessorSymbol),
+ Method = WorkerMethodKeys.FormatSourceLabel(explicitImplementations, accessorSymbol),
Reason = reason
});
}
diff --git a/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/OrdinaryMethodQueue.cs b/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/OrdinaryMethodQueue.cs
index 4db63ffa0..9d9bfac2a 100644
--- a/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/OrdinaryMethodQueue.cs
+++ b/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/OrdinaryMethodQueue.cs
@@ -51,10 +51,11 @@ internal static void QueueOrdinaryMethod(
// for an explicit implementation can differ from the source spelling (global::).
string methodKey = WorkerMethodKeys.BuildMethodKey(
CecilTypeNames.ToMetadataName(typeState.TypeSymbol),
- ExplicitImplementationMatcher.RowMethodName(compiledType, methodSymbol),
+ typeState.SourceUnit.ExplicitImplementations.RowMethodName(compiledType, methodSymbol),
parameterTypeFullNames,
methodSymbol.Arity);
(bool isAddedMethod, bool replacesCompiledMethod) = ClassifyOrdinaryMethodAddedState(
+ typeState.SourceUnit.ExplicitImplementations,
methodDeclaration,
compiledType,
methodSymbol);
@@ -72,6 +73,7 @@ internal static void QueueOrdinaryMethod(
}
bool bodylessNotCompared = IsBodylessCompiledMethodWithoutBaseline(
+ typeState.SourceUnit.ExplicitImplementations,
isAddedMethod,
hasBaseline,
methodDeclaration,
@@ -151,7 +153,7 @@ internal static void QueueOrdinaryMethod(
skipped.Add(new WorkerSkipped
{
SourceProjectRelativePath = typeState.SourceUnit.Input.ProjectRelativePath,
- Method = WorkerMethodKeys.FormatRowLabel(typeState.CompiledType, methodSymbol),
+ Method = WorkerMethodKeys.FormatRowLabel(typeState.SourceUnit.ExplicitImplementations, typeState.CompiledType, methodSymbol),
Reason = skipReason
});
if (isAddedMethod)
@@ -192,6 +194,7 @@ internal static void QueueOrdinaryMethod(
}
internal static (bool IsAddedMethod, bool ReplacesCompiledMethod) ClassifyOrdinaryMethodAddedState(
+ ExplicitImplementationMatcher explicitImplementations,
MethodDeclarationSyntax methodDeclaration,
INamedTypeSymbol compiledType,
IMethodSymbol methodSymbol)
@@ -201,7 +204,7 @@ internal static (bool IsAddedMethod, bool ReplacesCompiledMethod) ClassifyOrdina
// signature is a different member, so an explicit implementation never replaces one.
if (methodDeclaration.ExplicitInterfaceSpecifier != null)
{
- return (ExplicitImplementationMatcher.FindCompiledImplementation(compiledType, methodSymbol) == null, false);
+ return (explicitImplementations.FindCompiledImplementation(compiledType, methodSymbol) == null, false);
}
CompiledMethodMatch compiledMatch = CompiledMemberMatcher.MatchCompiledOrdinaryMethod(compiledType, methodSymbol);
@@ -223,7 +226,7 @@ private static string ResolveEntryMethodName(
return methodSymbol.Name;
}
- IMethodSymbol compiledMethod = ExplicitImplementationMatcher.FindCompiledImplementation(typeState.CompiledType, methodSymbol);
+ IMethodSymbol compiledMethod = typeState.SourceUnit.ExplicitImplementations.FindCompiledImplementation(typeState.CompiledType, methodSymbol);
if (compiledMethod == null)
{
throw new InvalidOperationException(
@@ -296,7 +299,7 @@ internal static bool TrySkipInterfaceOrdinaryMethod(
skipped.Add(new WorkerSkipped
{
SourceProjectRelativePath = typeState.SourceUnit.Input.ProjectRelativePath,
- Method = WorkerMethodKeys.FormatRowLabel(typeState.CompiledType, methodSymbol),
+ Method = WorkerMethodKeys.FormatRowLabel(typeState.SourceUnit.ExplicitImplementations, typeState.CompiledType, methodSymbol),
Reason = bodylessNotCompared
? WorkerReason.Of(HotReloadWorkerReasonCode.MethodTransformBodylessNotCompared)
: WorkerReason.Of(HotReloadWorkerReasonCode.AddedMethodInterfaceMember)
@@ -328,6 +331,7 @@ internal static bool TrySkipInterfaceOrdinaryMethod(
/// compiled body running until a compile.
///
internal static bool IsBodylessCompiledMethodWithoutBaseline(
+ ExplicitImplementationMatcher explicitImplementations,
bool isAddedMethod,
bool hasBaseline,
MethodDeclarationSyntax methodDeclaration,
@@ -344,7 +348,7 @@ internal static bool IsBodylessCompiledMethodWithoutBaseline(
return false;
}
- IMethodSymbol compiledMethod = FindCompiledCounterpart(methodDeclaration, compiledType, methodSymbol);
+ IMethodSymbol compiledMethod = FindCompiledCounterpart(explicitImplementations, methodDeclaration, compiledType, methodSymbol);
if (compiledMethod == null)
{
throw new InvalidOperationException(
@@ -356,12 +360,13 @@ internal static bool IsBodylessCompiledMethodWithoutBaseline(
/// The compiled method a source method classified as compiled replaces; null when there is none.
internal static IMethodSymbol FindCompiledCounterpart(
+ ExplicitImplementationMatcher explicitImplementations,
MethodDeclarationSyntax methodDeclaration,
INamedTypeSymbol compiledType,
IMethodSymbol methodSymbol)
{
return methodDeclaration.ExplicitInterfaceSpecifier != null
- ? ExplicitImplementationMatcher.FindCompiledImplementation(compiledType, methodSymbol)
+ ? explicitImplementations.FindCompiledImplementation(compiledType, methodSymbol)
: CompiledMemberMatcher.FindCompiledOrdinaryMethod(compiledType, methodSymbol);
}
@@ -477,7 +482,7 @@ internal static void QueueDecidedOrdinaryMethod(
// (Ns.IFoo.Run), which is not a legal shim identifier.
bool isExplicitImplementation = methodDeclaration.ExplicitInterfaceSpecifier != null;
string shimMethodName = shimNames.NextShimMethodName(
- isExplicitImplementation ? ExplicitImplementationMatcher.ImplementedMemberName(methodSymbol) : methodSymbol.Name);
+ isExplicitImplementation ? typeState.SourceUnit.ExplicitImplementations.ImplementedMemberName(methodSymbol) : methodSymbol.Name);
FileLinePositionSpan originalSpan = methodDeclaration.GetLocation().GetLineSpan();
QueuedShimMethod queued = new QueuedShimMethod
diff --git a/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/PropertyGetterClassifier.cs b/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/PropertyGetterClassifier.cs
index 360cc487a..358218b3d 100644
--- a/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/PropertyGetterClassifier.cs
+++ b/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/PropertyGetterClassifier.cs
@@ -65,11 +65,12 @@ internal static bool TryRecordUnchangedPropertyGetter(
// artifact serves stays Skipped as its setter does: explicit accessors are patched only on
// compiled types.
internal static WorkerReason DescribeUnpatchableGetterOrNull(
+ ExplicitImplementationMatcher explicitImplementations,
IPropertySymbol propertySymbol,
INamedTypeSymbol compiledType,
string homeAssemblyName)
{
- bool isExplicit = propertySymbol.ExplicitInterfaceImplementations.Length > 0;
+ bool isExplicit = explicitImplementations.IsExplicitImplementation(propertySymbol);
if (isExplicit && homeAssemblyName != null)
{
return WorkerReason.Of(HotReloadWorkerReasonCode.MethodTransformExplicitInterfaceImplementation);
@@ -81,7 +82,7 @@ internal static WorkerReason DescribeUnpatchableGetterOrNull(
}
IPropertySymbol compiledProperty = isExplicit
- ? ExplicitImplementationMatcher.FindCompiledPropertyImplementation(compiledType, propertySymbol)
+ ? explicitImplementations.FindCompiledPropertyImplementation(compiledType, propertySymbol)
: compiledType.GetMembers(propertySymbol.Name)
.OfType()
.FirstOrDefault(candidate => !candidate.IsIndexer);
@@ -110,6 +111,7 @@ private static bool HasMatchingCompiledGetter(IPropertySymbol compiledProperty,
// What: runs a property accessor body through the same transform decision and name/added-call
// guards as an ordinary method, adding the skip row itself when one applies.
internal static (bool SkipAccessor, MethodTransformDecision Decision) TrySkipPropertyAccessorByDecision(
+ ExplicitImplementationMatcher explicitImplementations,
string sourceProjectRelativePath,
TypeDeclarationSyntax typeDeclaration,
INamedTypeSymbol typeSymbol,
@@ -142,7 +144,7 @@ internal static (bool SkipAccessor, MethodTransformDecision Decision) TrySkipPro
skipped.Add(new WorkerSkipped
{
SourceProjectRelativePath = sourceProjectRelativePath,
- Method = WorkerMethodKeys.FormatRowLabel(compiledType, accessorSymbol),
+ Method = WorkerMethodKeys.FormatRowLabel(explicitImplementations, compiledType, accessorSymbol),
Reason = decision.SkipReason
});
return (true, decision);
@@ -161,7 +163,7 @@ internal static (bool SkipAccessor, MethodTransformDecision Decision) TrySkipPro
skipped.Add(new WorkerSkipped
{
SourceProjectRelativePath = sourceProjectRelativePath,
- Method = WorkerMethodKeys.FormatRowLabel(compiledType, accessorSymbol),
+ Method = WorkerMethodKeys.FormatRowLabel(explicitImplementations, compiledType, accessorSymbol),
Reason = unresolvedNameSkip
});
return (true, MethodTransformDecision.Skip(unresolvedNameSkip));
@@ -182,12 +184,12 @@ internal static (bool SkipAccessor, MethodTransformDecision Decision) TrySkipPro
skipped.Add(new WorkerSkipped
{
SourceProjectRelativePath = sourceProjectRelativePath,
- Method = WorkerMethodKeys.FormatRowLabel(compiledType, accessorSymbol),
+ Method = WorkerMethodKeys.FormatRowLabel(explicitImplementations, compiledType, accessorSymbol),
Reason = addedCallSiteSkip,
CalledAddedMethodKey = calledAddedMethodKey,
MethodKey = calledAddedMethodKey == null
? null
- : WorkerMethodKeys.BuildRowMethodKey(compiledType, accessorSymbol)
+ : WorkerMethodKeys.BuildRowMethodKey(explicitImplementations, compiledType, accessorSymbol)
});
return (true, decision);
}
diff --git a/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/PropertyGetterEmitter.cs b/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/PropertyGetterEmitter.cs
index 1bcc70f30..041d16401 100644
--- a/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/PropertyGetterEmitter.cs
+++ b/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/PropertyGetterEmitter.cs
@@ -76,6 +76,7 @@ internal static void EmitPropertyGettersForType(
}
typeState.CurrentShimType = AppendPropertyGetterEntry(
+ typeState.SourceUnit.ExplicitImplementations,
propertyDeclaration,
typeState.TypeDeclaration,
typeState.TypeSymbol,
@@ -111,6 +112,7 @@ internal static void EmitPropertyGettersForType(
// What: emit a get_ entry / unchanged row / skip for one property with a getter body.
internal static ShimTypeBuilder AppendPropertyGetterEntry(
+ ExplicitImplementationMatcher explicitImplementations,
PropertyDeclarationSyntax propertyDeclaration,
TypeDeclarationSyntax typeDeclaration,
INamedTypeSymbol typeSymbol,
@@ -164,7 +166,7 @@ internal static ShimTypeBuilder AppendPropertyGetterEntry(
string[] parameterTypeFullNames = Array.Empty();
// Why the row name: the Editor finds, excludes and reverts the getter by its compiled name,
// which for an explicit property differs from the source name when the specifier is respelled.
- string getterRowName = ExplicitImplementationMatcher.RowMethodName(compiledType, getterSymbol);
+ string getterRowName = explicitImplementations.RowMethodName(compiledType, getterSymbol);
string methodKey = WorkerMethodKeys.BuildMethodKey(
CecilTypeNames.ToMetadataName(typeSymbol),
getterRowName,
@@ -192,6 +194,7 @@ internal static ShimTypeBuilder AppendPropertyGetterEntry(
}
WorkerReason unpatchableGetter = PropertyGetterClassifier.DescribeUnpatchableGetterOrNull(
+ explicitImplementations,
propertySymbol,
compiledType,
homeAssemblyName);
@@ -200,7 +203,7 @@ internal static ShimTypeBuilder AppendPropertyGetterEntry(
skipped.Add(new WorkerSkipped
{
SourceProjectRelativePath = sourceProjectRelativePath,
- Method = WorkerMethodKeys.FormatRowLabel(compiledType, getterSymbol),
+ Method = WorkerMethodKeys.FormatRowLabel(explicitImplementations, compiledType, getterSymbol),
Reason = unpatchableGetter
});
return currentShimType;
@@ -212,6 +215,7 @@ internal static ShimTypeBuilder AppendPropertyGetterEntry(
?? (SyntaxNode)getAccessor.Body
?? getAccessor.ExpressionBody;
(bool skipGetter, MethodTransformDecision decision) = PropertyGetterClassifier.TrySkipPropertyAccessorByDecision(
+ explicitImplementations,
sourceProjectRelativePath,
typeDeclaration,
typeSymbol,
@@ -248,7 +252,7 @@ internal static ShimTypeBuilder AppendPropertyGetterEntry(
skipped.Add(new WorkerSkipped
{
SourceProjectRelativePath = sourceProjectRelativePath,
- Method = WorkerMethodKeys.FormatRowLabel(compiledType, getterSymbol),
+ Method = WorkerMethodKeys.FormatRowLabel(explicitImplementations, compiledType, getterSymbol),
Reason = siblingSkip
});
return currentShimType;
@@ -256,6 +260,7 @@ internal static ShimTypeBuilder AppendPropertyGetterEntry(
}
return EmitPropertyGetterShim(
+ explicitImplementations,
propertyDeclaration,
typeDeclaration,
typeSymbol,
@@ -281,6 +286,7 @@ internal static ShimTypeBuilder AppendPropertyGetterEntry(
}
internal static ShimTypeBuilder EmitPropertyGetterShim(
+ ExplicitImplementationMatcher explicitImplementations,
PropertyDeclarationSyntax propertyDeclaration,
TypeDeclarationSyntax typeDeclaration,
INamedTypeSymbol typeSymbol,
@@ -315,7 +321,7 @@ internal static ShimTypeBuilder EmitPropertyGetterShim(
assemblyGlobalUsings,
targetAssembly);
- string shimMethodName = shimNames.NextShimMethodName(ShimBaseName(getterSymbol));
+ string shimMethodName = shimNames.NextShimMethodName(ShimBaseName(explicitImplementations, getterSymbol));
// Why narrow to the get accessor beside a bodied set or init: the setter gets an entry of
// its own, and a Skipped init body must not resolve to the getter's patch, so the getter
@@ -382,10 +388,10 @@ internal static ShimTypeBuilder EmitPropertyGetterShim(
// What: the name a shim of the accessor is built from. An explicit accessor's own name holds the
// interface name with dots, which is not a legal identifier, so its shim takes the interface
// accessor's name.
- internal static string ShimBaseName(IMethodSymbol accessorSymbol)
+ internal static string ShimBaseName(ExplicitImplementationMatcher explicitImplementations, IMethodSymbol accessorSymbol)
{
- return accessorSymbol.ExplicitInterfaceImplementations.Length > 0
- ? ExplicitImplementationMatcher.ImplementedMemberName(accessorSymbol)
+ return explicitImplementations.IsExplicitImplementation(accessorSymbol)
+ ? explicitImplementations.ImplementedMemberName(accessorSymbol)
: accessorSymbol.Name;
}
diff --git a/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/PropertySetterClassifier.cs b/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/PropertySetterClassifier.cs
index 4df4c9b27..c15c1a8e3 100644
--- a/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/PropertySetterClassifier.cs
+++ b/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/PropertySetterClassifier.cs
@@ -14,6 +14,7 @@ internal static class PropertySetterClassifier
// not have (or takes another type) fails the Editor's signature lookup and turns the run into
// Failed, while Skipped keeps pointing the reader at 'uloop compile'.
internal static bool IsPatchableCompiledSetter(
+ ExplicitImplementationMatcher explicitImplementations,
PropertyDeclarationSyntax propertyDeclaration,
IPropertySymbol propertySymbol,
INamedTypeSymbol compiledType,
@@ -31,7 +32,7 @@ internal static bool IsPatchableCompiledSetter(
// Why an explicit interface init stays with the accessor row: init patching covers ordinary
// properties only; an explicit interface init accessor is not part of that support yet.
- if (propertySymbol.SetMethod.IsInitOnly && propertySymbol.ExplicitInterfaceImplementations.Length > 0)
+ if (propertySymbol.SetMethod.IsInitOnly && explicitImplementations.IsExplicitImplementation(propertySymbol))
{
return false;
}
@@ -45,8 +46,8 @@ internal static bool IsPatchableCompiledSetter(
// Why the matcher for an explicit property: its name follows the specifier's spelling, so a
// respelled specifier would not find the compiled property by name.
- IPropertySymbol compiledProperty = propertySymbol.ExplicitInterfaceImplementations.Length > 0
- ? ExplicitImplementationMatcher.FindCompiledPropertyImplementation(compiledType, propertySymbol)
+ IPropertySymbol compiledProperty = explicitImplementations.IsExplicitImplementation(propertySymbol)
+ ? explicitImplementations.FindCompiledPropertyImplementation(compiledType, propertySymbol)
: compiledType.GetMembers(propertySymbol.Name)
.OfType()
.FirstOrDefault(candidate => !candidate.IsIndexer);
diff --git a/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/PropertySetterEmitter.cs b/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/PropertySetterEmitter.cs
index c244ec328..511269b0a 100644
--- a/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/PropertySetterEmitter.cs
+++ b/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/PropertySetterEmitter.cs
@@ -31,6 +31,7 @@ internal static void EmitPropertySettersForType(
// Added properties are AddedPropertyEmitter's; the rest the skip collector reported.
if (addedPropertyCatalog.FindBySymbolOrNull(propertySymbol) != null
|| !PropertySetterClassifier.IsPatchableCompiledSetter(
+ typeState.SourceUnit.ExplicitImplementations,
property,
propertySymbol,
typeState.CompiledType,
@@ -75,7 +76,7 @@ private static void EmitPropertySetter(
string typeMetadataName = CecilTypeNames.ToMetadataName(typeState.TypeSymbol);
string[] parameterTypeFullNames = new[] { CecilTypeNames.ToCecilFullName(propertySymbol.Type) };
// Why the row name: as for the getter, the Editor knows the setter by its compiled name.
- string setterRowName = ExplicitImplementationMatcher.RowMethodName(typeState.CompiledType, setterSymbol);
+ string setterRowName = typeState.SourceUnit.ExplicitImplementations.RowMethodName(typeState.CompiledType, setterSymbol);
string methodKey = WorkerMethodKeys.BuildMethodKey(
typeMetadataName,
setterRowName,
@@ -110,7 +111,7 @@ private static void EmitPropertySetter(
if (setterSymbol.IsInitOnly
&& InitAccessorWriteRules.WritesInitOnlyMember(setterBodyNode, typeState.SourceUnit.SemanticModel))
{
- AddSkip(skipped, sourceProjectRelativePath, typeState.CompiledType, setterSymbol, WorkerReason.Of(HotReloadWorkerReasonCode.MethodTransformInitAccessorWritesInitOnlyMember));
+ AddSkip(skipped, sourceProjectRelativePath, typeState.SourceUnit.ExplicitImplementations, typeState.CompiledType, setterSymbol, WorkerReason.Of(HotReloadWorkerReasonCode.MethodTransformInitAccessorWritesInitOnlyMember));
return;
}
@@ -138,7 +139,7 @@ private static void EmitPropertySetter(
assemblyGlobalUsings,
typeState.TargetAssembly);
ShimTypeBuilder shimType = typeState.CurrentShimType;
- string shimMethodName = shimNames.NextShimMethodName(PropertyGetterEmitter.ShimBaseName(setterSymbol));
+ string shimMethodName = shimNames.NextShimMethodName(PropertyGetterEmitter.ShimBaseName(typeState.SourceUnit.ExplicitImplementations, setterSymbol));
MethodDeclarationSyntax rewrittenMethod = RewritePropertySetterBody(
property,
setterBodyNode,
@@ -191,6 +192,7 @@ private static MethodTransformDecision DecideOrSkip(
{
string sourceProjectRelativePath = typeState.SourceUnit.Input.ProjectRelativePath;
(bool skipSetter, MethodTransformDecision decision) = PropertyGetterClassifier.TrySkipPropertyAccessorByDecision(
+ typeState.SourceUnit.ExplicitImplementations,
sourceProjectRelativePath,
typeState.TypeDeclaration,
typeState.TypeSymbol,
@@ -229,7 +231,7 @@ private static MethodTransformDecision DecideOrSkip(
return decision;
}
- AddSkip(skipped, sourceProjectRelativePath, typeState.CompiledType, setterSymbol, siblingSkip);
+ AddSkip(skipped, sourceProjectRelativePath, typeState.SourceUnit.ExplicitImplementations, typeState.CompiledType, setterSymbol, siblingSkip);
return null;
}
@@ -319,6 +321,7 @@ private static MethodDeclarationSyntax RewritePropertySetterBody(
private static void AddSkip(
List skipped,
string sourceProjectRelativePath,
+ ExplicitImplementationMatcher explicitImplementations,
INamedTypeSymbol compiledType,
IMethodSymbol setterSymbol,
WorkerReason reason)
@@ -326,7 +329,7 @@ private static void AddSkip(
skipped.Add(new WorkerSkipped
{
SourceProjectRelativePath = sourceProjectRelativePath,
- Method = WorkerMethodKeys.FormatRowLabel(compiledType, setterSymbol),
+ Method = WorkerMethodKeys.FormatRowLabel(explicitImplementations, compiledType, setterSymbol),
Reason = reason
});
}
diff --git a/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/SkippedWriterUseSite.cs b/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/SkippedWriterUseSite.cs
index 865c635b5..ac91520ae 100644
--- a/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/SkippedWriterUseSite.cs
+++ b/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/SkippedWriterUseSite.cs
@@ -54,6 +54,7 @@ internal sealed class SkippedWriterUseSiteClassifier
private readonly HashSet _queuedMethods;
private readonly AddedPropertyCatalog _addedPropertyCatalog;
private readonly IReadOnlyDictionary _compiledTypeBySourceType;
+ private readonly ExplicitImplementationMatcher _explicitImplementations;
// compiledTypeBySourceType lets a method be labelled the way its skip row is: an explicit
// implementation by its compiled name, which can differ from the source spelling.
@@ -61,8 +62,11 @@ public SkippedWriterUseSiteClassifier(
HashSet skippedLabels,
HashSet queuedMethods,
AddedPropertyCatalog addedPropertyCatalog,
- IReadOnlyDictionary compiledTypeBySourceType)
+ IReadOnlyDictionary compiledTypeBySourceType,
+ ExplicitImplementationMatcher explicitImplementations)
{
+ _explicitImplementations = explicitImplementations
+ ?? throw new ArgumentNullException(nameof(explicitImplementations));
_compiledTypeBySourceType = compiledTypeBySourceType
?? throw new ArgumentNullException(nameof(compiledTypeBySourceType));
_skippedLabels = skippedLabels ?? throw new ArgumentNullException(nameof(skippedLabels));
@@ -90,7 +94,7 @@ private SkippedWriterUseSite ClassifyMethod(SemanticModel semanticModel, MethodD
{
IMethodSymbol methodSymbol = semanticModel.GetDeclaredSymbol(method);
_compiledTypeBySourceType.TryGetValue(methodSymbol.ContainingType, out INamedTypeSymbol compiledType);
- string label = WorkerMethodKeys.FormatRowLabel(compiledType, methodSymbol);
+ string label = WorkerMethodKeys.FormatRowLabel(_explicitImplementations, compiledType, methodSymbol);
if (_skippedLabels.Contains(label))
{
return new SkippedWriterUseSite(label, SkippedWriterUseSiteKind.Skipped);
diff --git a/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/TypeEmitPlanner.cs b/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/TypeEmitPlanner.cs
index 281ff101d..3c19bba04 100644
--- a/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/TypeEmitPlanner.cs
+++ b/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/TypeEmitPlanner.cs
@@ -99,6 +99,7 @@ internal static List QueueAllTypeEmitStates(
Dictionary plainCurrentIndexerMap) =
baseline.GetAccessorBaselineMaps();
UnsupportedMemberSkipCollector.AppendExplicitAccessorSkips(
+ sourceUnit.ExplicitImplementations,
sourceUnit.Input.ProjectRelativePath,
typeDeclaration,
typeMetadataNameFromSyntax,
@@ -123,6 +124,7 @@ internal static List QueueAllTypeEmitStates(
baseline.GetUnsupportedMemberBaselineMaps();
UnsupportedMemberSkipCollector.AppendUnsupportedMemberKindSkips(
+ sourceUnit.ExplicitImplementations,
sourceUnit.Input.ProjectRelativePath,
typeDeclaration,
typeMetadataNameFromSyntax,
diff --git a/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/UnboundPartialSignatureSkip.cs b/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/UnboundPartialSignatureSkip.cs
index 14a9f7a8a..156d87aea 100644
--- a/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/UnboundPartialSignatureSkip.cs
+++ b/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/UnboundPartialSignatureSkip.cs
@@ -42,7 +42,7 @@ internal static bool TrySkip(
skipped.Add(new WorkerSkipped
{
SourceProjectRelativePath = typeState.SourceUnit.Input.ProjectRelativePath,
- Method = WorkerMethodKeys.FormatRowLabel(typeState.CompiledType, methodSymbol),
+ Method = WorkerMethodKeys.FormatRowLabel(typeState.SourceUnit.ExplicitImplementations, typeState.CompiledType, methodSymbol),
Reason = untrustedPart
});
RecordGenuinelyAddedMethod(standing, syntaxMethodKey, methodKey, addedMethodCatalog);
diff --git a/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/UnchangedOrdinaryMethodRecorder.cs b/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/UnchangedOrdinaryMethodRecorder.cs
index 0871d015e..704ae3c57 100644
--- a/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/UnchangedOrdinaryMethodRecorder.cs
+++ b/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/UnchangedOrdinaryMethodRecorder.cs
@@ -106,7 +106,7 @@ private static WorkerUnchangedMethod BuildUnchangedMethod(
{
SourceProjectRelativePath = typeState.SourceUnit.Input.ProjectRelativePath,
TypeMetadataName = CecilTypeNames.ToMetadataName(typeState.TypeSymbol),
- MethodName = ExplicitImplementationMatcher.RowMethodName(typeState.CompiledType, methodSymbol),
+ MethodName = typeState.SourceUnit.ExplicitImplementations.RowMethodName(typeState.CompiledType, methodSymbol),
ParameterTypeFullNames = parameterTypeFullNames,
GenericArity = methodSymbol.Arity,
HomeAssemblyName = typeState.HomeAssemblyName
diff --git a/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/UnsupportedMemberSkipCollector.cs b/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/UnsupportedMemberSkipCollector.cs
index 6f5ba2850..d96547b5e 100644
--- a/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/UnsupportedMemberSkipCollector.cs
+++ b/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/UnsupportedMemberSkipCollector.cs
@@ -26,6 +26,7 @@ internal static class UnsupportedMemberSkipCollector
// accessor at a time, so a set or init body equal to the snapshot's is omitted even when
// another part of the property changed.
internal static void AppendExplicitAccessorSkips(
+ ExplicitImplementationMatcher explicitImplementations,
string sourceProjectRelativePath,
TypeDeclarationSyntax typeDeclaration,
string typeMetadataNameFromSyntax,
@@ -66,6 +67,7 @@ internal static void AppendExplicitAccessorSkips(
}
AppendExplicitAccessorSkipsForProperty(
+ explicitImplementations,
propertyDeclaration,
propertySymbol,
skipped,
@@ -82,6 +84,7 @@ internal static void AppendExplicitAccessorSkips(
if (member is IndexerDeclarationSyntax indexerDeclaration)
{
AppendIndexerAccessorSkips(
+ explicitImplementations,
indexerDeclaration,
semanticModel.GetDeclaredSymbol(indexerDeclaration),
skipped,
@@ -100,6 +103,7 @@ internal static void AppendExplicitAccessorSkips(
// tree's declarations of this property, or null when either side has none; an accessor is
// compared against the snapshot only when both are present.
internal static void AppendExplicitAccessorSkipsForProperty(
+ ExplicitImplementationMatcher explicitImplementations,
BasePropertyDeclarationSyntax propertyDeclaration,
IPropertySymbol propertySymbol,
List skipped,
@@ -124,6 +128,7 @@ internal static void AppendExplicitAccessorSkipsForProperty(
}
bool emittedSkip = AppendChangedSetOrInitAccessorSkips(
+ explicitImplementations,
propertyDeclaration,
propertySymbol,
skipped,
@@ -138,6 +143,7 @@ internal static void AppendExplicitAccessorSkipsForProperty(
// reads the whole property as an edit outside method bodies.
bool setterReportedByEmitter = namedProperty != null
&& PropertySetterClassifier.IsPatchableCompiledSetter(
+ explicitImplementations,
namedProperty,
propertySymbol,
compiledType,
@@ -160,6 +166,7 @@ internal static void AppendExplicitAccessorSkipsForProperty(
// Reports each set or init accessor that has a body, differs from the snapshot, and is not
// reported by the setter emitter, and returns whether it reported any.
private static bool AppendChangedSetOrInitAccessorSkips(
+ ExplicitImplementationMatcher explicitImplementations,
BasePropertyDeclarationSyntax propertyDeclaration,
IPropertySymbol propertySymbol,
List skipped,
@@ -180,6 +187,7 @@ private static bool AppendChangedSetOrInitAccessorSkips(
if ((accessor.IsKind(SyntaxKind.SetAccessorDeclaration) || accessor.IsKind(SyntaxKind.InitAccessorDeclaration))
&& propertyDeclaration is PropertyDeclarationSyntax namedProperty
&& PropertySetterClassifier.IsPatchableCompiledSetter(
+ explicitImplementations,
namedProperty,
propertySymbol,
compiledType,
@@ -211,7 +219,7 @@ private static bool AppendChangedSetOrInitAccessorSkips(
skipped.Add(new WorkerSkipped
{
- Method = WorkerMethodKeys.FormatMethodLabel(accessorMethod),
+ Method = WorkerMethodKeys.FormatSourceLabel(explicitImplementations, accessorMethod),
Reason = WorkerReason.Of(HotReloadWorkerReasonCode.UnsupportedMemberExplicitAccessor)
});
emittedSkip = true;
@@ -258,6 +266,7 @@ private static AccessorDeclarationSyntax FindPropertyAccessor(
// and that the indexer emitter does not report itself (no matching compiled accessor, an init
// accessor, or a type a retained artifact serves).
private static void AppendIndexerAccessorSkips(
+ ExplicitImplementationMatcher explicitImplementations,
IndexerDeclarationSyntax indexerDeclaration,
IPropertySymbol indexerSymbol,
List skipped,
@@ -298,7 +307,7 @@ private static void AppendIndexerAccessorSkips(
skipped.Add(new WorkerSkipped
{
- Method = WorkerMethodKeys.FormatMethodLabel(accessorMethod),
+ Method = WorkerMethodKeys.FormatSourceLabel(explicitImplementations, accessorMethod),
Reason = WorkerReason.Of(HotReloadWorkerReasonCode.UnsupportedMemberExplicitAccessor)
});
}
@@ -326,6 +335,7 @@ internal static IMethodSymbol ResolveAccessorMethodSymbol(
// explicit event accessors as Skipped. Unchanged members matching a verified snapshot
// are omitted. Field-like events are not listed.
internal static void AppendUnsupportedMemberKindSkips(
+ ExplicitImplementationMatcher explicitImplementations,
string sourceProjectRelativePath,
TypeDeclarationSyntax typeDeclaration,
string typeMetadataNameFromSyntax,
@@ -373,6 +383,7 @@ internal static void AppendUnsupportedMemberKindSkips(
snapshotOperatorMap,
plainCurrentOperatorMap);
EventAccessorSkipCollector.AppendEventAccessorSkips(
+ explicitImplementations,
typeDeclaration,
typeMetadataNameFromSyntax,
semanticModel,
@@ -424,7 +435,7 @@ internal static void AppendConstructorSkips(
}
IMethodSymbol methodSymbol = semanticModel.GetDeclaredSymbol(constructorDeclaration);
- AppendUnsupportedKindSkip(skipped, methodSymbol);
+ AppendUnsupportedKindSkip(skipped, methodSymbol, WorkerMethodKeys.FormatMethodLabel(methodSymbol));
}
}
@@ -456,7 +467,7 @@ internal static void AppendFinalizerSkips(
}
IMethodSymbol methodSymbol = semanticModel.GetDeclaredSymbol(destructorDeclaration);
- AppendUnsupportedKindSkip(skipped, methodSymbol);
+ AppendUnsupportedKindSkip(skipped, methodSymbol, WorkerMethodKeys.FormatMethodLabel(methodSymbol));
}
}
@@ -486,11 +497,11 @@ internal static void AppendOperatorSkips(
}
IMethodSymbol methodSymbol = semanticModel.GetDeclaredSymbol(member) as IMethodSymbol;
- AppendUnsupportedKindSkip(skipped, methodSymbol);
+ AppendUnsupportedKindSkip(skipped, methodSymbol, WorkerMethodKeys.FormatMethodLabel(methodSymbol));
}
}
- internal static void AppendUnsupportedKindSkip(List skipped, IMethodSymbol methodSymbol)
+ internal static void AppendUnsupportedKindSkip(List skipped, IMethodSymbol methodSymbol, string label)
{
if (methodSymbol == null)
{
@@ -499,7 +510,7 @@ internal static void AppendUnsupportedKindSkip(List skipped, IMet
skipped.Add(new WorkerSkipped
{
- Method = WorkerMethodKeys.FormatMethodLabel(methodSymbol),
+ Method = label,
Reason = WorkerReason.Of(HotReloadWorkerReasonCode.UnsupportedMemberUnsupportedKind)
});
}
diff --git a/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/WorkerGroupPipeline.cs b/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/WorkerGroupPipeline.cs
index aa7cca466..75b04f44a 100644
--- a/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/WorkerGroupPipeline.cs
+++ b/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/WorkerGroupPipeline.cs
@@ -134,11 +134,17 @@ internal static WorkerOutput Transform(WorkerInput input, WorkerRequestTimings t
projectRelativePathsByBindingTree[transformUnit.BindingSyntaxTree] = transformUnit.Input.ProjectRelativePath;
}
+ // Why every tree of the compilation: a partial type's explicit implementation can sit in a
+ // part another file declares, and the type's members are read across all of its parts.
+ ExplicitImplementationMatcher explicitImplementations = new ExplicitImplementationMatcher(
+ ExplicitInterfaceMemberResolver.Resolve(compilation.SyntaxTrees.Select(tree =>
+ compilation.GetSemanticModel(tree, ignoreAccessibility: true))));
foreach (WorkerSourceUnit unit in transformUnits)
{
unit.SemanticModel = compilation.GetSemanticModel(unit.BindingSyntaxTree, ignoreAccessibility: true);
unit.RunProjectRelativePathsByBindingTree = projectRelativePathsByBindingTree;
unit.PartialTypeParts = partialTypeParts;
+ unit.ExplicitImplementations = explicitImplementations;
}
WorkerTypeHome home = new WorkerTypeHome(input.TargetAssemblyName, targetAssemblyWithAllMembers);
@@ -336,6 +342,7 @@ private static void QueueUnit(
// touched body, so the generic outside-body warning would bury the name.
unit.KindChangeSyntaxKeys =
CompiledMemberKindChangeWarnings.AppendCompiledPropertyOrEventKindChangeWarnings(
+ unit.ExplicitImplementations,
unit.BindingRoot,
unit.SemanticModel,
home,
diff --git a/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/WorkerMethodKeys.cs b/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/WorkerMethodKeys.cs
index 48bdb2c35..94a701a5e 100644
--- a/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/WorkerMethodKeys.cs
+++ b/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/WorkerMethodKeys.cs
@@ -45,9 +45,9 @@ internal static string BuildMethodKeyFromSymbol(IMethodSymbol methodSymbol)
/// The key of a source method as the Editor builds it from the compiled method: an explicit
/// implementation the compiled type holds is keyed by its compiled metadata name.
///
- internal static string BuildRowMethodKey(INamedTypeSymbol compiledType, IMethodSymbol methodSymbol)
+ internal static string BuildRowMethodKey(ExplicitImplementationMatcher explicitImplementations, INamedTypeSymbol compiledType, IMethodSymbol methodSymbol)
{
- return BuildMethodKeyNamed(methodSymbol, ExplicitImplementationMatcher.RowMethodName(compiledType, methodSymbol));
+ return BuildMethodKeyNamed(methodSymbol, explicitImplementations.RowMethodName(compiledType, methodSymbol));
}
private static string BuildMethodKeyNamed(IMethodSymbol methodSymbol, string methodName)
@@ -66,9 +66,9 @@ private static string BuildMethodKeyNamed(IMethodSymbol methodSymbol, string met
/// The label of a source method as the Editor builds it from the compiled method: an explicit
/// implementation the compiled type holds is named by its compiled metadata name.
///
- internal static string FormatRowLabel(INamedTypeSymbol compiledType, IMethodSymbol methodSymbol)
+ internal static string FormatRowLabel(ExplicitImplementationMatcher explicitImplementations, INamedTypeSymbol compiledType, IMethodSymbol methodSymbol)
{
- return FormatMethodLabelNamed(methodSymbol, ExplicitImplementationMatcher.RowMethodName(compiledType, methodSymbol));
+ return FormatMethodLabelNamed(methodSymbol, explicitImplementations.RowMethodName(compiledType, methodSymbol));
}
/// The label of under .
@@ -89,6 +89,15 @@ internal static string FormatMethodLabel(IMethodSymbol methodSymbol)
return FormatMethodLabelNamed(methodSymbol, methodSymbol.Name);
}
+ ///
+ /// The label of a source method named as the compiler names it when its interface is
+ /// accessible, for a row that has no compiled counterpart to take the name from.
+ ///
+ internal static string FormatSourceLabel(ExplicitImplementationMatcher explicitImplementations, IMethodSymbol methodSymbol)
+ {
+ return FormatMethodLabelNamed(methodSymbol, explicitImplementations.SourceMethodName(methodSymbol));
+ }
+
// Keep in sync with HotReloadMethodKeys.FormatMethodLabelParts (Unity package side).
// Why one label shape: Methods[].Method must use one label for every Kind.
// Roslyn FullyQualifiedFormat (global::, type arguments) was the Skipped-only outlier.
diff --git a/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/WorkerSourceUnit.cs b/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/WorkerSourceUnit.cs
index be911647e..430eb6a3c 100644
--- a/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/WorkerSourceUnit.cs
+++ b/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/WorkerSourceUnit.cs
@@ -106,6 +106,12 @@ internal sealed class WorkerSourceUnit
// bind them against a type that is missing those parts.
public PartialTypeParts PartialTypeParts { get; set; } = PartialTypeParts.Unverified;
+ // What every explicit interface implementation of the run implements. Why the declared
+ // members alone until a pipeline resolves the rest: a pipeline that never does keeps reading
+ // an implementation of an inaccessible interface as implementing nothing, as before.
+ public ExplicitImplementationMatcher ExplicitImplementations { get; set; } =
+ new ExplicitImplementationMatcher(new Dictionary());
+
public CompiledMemberKindChangeWarnings.SyntaxKeys KindChangeSyntaxKeys { get; set; }
public List TypeEmitStates { get; set; } = new List();