MerlinVR / UdonSharp

An experimental compiler for compiling C# to Udon assembly
MIT License
678 stars 89 forks source link

Compiler backend switch from Roslyn AST API to Roslyn Semantic API #105

Closed MerlinVR closed 3 years ago

MerlinVR commented 3 years ago

While Roslyn's AST view has worked well enough to let us parse the AST of code, it requires us to bind and figure out the meaning of symbols ourselves.

This largely manifested in the ExpressionCaptureScope in 0.x. This worked, but was inefficient and very prone to error.

The semantic API gives us insight into what a particular syntax node is referring to, along with extensive information on types and their symbols. It solves most of the hard problems that can be solved generically from a C# point of view such as overload resolution and ambiguity between multiple symbols with the same name.

Using the semantic API means that Roslyn runs a full compile of user code without the emit step, this means we can rely on Roslyn to encounter compile errors before we start parsing user code. So we require much less sanitation on inputs since we can assume that all things not valid in C# that can be determined ahead of time will not make their way to UdonSharp.

The semantic API passively allows proper support for some lower level things like static using directives and alias directives.