Skip to content

Commit

Permalink
Merge remote-tracking branch 'dotnet/features/ioperation' into remove…
Browse files Browse the repository at this point in the history
…-literal-text

* dotnet/features/ioperation:
  Fix NamedArgumentInParameterOrderWithDefaultValue test for new IOperation output.
  EnC and EE cleanup (dotnet#21226)
  Fix crash when encountering a parenthesized expression when converting an if to a switch.
  this makes OOM to crash OOP process. this won't crash VS, instead it will show info bar and notify users to close VS and re-open.
  Turn on ref assemblies in all projects (dotnet#21346)
  Re-baseline some emit tests
  Move MakeFrames logic into Analysis
  Use langver=latest for scripting (dotnet#21331)
  Enable skipped tests and fix them (dotnet#21335)
  Replace project reference with linked file
  removed left out from deleted esent code.
  • Loading branch information
333fred committed Aug 10, 2017
2 parents 45a2a89 + 74cf8be commit 6335890
Show file tree
Hide file tree
Showing 49 changed files with 1,349 additions and 733 deletions.
1 change: 1 addition & 0 deletions build/Targets/Settings.props
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<RoslynPortableTargetFrameworks>net46;netcoreapp2.0</RoslynPortableTargetFrameworks>

<Features>strict,IOperation</Features>
<ProduceReferenceAssembly>true</ProduceReferenceAssembly>
<Configuration Condition="'$(Configuration)' == ''">Debug</Configuration>
<SignAssembly>true</SignAssembly>
<!-- The new SDK introduced a GenerateAssemblyInfo target, which is disabled by GenerateAssemblyInfo=false.
Expand Down
4 changes: 4 additions & 0 deletions build/scripts/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,10 @@ function Test-XUnit() {
# Exclude out the multi-targetted netcore app projects
$dlls = $dlls | ?{ -not ($_.FullName -match ".*netcoreapp.*") }

# Exclude out the ref assemblies
$dlls = $dlls | ?{ -not ($_.FullName -match ".*\\ref\\.*") }
$dlls = $dlls | ?{ -not ($_.FullName -match ".*/ref/.*") }

if ($cibuild) {
# Use a 50 minute timeout on CI
$args += " -xml -timeout:50"
Expand Down
2 changes: 1 addition & 1 deletion src/Compilers/CSharp/Portable/CSharpParseOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public override IEnumerable<string> PreprocessorSymbolNames
LanguageVersion languageVersion,
DocumentationMode documentationMode,
SourceCodeKind kind,
IEnumerable<string> preprocessorSymbols,
ImmutableArray<string> preprocessorSymbols,
IReadOnlyDictionary<string, string> features)
: base(kind, documentationMode)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ internal MethodWithBody(MethodSymbol method, BoundStatement body, ImportChain im

public readonly CSharpCompilation Compilation;

public LambdaFrame StaticLambdaFrame;
public ClosureEnvironment StaticLambdaFrame;

/// <summary>
/// A graph of method->method references for this(...) constructor initializers.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,16 +183,13 @@ internal override bool TryGetPropertyHandle(Cci.IPropertyDefinition def, out Pro
awaiterSlotCount = maxAwaiterSlotIndex + 1;
}

protected override ImmutableArray<EncLocalInfo> TryGetLocalSlotMapFromMetadata(MethodDefinitionHandle handle, EditAndContinueMethodDebugInformation debugInfo)
protected override ImmutableArray<EncLocalInfo> GetLocalSlotMapFromMetadata(StandaloneSignatureHandle handle, EditAndContinueMethodDebugInformation debugInfo)
{
ImmutableArray<LocalInfo<TypeSymbol>> slotMetadata;
if (!_metadataDecoder.TryGetLocals(handle, out slotMetadata))
{
return default(ImmutableArray<EncLocalInfo>);
}
Debug.Assert(!handle.IsNil);

var result = CreateLocalSlotMap(debugInfo, slotMetadata);
Debug.Assert(result.Length == slotMetadata.Length);
var localInfos = _metadataDecoder.GetLocalsOrThrow(handle);
var result = CreateLocalSlotMap(debugInfo, localInfos);
Debug.Assert(result.Length == localInfos.Length);
return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ private LambdaCapturedVariable(SynthesizedContainer frame, TypeSymbol type, stri
_isThis = isThisParameter;
}

public static LambdaCapturedVariable Create(LambdaFrame frame, Symbol captured, ref int uniqueId)
public static LambdaCapturedVariable Create(ClosureEnvironment frame, Symbol captured, ref int uniqueId)
{
Debug.Assert(captured is LocalSymbol || captured is ParameterSymbol);

Expand Down Expand Up @@ -87,7 +87,7 @@ private static TypeSymbol GetCapturedVariableFieldType(SynthesizedContainer fram
if ((object)local != null)
{
// if we're capturing a generic frame pointer, construct it with the new frame's type parameters
var lambdaFrame = local.Type.OriginalDefinition as LambdaFrame;
var lambdaFrame = local.Type.OriginalDefinition as ClosureEnvironment;
if ((object)lambdaFrame != null)
{
// lambdaFrame may have less generic type parameters than frame, so trim them down (the first N will always match)
Expand Down
102 changes: 36 additions & 66 deletions src/Compilers/CSharp/Portable/Lowering/LambdaRewriter/LambdaFrame.cs
Original file line number Diff line number Diff line change
@@ -1,44 +1,58 @@
// 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.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using Microsoft.CodeAnalysis.CodeGen;
using Microsoft.CodeAnalysis.CSharp.Symbols;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Roslyn.Utilities;

namespace Microsoft.CodeAnalysis.CSharp
{
/// <summary>
/// A class that represents the set of variables in a scope that have been
/// captured by lambdas within that scope.
/// captured by nested functions within that scope.
/// </summary>
internal sealed class LambdaFrame : SynthesizedContainer, ISynthesizedMethodBodyImplementationSymbol
internal sealed class ClosureEnvironment : SynthesizedContainer, ISynthesizedMethodBodyImplementationSymbol
{
private readonly TypeKind _typeKind;
private readonly MethodSymbol _topLevelMethod;
private readonly MethodSymbol _containingMethod;
private readonly MethodSymbol _constructor;
private readonly MethodSymbol _staticConstructor;
private readonly FieldSymbol _singletonCache;
internal readonly SyntaxNode ScopeSyntaxOpt;
internal readonly int ClosureOrdinal;

internal LambdaFrame(MethodSymbol topLevelMethod, MethodSymbol containingMethod, bool isStruct, SyntaxNode scopeSyntaxOpt, DebugId methodId, DebugId closureId)
/// <summary>
/// The closest method/lambda that this frame is originally from. Null if nongeneric static closure.
/// Useful because this frame's type parameters are constructed from this method and all methods containing this method.
/// </summary>
internal readonly MethodSymbol OriginalContainingMethodOpt;
internal readonly FieldSymbol SingletonCache;
internal readonly MethodSymbol StaticConstructor;
public readonly IEnumerable<Symbol> CapturedVariables;

public override TypeKind TypeKind { get; }
internal override MethodSymbol Constructor { get; }

internal ClosureEnvironment(
IEnumerable<Symbol> capturedVariables,
MethodSymbol topLevelMethod,
MethodSymbol containingMethod,
bool isStruct,
SyntaxNode scopeSyntaxOpt,
DebugId methodId,
DebugId closureId)
: base(MakeName(scopeSyntaxOpt, methodId, closureId), containingMethod)
{
_typeKind = isStruct ? TypeKind.Struct : TypeKind.Class;
CapturedVariables = capturedVariables;
TypeKind = isStruct ? TypeKind.Struct : TypeKind.Class;
_topLevelMethod = topLevelMethod;
_containingMethod = containingMethod;
_constructor = isStruct ? null : new LambdaFrameConstructor(this);
OriginalContainingMethodOpt = containingMethod;
Constructor = isStruct ? null : new LambdaFrameConstructor(this);
this.ClosureOrdinal = closureId.Ordinal;

// static lambdas technically have the class scope so the scope syntax is null
if (scopeSyntaxOpt == null)
{
_staticConstructor = new SynthesizedStaticConstructor(this);
StaticConstructor = new SynthesizedStaticConstructor(this);
var cacheVariableName = GeneratedNames.MakeCachedFrameInstanceFieldName();
_singletonCache = new SynthesizedLambdaCacheFieldSymbol(this, this, cacheVariableName, topLevelMethod, isReadOnly: true, isStatic: true);
SingletonCache = new SynthesizedLambdaCacheFieldSymbol(this, this, cacheVariableName, topLevelMethod, isReadOnly: true, isStatic: true);
}

AssertIsClosureScopeSyntax(scopeSyntaxOpt);
Expand Down Expand Up @@ -77,69 +91,25 @@ private static void AssertIsClosureScopeSyntax(SyntaxNode syntaxOpt)
throw ExceptionUtilities.UnexpectedValue(syntaxOpt.Kind());
}

public override TypeKind TypeKind
{
get { return _typeKind; }
}

internal override MethodSymbol Constructor
{
get { return _constructor; }
}

internal MethodSymbol StaticConstructor
{
get { return _staticConstructor; }
}

/// <summary>
/// The closest method/lambda that this frame is originally from. Null if nongeneric static closure.
/// Useful because this frame's type parameters are constructed from this method and all methods containing this method.
/// </summary>
internal MethodSymbol ContainingMethod
{
get { return _containingMethod; }
}

public override ImmutableArray<Symbol> GetMembers()
{
var members = base.GetMembers();
if ((object)_staticConstructor != null)
if ((object)StaticConstructor != null)
{
members = ImmutableArray.Create<Symbol>(_staticConstructor, _singletonCache).AddRange(members);
members = ImmutableArray.Create<Symbol>(StaticConstructor, SingletonCache).AddRange(members);
}

return members;
}

internal FieldSymbol SingletonCache
{
get { return _singletonCache; }
}

// display classes for static lambdas do not have any data and can be serialized.
internal override bool IsSerializable
{
get { return (object)_singletonCache != null; }
}
internal override bool IsSerializable => (object)SingletonCache != null;

public override Symbol ContainingSymbol
{
get { return _topLevelMethod.ContainingSymbol; }
}
public override Symbol ContainingSymbol => _topLevelMethod.ContainingSymbol;

bool ISynthesizedMethodBodyImplementationSymbol.HasMethodBodyDependency
{
get
{
// the lambda method contains user code from the lambda:
return true;
}
}
// The lambda method contains user code from the lambda
bool ISynthesizedMethodBodyImplementationSymbol.HasMethodBodyDependency => true;

IMethodSymbol ISynthesizedMethodBodyImplementationSymbol.Method
{
get { return _topLevelMethod; }
}
IMethodSymbol ISynthesizedMethodBodyImplementationSymbol.Method => _topLevelMethod;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Microsoft.CodeAnalysis.CSharp
{
internal sealed class LambdaFrameConstructor : SynthesizedInstanceConstructor, ISynthesizedMethodBodyImplementationSymbol
{
internal LambdaFrameConstructor(LambdaFrame frame)
internal LambdaFrameConstructor(ClosureEnvironment frame)
: base(frame)
{
}
Expand Down

0 comments on commit 6335890

Please sign in to comment.