Skip to content

F# compiler internal error when try to compile an inherited padded generic class with inline members #614

Closed

Description

@zpodlovics

Maybe it's a known (compiler) limitation but it seems that an inherited padded generic class with inline members will result compiler internal errors. Please note I already have a struct based field padding implementation - but I would like to also make this work with this object inheritance based padding mechanism. Unfortunately a single class and padding fields will not work, because the JIT free to reorder the fields within a clas but it will not reorder the fields across "inheritance borders".

The non-full example code looks like this:

[<NoEquality; NoComparison>]
[<Class>]
type PaddedReferenceRightPad<'T when 'T : not struct> =
    inherit PaddedReferenceBase<'T>
    val mutable Right: PaddedReferenceRightPadding
    new() = { inherit PaddedReferenceBase<'T>(); Right = PaddedReferenceRightPadding() }
    new(v: 'T) = { inherit PaddedReferenceBase<'T>(v); Right = PaddedReferenceRightPadding() }

[<NoEquality; NoComparison>]
[<Class>]
type PaddedReference<'T when 'T : not struct> =
    inherit PaddedReferenceRightPad<'T>
    new(value) = { inherit PaddedReferenceRightPad<'T>(value) }

    member inline x.Read() =
        GenericOperations.read x.Value

    member inline x.ReadByRef() =
        GenericOperations.readByRef &x.Value

The full example code are available here:
https://gist.github.com/zpodlovics/aa333619a39facdeba90

Compilation will result the following errors

/tmp/fsharpgenericpaddedinlinemember.fs(84,21): error FS0073: internal error: the mustinline value 'Read' was not inferred to have a known value
/tmp/fsharpgenericpaddedinlinemember.fs(87,21): error FS0073: internal error: the mustinline value 'ReadByRef' was not inferred to have a known value
/tmp/fsharpgenericpaddedinlinemember.fs(84,21): error FS1113: The value 'Read' was marked inline but its implementation makes use of an internal or private function which is not sufficiently accessible
/tmp/fsharpgenericpaddedinlinemember.fs(87,21): error FS1113: The value 'ReadByRef' was marked inline but its implementation makes use of an internal or private function which is not sufficiently accessible
/tmp/fsharpgenericpaddedinlinemember.fs(84,21): error FS0073: internal error: the mustinline value 'Read' was not inferred to have a known value
/tmp/fsharpgenericpaddedinlinemember.fs(87,21): error FS0073: internal error: the mustinline value 'ReadByRef' was not inferred to have a known value
/tmp/fsharpgenericpaddedinlinemember.fs(84,21): error FS1113: The value 'Read' was marked inline but its implementation makes use of an internal or private function which is not sufficiently accessible
/tmp/fsharpgenericpaddedinlinemember.fs(87,21): error FS1113: The value 'ReadByRef' was marked inline but its implementation makes use of an internal or private function which is not sufficiently accessible

Is there any workaround available to use this object inheritance based padding mechanism?

Thanks for your help,
Zoltan

Activity

  1. abelbraaksma commented on Nov 26, 2015

    @abelbraaksma
    Contributor

    Note, for one of those errors, the error:

    error FS0073: internal error: the mustinline value 'Read' was not inferred to have a known value

    you do not need to have a padded, or even generic class, it simply happens "always", as soon as you inherit a class and it has any inline method in the derived class. I reported that earlier here, and there's a StackOverflow question that shows this bug has been around since F# 2.0.

  2. mpetruska commented on Dec 23, 2015

    @mpetruska
    Contributor

    Started to investigate this bug, here's my current progress:

    • When trying to compile the module below the internal error is reported and assertion failures are triggered in line 3058 of Optimizer.fs
    let inline foo x = x
    
    type Base<'T>() = class end
    
    type Class<'T>() =
        inherit Base<'T>()
    
        member inline __.Bar x = foo x
  3. mpetruska commented on Dec 23, 2015

    @mpetruska
    Contributor

    I think PR #763 contains the fix for this bug.

  4. abelbraaksma commented on Dec 23, 2015

    @abelbraaksma
    Contributor

    Have you also seen #763? It contains a fix for my later bug #740, which I think is the same issue (though I'm not 100% sure). Would be a pity if you'd be doing the work twice... ;)

  5. abelbraaksma commented on Dec 23, 2015

    @abelbraaksma
    Contributor

    Oops, sorry, should've refreshed my window... you found it already ;)

  6. mpetruska commented on Dec 23, 2015

    @mpetruska
    Contributor

    Hi, tested the changes in PR #763 on .Net 4.5, it seems that it solves this issue (both the original and the simplified code) compilation succeeds.

  7. abelbraaksma commented on Dec 24, 2015

    @abelbraaksma
    Contributor

    Glad to hear it fixes the issue! The PR is in need of test cases, I haven't gotten around to looking into it yet (I'm not that accustomed to the whole process flow yet), but if you have test cases and you want to / can add them for #763, please do.

  8. eriawan commented on Dec 24, 2015

    @eriawan
    Member

    @KevinRansom ,

    Just FYI, if this issue is fixed, (according to previous conversations) we should close this issue. I also think this issue doesn't need to be tracked anymore.

    cc @dsyme

  9. added
    Impact-Medium
    on Jan 8, 2016
  10. added and removed
    Impact-Medium
    on Jul 5, 2016
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions