Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow WatchHotReloadService to specify runtime apply-update capabilities #54012

Merged
merged 1 commit into from
Jun 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions eng/targets/Settings.props
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<Nullable>enable</Nullable>
</PropertyGroup>

<!--
<!--
Disable Source Link and Xliff in WPF temp projects to avoid generating non-deterministic file names to obj dir.
The project name is non-deterministic and is included in the Source Link json file name and xlf directory names.
It's also not necessary to generate these assets.
Expand Down Expand Up @@ -72,6 +72,7 @@
<VisualStudioKey>002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293</VisualStudioKey>
<MonoDevelopKey>002400000c800000940000000602000000240000525341310004000001000100e1290d741888d13312c0cd1f72bb843236573c80158a286f11bb98de5ee8acc3142c9c97b472684e521ae45125d7414558f2e70ac56504f3e8fe80830da2cdb1cda8504e8d196150d05a214609234694ec0ebf4b37fc7537e09d877c3e65000f7467fa3adb6e62c82b10ada1af4a83651556c7d949959817fed97480839dd39b</MonoDevelopKey>
<RazorKey>0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb</RazorKey>
<AspNetCoreKey>$(RazorKey)</AspNetCoreKey>
<IntelliCodeCSharpKey>0024000004800000940000000602000000240000525341310004000001000100b5fc90e7027f67871e773a8fde8938c81dd402ba65b9201d60593e96c492651e889cc13f1415ebb53fac1131ae0bd333c5ee6021672d9718ea31a8aebd0da0072f25d87dba6fc90ffd598ed4da35e44c398c454307e8e33b8426143daec9f596836f97c8f74750e5975c64e2189f45def46b2a2b1247adc3652bf5c308055da9</IntelliCodeCSharpKey>
<IntelliCodeKey>002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293</IntelliCodeKey>
<FSharpKey>$(VisualStudioKey)</FSharpKey>
Expand All @@ -82,19 +83,19 @@
<OmniSharpKey>0024000004800000940000000602000000240000525341310004000001000100917302efc152e6464679d4625bd9989e12d4662a9eaadf284d04992881c0e7b16e756e63ef200a02c4054d4d31e21b9aa0b0b873bcefca8cd42ec583a3db509665c9b22318ceceec581663fc07e2422bb2135539ba8a517c209ac175fff07c5af10cef636e04cae91d28f51fcde5d14c1a9bfed06e096cf977fd0d60002a3ea6</OmniSharpKey>
</PropertyGroup>

<!--
Enable hard links for the build. This is not done by default due to fears about
<!--
Enable hard links for the build. This is not done by default due to fears about
inadvertently corrupting the NuGet cache (hard links in the output directory will
point into the cache). The build itself will not due this but a developer directly
modifying this directory could cause it to happen.

Developers who do not modify the output directory directly can enable this safely
Developers who do not modify the output directory directly can enable this safely

Related discussion in https://github.com/dotnet/roslyn/issues/30005
-->
<PropertyGroup Condition="'$(ROSLYNUSEHARDLINKS)' != ''">
<CreateHardLinksForCopyFilesToOutputDirectoryIfPossible>true</CreateHardLinksForCopyFilesToOutputDirectoryIfPossible>
<CreateHardLinksForCopyAdditionalFilesIfPossible>true</CreateHardLinksForCopyAdditionalFilesIfPossible>
<CreateHardLinksForCopyAdditionalFilesIfPossible>true</CreateHardLinksForCopyAdditionalFilesIfPossible>
<CreateHardLinksForCopyLocalIfPossible>true</CreateHardLinksForCopyLocalIfPossible>
<CreateHardLinksForPublishFilesIfPossible>true</CreateHardLinksForPublishFilesIfPossible>
</PropertyGroup>
Expand All @@ -110,7 +111,7 @@
<DevEnvDir>$([System.IO.Path]::GetFullPath('$(DevEnvDir)'))</DevEnvDir>
</PropertyGroup>

<!--
<!--
Bootstrapping compilers
-->
<Import Project="Bootstrap.props" Condition="'$(BootstrapBuildPath)' != ''" />
Expand All @@ -130,14 +131,14 @@
<EnableNetAnalyzers>false</EnableNetAnalyzers>
</PropertyGroup>

<!--
<!--
Code indexing targets to help generating LSIF from indexing builds.
-->
<ItemGroup Condition="'$(DotNetBuildFromSource)' != 'true'">
<PackageReference Include="RichCodeNav.EnvVarDump" Version="$(RichCodeNavEnvVarDumpVersion)" PrivateAssets="all" />
</ItemGroup>

<!--
<!--
Don't inject PerformanceSensitiveAttribute source by default to avoid duplicate definitions caused by IVT.
This needs to be set to true in projects at the root of IVT trees, in order for PerformanceSensitiveAnalyzers to work.
-->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -986,25 +986,25 @@ public async Task BreakMode_ModuleDisallowsEditAndContinue()
var moduleId = Guid.NewGuid();

var source1 = @"
class C1
{
void M()
class C1
{
void M()
{
System.Console.WriteLine(1);
System.Console.WriteLine(2);
System.Console.WriteLine(3);
}
System.Console.WriteLine(1);
System.Console.WriteLine(2);
System.Console.WriteLine(3);
}
}";
var source2 = @"
class C1
{
class C1
{

void M()
void M()
{
System.Console.WriteLine(9);
System.Console.WriteLine();
System.Console.WriteLine(30);
}
System.Console.WriteLine(9);
System.Console.WriteLine();
System.Console.WriteLine(30);
}
}";
using var _ = CreateWorkspace(out var solution, out var service);
(solution, var document) = AddDefaultTestProject(solution, source1);
Expand Down Expand Up @@ -1158,7 +1158,7 @@ public async Task BreakMode_RudeEdits_SourceGenerators()
var sourceV1 = @"
/* GENERATE: class G { int X1 => 1; } */

class C { int Y => 1; }
class C { int Y => 1; }
";
var sourceV2 = @"
/* GENERATE: class G { int X2 => 1; } */
Expand Down Expand Up @@ -2236,7 +2236,7 @@ public async Task BreakMode_ValidSignificantChange_SourceGenerators_DocumentUpda
var sourceV1 = @"
/* GENERATE: class G { int X => 1; } */

class C { int Y => 1; }
class C { int Y => 1; }
";
var sourceV2 = @"
/* GENERATE: class G { int X => 2; } */
Expand Down Expand Up @@ -2282,7 +2282,7 @@ public async Task BreakMode_ValidSignificantChange_SourceGenerators_DocumentUpda
/* GENERATE:
class G
{
int M()
int M()
{
return 1;
}
Expand All @@ -2294,7 +2294,7 @@ int M()
class G
{

int M()
int M()
{
return 1;
}
Expand Down Expand Up @@ -2340,7 +2340,7 @@ int M()
public async Task BreakMode_ValidSignificantChange_SourceGenerators_DocumentUpdate_GeneratedDocumentInsert()
{
var sourceV1 = @"
partial class C { int X = 1; }
partial class C { int X = 1; }
";
var sourceV2 = @"
/* GENERATE: partial class C { int Y = 2; } */
Expand Down Expand Up @@ -2383,7 +2383,7 @@ partial class C { int X = 1; }
public async Task BreakMode_ValidSignificantChange_SourceGenerators_AdditionalDocumentUpdate()
{
var source = @"
class C { int Y => 1; }
class C { int Y => 1; }
";

var additionalSourceV1 = @"
Expand Down Expand Up @@ -2429,7 +2429,7 @@ class C { int Y => 1; }
public async Task BreakMode_ValidSignificantChange_SourceGenerators_AnalyzerConfigUpdate()
{
var source = @"
class C { int Y => 1; }
class C { int Y => 1; }
";

var configV1 = new[] { ("enc_generator_output", "1") };
Expand Down Expand Up @@ -2948,7 +2948,7 @@ public async Task ActiveStatements_LinkedDocuments()
methodRowIds: new[] { 1, 2, 1 },
modules: new[] { module4, module2, module1 });

// Project1: Test1.cs, Test2.cs
// Project1: Test1.cs, Test2.cs
// Project2: Test1.cs (link from P1)
// Project3: Test1.cs (link from P1)
// Project4: Test2.cs (link from P1)
Expand Down Expand Up @@ -3030,7 +3030,7 @@ public async Task ActiveStatements_OutOfSyncDocuments()
{
static void M()
{
try
try
{
}
catch (Exception e)
Expand All @@ -3044,7 +3044,7 @@ static void M()
{
static void M()
{
try
try
{
}
catch (Exception e)
Expand Down Expand Up @@ -3209,7 +3209,7 @@ void F()
/// 2) Hot-reload edit F (without breaking) to version 3.
/// Function remapping is produced for F v2 -> F v3 based on the last set of active statements calculated for F v2.
/// Assume that the execution did not progress since the last resume.
/// These active statements will likely not match the actual runtime active statements,
/// These active statements will likely not match the actual runtime active statements,
/// however F v2 will never be remapped since it was hot-reloaded and not EnC'd.
/// This remapping is needed for mapping from F v1 to F v3.
/// 3) Break. Update F to v4.
Expand Down Expand Up @@ -3290,7 +3290,7 @@ static void F()
// EnC update F v3 -> v4

EnterBreakState(debuggingSession, GetActiveStatementDebugInfosCSharp(
new[] { markedSourceV1 }, // matches F v1
new[] { markedSourceV1 }, // matches F v1
modules: new[] { moduleId, moduleId },
methodRowIds: new[] { 2, 3 },
methodVersions: new[] { 1, 1 }, // frame F v1 is still executing (G has not returned)
Expand Down Expand Up @@ -3608,7 +3608,7 @@ public async Task WatchHotReloadServiceTest()
loader: new FileTextLoader(sourceFileA.Path, Encoding.UTF8),
filePath: sourceFileA.Path));

var hotReload = new WatchHotReloadService(workspace.Services);
var hotReload = new WatchHotReloadService(workspace.Services, ImmutableArray.Create("Baseline", "AddDefinitionToExistingType", "NewTypeDefinition"));

await hotReload.StartSessionAsync(solution, CancellationToken.None);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

using System;
using System.Collections.Immutable;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
Expand All @@ -19,17 +18,18 @@ internal sealed class WatchHotReloadService
{
private sealed class DebuggerService : IManagedEditAndContinueDebuggerService
{
public static readonly DebuggerService Instance = new();
private readonly ImmutableArray<string> _capabilities;

public DebuggerService(ImmutableArray<string> capabilities)
=> _capabilities = capabilities;

public Task<ImmutableArray<ManagedActiveStatementDebugInfo>> GetActiveStatementsAsync(CancellationToken cancellationToken)
=> Task.FromResult(ImmutableArray<ManagedActiveStatementDebugInfo>.Empty);

public Task<ManagedEditAndContinueAvailability> GetAvailabilityAsync(Guid module, CancellationToken cancellationToken)
=> Task.FromResult(new ManagedEditAndContinueAvailability(ManagedEditAndContinueAvailabilityStatus.Available));

// TODO: get capabilities from the runtime: https://github.com/dotnet/aspnetcore/issues/33402
public Task<ImmutableArray<string>> GetCapabilitiesAsync(CancellationToken cancellationToken)
=> Task.FromResult(ImmutableArray.Create("Baseline", "AddDefinitionToExistingType", "NewTypeDefinition"));
public Task<ImmutableArray<string>> GetCapabilitiesAsync(CancellationToken cancellationToken) => Task.FromResult(_capabilities);

public Task PrepareModuleForUpdateAsync(Guid module, CancellationToken cancellationToken)
=> Task.CompletedTask;
Expand All @@ -56,9 +56,10 @@ public Update(Guid moduleId, ImmutableArray<byte> ilDelta, ImmutableArray<byte>

private readonly IEditAndContinueWorkspaceService _encService;
private DebuggingSessionId _sessionId;
private readonly ImmutableArray<string> _capabilities;

public WatchHotReloadService(HostWorkspaceServices services)
=> _encService = services.GetRequiredService<IEditAndContinueWorkspaceService>();
public WatchHotReloadService(HostWorkspaceServices services, ImmutableArray<string> capabilities)
=> (_encService, _capabilities) = (services.GetRequiredService<IEditAndContinueWorkspaceService>(), capabilities);

/// <summary>
/// Starts the watcher.
Expand All @@ -67,13 +68,13 @@ public WatchHotReloadService(HostWorkspaceServices services)
/// <param name="cancellationToken">Cancellation token.</param>
public async Task StartSessionAsync(Solution solution, CancellationToken cancellationToken)
{
var newSessionId = await _encService.StartDebuggingSessionAsync(solution, DebuggerService.Instance, captureMatchingDocuments: true, reportDiagnostics: false, cancellationToken).ConfigureAwait(false);
var newSessionId = await _encService.StartDebuggingSessionAsync(solution, new DebuggerService(_capabilities), captureMatchingDocuments: true, reportDiagnostics: false, cancellationToken).ConfigureAwait(false);
Contract.ThrowIfFalse(_sessionId == default, "Session already started");
_sessionId = newSessionId;
}

/// <summary>
/// Emits updates for all projects that differ between the given <paramref name="solution"/> snapshot and the one given to the previous successful call or
/// Emits updates for all projects that differ between the given <paramref name="solution"/> snapshot and the one given to the previous successful call or
/// the one passed to <see cref="StartSessionAsync(Solution, CancellationToken)"/> for the first invocation.
/// </summary>
/// <param name="solution">Solution snapshot.</param>
Expand Down