Skip to content

RFC FS-1124 - Interfaces with static abstract methods - #13119

Merged
vzarytovskii merged 126 commits into
dotnet:mainfrom
vzarytovskii:statics-in-interfaces-2
Aug 9, 2022
Merged

RFC FS-1124 - Interfaces with static abstract methods#13119
vzarytovskii merged 126 commits into
dotnet:mainfrom
vzarytovskii:statics-in-interfaces-2

Conversation

@vzarytovskii

@vzarytovskiivzarytovskii commented May 9, 2022

Copy link
Copy Markdown
Member

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

vzarytovskiiand 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
@vzarytovskiivzarytovskii 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

dsyme commented Aug 1, 2022

Copy link
Copy Markdown
Contributor

@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
Copy Markdown
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
Copy Markdown
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

Comment threadtests/projects/Sample_ConsoleApp_net7/Program.fs Outdated

<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
Copy Markdown
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
Copy Markdown
MemberAuthor

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

@0101

0101 commented Aug 8, 2022

Copy link
Copy Markdown
Contributor

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
Copy Markdown
MemberAuthor

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.

0101
0101 approved these changes Aug 9, 2022
@cmeeren

cmeeren commented Nov 9, 2022

Copy link
Copy Markdown
Contributor

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 inlineoldSyntax<^a,^bwhen(^a or ^b):(static member create:^a->^b)>(x:^a):^b =((^aor^b):(static membercreate:^a->^b) x)

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

let inlinenewSyntax<'a,'bwhen('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

cmeeren commented Nov 9, 2022

Copy link
Copy Markdown
Contributor

It also seems like

let inlinef(x:'a):'b =(^a:(static membercreate: '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
Copy Markdown
MemberAuthor

It also seems like

let inlinef(x:'a):'b =(^a:(static membercreate: '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
Copy Markdown
Contributor

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

@Xyncgas

Copy link
Copy Markdown

how can I implement static abstract members in my derived classes

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area-Compiler-CheckingType checking, attributes and all aspects of logic checkingArea-Compiler-ImportAndInteropimport of .NET DLLs and interopArea-Compiler-Syntaxlexfilter, indentation and parsingFeature ImprovementNeeds-RFC

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Tracking Static abstract interface members support

8 participants

@vzarytovskii@dsyme@0101@cmeeren@Xyncgas@smoothdeveloper@KevinRansom@psfinaki