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

Remove remaining prototype comments #19392

Merged
merged 7 commits into from
May 11, 2017
Merged
Show file tree
Hide file tree
Changes from 4 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
Original file line number Diff line number Diff line change
Expand Up @@ -1512,9 +1512,8 @@ bool CheckValid(MethodSymbol candidate, bool isCandidate, DiagnosticBag specific
{
foreach (var (IsValid, Candidate, SpecificDiagnostics) in taskEntryPoints)
{
// PROTOTYPE(async-main): Get the diagnostic to point to a smaller syntax piece.
if (CheckValid(Candidate, IsValid, SpecificDiagnostics) &&
CheckFeatureAvailability(Candidate.GetNonNullSyntaxNode(), MessageID.IDS_FeatureAsyncMain, diagnostics))
CheckFeatureAvailability(Candidate.ExtractReturnTypeSyntax(), MessageID.IDS_FeatureAsyncMain, diagnostics))
{
diagnostics.AddRange(SpecificDiagnostics);
viableEntryPoints.Add(Candidate);
Expand Down Expand Up @@ -1611,7 +1610,6 @@ internal bool ReturnsAwaitableToVoidOrInt(MethodSymbol method, DiagnosticBag dia

var syntax = method.ExtractReturnTypeSyntax();
var dumbInstance = new BoundLiteral(syntax, ConstantValue.Null, method.ReturnType);
// PROTOTYPE(async-main): We might need to adjust the containing member of the binder to be the Main method
var binder = GetBinder(syntax);
BoundExpression result;
var success = binder.GetAwaitableExpressionInfo(dumbInstance, out _, out _, out _, out result, syntax, diagnostics);
Expand Down
35 changes: 33 additions & 2 deletions src/Compilers/CSharp/Portable/Compiler/MethodCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -221,13 +221,44 @@ private static MethodSymbol GetEntryPoint(CSharpCompilation compilation, PEModul
!hasDeclarationErrors &&
!diagnostics.HasAnyErrors())
{
var body = synthesizedEntryPoint.CreateBody();
BoundStatement body = synthesizedEntryPoint.CreateBody();

var dynamicAnalysisSpans = ImmutableArray<SourceSpan>.Empty;
VariableSlotAllocator lazyVariableSlotAllocator = null;
var lambdaDebugInfoBuilder = ArrayBuilder<LambdaDebugInfo>.GetInstance();
var closureDebugInfoBuilder = ArrayBuilder<ClosureDebugInfo>.GetInstance();
StateMachineTypeSymbol stateMachineTypeOpt = null;
const int methodOrdinal = -1;

var loweredBody = LowerBodyOrInitializer(
synthesizedEntryPoint,
methodOrdinal,
body,
null,
new TypeCompilationState(synthesizedEntryPoint.ContainingType, compilation, moduleBeingBuilt),
false ,
null,
ref dynamicAnalysisSpans,
diagnostics,
ref lazyVariableSlotAllocator,
lambdaDebugInfoBuilder,
closureDebugInfoBuilder,
out stateMachineTypeOpt);
Copy link
Member

Choose a reason for hiding this comment

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

Could we call LocalRewriter.Rewrite() instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Yes, the same method that LowerBodyOrInitializer calls. It looks like LowerBodyOrInitializer handles extra cases (await, local functions, iterators) that are not needed here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My understanding is that LowerBodyOrInitializer is the main entrypoint to lowering a method body, so even though all of its functionality isn't used.


Debug.Assert((object)lazyVariableSlotAllocator == null);
Debug.Assert((object)stateMachineTypeOpt == null);
Debug.Assert(dynamicAnalysisSpans.IsEmpty);
Debug.Assert(lambdaDebugInfoBuilder.IsEmpty());
Debug.Assert(closureDebugInfoBuilder.IsEmpty());
Copy link
Member

@cston cston May 10, 2017

Choose a reason for hiding this comment

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

ArrayBuilder instances and diagsForCurrentMethod are not freed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.


lambdaDebugInfoBuilder.Free();
closureDebugInfoBuilder.Free();

var emittedBody = GenerateMethodBody(
moduleBeingBuilt,
synthesizedEntryPoint,
methodOrdinal,
body,
loweredBody,
ImmutableArray<LambdaDebugInfo>.Empty,
ImmutableArray<ClosureDebugInfo>.Empty,
stateMachineTypeOpt: null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ internal abstract class SynthesizedEntryPointSymbol : MethodSymbol
internal const string FactoryName = "<Factory>";

private readonly NamedTypeSymbol _containingType;
// PROTOTYPE(async-main): remove this and move it out into inheriting classes?
private TypeSymbol _returnType;

internal static SynthesizedEntryPointSymbol Create(SynthesizedInteractiveInitializerMethod initializerMethod, DiagnosticBag diagnostics)
{
Expand Down Expand Up @@ -57,12 +55,11 @@ internal static SynthesizedEntryPointSymbol Create(SynthesizedInteractiveInitial
}
}

private SynthesizedEntryPointSymbol(NamedTypeSymbol containingType, TypeSymbol returnType = null)
private SynthesizedEntryPointSymbol(NamedTypeSymbol containingType)
{
Debug.Assert((object)containingType != null);

_containingType = containingType;
_returnType = returnType;
}

internal override bool GenerateDebugInfo
Expand Down Expand Up @@ -130,11 +127,6 @@ internal override RefKind RefKind
get { return RefKind.None; }
}

public override TypeSymbol ReturnType
{
get { return _returnType; }
}

public override ImmutableArray<CustomModifier> ReturnTypeCustomModifiers
{
get { return ImmutableArray<CustomModifier>.Empty; }
Expand Down Expand Up @@ -162,7 +154,7 @@ public override int Arity

public override bool ReturnsVoid
{
get { return _returnType.SpecialType == SpecialType.System_Void; }
get { return ReturnType.SpecialType == SpecialType.System_Void; }
}

public override MethodKind MethodKind
Expand Down Expand Up @@ -349,7 +341,6 @@ internal AsyncForwardEntryPoint(CSharpCompilation compilation, DiagnosticBag dia
Debug.Assert(userMain.ParameterCount == 0 || userMain.ParameterCount == 1);

_userMainReturnTypeSyntax = userMain.ExtractReturnTypeSyntax();
// PROTOTYPE(async-main): we might need to adjust the containing member of the binder to be the Main method.
var binder = compilation.GetBinder(_userMainReturnTypeSyntax);
_parameters = SynthesizedParameterSymbol.DeriveParameters(userMain, this);

Expand All @@ -371,9 +362,7 @@ internal AsyncForwardEntryPoint(CSharpCompilation compilation, DiagnosticBag dia
type: userMain.ReturnType)
{ WasCompilerGenerated = true };

// PROTOTYPE(async-main): lower the tree.
var success = binder.GetAwaitableExpressionInfo(userMainInvocation, out _, out _, out _, out _getAwaiterGetResultCall, _userMainReturnTypeSyntax, diagnosticBag);
_returnType = _getAwaiterGetResultCall.Type;

Debug.Assert(
ReturnType.SpecialType == SpecialType.System_Void ||
Expand All @@ -384,6 +373,8 @@ internal AsyncForwardEntryPoint(CSharpCompilation compilation, DiagnosticBag dia

public override ImmutableArray<ParameterSymbol> Parameters => _parameters;

public override TypeSymbol ReturnType => _getAwaiterGetResultCall.Type;

internal override BoundBlock CreateBody()
{
var syntax = _userMainReturnTypeSyntax;
Expand Down Expand Up @@ -432,21 +423,25 @@ private sealed class ScriptEntryPoint : SynthesizedEntryPointSymbol
{
private readonly MethodSymbol _getAwaiterMethod;
private readonly MethodSymbol _getResultMethod;
private readonly TypeSymbol _returnType;

internal ScriptEntryPoint(NamedTypeSymbol containingType, TypeSymbol returnType, MethodSymbol getAwaiterMethod, MethodSymbol getResultMethod) :
base(containingType, returnType)
base(containingType)
{
Debug.Assert(containingType.IsScriptClass);
Debug.Assert(returnType.SpecialType == SpecialType.System_Void);

_getAwaiterMethod = getAwaiterMethod;
_getResultMethod = getResultMethod;
_returnType = returnType;
}

public override string Name => MainName;

public override ImmutableArray<ParameterSymbol> Parameters => ImmutableArray<ParameterSymbol>.Empty;

public override TypeSymbol ReturnType => _returnType;

// private static void <Main>()
// {
// var script = new Script();
Expand Down Expand Up @@ -516,13 +511,15 @@ internal override BoundBlock CreateBody()
private sealed class SubmissionEntryPoint : SynthesizedEntryPointSymbol
{
private readonly ImmutableArray<ParameterSymbol> _parameters;
private readonly TypeSymbol _returnType;

internal SubmissionEntryPoint(NamedTypeSymbol containingType, TypeSymbol returnType, TypeSymbol submissionArrayType) :
base(containingType, returnType)
base(containingType)
{
Debug.Assert(containingType.IsSubmissionClass);
Debug.Assert(returnType.SpecialType != SpecialType.System_Void);
_parameters = ImmutableArray.Create<ParameterSymbol>(SynthesizedParameterSymbol.Create(this, submissionArrayType, 0, RefKind.None, "submissionArray"));
_returnType = returnType;
}

public override string Name
Expand All @@ -535,6 +532,8 @@ public override ImmutableArray<ParameterSymbol> Parameters
get { return _parameters; }
}

public override TypeSymbol ReturnType => _returnType;

// private static T <Factory>(object[] submissionArray)
// {
// var submission = new Submission#N(submissionArray);
Expand Down
Loading