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

Regression with quotations of List.sum on non-primitive type #10364

Closed
dsyme opened this issue Oct 30, 2020 · 5 comments
Closed

Regression with quotations of List.sum on non-primitive type #10364

dsyme opened this issue Oct 30, 2020 · 5 comments
Milestone

Comments

@dsyme
Copy link
Contributor

dsyme commented Oct 30, 2020

Description

When using --langversion:5.0 (the default in F# 5.0), taking the quotation of a use of List.sum on a non-primitive type causes a compilation exception related to generating the witness for the Zero property.

This will apply to a quotation of any code calling let inline SRTP code which uses a constraint on a get_Foo property method or any SRTP constraint that takes no arguments member M : unit -> ...

Repro

type Point =
    { x: int; y: int }
    static member Zero = { x=0; y=0 }
    static member (+) (p1, p2) = { x= p1.x + p2.x; y = p1.y + p2.y }
let p1 = {x=1; y=10}

<@ List.sum [p1] @>

gives

stdin(0,1): error FS0073: internal error: The lists had different lengths.
list2 is 1 element shorter than list1
Parameter name: list2 (ArgumentException)
Stack Trace
FSharp.Compiler.ErrorLogger+InternalError: The lists had different lengths.
list2 is 1 element shorter than list1
Parameter name: list2 (ArgumentException)stdin (0,0--0,0) IsSynthetic=false

Another repro is

#r "System.Numerics.Vectors.dll";;
<@ List.sum [System.Numerics.Vector4.Zero] @>;;

Workarounds

One workaround is to use --langversion:4.7

Another possible workaround is to define a non-inlined helper function outside the quotation, e.g. as follows. If necessary label the function as ReflectedDefinition. This may not work if the quotation is being processed requires access to the full quotation tree.

type Point =
    { x: int; y: int }
    static member Zero = { x=0; y=0 }
    static member (+) (p1, p2) = { x= p1.x + p2.x; y = p1.y + p2.y }
let p1 = {x=1; y=10}

let sumPoints (points: Point list) = List.sum points

<@ sumPoints [p1] @>

Severity

This bug has not yet been seen in actual user code, but was instead noticed as part of #9510, which applies witness generation to a much broader range of code (all code going through Fable).

However it's likely to affect some user code.

Since a workaround is to use --langversion:4.7 it is likely that the actual severity in practice will be low.

@dsyme
Copy link
Contributor Author

dsyme commented Oct 30, 2020

The relevant fix is here: c4b28a1

@cartermp
Copy link
Contributor

@dsyme at most we're looking at a servicing release for .NET 5 or 16.8. Is that necessary, or would you be fine just having this as a known issue and letting the fix flow into 16.9 and the patch to .NET 5 that will go with it? Both are set to go out around February.

@dsyme
Copy link
Contributor Author

dsyme commented Oct 30, 2020

@dsyme at most we're looking at a servicing release for .NET 5 or 16.8. Is that necessary, or would you be fine just having this as a known issue and letting the fix flow into 16.9 and the patch to .NET 5 that will go with it? Both are set to go out around February.

I presume the workaround will be sufficient for customers, I'll let you make the call, and how to document it as a known issue so it's discoverable by a search.

That is, assuming the problem actually gets reported in practice. It feels like it will but I may be wrong

@cartermp cartermp added this to the 16.9 milestone Oct 30, 2020
@cartermp
Copy link
Contributor

Sounds goood, i'll tag it as 16.9.

@dsyme
Copy link
Contributor Author

dsyme commented Dec 1, 2020

This was fixed in #9510

@dsyme dsyme closed this as completed Dec 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants