From 37e8a94ac92c48e2d0298ffe4ed1d77274c6a347 Mon Sep 17 00:00:00 2001 From: Ty Overby Date: Tue, 30 Aug 2016 13:28:12 -0700 Subject: [PATCH] added a local-functionsless constructor for BoundBlock (#13408) --- src/Compilers/CSharp/Portable/Binder/Binder.cs | 4 +--- .../CSharp/Portable/Binder/Binder_Statements.cs | 2 +- .../CSharp/Portable/BoundTree/Constructors.cs | 11 +++++++---- .../CSharp/Portable/Compiler/MethodBodySynthesizer.cs | 3 --- .../CSharp/Portable/Compiler/MethodCompiler.cs | 2 +- .../CSharp/Portable/FlowAnalysis/FlowAnalysisPass.cs | 2 +- .../Lowering/LambdaRewriter/LambdaRewriter.cs | 6 +++--- .../Lowering/LocalRewriter/LocalRewriter_Block.cs | 2 +- .../LocalRewriter/LocalRewriter_ForEachStatement.cs | 7 ------- .../LocalRewriter/LocalRewriter_ForStatement.cs | 2 +- .../LocalRewriter/LocalRewriter_LockStatement.cs | 2 -- .../LocalRewriter/LocalRewriter_SwitchStatement.cs | 1 - .../LocalRewriter/LocalRewriter_UsingStatement.cs | 3 --- .../Portable/Lowering/SyntheticBoundNodeFactory.cs | 2 +- .../Synthesized/SynthesizedEntryPointSymbol.cs | 2 -- .../ExpressionCompiler/Symbols/EEConstructorSymbol.cs | 2 -- .../ExpressionCompiler/Symbols/EEMethodSymbol.cs | 2 +- 17 files changed, 18 insertions(+), 37 deletions(-) diff --git a/src/Compilers/CSharp/Portable/Binder/Binder.cs b/src/Compilers/CSharp/Portable/Binder/Binder.cs index b7fbb1403e3..cf6d869686d 100644 --- a/src/Compilers/CSharp/Portable/Binder/Binder.cs +++ b/src/Compilers/CSharp/Portable/Binder/Binder.cs @@ -755,9 +755,7 @@ internal BoundStatement WrapWithVariablesIfAny(CSharpSyntaxNode scopeDesignator, return statement; } - return new BoundBlock(statement.Syntax, locals, - ImmutableArray.Empty, - ImmutableArray.Create(statement)) + return new BoundBlock(statement.Syntax, locals, ImmutableArray.Create(statement)) { WasCompilerGenerated = true }; } diff --git a/src/Compilers/CSharp/Portable/Binder/Binder_Statements.cs b/src/Compilers/CSharp/Portable/Binder/Binder_Statements.cs index 42b04ee62ad..9997c9ae60a 100644 --- a/src/Compilers/CSharp/Portable/Binder/Binder_Statements.cs +++ b/src/Compilers/CSharp/Portable/Binder/Binder_Statements.cs @@ -3606,7 +3606,7 @@ internal BoundBlock CreateBlockFromExpression(CSharpSyntaxNode node, ImmutableAr } // Need to attach the tree for when we generate sequence points. - return new BoundBlock(node, locals, ImmutableArray.Empty, ImmutableArray.Create(statement)) { WasCompilerGenerated = node.Kind() != SyntaxKind.ArrowExpressionClause }; + return new BoundBlock(node, locals, ImmutableArray.Create(statement)) { WasCompilerGenerated = node.Kind() != SyntaxKind.ArrowExpressionClause }; } /// diff --git a/src/Compilers/CSharp/Portable/BoundTree/Constructors.cs b/src/Compilers/CSharp/Portable/BoundTree/Constructors.cs index 4946f2c8a26..8c7a1f90eb9 100644 --- a/src/Compilers/CSharp/Portable/BoundTree/Constructors.cs +++ b/src/Compilers/CSharp/Portable/BoundTree/Constructors.cs @@ -502,21 +502,24 @@ public BoundGotoStatement(SyntaxNode syntax, LabelSymbol label, bool hasErrors = internal partial class BoundBlock { + public BoundBlock(SyntaxNode syntax, ImmutableArray locals, ImmutableArray statements, bool hasErrors = false): this(syntax, locals, ImmutableArray.Empty, statements, hasErrors) + { + } + public static BoundBlock SynthesizedNoLocals(SyntaxNode syntax, BoundStatement statement) { - return new BoundBlock(syntax, ImmutableArray.Empty, ImmutableArray.Empty, - ImmutableArray.Create(statement)) + return new BoundBlock(syntax, ImmutableArray.Empty, ImmutableArray.Create(statement)) { WasCompilerGenerated = true }; } public static BoundBlock SynthesizedNoLocals(SyntaxNode syntax, ImmutableArray statements) { - return new BoundBlock(syntax, ImmutableArray.Empty, ImmutableArray.Empty, statements) { WasCompilerGenerated = true }; + return new BoundBlock(syntax, ImmutableArray.Empty, statements) { WasCompilerGenerated = true }; } public static BoundBlock SynthesizedNoLocals(SyntaxNode syntax, params BoundStatement[] statements) { - return new BoundBlock(syntax, ImmutableArray.Empty, ImmutableArray.Empty, statements.AsImmutableOrNull()) { WasCompilerGenerated = true }; + return new BoundBlock(syntax, ImmutableArray.Empty, statements.AsImmutableOrNull()) { WasCompilerGenerated = true }; } } diff --git a/src/Compilers/CSharp/Portable/Compiler/MethodBodySynthesizer.cs b/src/Compilers/CSharp/Portable/Compiler/MethodBodySynthesizer.cs index 80dc5bf8e09..605f7ca2030 100644 --- a/src/Compilers/CSharp/Portable/Compiler/MethodBodySynthesizer.cs +++ b/src/Compilers/CSharp/Portable/Compiler/MethodBodySynthesizer.cs @@ -498,7 +498,6 @@ internal static BoundBlock ConstructFieldLikeEventAccessorBody_Regular(SourceEve return new BoundBlock(syntax, locals: tmps.AsImmutable(), - localFunctions: ImmutableArray.Empty, statements: ImmutableArray.Create( tmp0Init, loopStart, @@ -542,7 +541,6 @@ internal static BoundBlock ConstructDestructorBody(MethodSymbol method, BoundBlo return new BoundBlock( syntax, ImmutableArray.Empty, - ImmutableArray.Empty, ImmutableArray.Create( new BoundTryStatement( syntax, @@ -551,7 +549,6 @@ internal static BoundBlock ConstructDestructorBody(MethodSymbol method, BoundBlo new BoundBlock( syntax, ImmutableArray.Empty, - ImmutableArray.Empty, ImmutableArray.Create( baseFinalizeCall) ) diff --git a/src/Compilers/CSharp/Portable/Compiler/MethodCompiler.cs b/src/Compilers/CSharp/Portable/Compiler/MethodCompiler.cs index 11754af13f5..b963c604aaa 100644 --- a/src/Compilers/CSharp/Portable/Compiler/MethodCompiler.cs +++ b/src/Compilers/CSharp/Portable/Compiler/MethodCompiler.cs @@ -854,7 +854,7 @@ public override object VisitField(FieldSymbol symbol, TypeCompilationState argum if (methodSymbol.IsScriptConstructor) { - body = new BoundBlock(methodSymbol.GetNonNullSyntaxNode(), ImmutableArray.Empty, ImmutableArray.Empty, ImmutableArray.Empty) { WasCompilerGenerated = true }; + body = new BoundBlock(methodSymbol.GetNonNullSyntaxNode(), ImmutableArray.Empty, ImmutableArray.Empty) { WasCompilerGenerated = true }; } else if (methodSymbol.IsScriptInitializer) { diff --git a/src/Compilers/CSharp/Portable/FlowAnalysis/FlowAnalysisPass.cs b/src/Compilers/CSharp/Portable/FlowAnalysis/FlowAnalysisPass.cs index 7174e35bd6f..f5855486af4 100644 --- a/src/Compilers/CSharp/Portable/FlowAnalysis/FlowAnalysisPass.cs +++ b/src/Compilers/CSharp/Portable/FlowAnalysis/FlowAnalysisPass.cs @@ -58,7 +58,7 @@ internal class FlowAnalysisPass var trailingExpression = new BoundDefaultOperator(method.GetNonNullSyntaxNode(), submissionResultType); var newStatements = block.Statements.Add(new BoundReturnStatement(trailingExpression.Syntax, RefKind.None, trailingExpression)); - block = new BoundBlock(block.Syntax, ImmutableArray.Empty, ImmutableArray.Empty, newStatements) { WasCompilerGenerated = true }; + block = new BoundBlock(block.Syntax, ImmutableArray.Empty, newStatements) { WasCompilerGenerated = true }; #if DEBUG // It should not be necessary to repeat analysis after adding this node, because adding a trailing // return in cases where one was missing should never produce different Diagnostics. diff --git a/src/Compilers/CSharp/Portable/Lowering/LambdaRewriter/LambdaRewriter.cs b/src/Compilers/CSharp/Portable/Lowering/LambdaRewriter/LambdaRewriter.cs index 0d30c291af4..522716c6ff3 100644 --- a/src/Compilers/CSharp/Portable/Lowering/LambdaRewriter/LambdaRewriter.cs +++ b/src/Compilers/CSharp/Portable/Lowering/LambdaRewriter/LambdaRewriter.cs @@ -267,7 +267,7 @@ private BoundStatement AddStatementsIfNeeded(BoundStatement body) if (_addedLocals != null) { _addedStatements.Add(body); - body = new BoundBlock(body.Syntax, _addedLocals.ToImmutableAndFree(), ImmutableArray.Empty, _addedStatements.ToImmutableAndFree()) { WasCompilerGenerated = true }; + body = new BoundBlock(body.Syntax, _addedLocals.ToImmutableAndFree(), _addedStatements.ToImmutableAndFree()) { WasCompilerGenerated = true }; _addedLocals = null; _addedStatements = null; } @@ -1046,7 +1046,7 @@ public override BoundNode VisitStatementList(BoundStatementList node) newStatements.Add((BoundStatement)this.Visit(s)); } - return new BoundBlock(node.Syntax, newLocals.ToImmutableAndFree(), ImmutableArray.Empty, newStatements.ToImmutableAndFree(), node.HasErrors); + return new BoundBlock(node.Syntax, newLocals.ToImmutableAndFree(), newStatements.ToImmutableAndFree(), node.HasErrors); }); } else @@ -1067,7 +1067,7 @@ public override BoundNode VisitSwitchStatement(BoundSwitchStatement node) InsertAndFreePrologue(newStatements, prologue); newStatements.Add((BoundStatement)base.VisitSwitchStatement(node)); - return new BoundBlock(node.Syntax, newLocals.ToImmutableAndFree(), ImmutableArray.Empty, newStatements.ToImmutableAndFree(), node.HasErrors); + return new BoundBlock(node.Syntax, newLocals.ToImmutableAndFree(), newStatements.ToImmutableAndFree(), node.HasErrors); }); } else diff --git a/src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_Block.cs b/src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_Block.cs index 0de52e2119c..44a3453ee2d 100644 --- a/src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_Block.cs +++ b/src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_Block.cs @@ -44,7 +44,7 @@ public override BoundNode VisitBlock(BoundBlock node) public override BoundNode VisitNoOpStatement(BoundNoOpStatement node) { return (node.WasCompilerGenerated || !this.Instrument) - ? new BoundBlock(node.Syntax, ImmutableArray.Empty, ImmutableArray.Empty, ImmutableArray.Empty) + ? new BoundBlock(node.Syntax, ImmutableArray.Empty, ImmutableArray.Empty) : _instrumenter.InstrumentNoOpStatement(node, node); } } diff --git a/src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_ForEachStatement.cs b/src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_ForEachStatement.cs index da825de8dbe..3fa5b2acdbc 100644 --- a/src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_ForEachStatement.cs +++ b/src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_ForEachStatement.cs @@ -209,7 +209,6 @@ private BoundStatement RewriteEnumeratorForEachStatement(BoundForEachStatement n finallyBlockOpt = new BoundBlock(forEachSyntax, locals: ImmutableArray.Empty, - localFunctions: ImmutableArray.Empty, statements: ImmutableArray.Create(disposeStmt)); } else @@ -261,7 +260,6 @@ private BoundStatement RewriteEnumeratorForEachStatement(BoundForEachStatement n // if (d != null) d.Dispose(); finallyBlockOpt = new BoundBlock(forEachSyntax, locals: ImmutableArray.Create(disposableVar), - localFunctions: ImmutableArray.Empty, statements: ImmutableArray.Create(disposableVarDecl, ifStmt)); } @@ -277,7 +275,6 @@ private BoundStatement RewriteEnumeratorForEachStatement(BoundForEachStatement n BoundStatement tryFinally = new BoundTryStatement(forEachSyntax, tryBlock: new BoundBlock(forEachSyntax, locals: ImmutableArray.Empty, - localFunctions: ImmutableArray.Empty, statements: ImmutableArray.Create(whileLoop)), catchBlocks: ImmutableArray.Empty, finallyBlockOpt: finallyBlockOpt); @@ -288,7 +285,6 @@ private BoundStatement RewriteEnumeratorForEachStatement(BoundForEachStatement n result = new BoundBlock( syntax: forEachSyntax, locals: ImmutableArray.Create(enumeratorVar), - localFunctions: ImmutableArray.Empty, statements: ImmutableArray.Create(enumeratorVarDecl, tryFinally)); } else @@ -301,7 +297,6 @@ private BoundStatement RewriteEnumeratorForEachStatement(BoundForEachStatement n result = new BoundBlock( syntax: forEachSyntax, locals: ImmutableArray.Create(enumeratorVar), - localFunctions: ImmutableArray.Empty, statements: ImmutableArray.Create(enumeratorVarDecl, whileLoop)); } @@ -549,7 +544,6 @@ private BoundStatement RewriteStringForEachStatement(BoundForEachStatement node) return new BoundBlock( forEachSyntax, locals: iterationVariables, - localFunctions: ImmutableArray.Empty, statements: ImmutableArray.Create(iteratorVariableInitialization, rewrittenBody)); } @@ -865,7 +859,6 @@ private BoundStatement RewriteMultiDimensionalArrayForEachStatement(BoundForEach BoundStatement result = new BoundBlock( forEachSyntax, ImmutableArray.Create(arrayVar).Concat(upperVar.AsImmutableOrNull()), - ImmutableArray.Empty, ImmutableArray.Create(arrayVarDecl).Concat(upperVarDecl.AsImmutableOrNull()).Add(forLoop)); InstrumentForEachStatement(node, ref result); diff --git a/src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_ForStatement.cs b/src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_ForStatement.cs index 49d8d046682..eb2e9cf0ce1 100644 --- a/src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_ForStatement.cs +++ b/src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_ForStatement.cs @@ -168,7 +168,7 @@ public override BoundNode VisitForStatement(BoundForStatement node) statementBuilder.Add(new BoundLabelStatement(syntax, breakLabel)); var statements = statementBuilder.ToImmutableAndFree(); - return new BoundBlock(syntax, outerLocals, ImmutableArray.Empty, statements, hasErrors); + return new BoundBlock(syntax, outerLocals, statements, hasErrors); } } } diff --git a/src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_LockStatement.cs b/src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_LockStatement.cs index 822726ace43..f458e9151e8 100644 --- a/src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_LockStatement.cs +++ b/src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_LockStatement.cs @@ -120,7 +120,6 @@ public override BoundNode VisitLockStatement(BoundLockStatement node) return new BoundBlock( lockSyntax, ImmutableArray.Create(boundLockTemp.LocalSymbol, boundLockTakenTemp.LocalSymbol), - ImmutableArray.Empty, ImmutableArray.Create( InstrumentLockTargetCapture(node, boundLockTempInit), boundLockTakenTempInit, @@ -171,7 +170,6 @@ public override BoundNode VisitLockStatement(BoundLockStatement node) return new BoundBlock( lockSyntax, ImmutableArray.Create(boundLockTemp.LocalSymbol), - ImmutableArray.Empty, ImmutableArray.Create( InstrumentLockTargetCapture(node, boundLockTempInit), enterCall, diff --git a/src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_SwitchStatement.cs b/src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_SwitchStatement.cs index c30ea504f63..3eae57e0040 100644 --- a/src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_SwitchStatement.cs +++ b/src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_SwitchStatement.cs @@ -184,7 +184,6 @@ public override BoundNode VisitSwitchStatement(BoundSwitchStatement node) return new BoundBlock( syntax, locals: (object)tempLocal == null ? ImmutableArray.Empty : ImmutableArray.Create(tempLocal), - localFunctions: ImmutableArray.Empty, statements: statementBuilder.ToImmutableAndFree()); } diff --git a/src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_UsingStatement.cs b/src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_UsingStatement.cs index b35a94f8d17..0c5cc767481 100644 --- a/src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_UsingStatement.cs +++ b/src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_UsingStatement.cs @@ -56,7 +56,6 @@ public override BoundNode VisitUsingStatement(BoundUsingStatement node) return new BoundBlock( usingSyntax, node.Locals, - ImmutableArray.Empty, ImmutableArray.Create(result)); } } @@ -142,7 +141,6 @@ private BoundBlock RewriteExpressionUsingStatement(BoundUsingStatement node, Bou return new BoundBlock( syntax: usingSyntax, locals: node.Locals.Add(boundTemp.LocalSymbol), - localFunctions: ImmutableArray.Empty, statements: ImmutableArray.Create(expressionStatement, tryFinally)); } @@ -192,7 +190,6 @@ private BoundBlock RewriteDeclarationUsingStatement(SyntaxNode usingSyntax, Boun return new BoundBlock( syntax: usingSyntax, locals: ImmutableArray.Create(boundTemp.LocalSymbol), //localSymbol will be declared by an enclosing block - localFunctions: ImmutableArray.Empty, statements: ImmutableArray.Create( rewrittenDeclaration, new BoundExpressionStatement(declarationSyntax, tempAssignment), diff --git a/src/Compilers/CSharp/Portable/Lowering/SyntheticBoundNodeFactory.cs b/src/Compilers/CSharp/Portable/Lowering/SyntheticBoundNodeFactory.cs index 95db33d5761..1e43028d57b 100644 --- a/src/Compilers/CSharp/Portable/Lowering/SyntheticBoundNodeFactory.cs +++ b/src/Compilers/CSharp/Portable/Lowering/SyntheticBoundNodeFactory.cs @@ -408,7 +408,7 @@ public BoundBlock Block(ImmutableArray locals, params BoundStatemen public BoundBlock Block(ImmutableArray locals, ImmutableArray statements) { - return new BoundBlock(Syntax, locals, ImmutableArray.Empty, statements) { WasCompilerGenerated = true }; + return new BoundBlock(Syntax, locals, statements) { WasCompilerGenerated = true }; } public BoundBlock Block(ImmutableArray locals, ImmutableArray localFunctions, params BoundStatement[] statements) diff --git a/src/Compilers/CSharp/Portable/Symbols/Synthesized/SynthesizedEntryPointSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Synthesized/SynthesizedEntryPointSymbol.cs index 763bfd94b71..d6617574b5f 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Synthesized/SynthesizedEntryPointSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Synthesized/SynthesizedEntryPointSymbol.cs @@ -377,7 +377,6 @@ internal override BoundBlock CreateBody() return new BoundBlock(syntax, ImmutableArray.Create(scriptLocal.LocalSymbol), - ImmutableArray.Empty, ImmutableArray.Create( // var script = new Script(); new BoundExpressionStatement( @@ -497,7 +496,6 @@ internal override BoundBlock CreateBody() return new BoundBlock(syntax, ImmutableArray.Create(submissionLocal.LocalSymbol), - ImmutableArray.Empty, ImmutableArray.Create(submissionAssignment, returnStatement)) { WasCompilerGenerated = true }; } diff --git a/src/ExpressionEvaluator/CSharp/Source/ExpressionCompiler/Symbols/EEConstructorSymbol.cs b/src/ExpressionEvaluator/CSharp/Source/ExpressionCompiler/Symbols/EEConstructorSymbol.cs index 4c232f3e309..8207923ab49 100644 --- a/src/ExpressionEvaluator/CSharp/Source/ExpressionCompiler/Symbols/EEConstructorSymbol.cs +++ b/src/ExpressionEvaluator/CSharp/Source/ExpressionCompiler/Symbols/EEConstructorSymbol.cs @@ -18,7 +18,6 @@ internal EEConstructorSymbol(NamedTypeSymbol containingType) internal override void GenerateMethodBody(TypeCompilationState compilationState, DiagnosticBag diagnostics) { var noLocals = ImmutableArray.Empty; - var noLocalFunctions = ImmutableArray.Empty; var initializerInvocation = MethodCompiler.BindConstructorInitializer(this, diagnostics, compilationState.Compilation); var syntax = initializerInvocation.Syntax; @@ -26,7 +25,6 @@ internal override void GenerateMethodBody(TypeCompilationState compilationState, new BoundBlock( syntax, noLocals, - noLocalFunctions, ImmutableArray.Create( new BoundExpressionStatement(syntax, initializerInvocation), new BoundReturnStatement(syntax, RefKind.None, null)))); diff --git a/src/ExpressionEvaluator/CSharp/Source/ExpressionCompiler/Symbols/EEMethodSymbol.cs b/src/ExpressionEvaluator/CSharp/Source/ExpressionCompiler/Symbols/EEMethodSymbol.cs index d1c1c0eac06..add246f2455 100644 --- a/src/ExpressionEvaluator/CSharp/Source/ExpressionCompiler/Symbols/EEMethodSymbol.cs +++ b/src/ExpressionEvaluator/CSharp/Source/ExpressionCompiler/Symbols/EEMethodSymbol.cs @@ -492,7 +492,7 @@ internal override void GenerateMethodBody(TypeCompilationState compilationState, } localsSet.Free(); - body = new BoundBlock(syntax, localsBuilder.ToImmutableAndFree(), ImmutableArray.Empty, statementsBuilder.ToImmutableAndFree()) { WasCompilerGenerated = true }; + body = new BoundBlock(syntax, localsBuilder.ToImmutableAndFree(), statementsBuilder.ToImmutableAndFree()) { WasCompilerGenerated = true }; Debug.Assert(!diagnostics.HasAnyErrors()); Debug.Assert(!body.HasErrors); -- GitLab