net compiler platform codename roslyn

Post on 15-Jul-2015

90 Views

Category:

Software

6 Downloads

Preview:

Click to see full reader

TRANSCRIPT

.NET compiler platform

Roslyn

Piotr Benetkiewicz

ais.pl

Agenda

● Introduction, background, history

● Roslyn in new VS 2015

● Syntax API

● Semantics

● Compilation

● Analyzers, Fixes

● Scripting

When, what, why

● .NET compiler platform

● Compiler as a service, csc.exe API

● Started 2008 (PDC, Los Angeles, CA)

● Codeplex -> Github

● Now in beta RC on nuget

● VS 2015

What, when, why cont.

● “Poor” csc architectureo Different compiler forks for different tasks

o clear C# and VB separation

● C++ vs. .NET languages

Have you ever tried cat food?

What, when, why cont.

Roslyn must

● Have great throughput

● Be error insensitive

● Have great sense of error scope

● Support REPL-like scenarios

● be VS-agnostic

Getting started

● VS 2015 CTP6o watch out for side-by-side installation!

● VS SDK● Install-Package Microsoft.CodeAnalysis -Pre● Optional:

o .NET Compiler Platform SDK Templates

o Syntax Visualizer extension

DEMO

Syntax

Syntax cont.

● SyntaxTree - base abstraction, immutable

● Building STo from source

o using factory methods

● Navigating STo Members and casting

o OfType<>

o CSharpSyntaxWalker

DEMO

Syntax modules are smart

Syntax modules are smart

Semantics

Yesterday a parrot will drive a bitter,

encrypted car.

● english words

● punctuation

● yet it doesn’t make sense…

● binding

Semantics cont.

● Get the real meaning of the abstract content

● Linking to a Symbol

● Needs context:

o user defined (your code!)

o external metadata (ex. mscorlib)

● Reflection on steroids (not at runtime)

o GetSymbolInfo(), GetEnclosingSymbol()

o Control flow analysis

o Can be speculative

Semantics is smart too!

“Property is inaccessible due to its protection level”

● GetSpeculativeSymbolInfo()

● ISymbolInfo.CandidateSymbols

DEMO

Analyzers, code fixes

● VS project templates

● Derive from DiagnosticAnalyzer and apply

DiagnosticAnalyzer attribute

● Derive from CodeFixProvider and apply

ExportCodeFixProvider attribute

● Use “Add analyzer” in VS, nuget or csc.exe

Analyzers, code fixes cont.

DEMO

What to expect after Roslyn ships?

● Better vanilla VS user experience

● Alternative IDEs Editors (OmniSharp)● Even richer toolset (CI, metrics, diagnostics)

● Scripting (sciptcs)

● Exciting community and commercial projects

o code mutation

o ConfigR

Thank you

● @pbenetkiewicz

● http://benetkiewicz.github.io/blog/

● pbenetkiewicz@gmail.com, piotr@ais.pl

top related