Skip to content

Commit

Permalink
Remove remaining prototype comments (#19392)
Browse files Browse the repository at this point in the history
* remove remaining prototype comments, add extension method tests

* fix old test, address review feedback

* ReturnType implemented on each subclass

* added more tests on non-async task returning mains

* add obsolete tests

* autoformat

* add better tests for successful task overrides
  • Loading branch information
TyOverby authored May 11, 2017
1 parent e01e55a commit b0249ee
Show file tree
Hide file tree
Showing 5 changed files with 328 additions and 52 deletions.
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
39 changes: 35 additions & 4 deletions src/Compilers/CSharp/Portable/Compiler/MethodCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,9 @@ private static MethodSymbol GetEntryPoint(CSharpCompilation compilation, PEModul

// entryPoint can be a SynthesizedEntryPointSymbol if a script is being compiled.
SynthesizedEntryPointSymbol synthesizedEntryPoint = entryPoint as SynthesizedEntryPointSymbol;
if ((object)synthesizedEntryPoint == null && compilation.ReturnsAwaitableToVoidOrInt(entryPoint, diagnostics))
if ((object)synthesizedEntryPoint == null && (entryPoint.ReturnType.IsGenericTaskType(compilation) || entryPoint.ReturnType.IsNonGenericTaskType(compilation)))
{
synthesizedEntryPoint = new SynthesizedEntryPointSymbol.AsyncForwardEntryPoint(compilation, diagnostics, entryPoint.ContainingType, entryPoint);
synthesizedEntryPoint = new SynthesizedEntryPointSymbol.AsyncForwardEntryPoint(compilation, entryPoint.ContainingType, entryPoint);
entryPoint = synthesizedEntryPoint;
if ((object)moduleBeingBuilt != null)
{
Expand All @@ -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);

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

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 @@ -341,15 +333,14 @@ internal sealed class AsyncForwardEntryPoint : SynthesizedEntryPointSymbol

private readonly ImmutableArray<ParameterSymbol> _parameters;

internal AsyncForwardEntryPoint(CSharpCompilation compilation, DiagnosticBag diagnosticBag, NamedTypeSymbol containingType, MethodSymbol userMain) :
internal AsyncForwardEntryPoint(CSharpCompilation compilation, NamedTypeSymbol containingType, MethodSymbol userMain) :
base(containingType)
{
// There should be no way for a userMain to be passed in unless it already passed the
// parameter checks for determining entrypoint validity.
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,10 @@ 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;
// The diagnostics that would be produced here will already have been captured and returned.
var droppedBag = DiagnosticBag.GetInstance();
var success = binder.GetAwaitableExpressionInfo(userMainInvocation, out _, out _, out _, out _getAwaiterGetResultCall, _userMainReturnTypeSyntax, droppedBag);
droppedBag.Free();

Debug.Assert(
ReturnType.SpecialType == SpecialType.System_Void ||
Expand All @@ -384,6 +376,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 +426,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 +514,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 +535,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

0 comments on commit b0249ee

Please sign in to comment.