net compiler platform codename roslyn

24
.NET compiler platform Roslyn Piotr Benetkiewicz ais.pl

Upload: piotr-benetkiewicz

Post on 15-Jul-2015

90 views

Category:

Software


6 download

TRANSCRIPT

Page 1: NET compiler platform codename Roslyn

.NET compiler platform

Roslyn

Piotr Benetkiewicz

ais.pl

Page 2: NET compiler platform codename Roslyn

Agenda

● Introduction, background, history

● Roslyn in new VS 2015

● Syntax API

● Semantics

● Compilation

● Analyzers, Fixes

● Scripting

Page 3: NET compiler platform codename Roslyn

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

Page 4: NET compiler platform codename Roslyn

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?

Page 5: NET compiler platform codename Roslyn

What, when, why cont.

Page 6: NET compiler platform codename Roslyn
Page 7: NET compiler platform codename Roslyn
Page 8: NET compiler platform codename Roslyn

Roslyn must

● Have great throughput

● Be error insensitive

● Have great sense of error scope

● Support REPL-like scenarios

● be VS-agnostic

Page 9: NET compiler platform codename Roslyn

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

Page 10: NET compiler platform codename Roslyn

DEMO

Page 11: NET compiler platform codename Roslyn

Syntax

Page 12: NET compiler platform codename Roslyn

Syntax cont.

● SyntaxTree - base abstraction, immutable

● Building STo from source

o using factory methods

● Navigating STo Members and casting

o OfType<>

o CSharpSyntaxWalker

Page 13: NET compiler platform codename Roslyn

DEMO

Page 14: NET compiler platform codename Roslyn

Syntax modules are smart

Page 15: NET compiler platform codename Roslyn

Syntax modules are smart

Page 16: NET compiler platform codename Roslyn

Semantics

Yesterday a parrot will drive a bitter,

encrypted car.

● english words

● punctuation

● yet it doesn’t make sense…

● binding

Page 17: NET compiler platform codename Roslyn

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

Page 18: NET compiler platform codename Roslyn

Semantics is smart too!

“Property is inaccessible due to its protection level”

● GetSpeculativeSymbolInfo()

● ISymbolInfo.CandidateSymbols

Page 19: NET compiler platform codename Roslyn

DEMO

Page 20: NET compiler platform codename Roslyn

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

Page 21: NET compiler platform codename Roslyn

Analyzers, code fixes cont.

Page 22: NET compiler platform codename Roslyn

DEMO

Page 23: NET compiler platform codename Roslyn

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

Page 24: NET compiler platform codename Roslyn

Thank you

● @pbenetkiewicz

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

[email protected], [email protected]