Skip to content

InternalsVisibleTo + internal module + inline function error message could be improved #7110

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

Open
ForNeVeR opened this issue Jul 3, 2019 · 7 comments
Labels
Area-Diagnostics mistakes and possible improvements to diagnostics Feature Improvement
Milestone

Comments

@ForNeVeR
Copy link
Contributor

ForNeVeR commented Jul 3, 2019

Repro steps

  1. Create two F# projects, LibProject and TestProject, where TestProject references LibProject
  2. In LibProject, write the following code:
    module internal LibProject.Tools
    
    open System.Net
    open System.Runtime.CompilerServices
    
    [<assembly: InternalsVisibleTo("TestProject")>]
    do ()
    
    let inline int32FromBigEndian(num : int) =
        IPAddress.NetworkToHostOrder(num)
  3. In TestProject, write the following code:
    module TestProject.Tests
    
    open LibProject.Tools
    
    let testTheFunction() =
        let xx = int32FromBigEndian 100
        0

The repro solution is attached: ReproTestProject.zip

Expected behavior

I think that the code should compile successfully. But even if it isn't, then the compiler should print a sensible error message.

Actual behavior

The code doesn't compile and the compiler provides rather cryptic messages:

LibProject\LibProject.fs(9,12): Error FS1113 : The value 'int32FromBigEndian' was marked inline but its implementation makes use of an internal or private function which is not sufficiently accessible
TestProject\TestProject.fs(6,14): Warning FS1116 : A value marked as 'inline' has an unexpected value
TestProject\TestProject.fs(6,14): Error FS1118 : Failed to inline the value 'int32FromBigEndian' marked 'inline', perhaps because a recursive value was marked 'inline'

Known workarounds

Well, don't use inline functions within internal modules with the InternalsVisibleTo attribute :)

Related information

Reproduced using .NET Core SDK:

$ dotnet --info
.NET Core SDK (reflecting any global.json):
 Version:   2.2.300
 Commit:    73efd5bd87

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.18362
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\2.2.300\

Host (useful for support):
  Version: 2.2.5
  Commit:  0a3c9209c0
@dsyme
Copy link
Contributor

dsyme commented Jul 3, 2019

Well, don't use inline functions within internal modules with the InternalsVisibleTo attribute :)

This is correct - InternalsVisibleTo doesn't allow inlining across assembly boundaries and if you try to use both of these you will get the above errors. So this is by design.

@ForNeVeR
Copy link
Contributor Author

ForNeVeR commented Jul 3, 2019

I think that the error message could be improved. Let's consider the first one:

The value 'int32FromBigEndian' was marked inline but its implementation makes use of an internal or private function which is not sufficiently accessible

I can't see which "internal or private function" do int32FromBigEndian use. It uses only IPAddress.NetworkToHostOrder which is a public static method. But probably "the value 'int32FromBigEndian'" isn't the function body but something else, and I don't understand the error message?

Maybe we could change the text so it's more clear?

The value 'int32FromBigEndian' refers to an internal or private function which is not sufficiently accessible

The second message looks okay if you don't read the "perhaps" part, and the warning is probably okay, too.

@dsyme
Copy link
Contributor

dsyme commented Jul 3, 2019

The private/internal thing is int32FromBigEndian itself. So you can access it via InternalsVisibleTo but compilation will fail because the inlining information is thrown away at the assembly boundary.

We could indeed add a compilation error for that specific case (direct access to an internal inline function from another assembly via IVT).

Note we could really choose to keep the "internal" inlining information in the assembly whenever there is an IVT just in case the inline functions get used. But we don't do that to ensure assemblies are not bloated.

@ForNeVeR
Copy link
Contributor Author

ForNeVeR commented Jul 3, 2019

Okay, I understand that int32FromBigEndian is internal. But error message states that the implementation of int32FromBigEndian makes use of some other "private/internal symbol", and that part is confusing (I was legitimately confused by it). The message hints me that I should read the implementation of this function, and that isn't helpful, because the problem isn't in the implementation, but in the function itself (or even in the declaring module).

@dsyme
Copy link
Contributor

dsyme commented Jul 4, 2019

Okay, I understand that int32FromBigEndian is internal. But error message states that the implementation of int32FromBigEndian refers to some other "private/internal symbol", and that part is confusing (I was legitimately confused by it). The message hints me that I should read the implementation of this function, and that isn't helpful, because the problem isn't in the implementation, but in the function itself (or even in the declaring module) .

Yes, absolutely, the error message is rotten

@ForNeVeR ForNeVeR changed the title InternalsVisibleTo + internal module + inline function error InternalsVisibleTo + internal module + inline function error message could be improved Jul 4, 2019
@cartermp cartermp added this to the Unknown / not bug milestone Jul 4, 2019
@cartermp
Copy link
Contributor

cartermp commented Jul 4, 2019

Tagging as a feature improvement

@g5becks
Copy link

g5becks commented Apr 30, 2023

Ran into this today and this today and spent 30 min trying to figure out what the issue was. Had to come here to the repo, search for the specific error message, sift through these issues just to figure out exactly what was going wrong. Not user friendly at all imo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Diagnostics mistakes and possible improvements to diagnostics Feature Improvement
Projects
Status: New
Development

No branches or pull requests

4 participants