Skip to content

Commit 35cfcfc

Browse files
author
msftbot[bot]
authored
Merge pull request #41677 from dotnet/merges/master-to-features/local-function-attributes
Merge master to features/local-function-attributes
2 parents d0cd176 + d73f093 commit 35cfcfc

File tree

10 files changed

+79
-119
lines changed

10 files changed

+79
-119
lines changed

eng/Version.Details.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
<ProductDependencies>
44
</ProductDependencies>
55
<ToolsetDependencies>
6-
<Dependency Name="Microsoft.DotNet.Arcade.Sdk" Version="5.0.0-beta.20112.7">
6+
<Dependency Name="Microsoft.DotNet.Arcade.Sdk" Version="5.0.0-beta.20113.6">
77
<Uri>https://github.com/dotnet/arcade</Uri>
8-
<Sha>951ea7430678b2682ff861fe1149b8a2f55887ca</Sha>
8+
<Sha>ba6bfb25914e3434264352dd24ba00b406d23393</Sha>
99
</Dependency>
1010
</ToolsetDependencies>
1111
</Dependencies>

eng/common/post-build/darc-gather-drop.ps1

Lines changed: 0 additions & 44 deletions
This file was deleted.

eng/common/post-build/nuget-validation.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ param(
99
try {
1010
. $PSScriptRoot\post-build-utils.ps1
1111

12-
$url = 'https://raw.githubusercontent.com/NuGet/NuGetGallery/jver-verify/src/VerifyMicrosoftPackage/verify.ps1'
12+
$url = 'https://raw.githubusercontent.com/NuGet/NuGetGallery/3e25ad135146676bcab0050a516939d9958bfa5d/src/VerifyMicrosoftPackage/verify.ps1'
1313

1414
New-Item -ItemType 'directory' -Path ${ToolDestinationPath} -Force
1515

eng/common/templates/post-build/darc-gather-drop.yml

Lines changed: 0 additions & 23 deletions
This file was deleted.

global.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
"xcopy-msbuild": "16.4.0-alpha"
88
},
99
"msbuild-sdks": {
10-
"Microsoft.DotNet.Arcade.Sdk": "5.0.0-beta.20112.7"
10+
"Microsoft.DotNet.Arcade.Sdk": "5.0.0-beta.20113.6"
1111
}
1212
}

src/Compilers/CSharp/Portable/Parser/LanguageParser.cs

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System;
66
using System.Collections.Generic;
77
using System.Diagnostics;
8+
using System.Runtime.CompilerServices;
89
using System.Threading;
910
using Microsoft.CodeAnalysis.CSharp.Symbols;
1011
using Microsoft.CodeAnalysis.Text;
@@ -7180,35 +7181,44 @@ private bool IsEndOfFixedStatement()
71807181

71817182
private StatementSyntax ParseEmbeddedStatement()
71827183
{
7183-
// The consumers of embedded statements are expecting to receive a non-null statement
7184-
// yet there are several error conditions that can lead ParseStatementCore to return
7185-
// null. When that occurs create an error empty Statement and return it to the caller.
7186-
StatementSyntax statement = this.TryParseStatementCore() ?? SyntaxFactory.EmptyStatement(attributeLists: default, EatToken(SyntaxKind.SemicolonToken));
7184+
// ParseEmbeddedStatement is called through many recursive statement parsing cases. We
7185+
// keep the body exceptionally simple, and we optimize for the common case, to ensure it
7186+
// is inlined into the callers. Otherwise the overhead of this single method can have a
7187+
// deep impact on the number of recursive calls we can make (more than a hundred during
7188+
// empirical testing).
71877189

7188-
switch (statement.Kind)
7190+
return parseEmbeddedStatementRest(this.TryParseStatementCore());
7191+
7192+
StatementSyntax parseEmbeddedStatementRest(StatementSyntax statement)
71897193
{
7194+
if (statement == null)
7195+
{
7196+
// The consumers of embedded statements are expecting to receive a non-null statement
7197+
// yet there are several error conditions that can lead ParseStatementCore to return
7198+
// null. When that occurs create an error empty Statement and return it to the caller.
7199+
return SyntaxFactory.EmptyStatement(attributeLists: default, EatToken(SyntaxKind.SemicolonToken));
7200+
}
7201+
71907202
// In scripts, stand-alone expression statements may not be followed by semicolons.
71917203
// ParseExpressionStatement hides the error.
71927204
// However, embedded expression statements are required to be followed by semicolon.
7193-
case SyntaxKind.ExpressionStatement:
7194-
if (IsScript)
7195-
{
7196-
var expressionStatementSyntax = (ExpressionStatementSyntax)statement;
7197-
var semicolonToken = expressionStatementSyntax.SemicolonToken;
7205+
if (statement.Kind == SyntaxKind.ExpressionStatement &&
7206+
IsScript)
7207+
{
7208+
var expressionStatementSyntax = (ExpressionStatementSyntax)statement;
7209+
var semicolonToken = expressionStatementSyntax.SemicolonToken;
71987210

7199-
// Do not add a new error if the same error was already added.
7200-
if (semicolonToken.IsMissing &&
7201-
!semicolonToken.GetDiagnostics().Contains(diagnosticInfo => (ErrorCode)diagnosticInfo.Code == ErrorCode.ERR_SemicolonExpected))
7202-
{
7203-
semicolonToken = this.AddError(semicolonToken, ErrorCode.ERR_SemicolonExpected);
7204-
statement = expressionStatementSyntax.Update(expressionStatementSyntax.AttributeLists, expressionStatementSyntax.Expression, semicolonToken);
7205-
}
7211+
// Do not add a new error if the same error was already added.
7212+
if (semicolonToken.IsMissing &&
7213+
!semicolonToken.GetDiagnostics().Contains(diagnosticInfo => (ErrorCode)diagnosticInfo.Code == ErrorCode.ERR_SemicolonExpected))
7214+
{
7215+
semicolonToken = this.AddError(semicolonToken, ErrorCode.ERR_SemicolonExpected);
7216+
return expressionStatementSyntax.Update(expressionStatementSyntax.AttributeLists, expressionStatementSyntax.Expression, semicolonToken);
72067217
}
7218+
}
72077219

7208-
break;
7220+
return statement;
72097221
}
7210-
7211-
return statement;
72127222
}
72137223

72147224
private BreakStatementSyntax ParseBreakStatement(SyntaxList<AttributeListSyntax> attributes)

src/Compilers/CSharp/Portable/Symbols/NamespaceOrTypeSymbol.cs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5+
#nullable enable
6+
57
using System.Collections.Generic;
68
using System.Collections.Immutable;
79
using System.Diagnostics;
@@ -170,7 +172,7 @@ public virtual ImmutableArray<NamedTypeSymbol> GetTypeMembers(string name, int a
170172
/// Get a source type symbol for the given declaration syntax.
171173
/// </summary>
172174
/// <returns>Null if there is no matching declaration.</returns>
173-
internal SourceNamedTypeSymbol GetSourceTypeMember(TypeDeclarationSyntax syntax)
175+
internal SourceNamedTypeSymbol? GetSourceTypeMember(TypeDeclarationSyntax syntax)
174176
{
175177
return GetSourceTypeMember(syntax.Identifier.ValueText, syntax.Arity, syntax.Kind(), syntax);
176178
}
@@ -179,7 +181,7 @@ internal SourceNamedTypeSymbol GetSourceTypeMember(TypeDeclarationSyntax syntax)
179181
/// Get a source type symbol for the given declaration syntax.
180182
/// </summary>
181183
/// <returns>Null if there is no matching declaration.</returns>
182-
internal SourceNamedTypeSymbol GetSourceTypeMember(DelegateDeclarationSyntax syntax)
184+
internal SourceNamedTypeSymbol? GetSourceTypeMember(DelegateDeclarationSyntax syntax)
183185
{
184186
return GetSourceTypeMember(syntax.Identifier.ValueText, syntax.Arity, syntax.Kind(), syntax);
185187
}
@@ -189,7 +191,7 @@ internal SourceNamedTypeSymbol GetSourceTypeMember(DelegateDeclarationSyntax syn
189191
/// to those that are declared within the given syntax.
190192
/// </summary>
191193
/// <returns>Null if there is no matching declaration.</returns>
192-
internal SourceNamedTypeSymbol GetSourceTypeMember(
194+
internal SourceNamedTypeSymbol? GetSourceTypeMember(
193195
string name,
194196
int arity,
195197
SyntaxKind kind,
@@ -207,7 +209,7 @@ internal SourceNamedTypeSymbol GetSourceTypeMember(
207209
foreach (var member in GetTypeMembers(name, arity))
208210
{
209211
var memberT = member as SourceNamedTypeSymbol;
210-
if ((object)memberT != null && memberT.TypeKind == typeKind)
212+
if ((object?)memberT != null && memberT.TypeKind == typeKind)
211213
{
212214
if (syntax != null)
213215
{
@@ -251,7 +253,7 @@ internal virtual NamedTypeSymbol LookupMetadataType(ref MetadataTypeName emitted
251253
return new MissingMetadataTypeSymbol.Nested((NamedTypeSymbol)scope, ref emittedTypeName);
252254
}
253255

254-
NamedTypeSymbol namedType = null;
256+
NamedTypeSymbol? namedType = null;
255257

256258
ImmutableArray<NamedTypeSymbol> namespaceOrTypeMembers;
257259
bool isTopLevel = scope.IsNamespace;
@@ -271,7 +273,7 @@ internal virtual NamedTypeSymbol LookupMetadataType(ref MetadataTypeName emitted
271273
{
272274
if (emittedTypeName.InferredArity == named.Arity && named.MangleName)
273275
{
274-
if ((object)namedType != null)
276+
if ((object?)namedType != null)
275277
{
276278
namedType = null;
277279
break;
@@ -317,7 +319,7 @@ internal virtual NamedTypeSymbol LookupMetadataType(ref MetadataTypeName emitted
317319
{
318320
if (!named.MangleName && (forcedArity == -1 || forcedArity == named.Arity))
319321
{
320-
if ((object)namedType != null)
322+
if ((object?)namedType != null)
321323
{
322324
namedType = null;
323325
break;
@@ -328,7 +330,7 @@ internal virtual NamedTypeSymbol LookupMetadataType(ref MetadataTypeName emitted
328330
}
329331

330332
Done:
331-
if ((object)namedType == null)
333+
if ((object?)namedType == null)
332334
{
333335
if (isTopLevel)
334336
{
@@ -354,10 +356,10 @@ internal virtual NamedTypeSymbol LookupMetadataType(ref MetadataTypeName emitted
354356
/// <remarks>
355357
/// "C.D" matches C.D, C{T}.D, C{S,T}.D{U}, etc.
356358
/// </remarks>
357-
internal IEnumerable<NamespaceOrTypeSymbol> GetNamespaceOrTypeByQualifiedName(IEnumerable<string> qualifiedName)
359+
internal IEnumerable<NamespaceOrTypeSymbol>? GetNamespaceOrTypeByQualifiedName(IEnumerable<string> qualifiedName)
358360
{
359361
NamespaceOrTypeSymbol namespaceOrType = this;
360-
IEnumerable<NamespaceOrTypeSymbol> symbols = null;
362+
IEnumerable<NamespaceOrTypeSymbol>? symbols = null;
361363
foreach (string name in qualifiedName)
362364
{
363365
if (symbols != null)

src/Compilers/CSharp/Portable/Symbols/PublicModel/NamespaceOrTypeSymbol.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5+
#nullable enable
6+
57
using System.Collections.Immutable;
68

79
namespace Microsoft.CodeAnalysis.CSharp.Symbols.PublicModel

src/Compilers/CSharp/Portable/Symbols/SubstitutedMethodSymbol.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,8 @@ private int ComputeHashCode()
368368
// (e.g, ignoring nullability) and want to retain the same hashcode. As such, consider only
369369
// the original definition for the hashcode when we know equality is possible
370370
var containingHashCode = _containingType.GetHashCode();
371-
if (containingHashCode == this.OriginalDefinition.ContainingType.GetHashCode())
371+
if (containingHashCode == this.OriginalDefinition.ContainingType.GetHashCode() &&
372+
wasConstructedForAnnotations(this))
372373
{
373374
return code;
374375
}
@@ -402,6 +403,24 @@ private int ComputeHashCode()
402403
}
403404

404405
return code;
406+
407+
static bool wasConstructedForAnnotations(SubstitutedMethodSymbol method)
408+
{
409+
var typeArguments = method.TypeArgumentsWithAnnotations;
410+
var typeParameters = method.OriginalDefinition.TypeParameters;
411+
412+
for (int i = 0; i < typeArguments.Length; i++)
413+
{
414+
if (!typeParameters[i].Equals(
415+
typeArguments[i].Type,
416+
TypeCompareKind.ConsiderEverything))
417+
{
418+
return false;
419+
}
420+
}
421+
422+
return true;
423+
}
405424
}
406425

407426
public sealed override bool Equals(Symbol obj, TypeCompareKind compareKind)

src/Compilers/Core/Portable/AdditionalTextFile.cs

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,9 @@ internal sealed class AdditionalTextFile : AdditionalText
1919
{
2020
private readonly CommandLineSourceFile _sourceFile;
2121
private readonly CommonCompiler _compiler;
22-
private SourceText? _text;
22+
private readonly Lazy<SourceText?> _text;
2323
private IList<DiagnosticInfo> _diagnostics;
2424

25-
private readonly object _lockObject = new object();
26-
2725
public AdditionalTextFile(CommandLineSourceFile sourceFile, CommonCompiler compiler)
2826
{
2927
if (compiler == null)
@@ -34,6 +32,15 @@ public AdditionalTextFile(CommandLineSourceFile sourceFile, CommonCompiler compi
3432
_sourceFile = sourceFile;
3533
_compiler = compiler;
3634
_diagnostics = SpecializedCollections.EmptyList<DiagnosticInfo>();
35+
_text = new Lazy<SourceText?>(ReadText);
36+
}
37+
38+
private SourceText ReadText()
39+
{
40+
var diagnostics = new List<DiagnosticInfo>();
41+
var text = _compiler.TryReadFileContent(_sourceFile, diagnostics);
42+
_diagnostics = diagnostics;
43+
return text;
3744
}
3845

3946
/// <summary>
@@ -45,20 +52,7 @@ public AdditionalTextFile(CommandLineSourceFile sourceFile, CommonCompiler compi
4552
/// Returns a <see cref="SourceText"/> with the contents of this file, or <c>null</c> if
4653
/// there were errors reading the file.
4754
/// </summary>
48-
public override SourceText GetText(CancellationToken cancellationToken = default)
49-
{
50-
lock (_lockObject)
51-
{
52-
if (_text == null)
53-
{
54-
var diagnostics = new List<DiagnosticInfo>();
55-
_text = _compiler.TryReadFileContent(_sourceFile, diagnostics);
56-
_diagnostics = diagnostics;
57-
}
58-
}
59-
60-
return _text;
61-
}
55+
public override SourceText? GetText(CancellationToken cancellationToken = default) => _text.Value;
6256

6357
/// <summary>
6458
/// Errors encountered when trying to read the additional file. Always empty if

0 commit comments

Comments
 (0)