Skip to content

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

Open

Description

@ForNeVeR

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

Activity

  1. dsyme commented on Jul 3, 2019

    @dsyme
    Contributor

    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.

  2. ForNeVeR commented on Jul 3, 2019

    @ForNeVeR
    ContributorAuthor

    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.

  3. dsyme commented on Jul 3, 2019

    @dsyme
    Contributor

    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.

  4. ForNeVeR commented on Jul 3, 2019

    @ForNeVeR
    ContributorAuthor

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

  5. dsyme commented on Jul 4, 2019

    @dsyme
    Contributor

    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

  6. changed the title [-]InternalsVisibleTo + internal module + inline function error[/-] [+]InternalsVisibleTo + internal module + inline function error message could be improved[/+] on Jul 4, 2019
  7. added this to the Unknown / not bug milestone on Jul 4, 2019
  8. cartermp commented on Jul 4, 2019

    @cartermp
    Contributor

    Tagging as a feature improvement

  9. added
    Area-Diagnostics
    and removed on Mar 31, 2022
  10. g5becks commented on Apr 30, 2023

    @g5becks

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-DiagnosticsFeature Improvement

    Type

    No type

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions