Skip to content
This repository was archived by the owner on Nov 13, 2026. It is now read-only.

Establish interface between driver and compiler - #2045

Merged
MichalStrehovsky merged 5 commits into
dotnet:masterfrom
MichalStrehovsky:fix52
Oct 22, 2016
Merged

MichalStrehovsky merged 5 commits into
dotnet:masterfrom
MichalStrehovsky:fix52

Conversation

@MichalStrehovsky

Copy link
Copy Markdown
Member

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 Compilation class - 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 CompilerBuilder class, but it might be inevitable. Or maybe I can put the configuration side behind an explicitly implemented interface. Very open to feedback...

@nattress

Copy link
Copy Markdown
Contributor

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 Compilation support a second, codegen-facing interface might also be useful as once configuration is done, we don't really want the config methods to be available for messing with.

}

/// <summary>
/// Compiles the provided method code node while swapping it's body with a throwing stub.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, fixed.

Comment thread src/ILCompiler/src/Program.cs Outdated

compilation
.UseBackendOptions(_codegenOptions)
.ConfigureDependencyGraph(factory =>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the chaining ;)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, I added a bit more of it! And we'll have even more in the future.

@jkotas

jkotas commented Oct 18, 2016 •

Copy link
Copy Markdown
Member

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.

  • CSharpCompilationOptions, VisualBasicCompilationOptions - settings object with fluent design
  • CSharpCompilation, VisualBasicCompilation - the actual workhorse object

The basic C# compiler then looks like this:

    var options = new CSharpCompilationOptions(...).
           WithAllowUnsafe(true).
           WithWarningLevel(5);

    var compilation = CSharpCompilation.Create(..., options);
    compilation.Emit(...);

@MichalStrehovsky

Copy link
Copy Markdown
Member Author

@jkotas @nattress How about now?

I took some inspiration from Roslyn, but ended up with a Builder instead of Options anyway - the immutability of Options looked a bit annoying to maintain.


if (!_compilation.Options.NoLineNumbers)
// TODO: NoLineNumbers
//if (!_compilation.Options.NoLineNumbers)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@MichalStrehovsky MichalStrehovsky changed the title [WIP] Establish interface between driver and compiler Establish interface between driver and compiler Oct 19, 2016
// We might have already compiled this method.
if (methodCodeNodeNeedingCode.StaticDependenciesAreComputed)
continue;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe bulk of this logic should be in the base class - to make #2062 easier?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
{

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is also not RyuJITCompilation specific ... would be useful for #2062.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, okay, that seems reasonable. Done.

@jkotas

jkotas commented Oct 21, 2016

Copy link
Copy Markdown
Member

cc @mjsabby

@mjsabby

mjsabby commented Oct 21, 2016

Copy link
Copy Markdown
Contributor

Awesome I'll look in a few hours.

@mjsabby

mjsabby commented Oct 21, 2016

Copy link
Copy Markdown
Contributor

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.

@MichalStrehovsky
MichalStrehovsky merged commit e38b1d6 into dotnet:master Oct 22, 2016
@MichalStrehovsky
MichalStrehovsky deleted the fix52 branch October 22, 2016 03:55
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

nolinenumbers command option is overloaded Interface between driver .exe and compiler .dll

5 participants