-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Migrate to Roslyn typesystem? #896
Comments
Without commenting on the difficulty level, I'd love to see a system based on Roslyn. We've been discussing building decompilation into VS, with a plan to do so by levering ILSpy. One of the concerns has been what happens when we release a new language feature that ILSpy doesn't support. Moving ILSpy closer to Roslyn means that it would likely be easier to update. Who knows, maybe Roslyn team members would even contribute updates to support new language features. |
Just a suggestion, if you don’t mind relying on internals, you can use https://github.com/aelij/IgnoresAccessChecksToGenerator This is what I use to build the RoslynPad.Roslyn assembly. |
On the syntax side of things:
Except for the mutable AST, all of this looks like it could also done in Roslyn, but it's a lot of code churn for little benefit. |
I took a look at using the Roslyn type system in the decompiler.
|
I guess re-using overload resolution would be possible by feeding something like But Roslyn's overload resolution is only nice-to-have: our own implementation was fairly good for C# 5.0 code; and since the newer C# versions are backward-compatible with that, lacking the new features only means we end up sometimes emitting a few unnecessary casts. Currently the only really compelling reason I see to move to Roslyn is that we'd get to re-use the nullability flow analysis. This would allow us to infer nullable reference types for local variables. And the analysis is complex enough that we can't easily re-implement it. It's also quite possible (certainly in the short term) that porting relevant code pieces from Roslyn to the decompiler type system is better than porting the whole decompiler to the Roslyn type system. |
The
newdecompiler
branch just migrated ILSpy from Cecil (pretty much no type system at all), to the NRefactory type system.We picked NRefactory.TypeSystem because we knew it, and because all the logic we need is publicly available there (whereas with Roslyn, we'll likely need to fork it and access its internals).
However, NRefactory only supported up to C# 5, and even though we stripped it down to only the portions we need and integrated them into ICSharpCode.Decompiler, it would still be a lot of effort to upgrade the following parts to later C# versions:
The NRefactory API turned out to be great for this, because it allows all of these operations to be performed independently of the syntax tree. The Roslyn APIs seem to be less suitable for the case where we have already-bound subexpressions and want to determine how to generate an invocation expression so that it binds to the correct method: unlike NRefactory where
CSharpResolver.ResolveInvocation()
takes already-bound arguments as inputs, the equivalent RoslynBinding.BindInvocationExpression()
will itself recursively call BindExpression() on the arguments.Although this might not be an issue if there's a cache that lets us avoid re-binding the argument over and over again for each parent InvocationExpression we try.
So the big question is: do we keep maintaining our own implementation of a significant portion of the C# spec, or do we fork+patch Roslyn to be usable in ILSpy, and migrate everything over?
If we just went for C# 7 compatibility it's probably not too hard to keep maintaining NRefactory, especially since our own implementation of overload resolution doesn't have to be perfect -- if it emits a false positive compiler error, we'll just emit a few redundant casts.
But at some point we might try to revive the VB decompiler, and we certainly don't want to reimplement a big chunk of the VB spec using the NR typesystem.
The text was updated successfully, but these errors were encountered: