Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into RemoteSTJServices
Browse files Browse the repository at this point in the history
  • Loading branch information
davidwengier committed Jul 9, 2024
2 parents 8ff45d7 + 0971b49 commit e8a490a
Show file tree
Hide file tree
Showing 136 changed files with 4,377 additions and 1,004 deletions.
3 changes: 2 additions & 1 deletion Directory.Build.rsp
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
# This file intentionally left blank to avoid accidental import during build.
# Workaround for https://github.com/dotnet/sdk/issues/41791
-p:_IsDisjointMSBuildVersion=false

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ public static async Task<CollectionExpressionSyntax> CreateCollectionExpressionA
#if CODE_STYLE
var formattingOptions = CSharpSyntaxFormattingOptions.Default;
#else
var formattingOptions = (CSharpSyntaxFormattingOptions)await workspaceDocument.GetSyntaxFormattingOptionsAsync(
fallbackOptions, cancellationToken).ConfigureAwait(false);
var formattingOptions = (CSharpSyntaxFormattingOptions)await workspaceDocument.GetSyntaxFormattingOptionsAsync(cancellationToken).ConfigureAwait(false);
#endif

var indentationOptions = new IndentationOptions(formattingOptions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,7 @@ static async Task<SeparatedSyntaxList<ArgumentSyntax>> GetArgumentsAsync(
#if CODE_STYLE
var formattingOptions = SyntaxFormattingOptions.CommonDefaults;
#else
var formattingOptions = await document.GetSyntaxFormattingOptionsAsync(
fallbackOptions, cancellationToken).ConfigureAwait(false);
var formattingOptions = await document.GetSyntaxFormattingOptionsAsync(cancellationToken).ConfigureAwait(false);
#endif

using var _ = ArrayBuilder<SyntaxNodeOrToken>.GetInstance(out var nodesAndTokens);
Expand Down
136 changes: 46 additions & 90 deletions src/Analyzers/Core/Analyzers/AnalyzerOptionsProvider.cs

Large diffs are not rendered by default.

5 changes: 1 addition & 4 deletions src/Analyzers/Core/CodeFixes/AnalyzerOptionsProviders.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@
// 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;
using System.Threading;
using System.Threading.Tasks;
using System.Collections.Generic;
using System.Text;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.CodeAnalysis.Options;

Expand All @@ -20,6 +17,6 @@ public static async ValueTask<AnalyzerOptionsProvider> GetAnalyzerOptionsProvide
var analyzerOptions = document.Project.AnalyzerOptions;
var configOptions = analyzerOptions.AnalyzerConfigOptionsProvider.GetOptions(syntaxTree).GetOptionsReader();

return new AnalyzerOptionsProvider(configOptions, document.Project.Language, analyzerOptions);
return new AnalyzerOptionsProvider(configOptions, document.Project.Language);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,83 +18,61 @@ Namespace Microsoft.CodeAnalysis.Diagnostics
''' </summary>
Private ReadOnly _options As IOptionsReader

''' <summary>
''' Fallback options - the default options in Code Style layer.
''' </summary>
Private ReadOnly _fallbackOptions As IdeAnalyzerOptions

Public Sub New(options As IOptionsReader, fallbackOptions As IdeAnalyzerOptions)
Public Sub New(options As IOptionsReader)
_options = options
_fallbackOptions = fallbackOptions
End Sub

Public Sub New(options As IOptionsReader, fallbackOptions As AnalyzerOptions)
MyClass.New(options, fallbackOptions.GetIdeOptions())
End Sub

Public Function GetSimplifierOptions() As VisualBasicSimplifierOptions
Return New VisualBasicSimplifierOptions(_options, FallbackSimplifierOptions)
Return New VisualBasicSimplifierOptions(_options, fallbackOptions:=Nothing)
End Function

Public ReadOnly Property PreferredModifierOrder As CodeStyleOption2(Of String)
Get
Return GetOption(VisualBasicCodeStyleOptions.PreferredModifierOrder, FallbackCodeStyleOptions.PreferredModifierOrder)
Return GetOption(VisualBasicCodeStyleOptions.PreferredModifierOrder)
End Get
End Property

Public ReadOnly Property PreferIsNotExpression As CodeStyleOption2(Of Boolean)
Get
Return GetOption(VisualBasicCodeStyleOptions.PreferIsNotExpression, FallbackCodeStyleOptions.PreferIsNotExpression)
Return GetOption(VisualBasicCodeStyleOptions.PreferIsNotExpression)
End Get
End Property

Public ReadOnly Property PreferSimplifiedObjectCreation As CodeStyleOption2(Of Boolean)
Get
Return GetOption(VisualBasicCodeStyleOptions.PreferSimplifiedObjectCreation, FallbackCodeStyleOptions.PreferSimplifiedObjectCreation)
Return GetOption(VisualBasicCodeStyleOptions.PreferSimplifiedObjectCreation)
End Get
End Property

Public ReadOnly Property UnusedValueExpressionStatement As CodeStyleOption2(Of UnusedValuePreference)
Get
Return GetOption(VisualBasicCodeStyleOptions.UnusedValueExpressionStatement, FallbackCodeStyleOptions.UnusedValueExpressionStatement)
Return GetOption(VisualBasicCodeStyleOptions.UnusedValueExpressionStatement)
End Get
End Property

Public ReadOnly Property UnusedValueAssignment As CodeStyleOption2(Of UnusedValuePreference)
Get
Return GetOption(VisualBasicCodeStyleOptions.UnusedValueAssignment, FallbackCodeStyleOptions.UnusedValueAssignment)
Return GetOption(VisualBasicCodeStyleOptions.UnusedValueAssignment)
End Get
End Property

Private Function GetOption(Of TValue)([option] As Option2(Of CodeStyleOption2(Of TValue)), defaultValue As CodeStyleOption2(Of TValue)) As CodeStyleOption2(Of TValue)
Return _options.GetOption([option], defaultValue)
Private Function GetOption(Of TValue)([option] As Option2(Of CodeStyleOption2(Of TValue))) As CodeStyleOption2(Of TValue)
Return _options.GetOption([option])
End Function

Private ReadOnly Property FallbackSimplifierOptions As VisualBasicSimplifierOptions
Get
Return If(DirectCast(_fallbackOptions.CleanupOptions?.SimplifierOptions, VisualBasicSimplifierOptions), VisualBasicSimplifierOptions.Default)
End Get
End Property

Private ReadOnly Property FallbackCodeStyleOptions As VisualBasicIdeCodeStyleOptions
Get
Return If(DirectCast(_fallbackOptions.CodeStyleOptions, VisualBasicIdeCodeStyleOptions), VisualBasicIdeCodeStyleOptions.Default)
End Get
End Property

Public Shared Narrowing Operator CType(provider As AnalyzerOptionsProvider) As VisualBasicAnalyzerOptionsProvider
Return New VisualBasicAnalyzerOptionsProvider(provider.GetAnalyzerConfigOptions(), provider.GetFallbackOptions())
Return New VisualBasicAnalyzerOptionsProvider(provider.GetAnalyzerConfigOptions())
End Operator

Public Shared Widening Operator CType(provider As VisualBasicAnalyzerOptionsProvider) As AnalyzerOptionsProvider
Return New AnalyzerOptionsProvider(provider._options, LanguageNames.VisualBasic, provider._fallbackOptions)
Return New AnalyzerOptionsProvider(provider._options, LanguageNames.VisualBasic)
End Operator
End Structure

Friend Module VisualBasicAnalyzerOptionsProviders
<Extension>
Public Function GetVisualBasicAnalyzerOptions(options As AnalyzerOptions, syntaxTree As SyntaxTree) As VisualBasicAnalyzerOptionsProvider
Return New VisualBasicAnalyzerOptionsProvider(options.AnalyzerConfigOptionsProvider.GetOptions(syntaxTree).GetOptionsReader(), options)
Return New VisualBasicAnalyzerOptionsProvider(options.AnalyzerConfigOptionsProvider.GetOptions(syntaxTree).GetOptionsReader())
End Function

<Extension>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,10 @@ protected override BoundExpression FramePointer(SyntaxNode syntax, NamedTypeSymb
// However, frame pointer local variables themselves can be "captured". In that case
// the inner frames contain pointers to the enclosing frames. That is, nested
// frame pointers are organized in a linked list.
return proxyField.Replacement(syntax, frameType => FramePointer(syntax, frameType));
return proxyField.Replacement(
syntax,
static (frameType, arg) => arg.self.FramePointer(arg.syntax, frameType),
(syntax, self: this));
}

var localFrame = (LocalSymbol)framePointer;
Expand Down Expand Up @@ -777,7 +780,11 @@ private void InitVariableProxy(SyntaxNode syntax, Symbol symbol, LocalSymbol fra
throw ExceptionUtilities.UnexpectedValue(symbol.Kind);
}

var left = proxy.Replacement(syntax, frameType1 => new BoundLocal(syntax, framePointer, null, framePointer.Type));
var left = proxy.Replacement(
syntax,
static (frameType1, arg) => new BoundLocal(arg.syntax, arg.framePointer, null, arg.framePointer.Type),
(syntax, framePointer));

var assignToProxy = new BoundAssignmentOperator(syntax, left, value, value.Type);
if (_currentMethod.MethodKind == MethodKind.Constructor &&
symbol == _currentMethod.ThisParameter &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,11 @@ private bool TryReplaceWithProxy(Symbol parameterOrLocal, SyntaxNode syntax, [No
{
if (proxies.TryGetValue(parameterOrLocal, out CapturedSymbolReplacement? proxy))
{
replacement = proxy.Replacement(syntax, frameType => FramePointer(syntax, frameType));
replacement = proxy.Replacement(
syntax,
static (frameType, arg) => arg.self.FramePointer(arg.syntax, frameType),
(syntax, self: this));

return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public CapturedSymbolReplacement(bool isReusable)
/// Rewrite the replacement expression for the hoisted local so all synthesized field are accessed as members
/// of the appropriate frame.
/// </summary>
public abstract BoundExpression Replacement(SyntaxNode node, Func<NamedTypeSymbol, BoundExpression> makeFrame);
public abstract BoundExpression Replacement<TArg>(SyntaxNode node, Func<NamedTypeSymbol, TArg, BoundExpression> makeFrame, TArg arg);
}

internal sealed class CapturedToFrameSymbolReplacement : CapturedSymbolReplacement
Expand All @@ -36,9 +36,9 @@ public CapturedToFrameSymbolReplacement(LambdaCapturedVariable hoistedField, boo
this.HoistedField = hoistedField;
}

public override BoundExpression Replacement(SyntaxNode node, Func<NamedTypeSymbol, BoundExpression> makeFrame)
public override BoundExpression Replacement<TArg>(SyntaxNode node, Func<NamedTypeSymbol, TArg, BoundExpression> makeFrame, TArg arg)
{
var frame = makeFrame(this.HoistedField.ContainingType);
var frame = makeFrame(this.HoistedField.ContainingType, arg);
var field = this.HoistedField.AsMember((NamedTypeSymbol)frame.Type);
return new BoundFieldAccess(node, frame, field, constantValueOpt: null);
}
Expand All @@ -54,9 +54,9 @@ public CapturedToStateMachineFieldReplacement(StateMachineFieldSymbol hoistedFie
this.HoistedField = hoistedField;
}

public override BoundExpression Replacement(SyntaxNode node, Func<NamedTypeSymbol, BoundExpression> makeFrame)
public override BoundExpression Replacement<TArg>(SyntaxNode node, Func<NamedTypeSymbol, TArg, BoundExpression> makeFrame, TArg arg)
{
var frame = makeFrame(this.HoistedField.ContainingType);
var frame = makeFrame(this.HoistedField.ContainingType, arg);
var field = this.HoistedField.AsMember((NamedTypeSymbol)frame.Type);
return new BoundFieldAccess(node, frame, field, constantValueOpt: null);
}
Expand All @@ -74,7 +74,7 @@ public CapturedToExpressionSymbolReplacement(BoundExpression replacement, Immuta
this.HoistedFields = hoistedFields;
}

public override BoundExpression Replacement(SyntaxNode node, Func<NamedTypeSymbol, BoundExpression> makeFrame)
public override BoundExpression Replacement<TArg>(SyntaxNode node, Func<NamedTypeSymbol, TArg, BoundExpression> makeFrame, TArg arg)
{
// By returning the same replacement each time, it is possible we
// are constructing a DAG instead of a tree for the translation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public MethodToStateMachineRewriter(
proxies.TryGetValue(thisParameter, out thisProxy) &&
F.Compilation.Options.OptimizationLevel == OptimizationLevel.Release)
{
BoundExpression thisProxyReplacement = thisProxy.Replacement(F.Syntax, frameType => F.This());
BoundExpression thisProxyReplacement = thisProxy.Replacement(F.Syntax, static (frameType, F) => F.This(), F);
Debug.Assert(thisProxyReplacement.Type is not null);
this.cachedThis = F.SynthesizedLocal(thisProxyReplacement.Type, syntax: F.Syntax, kind: SynthesizedLocalKind.FrameCache);
}
Expand Down Expand Up @@ -925,7 +925,7 @@ protected BoundStatement CacheThisIfNeeded()
if ((object)this.cachedThis != null)
{
CapturedSymbolReplacement proxy = proxies[this.OriginalMethod.ThisParameter];
var fetchThis = proxy.Replacement(F.Syntax, frameType => F.This());
var fetchThis = proxy.Replacement(F.Syntax, static (frameType, F) => F.This(), F);
return F.Assignment(F.Local(this.cachedThis), fetchThis);
}

Expand Down Expand Up @@ -961,7 +961,7 @@ public sealed override BoundNode VisitThisReference(BoundThisReference node)
else
{
Debug.Assert(proxy != null);
return proxy.Replacement(F.Syntax, frameType => F.This());
return proxy.Replacement(F.Syntax, static (frameType, F) => F.This(), F);
}
}

Expand All @@ -977,7 +977,7 @@ public override BoundNode VisitBaseReference(BoundBaseReference node)

CapturedSymbolReplacement proxy = proxies[this.OriginalMethod.ThisParameter];
Debug.Assert(proxy != null);
return proxy.Replacement(F.Syntax, frameType => F.This());
return proxy.Replacement(F.Syntax, static (frameType, F) => F.This(), F);
}

#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,12 @@ protected BoundStatement GenerateParameterStorage(LocalSymbol stateMachineVariab
CapturedSymbolReplacement proxy;
if (proxies.TryGetValue(method.ThisParameter, out proxy))
{
bodyBuilder.Add(F.Assignment(proxy.Replacement(F.Syntax, frameType1 => F.Local(stateMachineVariable)), F.This()));
var leftExpression = proxy.Replacement(
F.Syntax,
static (frameType1, arg) => arg.F.Local(arg.stateMachineVariable),
(F, stateMachineVariable));

bodyBuilder.Add(F.Assignment(leftExpression, F.This()));
}
}

Expand All @@ -320,8 +325,12 @@ protected BoundStatement GenerateParameterStorage(LocalSymbol stateMachineVariab
CapturedSymbolReplacement proxy;
if (proxies.TryGetValue(parameter, out proxy))
{
bodyBuilder.Add(F.Assignment(proxy.Replacement(F.Syntax, frameType1 => F.Local(stateMachineVariable)),
F.Parameter(parameter)));
var leftExpression = proxy.Replacement(
F.Syntax,
static (frameType1, arg) => arg.F.Local(arg.stateMachineVariable),
(F, stateMachineVariable));

bodyBuilder.Add(F.Assignment(leftExpression, F.Parameter(parameter)));
}
}

Expand Down Expand Up @@ -456,10 +465,14 @@ protected SynthesizedImplementationMethod GenerateIteratorGetEnumerator(MethodSy
CapturedSymbolReplacement proxy;
if (copyDest.TryGetValue(method.ThisParameter, out proxy))
{
bodyBuilder.Add(
F.Assignment(
proxy.Replacement(F.Syntax, stateMachineType => F.Local(resultVariable)),
copySrc[method.ThisParameter].Replacement(F.Syntax, stateMachineType => F.This())));
var leftExpression = proxy.Replacement(
F.Syntax,
static (stateMachineType, arg) => arg.F.Local(arg.resultVariable),
(F, resultVariable));

var rightExpression = copySrc[method.ThisParameter].Replacement(F.Syntax, static (stateMachineType, F) => F.This(), F);

bodyBuilder.Add(F.Assignment(leftExpression, rightExpression));
}
}

Expand All @@ -471,9 +484,13 @@ protected SynthesizedImplementationMethod GenerateIteratorGetEnumerator(MethodSy
if (copyDest.TryGetValue(parameter, out proxy))
{
// result.parameter
BoundExpression resultParameter = proxy.Replacement(F.Syntax, stateMachineType => F.Local(resultVariable));
BoundExpression resultParameter = proxy.Replacement(
F.Syntax,
static (stateMachineType, arg) => arg.F.Local(arg.resultVariable),
(F, resultVariable));

// this.parameterProxy
BoundExpression parameterProxy = copySrc[parameter].Replacement(F.Syntax, stateMachineType => F.This());
BoundExpression parameterProxy = copySrc[parameter].Replacement(F.Syntax, static (stateMachineType, F) => F.This(), F);
BoundStatement copy = InitializeParameterField(getEnumeratorMethod, parameter, resultParameter, parameterProxy);

bodyBuilder.Add(copy);
Expand Down
Loading

0 comments on commit e8a490a

Please sign in to comment.