Repository navigation
Establish interface between driver and compiler - #2045
Conversation
|
I think an interface for configuration makes sense from a developer usability point of view. Classes where you have to know to call a bunch of methods in the right order are less easy to use than ones where you pass all the configuration in in one shot. Having the interface represent what's configurable would help document the config options available. We should make sure you can call any of them in arbitrary order obviously. Having |
| } | ||
|
|
||
| /// <summary> | ||
| /// Compiles the provided method code node while swapping it's body with a throwing stub. |
|
|
||
| compilation | ||
| .UseBackendOptions(_codegenOptions) | ||
| .ConfigureDependencyGraph(factory => |
There was a problem hiding this comment.
Cool, I added a bit more of it! And we'll have even more in the future.
|
I like the fluent design for options, but I do not think it should be applied to Compilation (the worker object). I like how Roslyn solved this problem - they have different compilations (C#, VB) that share some of the stuff, and that have a lot of differences as well. Pretty similar to our problem.
The basic C# compiler then looks like this: |
|
|
||
| if (!_compilation.Options.NoLineNumbers) | ||
| // TODO: NoLineNumbers | ||
| //if (!_compilation.Options.NoLineNumbers) |
There was a problem hiding this comment.
Note: I can pipe this through, but do we actually have a use case for this? I think it will be more valuable to have the general "do not generate debug info" switch (that just passes the flag to RyuJIT) instead of trying to restrict what RyuJIT sees.
| // We might have already compiled this method. | ||
| if (methodCodeNodeNeedingCode.StaticDependenciesAreComputed) | ||
| continue; | ||
|
|
There was a problem hiding this comment.
Maybe bulk of this logic should be in the base class - to make #2062 easier?
There was a problem hiding this comment.
Yes, I thought about it (and it's the reason why ShadowConcreteMethodNode is generic over whatever is the code node in the compilation) - I specifically avoided this though because this is the place where we're going to make the compiler multi-threaded. That work should not be slowed down by having to multi-thread cppcodegen too.
| /// Compiles the provided method code node while swapping its body with a throwing stub. | ||
| /// </summary> | ||
| private bool TryCompileWithThrowingBody(MethodCodeNode methodNode, TypeSystemException exception) | ||
| { |
There was a problem hiding this comment.
This is also not RyuJITCompilation specific ... would be useful for #2062.
There was a problem hiding this comment.
I looked into this, but this is same argument as above: this depends on MethodCodeNode that is RyuJIT specific. Factoring it out will make us share more code with CppCodegen that I'm comfortable with (I would need to dig into factoring of ComputeDependencyNodeDependencies, make Compilation a generic type over the type of the node that represents methods and start sharing codepaths where we're going to do multithreaded compilation in RyuJIT).
I would prefer not to share those parts yet, or do it in a separate commit that is easy to revert when it gets inconvenient (because I have a feeling it will).
There was a problem hiding this comment.
A single line in the method depends on MethodCodeNode. The rest is general IL stub emitting - perhaps it can live where all other IL stub emitters live?
There was a problem hiding this comment.
Oh, okay, that seems reasonable. Done.
|
cc @mjsabby |
|
Awesome I'll look in a few hours. |
|
Good general direction, I like it. The main way I approach a new C# codebase is looking at all news and seeing why they are there and if they can be DI'd (dependency injection), and that usually percolates to cleaner interfaces in my experience. So that's how I'm going to see (on top of this change) to see how the split can happen. |
I'm experimenting with separating out the RyuJit/CppCodegen pieces of Compilation.
This is an attempt to fix #52. I'll also fix #875 in the process.
I think the "what should go where" question is decided, but I'm still trying to settle on a nicer interface. I'm trying to see if I can make the fluent API stick, but I'm not sure about it.
The main problem I still didn't solve is in the duality of the
Compilationclass - from one side it's a class you need to configure to use (so we need public API for that), but on the other side it's a class that code generator backends use to talk to the driver (so we need API for that too). The result is a confusing public API surface.I'm trying hard to avoid a
CompilerBuilderclass, but it might be inevitable. Or maybe I can put the configuration side behind an explicitly implemented interface. Very open to feedback...