What's New in the Microsoft "Roslyn" June 2012 CTP

Locked What's New in the Microsoft "Roslyn" June 2012 CTP

Locked

  • Tuesday, June 05, 2012 7:15 PM
    Owner
     
     

    This refresh from the Oct 2011 CTP includes support for Visual Studio 2012 RC, several significant API changes, new walkthroughs and samples, and an updated set of supported language features.

    New Language Features Implemented Since CTP1

    Implemented in C#

    • Anonymous Types
    • Attributes (full support)
    • Base call support
    • Checked and unchecked expressions and blocks
    • Events
    • Finalizers
    • Generic constraints
    • Implicitly-typed arrays
    • Indexers
    • Iterators
    • Lock statements
    • Named and optional parameters
    • Param array parameters
    • Partial methods
    • Operator overloading
    • Query expressions
    • Switch statements
    • User-defined conversions
    • Using statements
    • Volative fields

    Implemented in Visual Basic

    • Anonymous Delegates
    • Anonymous Types
    • Attributes (full support)
    • Conditional expressions (ternary If operator)
    • Delegate Relaxation
    • Event declarations
    • Explicit conversions (CType, DirectCast)
    • Extension methods
    • For statements
    • For Each statements
    • Generic constraints
    • GetType expressions
    • GoTo statements
    • Implicitly-declared local variables (Option Explicit)
    • Implicitly-typed local variables (Option Infer)
    • Instance expressions (Me, MyBase, MyClass)
    • Local Consts
    • Multi-dimensional arrays
    • Null-coalescing expressions (binary If operator)
    • Optional parameters
    • Query expressions
    • Redim statements
    • Select Case blocks
    • Structures
    • SyncLock blocks
    • Try/Catch/Finally statements
    • TypeOf ... Is ... expressions
    • Using blocks

    API Changes Since CTP1

    There have been many updates to the Roslyn APIs introduced since the first CTP was released in October of 2011. Below is a summary of some of the most important changes, many of which are breaking.

    • Compiler APIs

      • The "Opt" suffix has been removed from all property names in the Syntax API.
      • Several "With" and "Add" methods have been added to specific SyntaxNode types to make it easier to modify them. For example:
        using Roslyn.Compilers.CSharp;

        var compilationUnit = Syntax.ParseCompilationUnit("internal class C { }");
        var classDeclaration = (ClassDeclarationSyntax)compilationUnit.Members[0];
        var newClassDeclaration = classDeclaration
            .AddBaseListTypes(Syntax.ParseTypeName("B"))
            .WithModifiers(Syntax.TokenList(Syntax.Token(SyntaxKind.PublicKeyword)))
            .NormalizeWhitespace();

        newClassDeclaration.ToString(); // public class C : B { }
      • ICompilation interface has been replaced with an abstract class, CommonCompilation.
      • CommonSyntaxTree.Root and SyntaxTree.Root have been removed. Use GetRoot() instead.
      • SyntaxTree.FileName has been renamed to SyntaxTree.FilePath
      • SyntaxVisitor Visit and Accept methods have been changed from protected to public.
      • SemanticModel.GetSemanticInfo() and the SemanticInfo type have been replaced by a family of methods that retrieve specific semantic information:

        C#
        SymbolInfo GetSymbolInfo(AttributeSyntax attributeSyntax)
        SymbolInfo GetSymbolInfo(ConstructorInitializerSyntax constructorInitializer)
        SymbolInfo GetSymbolInfo(ExpressionSyntax expression)
        SymbolInfo GetSymbolInfo(OrderingSyntax node)
        SymbolInfo GetSymbolInfo(SelectOrGroupClauseSyntax node)

        SymbolInfo GetSpeculativeSymbolInfo(
            int position,
            ExpressionSyntax expression,
            SpeculativeBindingOption bindingOption)

        TypeInfo GetTypeInfo(AttributeSyntax attributeSyntax)
        TypeInfo GetTypeInfo(ConstructorInitializerSyntax constructorInitializer)
        TypeInfo GetTypeInfo(ExpressionSyntax expression)
        TypeInfo GetTypeInfo(SelectOrGroupClauseSyntax node)

        TypeInfo GetSpeculativeTypeInfo(
            int position,
            ExpressionSyntax expression,
            SpeculativeBindingOption bindingOption)

        ReadOnlyArray<MethodSymbol> GetMethodGroup(AttributeSyntax attribute)
        ReadOnlyArray<MethodSymbol> GetMethodGroup(ConstructorInitializerSyntax initializer)
        ReadOnlyArray<MethodSymbol> GetMethodGroup(ExpressionSyntax expression)

        Optional<object> GetConstantValue(ExpressionSyntax expression)

        Visual Basic
        Function GetSymbolInfo(attributeSyntax As AttributeSyntax) As SymbolInfo
        Function GetSymbolInfo(expression As ExpressionSyntax) As SymbolInfo

        Function GetSpeculativeSymbolInfo(
            position As Integer,
            expression As ExpressionSyntax,
            bindingOption As SpeculativeBindingOption) As SymbolInfo

        Function GetTypeInfo(attribute As AttributeSyntax) As TypeInfo
        Function GetTypeInfo(expression As ExpressionSyntax) As TypeInfo

        Function GetSpeculativeTypeInfo(
            position As Integer,
            expression As ExpressionSyntax,
            bindingOption As SpeculativeBindingOption) As TypeInfo

        Function GetMemberGroup(attribute As AttributeSyntax) As ReadOnlyArray(Of Symbol)
        Function GetMemberGroup(expression As ExpressionSyntax) As ReadOnlyArray(Of Symbol)

        Function GetSpeculativeMemberGroup(
            position As Integer,
            expression As ExpressionSyntax) As ReadOnlyArray(Of Symbol)

        Function GetConstantValue(expression As ExpressionSyntax) As Optional(Of Object)
      • Two methods have been added to SemanticModel to retrieve information about namespace and type aliases.

        C#
        AliasSymbol GetAliasInfo(IdentifierNameSyntax nameSyntax)

        AliasSymbol GetSpeculativeAliasInfo(
            int position,
            IdentifierNameSyntax nameSyntax,
            SpeculativeBindingOption bindingOption)

        Visual Basic
        Function GetAliasInfo(nameSyntax As IdentifierNameSyntax) As AliasSymbol

        Function GetSpeculativeAliasInfo(
            position As Integer,
            nameSyntax As IdentifierNameSyntax,
            bindingOption As SpeculativeBindingOption) As AliasSymbol
      • SemanticModel now exposes several methods for retrieving specific semantic information for various language constructs.

        C#
        ForEachStatementInfo GetForEachStatementInfo(ForEachStatementSyntax) node
        QueryClauseInfo GetQueryClauseInfo(QueryClauseSyntax node)

        Visual Basic
        Function GetForEachStatementInfo(node As ForBlockSyntax) As ForEachStatementInfo
        Function GetForEachStatementInfo(node As ForEachStatementSyntax) As ForEachStatementInfo
      • The TextSpan-based control and data flow analysis APIs have been replaced with a family of APIs targeting expressions, statements, and ranges of statements.

        C#
        RegionControlFlowAnalysis AnalyzeStatementControlFlow(StatementSyntax statement)
        RegionControlFlowAnalysis AnalyzeStatementsControlFlow(
            StatementSyntax firstStatement,
            StatementSyntax lastStatement)

        RegionDataFlowAnalysis AnalyzeExpressionDataFlow(ExpressionSyntax expression)
        RegionDataFlowAnalysis AnalyzeStatementDataFlow(StatementSyntax statement)
        RegionDataFlowAnalysis AnalyzeStatementsDataFlow(
            StatementSyntax firstStatement,
            StatementSyntax lastStatement)

        Visual Basic
        Function AnalyzeStatementControlFlow(statement As StatementSyntax) As RegionControlFlowAnalysis
        Function AnalyzeStatementsControlFlow(
            firstStatement As StatementSyntax,
            lastStatement As StatementSyntax) As RegionControlFlowAnalysis

        Function AnalyzeExpressionDataFlow(expression As ExpressionSyntax) As RegionDataFlowAnalysis
        Function AnalyzeStatementDataFlow(statement As StatementSyntax) As RegionDataFlowAnalysis
        Function AnalyzeStatementsDataFlow(
            firstStatement As StatementSyntax,
            lastStatement As StatementSyntax) As RegionDataFlowAnalysis

    • Services APIs

      • IWorkspaceRegistryService has been removed. This functionality is now exposed as static methods on the Workspace class.
      • IWorkspaceDiscoveryService has been removed. This functionality is not exposed as static methods on the Workspace class.
      • IWorkspaceListener has been removed. There is now a single Workspace.WorkspaceChanged event to which code can subscribe.
      • Several APIs have been relocated from the Editor Services layer to the Services layer.

        • Formatting
        • Find All References
        • Name Simplification

        These APIs are exposed as extension methods off of related compiler API types. For example, the Find All References API is an extension method on the ISymbol type:
        using Roslyn.Compilers.Common;
        using Roslyn.Services;

        ...

        ISymbol symbol;
        ISolution solution;
        IEnumerable<ReferencedSymbol> references = symbol.FindReferences(solution);
      • A new Source Code Generation API has been introduced in the Services layer for the purpose of generating types and members.

    • Editor Services APIs

      • ICodeActionEditFactory has been removed.
      • ICodeAction.GetEdit() now returns a CodeActionEdit rather than an ICodeActionEdit.
      • The Completion Item Provider API has been completely redesigned.
      • Extension methods have been added to facilitate retrieving a Roslyn API IDocument for a Visual Studio Editor API ITextSnapshot.
        using Microsoft.VisualStudio.Text;
        using Roslyn.Services.Editor;

        ...

        ITextSnapshot textSnapshot;
        IDocument document;
        if (textSnapshot.AsText().TryGetDocument(out document))
        {
            ...
        }

    Known Issues and Unimplemented Language Features

    The Microsoft "Roslyn" June 2012 CTP is technology preview and there are known issues. While the shape of the public API is complete, only a subset of the VB and C# languages have been implemented at this time. The set of Known Limitations and Unimplemented Language Features can be found here.


    Anthony D. Green | Program Manager | Visual Basic & C# Languages Team