Code Analysis with Project Roslyn
Microsoft's Lang.NEXT conference held in Redmond this month included a presentation providing a demonstration of the Roslyn's project code analysis tools. Dustin Campbell's presentation, "Going Deeper with Project Roslyn", gives a soft introduction to the project and concludes with the construction of a sample project.
The Roslyn framework is not intended to be a framework for building a custom compiler, rather it is intended to focus on maximizing the utility of C# and Visual Basic. Both of these languages have had their compilers rewritten from scratch, so that Roslyn's C# compiler is written in C# and Roslyn's VB compiler is written in VB. As Campbell observes, this has allowed for numerous corner cases and bugs in the original compilers to be corrected.
Roslyn Design Characteristics
Immutable – Objects cannot be changed, so changes are introduced by creating new objects on the originals
Complete – Full representation of the source code, including whitespace, comments, errors, etc.
Resilient– Fault tolerance to handle errors. For example, statement completion is almost always on broken code, so parsers must able to handle it.
Efficient– Project is exhibits efficiency at building snapshots, and possesses the ability incrementally parse code
When the Roslyn environment is open, two instances of the active workspace exist. The first is the traditional workspace that holds the currently loaded VS solution. The other instance holds the interactive window (REPL). This separation helps statement completion and IntelliSense to work correctly on the code in development.
Campbell notes that Roslyn while available since October in Beta format, release code (version 1.0) will not be shipping with the upcoming Visual Studio 11. Instead it will be released as part of a future VS. However, while Campbell does not specifically state this, given that the Beta supports VS2010, it would seem Microsoft could deploy it independently of a formal VS release.
Camille Fournier May 21, 2015