Compilers in .NET VNext

Embed Size (px)

Citation preview

  • 8/17/2019 Compilers in .NET VNext

    1/41

    Story about new set of compilers comingin the next version of .NET Framework:Roslyn Ryu!"T an# .NET Native

    $%&'"(ERS "N .NET )NE*T

    +ahru#in ,rn-ica $ &)'

    bhrn-ica/#aenet.com

    #aenet

  • 8/17/2019 Compilers in .NET VNext

    2/41

    01EN20

    • .NET vNext

    • Roslyn is everywhere

    • Ryu!"T new !"T compiler• .NET Native 3 native apps without .NET

    • Summary

    • 450

  • 8/17/2019 Compilers in .NET VNext

    3/41

    2"RE$T"%NS F%R .NET

    Nativ

    %pen

    $ross6platform

  • 8/17/2019 Compilers in .NET VNext

    4/41

    • Roslyn pro-ect is the next version of )+ an# $compilers an# language services.

    • "t is a co#ename for .NET $ompiler as Service$00S

    • %pen source pro-ect http:55roslyn.co#eplex.com 78958;9<

    •  Transforms compilers in to platform 0'"• &any opportunities for innovation in variousareas:

     – meta6programming co#e generation an#transformation interactive use of the $ an# )+

     – embe##ing of $ an# )+ in #omain speci=c

    >,0T "S R%S(?N

    http://roslyn.codeplex.com/http://roslyn.codeplex.com/http://roslyn.codeplex.com/http://roslyn.codeplex.com/http://roslyn.codeplex.com/

  • 8/17/2019 Compilers in .NET VNext

    5/41

    • @RoslynA is the basis for .NET an# )isual Stu#io

    vNext

    •Roslyn is

    everywhere

    "&'%RT0NT T% BN%>

  • 8/17/2019 Compilers in .NET VNext

    6/41

    • $ompiler is blackbox

     – "solate#5close# compilers

     – ,ar# to exten# #ev experience

    $CRRENT $ 0N2 )+ $%&'"(ERS

    .NETAssembli

    esSourceFiles

  • 8/17/2019 Compilers in .NET VNext

    7/41

    • "t opens the box of compiler

     – 0'": open platform

     – Rich "2E experiences5refactoring – $o#e analysis

     – $ustom #iagnostics

     – %pen Source compilers

    R%S(?N $%&'"(ERS

    .NETAssembli

    es

    SourceFiles

  • 8/17/2019 Compilers in .NET VNext

    8/41

    • $ommon compilers pipeline

    E*'%S"N1 T,E $%&'"(ER 0'"S

    $ompiler'ipeline 'arsers

    Symbols

    &eta#ata "mport

    +in#er "( Emiter

  • 8/17/2019 Compilers in .NET VNext

    9/41

    • Roslyn separates each phase in to component

    E*'%S"N1 T,E $%&'"(ER 0'"

    $ompiler0'"

    Syntax Tree 0'"

    Symbol0'"

    +in#ing

    an# Flow0nalysis

    0'"s

    Emit 0'"

    $ompiler'ipeline 'arsers

    Symbols

    &eta#ata "mport

    +in#er "( Emiter

  • 8/17/2019 Compilers in .NET VNext

    10/41

    E*'%S"N1 T,E $%&'"(ER 0'"

    $ompiler 0'"

    Syntax Tree0'"

    Symbol0'"

    +in#ing an# Flow 0nalysis 0'"s Em

    (anguage

    Service

    F  o

    r m at t  er 

     $ 

     ol   or i  D  er 

     %

     ut l  i  ni  n g

    N a

    vi   g at  eT  o

     % b  -   e c t 

    r  ow s  er 

     $  o

    m pl  i  t i   on

    ( i   s t 

    F i  n

     # 0 l  l  R  ef  .

     4 ui   c k "  nf   o

     S i   gn at  ur  e

    , el   p

    E xt r  a c t 

    &

     et h  o # 

     1 oT  o

    2 e= ni  t i   on

     en am e

     # i  t  an # 

     $ 

     ont i  n u e

  • 8/17/2019 Compilers in .NET VNext

    11/41

     

    R%S(?N 0'" (0?ERS

    $ompiler 0'"

    Syntax Tree0'"

    Symbol0'"

    +in#ing an# Flow 0nalysis0'"s

    Emit0'"

    >orkspace 0'"

    >orkspace 7Solution5'ro-ects52ocuments<

    $o#e FormatingFin# 0ll

    ReferenceExpan#5Re#uce

    >orkspace 0'"

    Refactorings $o#e Fixes

  • 8/17/2019 Compilers in .NET VNext

    12/41

    R%S(?N 2E&%

    Changing C# compiler 

  • 8/17/2019 Compilers in .NET VNext

    13/41

    • Sintax Tree

     – Representation of #ocument in tree form. 7like

    2%& in ,T&(<• Semantic "nformation

     – "mportant for analyDe# co#e 7info about interfaceimplemente# of given class etc<

     T>% BE? E(E&ENTS F%RREF0$T%R"N1

  • 8/17/2019 Compilers in .NET VNext

    14/41

    • Nodes – &ayor el. of the language 7eg. "fStatementSintax

    ..<• Tokens – Secon#ary element not less important 7eg.

    "#enti=ers string literlas numeric literal <

    • Trivia – 0ll the rest6 preprocessor #irectives

    whitespaces comments

    S?NT0* TREE7 B"N2 %F ENT"T"ES<

  • 8/17/2019 Compilers in .NET VNext

    15/41

    R%S(?N 2E&%

    SINTAX TREE

  • 8/17/2019 Compilers in .NET VNext

    16/41

    • >orking with solution an# pro-ects assembliesan# #ocuments.

    >%RBS'0$E 0'"

  • 8/17/2019 Compilers in .NET VNext

    17/41

    R%S(?N 2E&%

    Explorer Workspace

  • 8/17/2019 Compilers in .NET VNext

    18/41

    • Roslyn provi#er powerful Scripting 0'" for#ynamically compiler $ script.

    • Script execution is #one in Execution context• "nteractive with ,ost 0pplication

    R%S(?N S$R"'T"N1 0'"

  • 8/17/2019 Compilers in .NET VNext

    19/41

    R%S(?N 2E&%

    Scripting API

  • 8/17/2019 Compilers in .NET VNext

    20/41

    R%S(?N 2E&%

    C# !" eat$re %emo

  • 8/17/2019 Compilers in .NET VNext

    21/41

    • Next 1eneration of !"T $ompiler

    • &emory (imitation to 91+ for bit

    • 0lmost unlimite# for G9 bit• G9 bit !"T 3 twice slower than !"T

    • Ryu!"T the same co#e base as !"T

    • Ryu!"T for G9 bit architecture

    • x is faster that !"T

    • Ryu!"T app 8H faster than !"T

    R?C!"T NE> .NET !"T $%&'"(ER

  • 8/17/2019 Compilers in .NET VNext

    22/41

    • two ways to turn on Ryu!"T.

     – set an environment variable: $%&'(CSI0lt!itJK

     – for entire machine set the registry key,B(&LS%FT>0REL&icrosoftL.NETFrameworkL0lt!itto the string MKM.

    • +oth metho#s cause the G96bit $(R to use Ryu!"T

    instea# of !"TG9.• 0n# both are temporary settingsinstalling Ryu!"T

    #oesnOt make any permanent changes to yourmachine 7asi#e from installing the Ryu!"T =les in a

    #irectory<

    "NST0(( 0N2 SETT"N1 R?C!"T

  • 8/17/2019 Compilers in .NET VNext

    23/41

    ;. +uil# tab check 'refer 6bit checkbox

    . 2ebug tab check Enable native co#e #ebugging. 0fter buil# check if proto-it.#ll is loa#e#

    EN0+(E R?C!"T "N )S

  • 8/17/2019 Compilers in .NET VNext

    24/41

    R?C!"T 2E&%

    Setting $p R&$'IT compiler 

  • 8/17/2019 Compilers in .NET VNext

    25/41

    • 'recompilation technology buil#ing >in#ows Storeapp

    • .NET apps compile# to "( co#e.• 0t Run6Time !"T compiler translates "( co#e in to

    native

    • 0t 2esign Time .NET Native #irectly compiles $

    apps targets .NET in to native co#e

    .NET N0T")E

  • 8/17/2019 Compilers in .NET VNext

    26/41

    • 'rovi#es superior performance of native apps

    • Still using $ language an# .NET Framework• Still using #ebugging an# #eveloper experience of

    .NET

    >"T, .NET N0T")E ?%CR 0''S

  • 8/17/2019 Compilers in .NET VNext

    27/41

    • Fast execution times

    • $onsistently spee#y startup times

    • (ow #eployment an# up#ate cost• %ptimiDe# app memory usage

    • "t transform the way .NET apps are built an#execute#

     – 2uring precompilation .NET #ll are staticallylinke#

     – 0pps runs with local libs of .NET Framework

    • Same back en# as the $PP compiler optimiDe#for static precompileation scenarios

    02)0NT01ES %F .NET N0T")E

  • 8/17/2019 Compilers in .NET VNext

    28/41

    ;. +uil#ing the &S"( application from source

    . 1enerating interop marshaling an# serialiDation

    co#e. &erging the application

    9. Re#ucing the application

    Q. %ther &S"( transformations

    G. $ompiling from &S"( to &achine 2epen#ent"nterme#iate (anguage 7&2"(<

    . +in#ing from &2"( to native co#e

    STE'S "N +C"(2"N1 .NET N0T")E 0''

  • 8/17/2019 Compilers in .NET VNext

    29/41

    .NET N0T")E 0''S 0(RE02? "N T,EST%RE

  • 8/17/2019 Compilers in .NET VNext

    30/41

    )"SC0( STC2"% E*'ER"EN$E F%T .NETN0T")E

    ;. Enable . 2ebug5testapp

  • 8/17/2019 Compilers in .NET VNext

    31/41

    .NET N0T")E 2E&%

    Compiling (ith !NET Nati)e

  • 8/17/2019 Compilers in .NET VNext

    32/41

    • r#.xml whether #esignate# elements are available

    for reection.

    RCNT"&E 2"RE$T")ES 7R2.*&(< %F.NET N0T")E

  • 8/17/2019 Compilers in .NET VNext

    33/41

    • http:55schemas.microsoft.com5netfx58;58;5meta#ata namespace

    • root element is the 2irectives element• $an contain:

     –  8 or more (ibrary elements

     – 8 or more 0pplication element

    • 0pplication can #e=ne application6wi#e runtimereection policy or it can serve as a container forchil# elements

    • (ibrary element on the other han# is simply a

    container

    STRC$TCRE %F R2 2"RE$T")ES

  • 8/17/2019 Compilers in .NET VNext

    34/41

    • degree #eclares what youre planning on #oingwith that type or member at runtime

    • 2ynamic #egree means that youre planning tocreate ob-ects or invoke metho#s #ynamically

    • E1. 2ata$ontractSerialiDer #egree means thatyoull serialiDe a class using the

    2ata$ontractSerialiDer• 'olicy how to apply the #egree to the type or

    member.

     – 0ccessibility 7public or all6all members will be

    applie#<

    R2.*&(

  • 8/17/2019 Compilers in .NET VNext

    35/41

    • - &y$lass is available to

    #ynamic reection

    • VNamespace NameJM&yNamespaceMSerialiDeJMReUuire# 0llM 5W 6 inclu#e all types from

    namespace an# make them ReUuire# whether isreally nee# or not.

    R2.*&( 6 E*0&'(ES

  • 8/17/2019 Compilers in .NET VNext

    36/41

    • Replace the $ #ynamic keywor# with strongly

    type# co#e• Skip compile# ("N4 expressions because they are

    interprete# instea# of compile# an# use reectiontoo.

    • "nstea# of Type.1etType7@&y>ellBnownTypeAellBnownType

  • 8/17/2019 Compilers in .NET VNext

    37/41

    • Fill the slades

    &"1R0T"%N T% .NET N0T")E

  • 8/17/2019 Compilers in .NET VNext

    38/41

    .NET N0T")E 2E&%

    *sing R$n+Time %irections

    (ith !NET Nati)e

  • 8/17/2019 Compilers in .NET VNext

    39/41

    ;. Roslyn new .NET $ompiler 'latform

    . $ompiler as a 'latform. Ryu!"T 8H faster startup of G9 bit .NET apps

    9. .NET Native .NET app with performance as $PP

    SC&&0R?

  • 8/17/2019 Compilers in .NET VNext

    40/41

    • 450

  • 8/17/2019 Compilers in .NET VNext

    41/41

    %CR S'%NS%RS &02E T,"S '%SS"+(EX T,0NB ?%CX