Follow Slashdot stories on Twitter

 



Forgot your password?
typodupeerror
×
Programming Microsoft

Microsoft Roslyn: Reinventing the Compiler As We Know It 195

snydeq writes "Fatal Exception's Neil McAllister sees Microsoft's Project Roslyn potentially reinventing how we view compilers and compiled languages. 'Roslyn is a complete reengineering of Microsoft's .NET compiler toolchain in a new way, such that each phase of the code compilation process is exposed as a service that can be consumed by other applications,' McAllister writes. 'The most obvious advantage of this kind of "deconstructed" compiler is that it allows the entire compile-execute process to be invoked from within .NET applications. With the Roslyn technology, C# may still be a compiled language, but it effectively gains all the flexibility and expressiveness that dynamic languages such as Python and Ruby have to offer.'"
This discussion has been archived. No new comments can be posted.

Microsoft Roslyn: Reinventing the Compiler As We Know It

Comments Filter:
  • by ZeroExistenZ ( 721849 ) on Friday October 21, 2011 @11:42AM (#37793342)

    What do they exactly mean by "flexibility and expressiveness of other dynamic languages" ?

    I remember a demo at a Microsoft Developer congress where C# would be able to execute and rebuilt itself dynamically.

    At the time it got me really excited (as I've bumped into many problem which would have a much more beautiful solution should I be able to compile during runtime.) but this seems yet another technology?

    • by Dexter Herbivore ( 1322345 ) on Friday October 21, 2011 @11:45AM (#37793390) Journal
      I'm wondering if my programming skills have fallen away so much through lack of use that I don't understand this as well anymore, or if the summary/article is just full of buzzwords and impressive sounding jargon.
      • by Jonner ( 189691 ) on Friday October 21, 2011 @03:44PM (#37797484)

        I'm wondering if my programming skills have fallen away so much through lack of use that I don't understand this as well anymore, or if the summary/article is just full of buzzwords and impressive sounding jargon.

        It's entirely the latter. What they're describing is nothing Lisps haven't been doing for decades. Although I don't need to use in my everyday programming, standard Python also exposes APIs for compiling source and manipulating syntax trees.

    • by ackthpt ( 218170 ) on Friday October 21, 2011 @11:53AM (#37793508) Homepage Journal

      What do they exactly mean by "flexibility and expressiveness of other dynamic languages" ?

      I remember a demo at a Microsoft Developer congress where C# would be able to execute and rebuilt itself dynamically.

      At the time it got me really excited (as I've bumped into many problem which would have a much more beautiful solution should I be able to compile during runtime.) but this seems yet another technology?

      I don't think of it as a new technology, but Microsoft is finally getting around to it. They are such a big dog now that some people don't recognize change until Microsoft rolls it out - years after others have already been mucking about in it for years.

      If they roll it out in a good package, that's a good thing. If they price it above most developers budgets than they're going to be bypassed.

      • by ByOhTek ( 1181381 ) on Friday October 21, 2011 @12:11PM (#37793828) Journal

        They'll probably do exactly what they've done with the past 2 or 3 releases of Visual Studio.

        Roll it out, have something that's actually pretty damn good, and as long as you aren't making a commercial product, it is all free (except for a couple reporting tools and their code repository server, the latter of which can easily be replaced with 90% of the features by using Mercurial using VisualHG + TortoiseHG, which are free and better suited for most non-corporate development models anyway).

        Now, if you want to use it commercially, that's $750 or so a seat. For the quality of the software, I think it is worth it, but others may disagree.

      • by terjeber ( 856226 ) on Sunday October 23, 2011 @05:57PM (#37812354)

        years after others have already been mucking about in it for years

        Could you provide an example of that? This is not the ability to compile code at runtime, .NET has had that for years. I have several .NET projects where I generate code on the fly, compile and then run it. Have the same for Java. That is not what Roslyn is.

    • by Aladrin ( 926209 ) on Friday October 21, 2011 @11:58AM (#37793610)

      In the past, you could compile C# source code at runtime and load it into memory and use it. (I know, I was doing it for a MUD that didn't pan out.) But it wasn't very dynamic. (We were using it to reload the code without restarting the MUD.)

      I assume this news means that you can write code dynamically, without writing it to a text file first.

    • Re:3 years ago (Score:5, Insightful)

      by sourcerror ( 1718066 ) on Friday October 21, 2011 @12:01PM (#37793662)

      Tiny C compiler does this for years:
      http://bellard.org/tcc/ [bellard.org]

      Features

      SMALL! You can compile and execute C code everywhere, for example on rescue disks (about 100KB for x86 TCC executable, including C preprocessor, C compiler, assembler and linker).

      FAST! tcc generates x86 code. No byte code overhead. Compile, assemble and link several times faster than GCC.

      UNLIMITED! Any C dynamic library can be used directly. TCC is heading torward full ISOC99 compliance. TCC can of course compile itself.

      SAFE! tcc includes an optional memory and bound checker. Bound checked code can be mixed freely with standard code.
      Compile and execute C source directly. No linking or assembly necessary. Full C preprocessor and GNU-like assembler included.

      C script supported : just add '#!/usr/local/bin/tcc -run' at the first line of your C source, and execute it directly from the command line.

      With libtcc, you can use TCC as a backend for dynamic code generation.

      • Re:3 years ago (Score:2, Interesting)

        by Anonymous Coward on Friday October 21, 2011 @12:15PM (#37793880)

        You might want to read this wrt tinycc: http://www.landley.net/code/tinycc/
        Also, no x86-64.

        • by pclminion ( 145572 ) on Friday October 21, 2011 @12:39PM (#37794260)

          You might want to read this wrt tinycc: http://www.landley.net/code/tinycc/ [landley.net]

          Jesus. That is the saddest story I've ever read. I want to find that guy and give him a hug.

          That's a pretty good summary of why I never bother contributing to open source any more, even though I have tons of code lying around including cool modifications of some pretty big-name projects. I've been lucky enough to never work with douchebags in the salaried, closed source world. I sure as hell will not suffer it while also not making any money from my efforts.

          • by TheCarp ( 96830 ) <sjc@caCOMMArpanet.net minus punct> on Friday October 21, 2011 @03:49PM (#37797584) Homepage

            wow that sucks balls.

            If I were him, I would have just given up on them much sooner. I used CVS myself exclusively until recently but, I don't think I ever had the illusions of it being really good or even sufficient for real development (luckily for most of my use cases, cvs is borderline overkill)

            I can't imagine someone using CVS heavily, for any significant period of time, and still believeing it to be the bees knees. Unless you have a top notch CVS admin who swoops in fixes things, and makes the annoying stuff nearly transparent for you, then it shows its age and its bain drammge very quickly. I ended up playing that CVS admin for a while, even got good at it....but doing so disabused me of any delusion of CVS being great.

            Git on the other hand.... I can't imagine anyone using both git and CVS, and not wanting to convert everything to git, once and for all.

            Hell I even want to do it in the few places that I still use CVS, I am tempted to change it, and only don't because they are places where changing it and retraining people would be more work than its worth, since its a case where file moves never happen, and we never have multiple lines of development at the same time. (making it a glorified change tracker, rather than a collaboration tool)

            thats just....lame.

      • Re:3 years ago (Score:5, Informative)

        by TheRaven64 ( 641858 ) on Friday October 21, 2011 @02:24PM (#37796182) Journal
        LLVM is a better example. It's a set of libraries for generating a code in an intermediate representation, transforming that representation (usually for optimisation, but also for instrumentation and other things) and then emitting it as object code, assembly, or JIT'd executable code in memory. I've written compilers for Smalltalk and for a toy JavaScript-like language using it, and they share the same set of optimisations that I wrote for Objective-C and the same object model. The total amount of Smalltalk-specific code is about 15KLoC (including comments).
    • by ByOhTek ( 1181381 ) on Friday October 21, 2011 @12:07PM (#37793756) Journal

      I think the idea is that it will be easier than the current methods. Also, if I remember correctly from previous articles, there will be more profiling information available to help with optimization tasks.

    • by gbjbaanb ( 229885 ) on Friday October 21, 2011 @12:39PM (#37794274)

      yes, but a lot of that was built through the reflection feature of .NET, which in turn makes it very slow and clumsy. Reflection has its uses, but the easiest way to tell is to use the following rule: "if you're using it you're doing things wrong."

    • by tixxit ( 1107127 ) on Friday October 21, 2011 @01:01PM (#37794686)
      It makes little sense, in that the dynamism of dynamic languages have nothing to do with "eval" (how many people write Python programs that write Python programs?). More over, runtime compilation is hardly new. Clojure, for example, is always compiled to bytecode, even at runtime, and is a dynamic language. Scala's REPL is a great example of a statically typed language being dynamically compiled and run. With Scala, you can even easily hook into the compiler tools to create your own interpreter and compile code on the fly and run it. There may be new things in Roslyn (I don't know), but, if so, the summary/article missed them.
  • old news? (Score:4, Interesting)

    by Verunks ( 1000826 ) on Friday October 21, 2011 @11:44AM (#37793360)
  • by dkleinsc ( 563838 ) on Friday October 21, 2011 @11:44AM (#37793378) Homepage

    If I wanted to, I could rig GCC and the like to do that too: That's the wonderful thing about command-line tools and piping, you can munge things together any way you want. And of course you can always tell gcc to stop partway through the compilation if you need assembler code or a parse tree or something. This sort of thing is common in open-source compilers, because they need these features for debugging purposes and have no reason to leave them out of the released version.

    Of course, I probably don't want to include a feature like this dynamic code execution, because if I screw up, it would be a fantastic way to get a machine to execute code that it's not supposed to.

    • by Mr. McGibby ( 41471 ) on Friday October 21, 2011 @11:48AM (#37793438) Homepage Journal

      Yeah, just try it wtih GCC. Not easy. CLANG on the other hand is looking AWESOME for this sort of thing. Once a libraryized version of CLANG is good, it'll make this sort of thing easy.

      • by TheRaven64 ( 641858 ) on Friday October 21, 2011 @02:31PM (#37796312) Journal

        Uh, clang is 'libraryized'. The clang binary is a tiny wrapper around the various libraries. It's pretty simple to write a replacement or to embed the libraries in something else. Look at Cling, for example, which implements a C++ REPL system using the libraries, or LLDB, which uses clang to parse [Objective-]C[++] expressions in the debugger.

        If the grandparent thinks any of this is easy with gcc, then he's never tried hacking on gcc - even using it for syntax highlighting is almost impossible because the gcc team intentionally avoids clean layering incase someone uses their code evil proprietary programs.

    • by wootest ( 694923 ) on Friday October 21, 2011 @01:35PM (#37795312)

      The "dynamic code execution" just builds on top of support that's already there. You could build a string of a C# program, feed it to a compiler and run it dynamically previously as well. This just makes the compilation part less of a headache.

      Rigging GCC (other comments have already brought up clang) would maybe be more dangerous because arbitrary C code could do anything. Arbitrary IL code can be hamstrung by some security layers. Of course, the differences between managed and native code pale in comparison to what permissions they are executing with, the robustness of any jailing or sandboxing that might be in place and so on.

      If you worry that people can compile programs into executable code, you're not worrying about the right thing. You could write a C compiler in JavaScript or QBASIC. You should be worrying about what happens when that code executes.

    • by shutdown -p now ( 807394 ) on Friday October 21, 2011 @02:17PM (#37796030) Journal

      This is about much more than just a way to run the compiler. It exposes all lexer and parser layers, so you can get AST. It also exposes separate stages of semantic analysis of that tree, so you can e.g. get it with type annotations for all nodes (after all type inference and method overload resolution), or metadata specifying which of the three foo's in scope this particular identifier "foo" refers to.

      Basically, it's a toolkit that lets you write software that works with C# or VB code and requires deep understanding of it - think static code verifier, or IDE with code completion and refactoring - while reusing the same infrastructure that is used by the compiler itself.

  • by gnasher719 ( 869701 ) on Friday October 21, 2011 @11:46AM (#37793400)
    It seems that Neil McAllister has never heard of LLVM and Clang, while Microsoft obviously has.
  • by Toonol ( 1057698 ) on Friday October 21, 2011 @11:49AM (#37793452)
    That's something that I haven't seen a language really get right since FORTH. I'd love to be able to use C# in a similar way, entering small function definitions from the command line, compiling them as they're entered, interactively testing functions as they're written. It's a great way to speed development.
  • This sounds great if you're doing stuff like autotuning, but for the vast (vast, vast, vast) majority of programmers out there I don't really see how opening up the internals of the compiler is useful. Who cares if that loop gets fused or that function gets unrolled?

  • Sounds like LLVM (Score:3, Informative)

    by Dwonis ( 52652 ) * on Friday October 21, 2011 @11:56AM (#37793574)

    Roslyn is a complete reengineering of Microsoft's .NET compiler toolchain in a new way, such that each phase of the code compilation process is exposed as a service that can be consumed by other applications,

    Sounds like LLVM.

  • opengtl, llvm, krita (Score:2, Informative)

    by vurian ( 645456 ) on Friday October 21, 2011 @11:57AM (#37793592) Homepage
    Compile and execute code from within an application? That's exactly what Krita (http://www.krita.org) does with OpenGTL (http://opengtl.org) -- we have code written in special languages for filters and so on which gets compiled by Krita and then executed as native code. It's pretty safe as well.
  • by Animats ( 122034 ) on Friday October 21, 2011 @11:58AM (#37793606) Homepage

    This isn't exactly new. LISP had it from the early days. It's an idea that's been tried before, now available with more modern buzzwords, like "the compiler as a service".

    .NET as a virtual machine environment has become somewhat pointless, since the Windows/.NET environment is pretty much "write once, run on X86" now. Itanium support was dropped in 2010, and Microsoft's "Windows 8 for ARM" is apparently Metro-only.

  • by GameboyRMH ( 1153867 ) <[gameboyrmh] [at] [gmail.com]> on Friday October 21, 2011 @11:59AM (#37793614) Journal

    Can't wait to get my hands on a FOSS clone of it.

  • by robmv ( 855035 ) on Friday October 21, 2011 @12:03PM (#37793698)

    like the Scala compiler? an API, plugin support and more? the Scala shell uses it as an example of how to use it

  • by DragonWriter ( 970822 ) on Friday October 21, 2011 @12:23PM (#37794030)

    With the Roslyn technology, C# may still be a compiled language, but it effectively gains all the flexibility and expressiveness that dynamic languages such as Python and Ruby have to offer.

    C#, Ruby, and Python are all (in their main implementations) compiled languages. Where they differ is that C# is mostly-statically-typed, and Ruby and Python are dynamically-typed. The .NET compiler toolchain being exposed as a runtime service doesn't really make C# much more like Ruby or Python, since it doesn't change their main area of difference between the languages. It does mean that you can implement the equivalent of eval for .NET languages that don't already have it (like C#), which makes it a little bit more like Ruby or Python, but I don't think "C# doesn't have eval" is really the main reason people would think Ruby or Python is better for certain tasks than C#.

    • by Xest ( 935314 ) on Friday October 21, 2011 @01:14PM (#37794922)

      C# got optional dynamic typing in version 4 with the DLR, although the DLR is really a set of libraries that just helps with building the required expression tree at run time to allow the dynamic behaviour.

      I do somewhat agree though that I don't see how this gives it any more of the benefits of Python and Ruby than it already had.

      • by DragonWriter ( 970822 ) on Friday October 21, 2011 @01:43PM (#37795428)

        C# got optional dynamic typing in version 4 with the DLR

        Right. That's why I said it was mostly-statically-typed rather than just plain statically-typed.

        Compiler-as-a-service is a nice feature for the .NET runtime (and, as I understand it, this is a .NET runtime feature, not a C# language feature), but the Ruby/Python comparison doesn't really seem to be on-point as to why.

  • by menkhaura ( 103150 ) <espinafre@gmail.com> on Friday October 21, 2011 @12:56PM (#37794580) Homepage Journal

    They found a way to shove XML into the compiler! Kudos to MS!

    (see sig)

  • by juancn ( 596002 ) on Friday October 21, 2011 @01:18PM (#37794990) Homepage
    We used that approach for PBL [goo.gl] some years ago. It is wasteful to having to rewrite parsers and lexers for languages to build IDEs, and other tooling.

    For example, code indentation can be done by walking the AST (you need to be careful to preserve hidden tokens, such as comments).

    You can also allow code completion by changing the compiler to accept a "COMPLETION" token in some places in the grammar. Then, from the editor, when someone presses "Ctrl+SPACE" (or whatever) you mark the location in the lexer and send the code to the compiler. When you build the ast, you insert a completion node in the AST, and you have now contextual information about what can go in there and produce a list of potential things that can go in there.

    Also, syntax highlighting can use the lexer for basic coloring and some type information to then add more information (such as what are field, or functions, etc.)

    What's new is exposing these phases in a standardized manner in the language. That's a bold move, since backward compatibility will be tricky to maintain. Maybe they're thinking in finally stabilizing C#.
  • by LordMyren ( 15499 ) on Friday October 21, 2011 @01:26PM (#37795132) Homepage

    This premise, a managed AST you can manipulate programmatically (a SOM, Source Object Model), plus a managed compiler pipeline to compile, is nothing new. Boo language was doing this on .NET , and I'm sure there are many examples before it: Boo was started in 2003.

  • by sl4shd0rk ( 755837 ) on Friday October 21, 2011 @01:33PM (#37795274)

    Seems to me Microsoft is now attempting to do with compilers what they attempted to do with the mobile phone.

  • by brunes69 ( 86786 ) <slashdot@keir s t e a d.org> on Friday October 21, 2011 @01:47PM (#37795502)

    How is this any different at all from Javassist?

  • by benhattman ( 1258918 ) on Friday October 21, 2011 @06:28PM (#37799566)

    I see a lot of other tools that do this, but since C# mostly started off as a ripped off Java, it's also worth pointing out that since Java 1.6, that language also provided public interfaces to compile code at runtime [oracle.com].

    These are nice features. Sometimes, they are even useful (as opposed to just another hammer developers can abuse). But the announcement makes it seem, wrongly, that MSFT is doing something really unique here.

    • by spongman ( 182339 ) on Saturday October 22, 2011 @02:02AM (#37802102)

      LOL!

      C# Has had the equivalent of javax.tools.JavaCompiler since v1.1, Microsoft.CSharp.Compiler [microsoft.com] which is little more than a wrapper around the command-line compiler.

      But the .NET framework has also, for a long time, included Reflection.Emit [microsoft.com] which allows for direct manipulation of CIL bytecode, and System.CodeDom [microsoft.com] for generating and compiling source code in multiple languages from an abstract representation.

      I wouldn't bother reading about Roslyn, though. It couldn't possibly measure up to anything Java has had for ages now, right?

  • by BitZtream ( 692029 ) on Friday October 21, 2011 @09:01PM (#37800748)

    C# has always supported compiling additional code at runtime.

    I've had it in projects since the 1.0 release.

    They may be redoing the structure and making it easier to do, but doing it isn't new.

UNIX is hot. It's more than hot. It's steaming. It's quicksilver lightning with a laserbeam kicker. -- Michael Jay Tucker

Working...