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

Fix the OOM error in scripting tests #75163

Merged
merged 3 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 3 additions & 3 deletions src/Compilers/CSharp/Portable/Binder/Binder.ValueChecks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,7 @@ internal bool CheckValueKind(SyntaxNode node, BoundExpression expr, BindValueKin
break;

default:
Debug.Assert(expr is not BoundValuePlaceholderBase, $"Placeholder kind {expr.Kind} should be explicitly handled");
RoslynDebug.Assert(expr is not BoundValuePlaceholderBase, $"Placeholder kind {expr.Kind} should be explicitly handled");
break;
}

Expand Down Expand Up @@ -4492,7 +4492,7 @@ internal uint GetValEscape(BoundExpression expr, uint scopeOfTheContainingExpres
// in error situations some unexpected nodes could make here
// returning "scopeOfTheContainingExpression" seems safer than throwing.
// we will still assert to make sure that all nodes are accounted for.
Debug.Assert(false, $"{expr.Kind} expression of {expr.Type} type");
RoslynDebug.Assert(false, $"{expr.Kind} expression of {expr.Type} type");
return scopeOfTheContainingExpression;
}
}
Expand Down Expand Up @@ -5287,7 +5287,7 @@ internal bool CheckValEscape(SyntaxNode node, BoundExpression expr, uint escapeF
// in error situations some unexpected nodes could make here
// returning "false" seems safer than throwing.
// we will still assert to make sure that all nodes are accounted for.
Debug.Assert(false, $"{expr.Kind} expression of {expr.Type} type");
RoslynDebug.Assert(false, $"{expr.Kind} expression of {expr.Type} type");
diagnostics.Add(ErrorCode.ERR_InternalError, node.Location);
return false;

Expand Down
11 changes: 6 additions & 5 deletions src/Compilers/CSharp/Portable/Binder/ForEachEnumeratorInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

using System.Diagnostics;
using Microsoft.CodeAnalysis.CSharp.Symbols;
using Roslyn.Utilities;

namespace Microsoft.CodeAnalysis.CSharp
{
Expand Down Expand Up @@ -63,11 +64,11 @@ private ForEachEnumeratorInfo(
BoundExpression? currentConversion,
BinderFlags location)
{
Debug.Assert((object)collectionType != null, $"Field '{nameof(collectionType)}' cannot be null");
Debug.Assert(elementType.HasType, $"Field '{nameof(elementType)}' cannot be null");
Debug.Assert((object)getEnumeratorInfo != null, $"Field '{nameof(getEnumeratorInfo)}' cannot be null");
Debug.Assert((object)currentPropertyGetter != null, $"Field '{nameof(currentPropertyGetter)}' cannot be null");
Debug.Assert((object)moveNextInfo != null, $"Field '{nameof(moveNextInfo)}' cannot be null");
RoslynDebug.Assert((object)collectionType != null, $"Field '{nameof(collectionType)}' cannot be null");
RoslynDebug.Assert(elementType.HasType, $"Field '{nameof(elementType)}' cannot be null");
RoslynDebug.Assert((object)getEnumeratorInfo != null, $"Field '{nameof(getEnumeratorInfo)}' cannot be null");
RoslynDebug.Assert((object)currentPropertyGetter != null, $"Field '{nameof(currentPropertyGetter)}' cannot be null");
RoslynDebug.Assert((object)moveNextInfo != null, $"Field '{nameof(moveNextInfo)}' cannot be null");
Debug.Assert(patternDisposeInfo == null || needsDisposal);
Debug.Assert(inlineArraySpanType is WellKnownType.Unknown or WellKnownType.System_Span_T or WellKnownType.System_ReadOnlySpan_T);
Debug.Assert(inlineArraySpanType == WellKnownType.Unknown ||
Expand Down
4 changes: 2 additions & 2 deletions src/Compilers/CSharp/Portable/Binder/RefSafetyAnalysis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ private void TrackVisit(BoundNode? node)
if (_visited is { } && _visited.Count <= MaxTrackVisited)
{
bool added = _visited.Add(expr);
Debug.Assert(added, $"Expression {expr} `{expr.Syntax}` visited more than once.");
RoslynDebug.Assert(added, $"Expression {expr} `{expr.Syntax}` visited more than once.");
}
}
}
Expand All @@ -298,7 +298,7 @@ private void AssertVisited(BoundExpression expr)
}
else if (_visited is { } && _visited.Count <= MaxTrackVisited)
{
Debug.Assert(_visited.Contains(expr), $"Expected {expr} `{expr.Syntax}` to be visited.");
RoslynDebug.Assert(_visited.Contains(expr), $"Expected {expr} `{expr.Syntax}` to be visited.");
}
}
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ private static void AssertTrivialConversion(ConversionKind kind)
break;
}

Debug.Assert(isTrivial, "this conversion needs additional data: " + kind);
RoslynDebug.Assert(isTrivial, $"this conversion needs additional data: {kind}");
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To emphasize how much these changes matter: this Debug.Assert alone was causing 50MB of allocations in the slice I was debugging.

}

internal static Conversion GetTrivialConversion(ConversionKind kind)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ public int Id
}
internal set
{
Debug.Assert(value > 0, "Id must be positive but was set to " + value);
Debug.Assert(_id == -1, $"Id was set to {_id} and set again to {value}");
RoslynDebug.Assert(value > 0, "Id must be positive but was set to " + value);
RoslynDebug.Assert(_id == -1, $"Id was set to {_id} and set again to {value}");
_id = value;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Compilers/CSharp/Portable/BoundTree/BoundNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ public bool IsParamsArrayOrCollection
}
protected set
{
Debug.Assert((_attributes & BoundNodeAttributes.ParamsArrayOrCollection) == 0, $"{nameof(BoundNodeAttributes.ParamsArrayOrCollection)} flag should not be set twice or reset");
RoslynDebug.Assert((_attributes & BoundNodeAttributes.ParamsArrayOrCollection) == 0, $"{nameof(BoundNodeAttributes.ParamsArrayOrCollection)} flag should not be set twice or reset");
Debug.Assert(value || !IsParamsArrayOrCollection);
Debug.Assert(!value ||
this is BoundArrayCreation { Bounds: [BoundLiteral { WasCompilerGenerated: true }], InitializerOpt: BoundArrayInitialization { WasCompilerGenerated: true }, WasCompilerGenerated: true } or
Expand Down
2 changes: 1 addition & 1 deletion src/Compilers/CSharp/Portable/BoundTree/Formatting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public virtual object Display
{
get
{
Debug.Assert(this.Type is { }, $"Unexpected null type in {this.GetType().Name}");
RoslynDebug.Assert(this.Type is { }, $"Unexpected null type in {this.GetType().Name}");
return this.Type;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ private bool TryEmitOptimizedReadonlySpanCreation(NamedTypeSymbol spanType, Boun
// the null terminator off as part of creating the span instance.

Debug.Assert(inPlaceTarget is null || TargetIsNotOnHeap(inPlaceTarget), "in-place construction target should not be on heap");
Debug.Assert(_diagnostics.DiagnosticBag is not null, $"Expected non-null {nameof(_diagnostics)}.{nameof(_diagnostics.DiagnosticBag)}");
RoslynDebug.Assert(_diagnostics.DiagnosticBag is not null, $"Expected non-null {nameof(_diagnostics)}.{nameof(_diagnostics.DiagnosticBag)}");

if (start is null != length is null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1238,7 +1238,7 @@ private void BeginTemporaryString()
private string GetAndEndTemporaryString()
{
TemporaryStringBuilder t = _temporaryStringBuilders.Pop();
Debug.Assert(_indentDepth == t.InitialIndentDepth, $"Temporary strings should be indent-neutral (was {t.InitialIndentDepth}, is {_indentDepth})");
RoslynDebug.Assert(_indentDepth == t.InitialIndentDepth, $"Temporary strings should be indent-neutral (was {t.InitialIndentDepth}, is {_indentDepth})");
_indentDepth = t.InitialIndentDepth;
return t.Pooled.ToStringAndFree();
}
Expand Down
5 changes: 3 additions & 2 deletions src/Compilers/CSharp/Portable/Errors/ErrorFacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System.Diagnostics;
using System.Globalization;
using System.Reflection;
using Roslyn.Utilities;

namespace Microsoft.CodeAnalysis.CSharp
{
Expand Down Expand Up @@ -132,15 +133,15 @@ internal static DiagnosticSeverity GetSeverity(ErrorCode code)
public static string GetMessage(MessageID code, CultureInfo culture)
{
string message = ResourceManager.GetString(code.ToString(), culture);
Debug.Assert(!string.IsNullOrEmpty(message), code.ToString());
RoslynDebug.Assert(!string.IsNullOrEmpty(message), $"{code}");
return message;
}

/// <remarks>Don't call this during a parse--it loads resources</remarks>
public static string GetMessage(ErrorCode code, CultureInfo culture)
{
string message = ResourceManager.GetString(code.ToString(), culture);
Debug.Assert(!string.IsNullOrEmpty(message), code.ToString());
RoslynDebug.Assert(!string.IsNullOrEmpty(message), $"{code}");
return message;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -895,7 +895,7 @@ protected void RestorePending(SavedPending oldPending)
/// </summary>
public override BoundNode DefaultVisit(BoundNode node)
{
Debug.Assert(false, $"Should Visit{node.Kind} be overridden in {this.GetType().Name}?");
RoslynDebug.Assert(false, $"Should Visit{node.Kind} be overridden in {this.GetType().Name}?");
Diagnostics.Add(ErrorCode.ERR_InternalError, node.Syntax.Location);
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Collections.Immutable;
using System.Diagnostics;
using Microsoft.CodeAnalysis.CSharp.Symbols;
using Roslyn.Utilities;

namespace Microsoft.CodeAnalysis.CSharp
{
Expand Down Expand Up @@ -46,7 +47,7 @@ public static void Verify(ImmutableDictionary<BoundExpression, (NullabilityInfo
{
if (!verifier._visitedExpressions.Contains(analyzedNode))
{
Debug.Assert(false, $"Analyzed {verifier._analyzedNullabilityMap.Count} nodes in NullableWalker, but DebugVerifier expects {verifier._visitedExpressions.Count}. Example of unverified node: {analyzedNode.GetDebuggerDisplay()}");
RoslynDebug.Assert(false, $"Analyzed {verifier._analyzedNullabilityMap.Count} nodes in NullableWalker, but DebugVerifier expects {verifier._visitedExpressions.Count}. Example of unverified node: {analyzedNode.GetDebuggerDisplay()}");
}
}
}
Expand All @@ -56,7 +57,7 @@ public static void Verify(ImmutableDictionary<BoundExpression, (NullabilityInfo
{
if (!verifier._analyzedNullabilityMap.ContainsKey(verifiedNode))
{
Debug.Assert(false, $"Analyzed {verifier._analyzedNullabilityMap.Count} nodes in NullableWalker, but DebugVerifier expects {verifier._visitedExpressions.Count}. Example of unanalyzed node: {verifiedNode.GetDebuggerDisplay()}");
RoslynDebug.Assert(false, $"Analyzed {verifier._analyzedNullabilityMap.Count} nodes in NullableWalker, but DebugVerifier expects {verifier._visitedExpressions.Count}. Example of unanalyzed node: {verifiedNode.GetDebuggerDisplay()}");
}
}
}
Expand All @@ -67,11 +68,11 @@ private void VerifyExpression(BoundExpression expression, bool overrideSkippedEx
if (expression.IsParamsArrayOrCollection)
{
// Params collections are processed element wise.
Debug.Assert(!_analyzedNullabilityMap.ContainsKey(expression), $"Found unexpected {expression} `{expression.Syntax}` in the map.");
RoslynDebug.Assert(!_analyzedNullabilityMap.ContainsKey(expression), $"Found unexpected {expression} `{expression.Syntax}` in the map.");
}
else if (overrideSkippedExpression || !s_skippedExpressions.Contains(expression.Kind))
{
Debug.Assert(_analyzedNullabilityMap.ContainsKey(expression), $"Did not find {expression} `{expression.Syntax}` in the map.");
RoslynDebug.Assert(_analyzedNullabilityMap.ContainsKey(expression), $"Did not find {expression} `{expression.Syntax}` in the map.");
_visitedExpressions.Add(expression);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,18 +115,18 @@ internal void VerifyNode(BoundNode node)
{
Debug.Fail($"Did not find a snapshot for {node} `{node.Syntax}.`");
}
Debug.Assert(_walkerSharedStates.Length > _incrementalSnapshots[position].snapshot.SharedStateIndex, $"Did not find shared state for {node} `{node.Syntax}`.");
RoslynDebug.Assert(_walkerSharedStates.Length > _incrementalSnapshots[position].snapshot.SharedStateIndex, $"Did not find shared state for {node} `{node.Syntax}`.");
}

internal void VerifyUpdatedSymbols()
{
foreach (var ((expr, originalSymbol), updatedSymbol) in _updatedSymbolsMap)
{
var debugText = expr?.Syntax.ToFullString() ?? originalSymbol.ToDisplayString();
Debug.Assert((object)originalSymbol != updatedSymbol, $"Recorded exact same symbol for {debugText}");
RoslynDebug.Assert((object)originalSymbol != updatedSymbol, $"Recorded exact same symbol for {debugText}");
RoslynDebug.Assert(originalSymbol is object, $"Recorded null original symbol for {debugText}");
RoslynDebug.Assert(updatedSymbol is object, $"Recorded null updated symbol for {debugText}");
Debug.Assert(AreCloseEnough(originalSymbol, updatedSymbol), @$"Symbol for `{debugText}` changed:
RoslynDebug.Assert(AreCloseEnough(originalSymbol, updatedSymbol), @$"Symbol for `{debugText}` changed:
Was {originalSymbol.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)}
Now {updatedSymbol.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)}");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1835,7 +1835,7 @@ private void SetUpdatedSymbol(BoundNode node, Symbol originalSymbol, Symbol upda

#if DEBUG
Debug.Assert(node is object);
Debug.Assert(AreCloseEnough(originalSymbol, updatedSymbol), $"Attempting to set {node.Syntax} from {originalSymbol.ToDisplayString()} to {updatedSymbol.ToDisplayString()}");
RoslynDebug.Assert(AreCloseEnough(originalSymbol, updatedSymbol), $"Attempting to set {node.Syntax} from {originalSymbol.ToDisplayString()} to {updatedSymbol.ToDisplayString()}");
#endif

if (lambdaIsExactMatch || Symbol.Equals(originalSymbol, updatedSymbol, TypeCompareKind.ConsiderEverything))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,7 @@ private void PopScope(Scope scope)
return;
}

Debug.Assert(scope == _currentScope.Parent, $"{nameof(scope)} must be {nameof(_currentScope)} or {nameof(_currentScope)}.{nameof(_currentScope.Parent)}");
RoslynDebug.Assert(scope == _currentScope.Parent, $"{nameof(scope)} must be {nameof(_currentScope)} or {nameof(_currentScope)}.{nameof(_currentScope.Parent)}");

// Since it is forbidden to jump into a scope,
// we can forget all information we have about labels in the child scope
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1117,7 +1117,7 @@ internal static bool CanBePassedByReference(BoundExpression expr)
return expr is BoundConversion { Conversion: { IsInterpolatedStringHandler: true }, Type: { IsValueType: true } };
}

Debug.Assert(expr is not BoundValuePlaceholderBase, $"Placeholder kind {expr.Kind} must be handled explicitly");
RoslynDebug.Assert(expr is not BoundValuePlaceholderBase, $"Placeholder kind {expr.Kind} must be handled explicitly");

return false;
}
Expand Down Expand Up @@ -1250,7 +1250,7 @@ public static void Validate(BoundNode node)

private void Fail(BoundNode node)
{
Debug.Assert(false, $"Bound nodes of kind {node.Kind} should not survive past local rewriting");
RoslynDebug.Assert(false, $"Bound nodes of kind {node.Kind} should not survive past local rewriting");
}
}
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ protected void AddResumableState(ResumableStateMachineStateAllocator allocator,

protected void AddStateDebugInfo(SyntaxNode node, AwaitDebugId awaitId, StateMachineState state)
{
Debug.Assert(SyntaxBindingUtilities.BindsToResumableStateMachineState(node) || SyntaxBindingUtilities.BindsToTryStatement(node), $"Unexpected syntax: {node.Kind()}");
RoslynDebug.Assert(SyntaxBindingUtilities.BindsToResumableStateMachineState(node) || SyntaxBindingUtilities.BindsToTryStatement(node), $"Unexpected syntax: {node.Kind()}");

int syntaxOffset = CurrentMethod.CalculateLocalSyntaxOffset(node.SpanStart, node.SyntaxTree);
_stateDebugInfoBuilder.Add(new StateMachineStateDebugInfo(syntaxOffset, awaitId, state));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public sealed override ImmutableArray<ParameterSymbol> Parameters
{
get
{
Debug.Assert(!_parameters.IsDefault, $"Expected {nameof(InitializeParameters)} prior to accessing this property.");
RoslynDebug.Assert(!_parameters.IsDefault, $"Expected {nameof(InitializeParameters)} prior to accessing this property.");
return _parameters.NullToEmpty();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public override ImmutableArray<TypeParameterSymbol> TypeParameters
{
get
{
Debug.Assert(!_typeParameters.IsDefault, $"Expected {nameof(SetTypeParameters)} prior to accessing this property.");
RoslynDebug.Assert(!_typeParameters.IsDefault, $"Expected {nameof(SetTypeParameters)} prior to accessing this property.");
if (_typeParameters.IsDefault)
{
return ImmutableArray<TypeParameterSymbol>.Empty;
Expand All @@ -173,7 +173,7 @@ public override ImmutableArray<ParameterSymbol> Parameters
{
get
{
Debug.Assert(!_parameters.IsDefault, $"Expected {nameof(SetParameters)} prior to accessing this property.");
RoslynDebug.Assert(!_parameters.IsDefault, $"Expected {nameof(SetParameters)} prior to accessing this property.");
if (_parameters.IsDefault)
{
return ImmutableArray<ParameterSymbol>.Empty;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@
<Compile Include="..\Portable\InternalUtilities\ReflectionUtilities.cs" />
<Compile Include="..\Portable\InternalUtilities\RoslynString.cs" />
<Compile Include="..\Portable\InternalUtilities\UnicodeCharacterUtilities.cs" />
<Compile Include="..\Portable\InternalUtilities\InterpolatedStringHandlerAttribute.cs" />
<Compile Include="..\Portable\InternalUtilities\InterpolatedStringHandlerArgumentAttribute.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="ErrorString.resx" GenerateSource="true" />
Expand Down
Loading
Loading