Skip to content

Conversation

vzarytovskii
Copy link
Member

@vzarytovskii vzarytovskii commented May 9, 2022

Support interfaces with static abstract methods suggestion, RFC

Things included in this PR that are not yet documented in RFC:

  • Fix C<^int> to not need a space, including updating tests
  • Allow ((^T or C) : (static member P: int) ()) SRTP call syntax (i.e. nominal types after or)

TODO:

  • ILgen tests
  • Make sure we don't permit anything extra, other than statics in interfaces.
  • Consider glyphs for trait constraints
  • Completion for 'T. IWSAMs + tests
  • Go to definition for 'T.Name IWSAM (should work)
  • Consider tooltips for 'T - may be a larger issue since these are missing for any generic type parameters at the moment
  • Move tests/adhoc.fsx into individual unit tests including codegen
  • Test creating delegates to IWSAM-constrained target methods
  • Fix new SRTP call syntax for instance methods
  • Fix trait with expression warning
  • Test op_Implicit
  • Test active patterns
  • Test calling F#-defined function/method with IWSAM from C#
  • Test (^T or C) : ... call syntax for SRTP
  • Don - Fix type inference issue
  • Don - Fix SRTP trait calls with byref parameters
  • Petr/Vlad - Adhoc usage testing of autocomplete for trait calls + fix any bugs
  • Petr/Vlad - Adhoc usage testing against actual latest .NET 7 generic math preview
  • Petr - Test suppression of Systems.Numerics.I* interfaces on unitized types
  • Don/Petr/Vlad - Get it green

Other cleanup items currently in this PR (could be factored out):

  • Add ParamAttribs type in infos.fs for large tuple
  • Pass extra g parameter to Freshen routines
  • Remove wildcard matching when pattern matching on Item type, completing some cases in the obvious way
  • Factor out AddUnsolvedMemberConstraint, TraitsAreRelated, EnforceConstraintConsistency, CheckConstraintImplication, EnforceConstraintSetConsistency, EliminateRedundantConstraints, cleanup SolveTypeChoice in ConstraintSolver
  • Name fields of AssignedPropSetter
  • Factor out CrackParamAttribsInfo in infos.fs
  • Pipe into List.iter2 in ilxgen.fs
  • Add DecideStaticOptimizations call to Optimizer.fs
  • Some comments and cleanup in autocomplete implementation in FSharpCheckerResults.fs
  • Replace some uses of direct matching with TType_app (tcref, _, _) with AbbrevOrAppTy tcref which looks through type inference equations.
  • Some refactoring in SemanticClassification.fs to recude complexity
  • Fix TTypeConvOp in Exprs.fs to use type equality
  • Some cleanup for flags in TypedTree.fs
  • Field names for TraitWitnessInfo
  • Field names for ILMethSln
  • Add documentation to decideStaticOptimizationConstraint
  • Get HelpContextServiceTests.fs activated and working

Renamings:

  • TcLongIdent --> TcLongIdent
  • checkLanguageFeatureRuntimeErrorRecover --> checkLanguageFeatureRuntimeAndRecover`
  • mkILNonGenericVirtualMethod --> mkILNonGenericVirtualInstanceMethod
  • GetBaseClassCandidates --> IsInheritsCompletionCandidate
  • GetInterfaceCandidates --> IsInterfaceCompletionCandidate
  • IsInterfaceFile --> IsSignatureFile
  • For traits:
    • MemberName --> MemberLogicalName
    • ArgumentTypes --> CompiledObjectAndArgumentTypes
    • ReturnType --> CompiledReturnType
  • Microsoft.VisualStudio.FSharp.Editor.Tests.Roslyn --> VisualFSharp.UnitTests.Editor
  • CreateDocument --> CreateSingleDocumentSolution

vzarytovskii and others added 4 commits May 9, 2022 19:23
* cleanup

* split files

* rename

* split infos.fs and SymbolHelpres.fs

* split infos.fs and SymbolHelpres.fs

* fix code formating

* rename autobox --> LowerLocalMutables

* adjust names

* block --> ImmutableArray

* format

* Error --> SRDiagnostic

* Error --> SRDiagnostic

* this -> _

* rename and cleanup

* rename Diagnostic --> FormattedDiagnostic

* format sigs

* format sigs

* fix build

* fix build
@vzarytovskii vzarytovskii added Needs-RFC Feature Improvement Area-Compiler-Syntax lexfilter, indentation and parsing Area-Compiler-Checking Type checking, attributes and all aspects of logic checking Area-Compiler-ImportAndInterop import of .NET DLLs and interop labels May 25, 2022
@dsyme
Copy link
Contributor

dsyme commented Aug 1, 2022

@vzarytovskii @0101 I pushed a fix to allow byref arguments in the new syntax for SRTP trait calls, e.g. see tests/adhoc.fsx

These should be turned into proper tests please :)

There is a note about byref returns in member traits, which are not supported - they could be, but it is orthogonal to this PR

let typeParams = Seq.replicate paramCount "'T" |> String.concat ","
let genericType = $"{name}<{typeParams}>"
let potatoParams = Seq.replicate paramCount "float<potato>" |> String.concat ","
let potatoType = $"{name}<{potatoParams}>"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests look good!

Probably add a test when the user defines an interface in System.Numerics too

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also one where the user defines a new interface NOT in System.Numerics but derives from an interface in System.Numerics

@@ -8,6 +8,9 @@

<PropertyGroup>
<DotnetFscCompilerPath>$(MSBuildThisFileDirectory)../../../artifacts/bin/fsc/Debug/net6.0/fsc.dll</DotnetFscCompilerPath>
<Fsc_DotNET_DotnetFscCompilerPath>$(MSBuildThisFileDirectory)../../../artifacts/bin/fsc/Debug/net6.0/fsc.dll</Fsc_DotNET_DotnetFscCompilerPath>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably adjust the FSharp.Core.UnitTests and a few others to do this. I've noticed they use the Proto to build, perhaps it's better to just use the built compiler.

@vzarytovskii
Copy link
Member Author

This looks good to me.
@KevinRansom @0101 give it another go pls and we can merge.

@0101
Copy link
Contributor

0101 commented Aug 8, 2022

Would be nice to include the switch to net7.0 to enable the tests for System.Numerics suppression but I suppose that can be done later.

@vzarytovskii
Copy link
Member Author

Would be nice to include the switch to net7.0 to enable the tests for System.Numerics suppression but I suppose that can be done later.

Yeah, we probably shouldn't wait for it, can be done in parallel/later.

@cmeeren
Copy link
Contributor

cmeeren commented Nov 9, 2022

I can't find this info anywhere: When using ^a or ^b in the old syntax, what's the new syntax?

Here is the old syntax:

let inline oldSyntax< ^a, ^b when (^a or ^b): (static member create: ^a -> ^b)> (x: ^a) : ^b =
  ((^a or ^b): (static member create: ^a -> ^b) x)

But in F# 7, this doesn't compile:

let inline newSyntax<'a, 'b when ('a or 'b): (static member create: ^a -> 'b)> (x: 'a) : 'b =
  ('a or 'b).create x

Neither does replacing the second line with ('a or b).create x.

What is the new syntax in this case?

@cmeeren
Copy link
Contributor

cmeeren commented Nov 9, 2022

It also seems like

let inline f (x: 'a) : 'b = (^a: (static member create: 'a -> 'b) x) fails compilation if replacing ^a with 'a.

fails if replacing the ^ in the function body with '. Is that intended? Can ' only be used when defining the SRTP constraints directly in the function definition, not the body?

@vzarytovskii
Copy link
Member Author

It also seems like

let inline f (x: 'a) : 'b = (^a: (static member create: 'a -> 'b) x) fails compilation if replacing ^a with 'a.

fails if replacing the ^ in the function body with '. Is that intended? Can ' only be used when defining the SRTP constraints directly in the function definition, not the body?

Yeah, if the old syntax needs to be used, type ^ must be used, it's a known limitation.

@cmeeren
Copy link
Contributor

cmeeren commented Nov 9, 2022

Ok! But what about 'a or 'b? Does that still require the old syntax for invocation?

@Xyncgas
Copy link

Xyncgas commented Feb 27, 2024

how can I implement static abstract members in my derived classes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compiler-Checking Type checking, attributes and all aspects of logic checking Area-Compiler-ImportAndInterop import of .NET DLLs and interop Area-Compiler-Syntax lexfilter, indentation and parsing Feature Improvement Needs-RFC
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Tracking Static abstract interface members support
8 participants