You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@TIHan and I spent a while looking at the status of SRTP constraints on class type parameters.
F# is intended to only support a very limited version of this, namely
typeC<^Twhen^T:(static member Foo:unit ->unit)>()=member inlinex.Method1()=......member inlinex.Property1=......
Many cases of this are properly enforced, e.g. checking there are no non-inline members, or interface implementations etc. However there is another case that we should statically disallow (constructors) and there is also a case where this interacts badly with witness passing.
Problem 1 – "witness not available at runtime".
Here the problem is that a constructor attempts to make an SRTP call on ^T, e.g.
typeC<^Twhen^T:(static member Foo:unit ->unit)>()=letx=(^T:(static memberFoo: unit -> unit)())member inlinex.P=1typeB1()=static memberFoo()=()letcb1= C<B1>()
We should fail if ^T is used anywhere in the constructor (which can’t be inlined). As an aside, note that record types with constrained parameters and a fully inline Create method are allowed.
typeC<^Twhen^T:(static member Foo:unit ->unit)>={ F:unit -> unit }member inlinex.M()= x.F()static member inlineCreate():C<^T>={ F = f<^T >}typeB1()=static memberFoo()= printfn "hello B1"typeB2()=static memberFoo()= printfn "hello B2"letcb1= C<B1>.Create()letcb2= C<B2>.Create()
cb1.M()
cb2.M()
Problem 2 – "non-generation of witness".
In this case, one of the "inline" methods has code that requires a witness e.g. a quotation or indeed any use of the witness per RFC FS-1043 #6805. We believe this code can be fixed by removing let typs = typars |> List.skip numParentTypars in GetTraitWitnessInfosOfTypars
let inlinef<^Twhen^T:(static member Foo:unit ->unit)>()=(^T:(static memberFoo: unit -> unit)())typeC<^Twhen^T:(static member Foo:unit ->unit)>()=member inlinex.M()=<@ f<^T >()@>typeB1()=static memberFoo()= printfn "hello B1"typeB2()=static memberFoo()= printfn "hello B2"letcb1= C<B1>()letcb2= C<B2>()
cb1.M()
cb2.M()
We should be careful that inline properties are still ok even even if problem 2 is fixed
This discussion was converted from issue #10959 on February 06, 2021 21:22.
Heading
Bold
Italic
Quote
Code
Link
Numbered list
Unordered list
Task list
Attach files
Mention
Reference
Menu
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
@TIHan and I spent a while looking at the status of SRTP constraints on class type parameters.
F# is intended to only support a very limited version of this, namely
Many cases of this are properly enforced, e.g. checking there are no non-inline members, or interface implementations etc. However there is another case that we should statically disallow (constructors) and there is also a case where this interacts badly with witness passing.
Problem 1 – "witness not available at runtime".
Here the problem is that a constructor attempts to make an SRTP call on
^T
, e.g.We should fail if ^T is used anywhere in the constructor (which can’t be inlined). As an aside, note that record types with constrained parameters and a fully inline
Create
method are allowed.Problem 2 – "non-generation of witness".
In this case, one of the "inline" methods has code that requires a witness e.g. a quotation or indeed any use of the witness per RFC FS-1043 #6805. We believe this code can be fixed by removing
let typs = typars |> List.skip numParentTypars
inGetTraitWitnessInfosOfTypars
We should be careful that inline properties are still ok even even if problem 2 is fixed
Beta Was this translation helpful? Give feedback.
All reactions