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

EnC support for source-generated files #51526

Merged
merged 6 commits into from
Mar 1, 2021
Merged
Show file tree
Hide file tree
Changes from 4 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
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ protected readonly struct MappedMethod
public readonly IMethodSymbolInternal PreviousMethod;
public readonly Func<SyntaxNode, SyntaxNode> SyntaxMap;

public MappedMethod(IMethodSymbolInternal previousMethodOpt, Func<SyntaxNode, SyntaxNode> syntaxMap)
public MappedMethod(IMethodSymbolInternal previousMethod, Func<SyntaxNode, SyntaxNode> syntaxMap)
{
PreviousMethod = previousMethodOpt;
PreviousMethod = previousMethod;
tmat marked this conversation as resolved.
Show resolved Hide resolved
SyntaxMap = syntaxMap;
}
}
Expand Down Expand Up @@ -311,16 +311,10 @@ internal VariableSlotAllocator TryCreateVariableSlotAllocator(EmitBaseline basel
symbolMap = MapToMetadataSymbolMatcher;
}

var previousMethod = mappedMethod.PreviousMethod;
if (previousMethod is null)
{
previousMethod = (IMethodSymbolInternal)symbolMap.MapDefinitionOrNamespace(topLevelMethod);
}

return new EncVariableSlotAllocator(
symbolMap,
mappedMethod.SyntaxMap,
previousMethod,
mappedMethod.PreviousMethod,
methodId,
previousLocals,
lambdaMap,
Expand Down
4 changes: 2 additions & 2 deletions src/Compilers/Core/Portable/Emit/SemanticEdit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public struct SemanticEdit : IEquatable<SemanticEdit>
/// </summary>
/// <param name="kind">The type of edit.</param>
/// <param name="oldSymbol">
/// The symbol from the earlier compilation, or null if the edit represents an addition or an update of the symbol from the previous compilation that exactly matches <paramref name="newSymbol"/>.
/// The symbol from the earlier compilation, or null if the edit represents an addition.
/// </param>
/// <param name="newSymbol">
/// The symbol from the later compilation, or null if the edit represents a deletion.
Expand All @@ -74,7 +74,7 @@ public struct SemanticEdit : IEquatable<SemanticEdit>
/// </exception>
public SemanticEdit(SemanticEditKind kind, ISymbol? oldSymbol, ISymbol? newSymbol, Func<SyntaxNode, SyntaxNode?>? syntaxMap = null, bool preserveLocalVariables = false)
{
if (oldSymbol == null && kind is not (SemanticEditKind.Insert or SemanticEditKind.Update))
if (oldSymbol == null && kind != SemanticEditKind.Insert)
{
throw new ArgumentNullException(nameof(oldSymbol));
}
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -183,15 +183,21 @@ internal async Task TrackActiveSpansAsync()
}

Debug.Assert(openDocumentIds.Length == baseActiveStatementSpans.Length);
using var _ = ArrayBuilder<Document?>.GetInstance(out var documents);

foreach (var id in openDocumentIds)
{
documents.Add(await currentSolution.GetDocumentAsync(id, includeSourceGenerated: true, _cancellationSource.Token).ConfigureAwait(false));
}

lock (_trackingSpans)
{
for (var i = 0; i < baseActiveStatementSpans.Length; i++)
{
var document = currentSolution.GetDocument(openDocumentIds[i]);
var document = documents[i];
if (document == null)
{
// Document has been deleted.
// Document has been deleted
continue;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Microsoft.CodeAnalysis.Diagnostics;
using Roslyn.Utilities;

namespace Microsoft.CodeAnalysis.EditAndContinue.UnitTests
{
internal class EditAndContinueTestAnalyzerConfigOptions : AnalyzerConfigOptions
{
private readonly Dictionary<string, string> _options;

public EditAndContinueTestAnalyzerConfigOptions(IEnumerable<(string key, string value)> options)
=> _options = options.ToDictionary(e => e.key, e => e.value);

public override bool TryGetValue(string key, [NotNullWhen(true)] out string? value)
=> _options.TryGetValue(key, out value);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Collections.Generic;
using Microsoft.CodeAnalysis.Diagnostics;

namespace Microsoft.CodeAnalysis.EditAndContinue.UnitTests
{
internal class EditAndContinueTestAnalyzerConfigOptionsProvider : AnalyzerConfigOptionsProvider
{
public EditAndContinueTestAnalyzerConfigOptionsProvider(IEnumerable<(string, string)> options)
=> GlobalOptions = new EditAndContinueTestAnalyzerConfigOptions(options);

public override AnalyzerConfigOptions GlobalOptions { get; }

public override AnalyzerConfigOptions GetOptions(SyntaxTree tree)
=> GlobalOptions;

public override AnalyzerConfigOptions GetOptions(AdditionalText textFile)
=> GlobalOptions;
}
}
Loading