roslyn: el futuro de c#

29
Roslyn: el futuro de C# Rodolfo Finochietti [email protected] @rodolfof http://shockbyte.net

Upload: rodolfo-finochietti

Post on 10-Jun-2015

1.917 views

Category:

Technology


1 download

DESCRIPTION

Roslyn: el futuro de C#

TRANSCRIPT

Page 1: Roslyn: el futuro de C#

Roslyn: el futuro de C#

Rodolfo [email protected]@rodolfofhttp://shockbyte.net

Page 2: Roslyn: el futuro de C#

Construir un compilador es complejo

Page 3: Roslyn: el futuro de C#

Fundamentos de un compilador

Page 4: Roslyn: el futuro de C#

Compilador

?class Program{ void Main() { }} ▫

program.exe

CSC - VBC

Page 5: Roslyn: el futuro de C#

Se pueden agrupar en Front-end: sintaxis == “gramática“ Back-end: semántica == “significado"

5

Fases

Page 6: Roslyn: el futuro de C#

6

Fases

Page 7: Roslyn: el futuro de C#

Compiladores en .NET .NET siempre fue una plataforma amigable para la construcción de compiladores Intermediate Language (IL)

Stack de Pila Operaciones de alto nivel

Optimizaciones de bajo nivel via la plataforma Reflection Emit

Tools para construcción de compiladores http://irony.codeplex.com

Page 8: Roslyn: el futuro de C#

Demo

Reflection Emit

Page 9: Roslyn: el futuro de C#

Roslyn

Page 10: Roslyn: el futuro de C#

Roslyn – .NET Compiler PlatformCompleta reescritura de los compiladores C# y Visual BasicOpen Source

Language ServicesCode Analysis APIsExtensibilidadRead-Eval-Print-Loop (REPL)Scripting

Page 11: Roslyn: el futuro de C#

Ecosistema .NET

Core .NET

Next gen JIT (“RyuJIT”)

SIMD

Runtime Compilers .NET Compiler Platform (“Roslyn”)

Languages innovation

Windows Desktop

Azure and Windows Server

Universal projects

.NET NativeASP.NET updates

Windows Convergence

Native compilation

Web apps

.NET support for Azure Mobile Services

Cloud Services

Openness

Windows Store iOS and Android

.NET in devices and services

Page 12: Roslyn: el futuro de C#

Compiler APIs

Page 13: Roslyn: el futuro de C#

Symbol API

API Layers

Services

Compiler Syntax Tree API

Binding and Flow Analysis

APIs

Emit API

Scripting API

Workspace API

Code FormattingFind All

ReferencesName

Simplification …

Editor Services

Code Actions Classification Completion …Outlining

Page 14: Roslyn: el futuro de C#

Syntax Tree API – NodesCompilationUnit

TypeDeclaration

MethodDeclaration

class C{ void M() { }}// C▫

ParameterList

Block

var tree = CSharpSyntaxTree.ParseText("...");

Page 15: Roslyn: el futuro de C#

Syntax Tree API – TokensCompilationUnit

TypeDeclaration

class

C {MethodDeclaratio

n}

EOF

void MParameterLi

stBlock

( ) { }

class C{ void M() { }}// C▫

Page 16: Roslyn: el futuro de C#

Syntax Tree API – TriviaCompilationUnit

TypeDeclaration

class

C {MethodDeclaratio

n}

EOF

void MParameterLi

stBlock

( )

{ }

SP EOL EOL // C

SPx4 SP

EOL

EOL

EOLSPx4 EOL SPx4

class∙C{∙∙∙∙void∙M()∙∙∙∙{∙∙∙∙}}// C▫

Page 17: Roslyn: el futuro de C#

Demo

Syntax Tree APISymbol APISyntax TransformationCompilation API

Page 18: Roslyn: el futuro de C#

Workspace APIHost Environment

Workspace

Solution

Project Project

Document

Document

Solution2 Solutionn

Apply

Edit Edit

SyntaxTree

Compilation

Events (e.g. key presses)

Page 19: Roslyn: el futuro de C#

Demo

Diagnostics and Code Fix

Page 20: Roslyn: el futuro de C#

C# 6

Page 21: Roslyn: el futuro de C#

Primary ConstructorAuto-Property Initializerpublic class Point(int x, int y){ public int X { get; } = x; public int Y { get; } = y; public double R { get; } = Math.Sqrt(x ^ x + y ^ y);

public Point() : this(0, 0) { }

public override string ToString() { return string.Format("({0},{1},{2})", X, Y, R); }}

Page 22: Roslyn: el futuro de C#

Exception Filteringtry{

Task[] tasks = new Task[10]; for (int i = 0; i < 10; i++) { tasks[i] = Task.Factory.StartNew(() => DoSomeWork(10000000)); } var res = await Task.WhenAll(tasks);}catch (AggregateException e) if (e.InnerExceptions.Count > 2){

await WriteStatus(“filtered exception");}finally{

await WriteStatus(“finished");}

Page 23: Roslyn: el futuro de C#

Null propagating operator

Page 24: Roslyn: el futuro de C#

Using static members

Page 25: Roslyn: el futuro de C#

Lista completa

http://goo.gl/4vtQfr

Page 26: Roslyn: el futuro de C#

Demo

C# 6

Page 27: Roslyn: el futuro de C#

¿Preguntas?

Page 28: Roslyn: el futuro de C#

ReferenciasLibros

Compilers: Principles, Techniques, and Tools – Aho et all

Compiling for the .NET Common Language Runtime (CLR) - John Gough

Webhttp://irony.codeplex.comhttp://roslyn.codeplex.com

Page 29: Roslyn: el futuro de C#

¡ [email protected]@rodolfofhttp://shockbyte.net