Repository navigation
Conversation
|
Hi @wjk, I'm your friendly neighborhood .NET Foundation Pull Request Bot (You can call me DNFBOT). Thanks for your contribution! TTYL, DNFBOT; |
Ah yes, I was trying to fix this in the past and I remember hitting this too, so I postponed my work on this because I didn't really need it. The problem is that dotnet is dragging in a reference to |
| if (_typeSystemContext.InputFilePaths.ContainsKey(inputFile.Value)) continue; | ||
|
|
||
| var module = _typeSystemContext.GetModuleFromPath(inputFile.Value); | ||
| if (module.Equals(_typeSystemContext.SystemModule)) continue; |
There was a problem hiding this comment.
I think this is only needed because there is
AddCompilationRootsForExports((EcmaModule)_typeSystemContext.SystemModule);In SingleFileCompilationModuleGroup.cs. The right fix is to delete the line from there.
…thods Previously, it would ignore referenced assemblies (-r flag) except for System.Private.CoreLib. Note that the tests currently do not pass with this change applied.
|
@MichalStrehovsky I've just rebased this branch on top of |
I simply checked to see if the assembly in question is mscorlib when a double-reference error occurs, and if so simply ignore the reference. (All other double references still result in an exception.)
|
@MichalStrehovsky Assuming my fix to the double-reference error in commit 07be889 is OK, this PR is ready to merge now that the unit tests pass. |
|
|
||
| AddWellKnownTypes(rootProvider); | ||
| AddReflectionInitializationCode(rootProvider); | ||
| foreach (var inputFile in _typeSystemContext.ReferenceFilePaths) |
There was a problem hiding this comment.
This block should be placed in SingleFileCompilationModuleGroup::AddCompilationRoots. We don't want to generate exports for non-input modules when we're doing a multifile compilation (because those exports will be generated when we're compiling the referenced module itself).
|
|
||
| AddCompilationRootsForExports((EcmaModule)_typeSystemContext.SystemModule, rootProvider); | ||
| foreach (var inputFile in _typeSystemContext.ReferenceFilePaths) | ||
| { |
There was a problem hiding this comment.
I think it would be more appropriate to iterate over InputFilePaths instead.
The idea behind InputFilePaths and ReferenceFilePaths is that InputFilePaths is the source of roots - what is guaranteed to get compiled. ReferenceFilePaths can contain a lot of junk, but that it should not matter because of it will be touched and compiled in only if it gets actually referenced.
There was a problem hiding this comment.
Hm. Interesting. The main reason I brought up this change was because in my private-repo project I had a number of assemblies that needed to be scanned for NativeCallableAttribute. I only used ReferenceFilePaths because that was what worked for me at the time I first wrote it. If you want to go with InputFilePaths instead, it would easy enough for me to adjust my build scripts.
There was a problem hiding this comment.
Also note that we'll have to restore special-case handling for System.Private.CoreLib if we go this route.
There was a problem hiding this comment.
@jkotas It feels like the distinction between what's an input file and what's a reference is rather blurry for single file compilation. If I e.g. use a NuGet package with a library that has some NativeCallable methods, should those be exposed? Or only when the NativeCallable methods are in my entrypoint assembly? What's the "entrypoint assembly" if I'm compiling a library?
Maybe we should add a method on ModuleDesc that lets us enumerate all the NativeCallable and RuntimeExport methods without loading all the types and methods (because scanning all the junk is indeed rather expensive) and go with this?
There was a problem hiding this comment.
(I actually already experimented with the ModuleDesc extensions for this some time ago: MichalStrehovsky@52702cc. I ended up not using this because it wasn't saving anything because the NameMangler loads a bunch of junk types and methods from each assembly anyway.)
There was a problem hiding this comment.
The single file compilation is meant to mimic simplicity and efficiency of the classic compilers. You can do cl hello.cpp and it will quickly produce self-contained .exe. Underneath, the compiler has references to a ton of standard header files and the linker command line has references to number of .libs - so that you do not need to worry about adding just the right ones. You won't get any of it unless it is referenced from your .cpp file.
The simple things should be simple, the hard things should be possible. If you have multiple libraries with named NativeCallable exports, I think it is fine that you need to do a bit extra work for it. Also, I would not mind if we introduce more fine grained controls for it (e.g. scan named exports for given module, add full reflection for given module, etc.). But I do not think we should be adding roots for everything in the reference list by default.
There was a problem hiding this comment.
Okay, that makes sense - I was not looking at it from the right angle.
Per suggestion by @jkotas. Also re-added a special-case check for System.Private.CoreLib, without which ILC-generated object files will not link.
|
@wjk, Thanks for signing the contribution license agreement so quickly! Actual humans will now validate the agreement and then evaluate the PR. |
|
@wjk Is there anything in this pull request you would like to merge, or can we close it?
|
|
@MichalStrehovsky Yeah, this one can be closed. Following @jkotas’ comments above, the whole point of this PR is now already present in ILC. |
With this PR merged, ILC now scans referenced assemblies for methods marked with
NativeCallableAttribute. Previously, it would ignore referenced assemblies (-r flag) except for System.Private.CoreLib.Please note that the repo's unit tests currently do not pass with this change applied! (When used on my private-repo project, however, it works well.) I am only submitting this PR now for feedback and to hopefully gain an answer to why the tests are failing. I will not sign the CLA until these issues are resolved, or unless it is required for pre-merge code review.All unit tests now pass; see below.