提交 3fc4726d 编写于 作者: A Austin Wise 提交者: Julien Couvreur

Check for InsufficientExecutionStackException by type rather than by name. (#30817)

上级 4fd5cfc3
......@@ -224,7 +224,7 @@ private BoundExpression VisitExpressionWithStackGuard(BoundExpression node)
{
return VisitExpressionWithoutStackGuard(node);
}
catch (Exception ex) when (StackGuard.IsInsufficientExecutionStackException(ex))
catch (InsufficientExecutionStackException ex)
{
throw new CancelledByStackGuardException(ex, node);
}
......
......@@ -75,7 +75,7 @@ private void EmitExpressionCoreWithStackGuard(BoundExpression expression, bool u
EmitExpressionCore(expression, used);
Debug.Assert(_recursionDepth == 1);
}
catch (Exception ex) when (StackGuard.IsInsufficientExecutionStackException(ex))
catch (InsufficientExecutionStackException)
{
_diagnostics.Add(ErrorCode.ERR_InsufficientStack,
BoundTreeVisitor.CancelledByStackGuardException.GetTooLongOrComplexExpressionErrorLocation(expression));
......
......@@ -364,7 +364,7 @@ private void EmitCondBranchCoreWithStackGuard(BoundExpression condition, ref obj
EmitCondBranchCore(condition, ref dest, sense);
Debug.Assert(_recursionDepth == 1);
}
catch (Exception ex) when (StackGuard.IsInsufficientExecutionStackException(ex))
catch (InsufficientExecutionStackException)
{
_diagnostics.Add(ErrorCode.ERR_InsufficientStack,
BoundTreeVisitor.CancelledByStackGuardException.GetTooLongOrComplexExpressionErrorLocation(condition));
......
......@@ -522,7 +522,7 @@ private BoundExpression VisitExpressionCoreWithStackGuard(BoundExpression node,
Debug.Assert(_recursionDepth == 1);
return result;
}
catch (Exception ex) when (StackGuard.IsInsufficientExecutionStackException(ex))
catch (InsufficientExecutionStackException ex)
{
throw new CancelledByStackGuardException(ex, node);
}
......
......@@ -280,7 +280,7 @@ private BoundExpression VisitExpressionWithStackGuard(BoundExpression node)
{
return VisitExpressionWithoutStackGuard(node);
}
catch (Exception ex) when (StackGuard.IsInsufficientExecutionStackException(ex))
catch (InsufficientExecutionStackException ex)
{
throw new BoundTreeVisitor.CancelledByStackGuardException(ex, node);
}
......
......@@ -878,7 +878,7 @@ public static void Validate(BoundNode node)
{
new LocalRewritingValidator().Visit(node);
}
catch (Exception ex) when (StackGuard.IsInsufficientExecutionStackException(ex))
catch (InsufficientExecutionStackException)
{
// Intentionally ignored to let the overflow get caught in a more crucial visitor
}
......
......@@ -344,7 +344,7 @@ internal CompilationUnitSyntax ParseCompilationUnitCore()
{
return parseFunc();
}
catch (Exception ex) when (StackGuard.IsInsufficientExecutionStackException(ex))
catch (InsufficientExecutionStackException)
{
return CreateForGlobalFailure(lexer.TextWindow.Position, createEmptyNodeFunc());
}
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Diagnostics;
using System.Runtime.CompilerServices;
namespace Microsoft.CodeAnalysis
......@@ -10,6 +9,15 @@ internal static class StackGuard
{
public const int MaxUncheckedRecursionDepth = 20;
/// <summary>
/// Ensures that the remaining stack space is large enough to execute
/// the average function.
/// </summary>
/// <param name="recursionDepth">how many times the calling function has recursed</param>
/// <exception cref="InsufficientExecutionStackException">
/// The available stack space is insufficient to execute
/// the average function.
/// </exception>
public static void EnsureSufficientExecutionStack(int recursionDepth)
{
if (recursionDepth > MaxUncheckedRecursionDepth)
......@@ -17,12 +25,5 @@ public static void EnsureSufficientExecutionStack(int recursionDepth)
RuntimeHelpers.EnsureSufficientExecutionStack();
}
}
// TODO (DevDiv workitem 966425): Replace exception name test with a type test once the type
// is available in the PCL
public static bool IsInsufficientExecutionStackException(Exception ex)
{
return ex.GetType().Name == "InsufficientExecutionStackException";
}
}
}
......@@ -193,7 +193,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
Private Function VisitExpressionWithStackGuard(node As BoundExpression) As BoundExpression
Try
Return VisitExpressionWithoutStackGuard(node)
Catch ex As Exception When StackGuard.IsInsufficientExecutionStackException(ex)
Catch ex As InsufficientExecutionStackException
Throw New CancelledByStackGuardException(ex, node)
End Try
End Function
......
......@@ -60,7 +60,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeGen
EmitExpressionCore(expression, used)
Debug.Assert(_recursionDepth = 1)
Catch ex As Exception When StackGuard.IsInsufficientExecutionStackException(ex)
Catch ex As InsufficientExecutionStackException
_diagnostics.Add(ERRID.ERR_TooLongOrComplexExpression,
BoundTreeVisitor.CancelledByStackGuardException.GetTooLongOrComplexExpressionErrorLocation(expression))
Throw New EmitCancelledException()
......
......@@ -657,7 +657,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeGen
EmitCondBranchCore(condition, lazyDest, sense)
Debug.Assert(_recursionDepth = 1)
Catch ex As Exception When StackGuard.IsInsufficientExecutionStackException(ex)
Catch ex As InsufficientExecutionStackException
_diagnostics.Add(ERRID.ERR_TooLongOrComplexExpression,
BoundTreeVisitor.CancelledByStackGuardException.GetTooLongOrComplexExpressionErrorLocation(condition))
Throw New EmitCancelledException()
......
......@@ -196,7 +196,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeGen
Return result
Catch ex As Exception When StackGuard.IsInsufficientExecutionStackException(ex)
Catch ex As InsufficientExecutionStackException
Throw New CancelledByStackGuardException(ex, node)
End Try
End Function
......
......@@ -307,7 +307,7 @@ lSelect:
Private Function VisitExpressionWithStackGuard(node As BoundExpression) As BoundExpression
Try
Return VisitExpressionWithoutStackGuard(node)
Catch ex As Exception When StackGuard.IsInsufficientExecutionStackException(ex)
Catch ex As InsufficientExecutionStackException
Throw New BoundTreeVisitor.CancelledByStackGuardException(ex, node)
End Try
End Function
......
......@@ -165,9 +165,6 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
End If
Return expression
' TODO (DevDiv workitem 966425): Replace exception name test with a type test once the type
' Is available in the PCL
Finally
_recursionDepth -= 1
End Try
......
......@@ -514,7 +514,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
Try
Return parseFunc()
Catch ex As Exception When StackGuard.IsInsufficientExecutionStackException(ex)
Catch ex As InsufficientExecutionStackException
Return CreateForInsufficientStack(restorePoint, defaultFunc())
End Try
End Function
......
......@@ -144,7 +144,7 @@ public static RegexTree TryParse(ImmutableArray<VirtualChar> text, RegexOptions
text, options, captureNames, captureNumbers).ParseTree();
return tree2;
}
catch (Exception e) when (StackGuard.IsInsufficientExecutionStackException(e))
catch (InsufficientExecutionStackException)
{
return null;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册