Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/dotnet/roslyn into format…
Browse files Browse the repository at this point in the history
…perf
  • Loading branch information
heejaechang committed Jun 3, 2015
2 parents 390e49f + 75756ed commit e952752
Show file tree
Hide file tree
Showing 30 changed files with 701 additions and 147 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
## Welcome to the .NET Compiler Platform ("Roslyn")

|Windows|Linux|Mac OSX|
|:--:|:--:|:--:|
|[![Build Status](http://dotnet-ci.cloudapp.net/job/dotnet_roslyn_windows/badge/icon)](http://dotnet-ci.cloudapp.net/job/dotnet_roslyn_windows/)|[![Build Status](http://dotnet-ci.cloudapp.net/job/dotnet_roslyn_linux/badge/icon)](http://dotnet-ci.cloudapp.net/job/dotnet_roslyn_linux/)|[![Build Status](http://dotnet-ci.cloudapp.net/job/dotnet_roslyn_mac/badge/icon)](http://dotnet-ci.cloudapp.net/job/dotnet_roslyn_mac/)|
||Windows - Debug|Windows - Release|Linux|Mac OSX|
|:--:|:--:|:--:|:--:|:--:|
|**master**|[![Build Status](http://dotnet-ci.cloudapp.net/job/dotnet_roslyn_windows/badge/icon)](http://dotnet-ci.cloudapp.net/job/dotnet_roslyn_windows/)|[![Build Status](http://dotnet-ci.cloudapp.net/job/dotnet_roslyn_windows_release/badge/icon)](http://dotnet-ci.cloudapp.net/job/dotnet_roslyn_windows_release/)|[![Build Status](http://dotnet-ci.cloudapp.net/job/dotnet_roslyn_linux/badge/icon)](http://dotnet-ci.cloudapp.net/job/dotnet_roslyn_linux/)|[![Build Status](http://dotnet-ci.cloudapp.net/job/dotnet_roslyn_mac/badge/icon)](http://dotnet-ci.cloudapp.net/job/dotnet_roslyn_mac/)|
|**stabilization**|[![Build Status](http://dotnet-ci.cloudapp.net/job/dotnet_roslyn_stabilization_windows_debug/badge/icon)](http://dotnet-ci.cloudapp.net/job/dotnet_roslyn_stabilization_windows_debug/)|[![Build Status](http://dotnet-ci.cloudapp.net/job/dotnet_roslyn_stabilization_windows_release/badge/icon)](http://dotnet-ci.cloudapp.net/job/dotnet_roslyn_stabilization_windows_release/)|[![Build Status](http://dotnet-ci.cloudapp.net/job/dotnet_roslyn_stabilization_linux/badge/icon)](http://dotnet-ci.cloudapp.net/job/dotnet_roslyn_stabilization_linux/)|[![Build Status](http://dotnet-ci.cloudapp.net/job/dotnet_roslyn_stabilization_mac/badge/icon)](http://dotnet-ci.cloudapp.net/job/dotnet_roslyn_stabilization_mac/)|


[![Join the chat at https://gitter.im/dotnet/roslyn](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/dotnet/roslyn?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
Expand Down
4 changes: 2 additions & 2 deletions cibuild.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ if "%1" == "" goto :DoneParsing
if /I "%1" == "/?" call :Usage && exit /b 1
if /I "%1" == "/debug" set BuildConfiguration=Debug&&shift&& goto :ParseArguments
if /I "%1" == "/release" set BuildConfiguration=Release&&shift&& goto :ParseArguments
goto :Usage && exit /b 1
call :Usage && exit /b 1
:DoneParsing

call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x86
Expand Down Expand Up @@ -44,4 +44,4 @@ exit /b 0
@echo Usage: cibuild.cmd [/debug^|/release]
@echo /debug Perform debug build. This is the default.
@echo /release Perform release build
@goto :eof
@goto :eof
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// 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 Microsoft.CodeAnalysis.CSharp.Test.Utilities;
using System;
using System.IO;
using Xunit;

namespace Microsoft.CodeAnalysis.CSharp.UnitTests
{
public partial class InternalsVisibleToAndStrongNameTests : CSharpTestBase
{
/// <summary>
/// A strong name provider which throws an IOException while creating
/// the input stream.
/// </summary>
private class StrongNameProviderWithBadInputStream : StrongNameProvider
{
private StrongNameProvider _underlyingProvider;
public StrongNameProviderWithBadInputStream(StrongNameProvider underlyingProvider)
{
_underlyingProvider = underlyingProvider;
}

public override bool Equals(object other) => this == other;

public override int GetHashCode() => _underlyingProvider.GetHashCode();

internal override Stream CreateInputStream()
{
throw new IOException("This is a test IOException");
}

internal override StrongNameKeys CreateKeys(string keyFilePath, string keyContainerName, CommonMessageProvider messageProvider) =>
_underlyingProvider.CreateKeys(keyFilePath, keyContainerName, messageProvider);

internal override void SignAssembly(StrongNameKeys keys, Stream inputStream, Stream outputStream) =>
_underlyingProvider.SignAssembly(keys, inputStream, outputStream);
}

[Fact]
public void BadInputStream()
{
string src = @"
class C
{
public static void Main(string[] args) { }
}";
var testProvider = new StrongNameProviderWithBadInputStream(s_defaultProvider);
var options = TestOptions.DebugExe
.WithStrongNameProvider(testProvider)
.WithCryptoKeyContainer("RoslynTestContainer");

var comp = CreateCompilationWithMscorlib(src,
options: options);

comp.VerifyEmitDiagnostics(
// error CS7028: Error signing output with public key from container 'RoslynTestContainer' -- This is a test IOException
Diagnostic(ErrorCode.ERR_PublicKeyContainerFailure).WithArguments("RoslynTestContainer", "This is a test IOException").WithLocation(1, 1));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

namespace Microsoft.CodeAnalysis.CSharp.UnitTests
{
public class InternalsVisibleToAndStrongNameTests : CSharpTestBase
public partial class InternalsVisibleToAndStrongNameTests : CSharpTestBase
{
#region Helpers

Expand Down
5 changes: 3 additions & 2 deletions src/Compilers/CSharp/Test/Emit/CSharpCompilerEmitTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
<Reference Include="..\..\..\..\..\packages\Microsoft.DiaSymReader.1.0.4-rc2\lib\net45\Microsoft.DiaSymReader.dll" />
<Reference Include="xunit">
<HintPath>..\..\..\..\..\packages\xunit.1.9.2\lib\net20\xunit.dll</HintPath>
</Reference>
</Reference>
</ItemGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
Expand Down Expand Up @@ -151,6 +151,7 @@
<Compile Include="Emit\EmitErrorTests.cs" />
<Compile Include="Emit\EmitMetadata.cs" />
<Compile Include="Emit\EmitMetadataTestBase.cs" />
<Compile Include="Attributes\EmitTestStrongNameProvider.cs" />
<Compile Include="Emit\EntryPointTests.cs" />
<Compile Include="Emit\NoPiaEmbedTypes.cs" />
<Compile Include="Emit\OptionalArgumentsTests.cs" />
Expand Down Expand Up @@ -205,4 +206,4 @@
<Import Project="..\..\..\..\..\build\Roslyn.Toolsets.Xunit.targets" />
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
</ImportGroup>
</Project>
</Project>
19 changes: 17 additions & 2 deletions src/Compilers/Core/Portable/Compilation/Compilation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1665,8 +1665,17 @@ internal bool SerializeToPeStream(
{
Debug.Assert(Options.StrongNameProvider != null);

signingInputStream = Options.StrongNameProvider.CreateInputStream();
retStream = signingInputStream;
// Targeted try-catch for errors during CreateInputStream as found in TFS 1140649
// TODO: Put this wrapping in PeWriter to catch all potential PE writing exceptions
try
{
signingInputStream = Options.StrongNameProvider.CreateInputStream();
retStream = signingInputStream;
}
catch (Exception e)
{
throw new Cci.PeWritingException(e);
}
}
else
{
Expand Down Expand Up @@ -1720,6 +1729,12 @@ internal bool SerializeToPeStream(
diagnostics.Add(MessageProvider.CreateDiagnostic(MessageProvider.ERR_PdbWritingFailed, Location.None, ex.Message));
return false;
}
catch (Cci.PeWritingException e)
{
// Targeted fix for TFS 1140649
// TODO: Add resource and better error message for a variety of PE exceptions
diagnostics.Add(StrongNameKeys.GetError(StrongNameKeys.KeyFilePath, StrongNameKeys.KeyContainer, e.Message, MessageProvider));
}
catch (ResourceException e)
{
diagnostics.Add(MessageProvider.CreateDiagnostic(MessageProvider.ERR_CantReadResource, Location.None, e.Message, e.InnerException.Message));
Expand Down
7 changes: 7 additions & 0 deletions src/Compilers/Core/Portable/PEWriter/PeWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@

namespace Microsoft.Cci
{
internal sealed class PeWritingException : Exception
{
public PeWritingException(Exception inner)
: base(inner.Message, inner)
{ }
}

internal sealed class PeWriter
{
/// <summary>
Expand Down
91 changes: 75 additions & 16 deletions src/Compilers/Core/Portable/Syntax/AbstractSyntaxNavigator.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// 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.Collections.Generic;
using System.Diagnostics;
using Roslyn.Utilities;

namespace Microsoft.CodeAnalysis
{
Expand Down Expand Up @@ -51,38 +53,95 @@ internal SyntaxToken GetNextToken(SyntaxToken current, Func<SyntaxToken, bool> p
return GetNextToken(current, predicate, stepInto != null, stepInto);
}

private static readonly ObjectPool<Stack<ChildSyntaxList.Enumerator>> s_childEnumeratorStackPool
= new ObjectPool<Stack<ChildSyntaxList.Enumerator>>(() => new Stack<ChildSyntaxList.Enumerator>(), 10);

internal SyntaxToken GetFirstToken(SyntaxNode current, Func<SyntaxToken, bool> predicate, Func<SyntaxTrivia, bool> stepInto)
{
foreach (var child in current.ChildNodesAndTokens())
var stack = s_childEnumeratorStackPool.Allocate();
try
{
var token = child.IsToken
? GetFirstToken(child.AsToken(), predicate, stepInto)
: GetFirstToken(child.AsNode(), predicate, stepInto);
stack.Push(current.ChildNodesAndTokens().GetEnumerator());

if (token.RawKind != None)
while (stack.Count > 0)
{
return token;
var en = stack.Pop();
if (en.MoveNext())
{
var child = en.Current;

if (child.IsToken)
{
var token = GetFirstToken(child.AsToken(), predicate, stepInto);
if (token.RawKind != None)
{
return token;
}
}

// push this enumerator back, not done yet
stack.Push(en);

if (child.IsNode)
{
stack.Push(child.AsNode().ChildNodesAndTokens().GetEnumerator());
}
}
}
}

return default(SyntaxToken);
return default(SyntaxToken);
}
finally
{
stack.Clear();
s_childEnumeratorStackPool.Free(stack);
}
}

private static readonly ObjectPool<Stack<ChildSyntaxList.Reversed.Enumerator>> s_childReversedEnumeratorStackPool
= new ObjectPool<Stack<ChildSyntaxList.Reversed.Enumerator>>(() => new Stack<ChildSyntaxList.Reversed.Enumerator>(), 10);

internal SyntaxToken GetLastToken(SyntaxNode current, Func<SyntaxToken, bool> predicate, Func<SyntaxTrivia, bool> stepInto)
{
foreach (var child in current.ChildNodesAndTokens().Reverse())
var stack = s_childReversedEnumeratorStackPool.Allocate();
try
{
var token = child.IsToken
? GetLastToken(child.AsToken(), predicate, stepInto)
: GetLastToken(child.AsNode(), predicate, stepInto);
stack.Push(current.ChildNodesAndTokens().Reverse().GetEnumerator());

if (token.RawKind != None)
while (stack.Count > 0)
{
return token;
var en = stack.Pop();

if (en.MoveNext())
{
var child = en.Current;

if (child.IsToken)
{
var token = GetLastToken(child.AsToken(), predicate, stepInto);
if (token.RawKind != None)
{
return token;
}
}

// push this enumerator back, not done yet
stack.Push(en);

if (child.IsNode)
{
stack.Push(child.AsNode().ChildNodesAndTokens().Reverse().GetEnumerator());
}
}
}
}

return default(SyntaxToken);
return default(SyntaxToken);
}
finally
{
stack.Clear();
s_childReversedEnumeratorStackPool.Free(stack);
}
}

private SyntaxToken GetFirstToken(
Expand Down
29 changes: 0 additions & 29 deletions src/Compilers/VisualBasic/Test/CommandLine/CommandLineTests.vb
Original file line number Diff line number Diff line change
Expand Up @@ -7185,35 +7185,6 @@ vbc : error BC2015: the file '{1}' is not a text file
CleanupAllGeneratedFiles(nonCompilerInputFile)
End Sub

''' <summary>
''' Script compilation should be internal only.
''' </summary>
<WorkItem(1979, "https://github.com/dotnet/roslyn/issues/1979")>
<Fact>
Public Sub ScriptCompilationInternalOnly()
Dim source = "System.Console.WriteLine()"
Dim dir = Temp.CreateDirectory()
Dim file = dir.CreateFile("b.vbx")
file.WriteAllText(source)

' Compiling script file with internal API should be supported.
Dim compilation = CreateCompilationWithMscorlib(
<compilation>
<file name="b.vbx"><%= source %></file>
</compilation>,
parseOptions:=New VisualBasicParseOptions(LanguageVersion.VisualBasic14, DocumentationMode.Parse, SourceCodeKind.Script, ImmutableArray(Of KeyValuePair(Of String, Object)).Empty),
options:=New VisualBasicCompilationOptions(OutputKind.ConsoleApplication))
compilation.VerifyDiagnostics()

' Compiling with command-line compiler, should not treat .vbx as script.
Dim cmd = New MockVisualBasicCompiler(Nothing, _baseDirectory, {"/nologo", "/preferreduilang:en", file.Path})
Dim output As StringWriter = New StringWriter()
cmd.Run(output, Nothing)
Assert.True(output.ToString().Contains("error BC30689: Statement cannot appear outside of a method body."))

CleanupAllGeneratedFiles(file.Path)
End Sub

<Fact, WorkItem(1093063, "DevDiv")>
Public Sub VerifyDiagnosticSeverityNotLocalized()
Dim source = <![CDATA[
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
' Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

Imports System.IO
Imports Microsoft.CodeAnalysis
Imports Microsoft.CodeAnalysis.VisualBasic
Imports Microsoft.CodeAnalysis.VisualBasic.UnitTests

Partial Public Class InternalsVisibleToAndStrongNameTests
Inherits BasicTestBase

Private Class StrongNameProviderWithBadInputStream
Inherits StrongNameProvider
Private _underlyingProvider As StrongNameProvider
Public Sub New(underlyingProvider As StrongNameProvider)
_underlyingProvider = underlyingProvider
End Sub


Public Overrides Function Equals(other As Object) As Boolean
Return Me Is other
End Function

Public Overrides Function GetHashCode() As Integer
Return _underlyingProvider.GetHashCode()
End Function

Friend Overrides Function CreateInputStream() As Stream
Throw New IOException("This is a test IOException")
End Function

Friend Overrides Function CreateKeys(keyFilePath As String, keyContainerName As String, messageProvider As CommonMessageProvider) As StrongNameKeys
Return _underlyingProvider.CreateKeys(keyFilePath, keyContainerName, messageProvider)
End Function

Friend Overrides Sub SignAssembly(keys As StrongNameKeys, inputStream As Stream, outputStream As Stream)
_underlyingProvider.SignAssembly(keys, inputStream, outputStream)
End Sub
End Class

<Fact>
Public Sub BadInputStream()
Dim testProvider = New StrongNameProviderWithBadInputStream(s_defaultProvider)
Dim options = TestOptions.DebugDll.WithStrongNameProvider(testProvider).WithCryptoKeyContainer("RoslynTestContainer")

Dim comp = CreateCompilationWithMscorlib(
<compilation>
<file name="a.vb"><![CDATA[
Public Class C
Public Sub M()
End Sub
End Class
]]>
</file>
</compilation>, options:=options)

comp.VerifyEmitDiagnostics(
Diagnostic(ERRID.ERR_PublicKeyContainerFailure).WithArguments("RoslynTestContainer", "This is a test IOException").WithLocation(1, 1))
End Sub

End Class
Loading

0 comments on commit e952752

Please sign in to comment.