Skip to content
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

Metadata of C# (and other) Assemblies. #229

Merged
merged 6 commits into from
Jan 15, 2015
Merged

Metadata of C# (and other) Assemblies. #229

merged 6 commits into from
Jan 15, 2015

Conversation

matthid
Copy link
Contributor

@matthid matthid commented Oct 6, 2014

Better support for loading C# (and other) dlls (we need IsFSharp to be false to get all methods in "MembersFunctionsAndValues"). This will be used by FSharp.Formatting for example.

I used this with success in fsprojects/FSharp.Formatting#208 but I'm not exactly sure what I have done :)

If somebody can comment on this why it's needed or why it's wrong that would be nice. It looks like the right thing to do would be to get the ccu from the entitiy, but this seems to be impossible in this case (because it is not unresolved).

@forki
Copy link
Member

forki commented Oct 6, 2014

FSharp.Formatting support for C# would be really nice.

@7sharp9 @dsyme @vasily-kirichenko @dungpa could please take a look at this?

@dsyme
Copy link
Contributor

dsyme commented Oct 6, 2014

Yes, it is important to understand better why these are needed in FSharp.Formatting. Specifically the PR would need to have test cases that exercise these new cases.

Is there any chance you could extract an isolated simple repro from FSharp.Formatting's use of this API?

thanks
don

@matthid
Copy link
Contributor Author

matthid commented Oct 6, 2014

FSharp.Formatting is trying to load the assemblies: https://github.com/tpetricek/FSharp.Formatting/blob/master/src/FSharp.MetadataFormat/Main.fs#L816. But from the looks of it this is more a workaround than properly loading the dlls with an API call (is there even something like this?).

Because of this setup the current compile unit (ccu?) is an FSharp project so isFSharp is true and https://github.com/fsharp/FSharp.Compiler.Service/blob/master/src/fsharp/vs/Symbols.fs#L344 is doing the rest...

To get a setup like this one would either call the C# compiler or include a compiled C# dll. Are you sure you want any of those things included in this repro as unit test? Or are you asking for a simple repro in an extra git repository (which should actually not be too difficult to do, or just run FSharp.Formatting on any C# project/dll).

Maybe this more straightforward to do with more knowledge of the API (which I currently do not have)?

@dsyme
Copy link
Contributor

dsyme commented Oct 6, 2014

Strange, ccu.IsFSharp should be false for those DLLs

@matthid
Copy link
Contributor Author

matthid commented Oct 6, 2014

thisCcu is the compiling FSharp module and the entity seems to be ERefLocal for which the ccu is None -> isResolvedAndFSharp returns true (currently hardcoded actually).

My changes basically change the thisCcu pointer to point to the current dll (where IsFSharp is false like it should be). I don't know if this can do any harm, or how this design is supposed to work.

…o get all methods in "MembersFunctionsAndValues"). This will be used by FSharp.Formatting for example.
@matthid
Copy link
Contributor Author

matthid commented Jan 2, 2015

I have now added a C# project and a test-case showing the issue (I ensured that the test fails without the patch).
One sidenote: The API to analyse dll files is quite cumbersome to use and is basically a hack which first compiles a very simple F# project with the contents module M? I think it would be better to provide a more direct API in the future (to be used by FSharp.Formatting an other projects).

The commented lines in the test-method are not working (even with my patch), but they should eventually (imho).

I hope this can bring more attention to this issue!
PS: please tell me if that format is OK (ie. directly adding the C# project to the solution)

//String.IsNullOrWhiteSpace(members.["InterfaceEvent"].XmlDocSig) |> shouldEqual false

()
| None -> ()
Copy link
Member

Choose a reason for hiding this comment

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

I suppose that the code should fail in this case? (If the entity was not found, then something else went wrong...)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Correct :). While I noticed this shortly after pushing it, it's good to have a reminder comment, thanks. I guess it is no big deal for now (as that part is never executed), but I will fix that after getting an overall review/comment on the code.

@tpetricek
Copy link
Member

I don't know enough about F# compiler internals, but the test certainly looks correct to me!

Also +1 to providing simpler API for analyzing DLLs (so that the boilerplate code to create an empty project does not have to be repeated in F# Formatting and elsewhere).

@dungpa
Copy link
Contributor

dungpa commented Jan 3, 2015

It seems wrong to include a solution test case into FSharp.Compiler.Service.Tests solution. Could you move CSharp_Analysis solution to https://github.com/fsharp/FSharp.Compiler.Service/tree/master/tests/service/data instead?

@matthid
Copy link
Contributor Author

matthid commented Jan 3, 2015

The CSharp_Analysis.sln file was not really used anyway so I deleted it and moved the project to the destination you recommend.

Can the reference to the project and the project itself stay in the FSharp.Compiler.Service solution? Otherwise I'm not sure how to make the (new) test work by just opening the solution file and building FSharp.Compiler.Service.Tests...

@dungpa
Copy link
Contributor

dungpa commented Jan 5, 2015

@matthid I think it's fine as is. You need CSharp_Analysis project to be compiled anyway.

In general, this is a nice improvement. I wonder what @dsyme thinks about this.

@matthid matthid changed the title (WIP) Metadata of C# (and other) Assemblies. Metadata of C# (and other) Assemblies. Jan 13, 2015
| _ -> true
| _ ->
let ccu = defaultArg (ItemDescriptionsImpl.ccuOfItem cenv.g (getItem entity)) cenv.thisCcu
ccu.IsFSharp
Copy link
Contributor

Choose a reason for hiding this comment

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

I think these three lines should just be a single line that changes the "true" case on line 197 to "cenv.thisCcu.IsFSharp". I think the getItem change is then no longer needed and this part of the fix becomes one line.

@dsyme
Copy link
Contributor

dsyme commented Jan 14, 2015

It looks good, I've made one suggestion for a code simplification

@matthid
Copy link
Contributor Author

matthid commented Jan 14, 2015

Thanks for looking into this, I pushed the simplification.

fsgit added a commit that referenced this pull request Jan 15, 2015
Metadata of C# (and other) Assemblies.
@fsgit fsgit merged commit cf0b404 into fsharp:master Jan 15, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants