Skip to content

Conversation

@0x53A
Copy link
Contributor

@0x53A 0x53A commented Apr 16, 2017

Suggestion
Details: under discussion
RFC: merged

This now compiles:

type IA<'T> =
    abstract member Get : unit -> obj

type MyClass() =
    interface IA<int> with
        member x.Get() = upcast 1
    interface IA<string> with
        member x.Get() = upcast 2

image

image

This also compiles:

type IB<'T> =
    abstract member Get : unit -> 'T

type IC =
    abstract member Get : unit -> int

[<EntryPoint>]
let main argv =
    let x = { new IB<System.Int32> with member x.Get() = 1
              interface IB<string> with member x.Get() = "hello"
              interface IB<float> with member x.Get() = 1.
              interface IC with member x.Get() = 1 }
    0 // return an integer exit code

image

image

This does NOT compile, and is an explicit non-goal in the RFC:

type IGet<'T> =
    abstract member Get : unit -> 'T

[<EntryPoint>]
let main argv =
    let x = { new IGet<_> with member x.Get() = 1
              interface IGet<_> with member x.Get() = "hello"
              interface IGet<_> with member x.Get() = 1. }

This is now pretty near finished.

@KevinRansom KevinRansom changed the title [Prototype for RFC FS-1031] Allow implementing the same interface at different generic instantiations in the same type [WIP] Prototype for RFC FS-1031 - Allow implementing the same interface at different generic instantiations in the same type May 5, 2017
@0x53A 0x53A force-pushed the so-many-interfaces branch 3 times, most recently from 6a674bc to ae93ccd Compare May 23, 2017 21:11
@auduchinok
Copy link
Member

Thanks @0x53A! It would be great to see this feature merged.

@0x53A
Copy link
Contributor Author

0x53A commented Sep 21, 2017

Me too ;D

There is a little bit of clean-up missing, I mainly paused because at that time there seemed to be a feature-freeze.

@cartermp when is the cut-off date for F#4.2? Or to be more precise, what is the earliest date this could be merged? I didn't want to have to rebase it for months, that's why I stopped.

@dsyme
Copy link
Contributor

dsyme commented Sep 21, 2017

@cartermp when is the cut-off date for F#4.2? Or to be more precise, what is the earliest date this could be merged?

There's no specific cut off as yet.

I didn't want to have to rebase it for months, that's why I stopped.

I'm afraid that's just what needs to be done to keep language additions in the pipe. That said, you have almost no conflicts so a merge+update should be easy enough

@0x53A
Copy link
Contributor Author

0x53A commented Sep 21, 2017

I'm afraid that's just what needs to be done to keep language additions in the pipe.

In general I agree, but if it is clear that it can't be merged, then it doesn't really make sense.

Anyway, regarding this specific PR: I will plan some time this weekend to get it to a reviewable state.

@cartermp
Copy link
Contributor

I agree with @dsyme and I don't have any cutoff in mind, either. At some point, as we keep collecting bug fixes in F# 4.1, we may want to rev, but I don't feel that way right now. Certainly not without a few features like this.

@realvictorprm
Copy link
Contributor

realvictorprm commented Sep 22, 2017

@0x53A should I update this for you? I'm used to this stuff and so it's not a big effort for me 😄

@realvictorprm
Copy link
Contributor

realvictorprm commented Sep 22, 2017

understood @0x53A. You can always ping me and ask me for keeping this up-to-date.

@0x53A
Copy link
Contributor Author

0x53A commented Sep 22, 2017

thanks @realvictorprm for the offer, it was not that the effort of doing it once was so much, more that the effort of doing it every other day for a few months was something I didn't bother to do ;-)

@realvictorprm
Copy link
Contributor

I try to reduce this time with adding features @0x53A 😛 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I looked around for any suspiciously named methods (isObjectExpression and so on), but couldn't find anything. Help appreciated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Afaik this code path is only hit with classes, not OEs, but not sure if that is guaranteed

@0x53A
Copy link
Contributor Author

0x53A commented Sep 24, 2017

I would appreciate a review and additional positive as well as negative unit tests, especially combinations of measures and aliases and generics.

@0x53A 0x53A closed this Sep 26, 2017
@0x53A 0x53A reopened this Sep 26, 2017
@abelbraaksma
Copy link
Contributor

@0x53A, do we have an RFC for this? I have trouble finding it. In fsharp/fslang-design#185 you link to a possible RFC FS-1031, but this link is dead (it goes into your own repo) and I don't seem to be able to find the "official" one, if any exists. Or does the language suggestion #545 in the original post count as RFC?

I'm curious to the expected width of this submission, whether it puts extra strain on the type inference system (i.e., performance-wise), whether it influences type-inferenced signatures in quick-info tooltips or FSI feedback and whether there are certain restrictions we should be aware of.

Also of interest is this subtle bug introduced in VS2015, also related to generic type inheritance, according to Don's comment there, the bug is now a feature (i.e., no rollback will be done), meaning that code snippet should stay the same (and perhaps be made into a unit test).

As many out there, I have been bitten by this restriction in the past, so I very much hope to see it merged into master!

@0x53A
Copy link
Contributor Author

0x53A commented Oct 4, 2017

@abelbraaksma https://github.com/fsharp/fslang-design/blob/master/RFCs/FS-1031-Allow%20implementing%20the%20same%20interface%20at%20different%20generic%20instantiations%20in%20the%20same%20type.md

The scope of this RFC and PR is as small as possible - it just fixes the naming collision, and adapts the check which previously prohibited this.

There are certainly other additions which would round this feature out (e.g. see fsharp/fslang-design#185 (comment)), but that would - if approved by don - be implemented independent of this.

@dsyme dsyme changed the title [WIP] Prototype for RFC FS-1031 - Allow implementing the same interface at different generic instantiations in the same type [WIP, RFC FS-1031 ] Allow implementing the same interface at different generic instantiations in the same type Dec 1, 2017
@dsyme dsyme changed the title [WIP, RFC FS-1031 ] Allow implementing the same interface at different generic instantiations in the same type [WIP, FS-1031] Allow implementing the same interface at different generic instantiations in the same type Dec 1, 2017
@KevinRansom KevinRansom changed the base branch from master to dev15.6 December 7, 2017 19:16
@KevinRansom
Copy link
Contributor

The recent simplification commits -- introduced a bug

// #Conformance #ObjectOrientedTypes #InterfacesAndImplementations 
type MyInt = int
[<Measure>] type kg

type IB<'a> =
    interface 
        abstract X : unit -> int
    end

type C() =
    interface IB<int<kg>> with
        member x.X() = 1
    interface IB<MyInt> with
        member x.X() = 2
    
exit 1

should produce this output:

MultipleInst08.fs(10,6): error FS3360: 'C' cannot implement the interface 'IB<_>' with the two instantiations 'IB<MyInt>' and 'IB<int<kg>>' because they may unify.

actually produces this output:

Microsoft (R) F# Compiler version 10.10.0.0 for F# 4.7
Copyright (c) Microsoft Corporation. All Rights Reserved.
Duplicate in method table is:
 Type index: 5
 Method name: MultipleInst08.IB<System.Int32>.X
 Method arity (num generic params): 0

error FS2014: A problem occurred writing the binary 'c:\kevinransom\fsharp\tests\fsharpqa\Source\Conformance\ObjectOrientedTypeDefinitions\InterfaceTypes\MultipleInst08.exe': Error in pass2 for type MultipleInst08, error: Error in pass2 for type C, error: duplicate entry 'MultipleInst08.IB<System.Int32>.X' in method table

dotnet-bot and others added 9 commits June 27, 2020 12:13
* Update dependencies from https://github.com/dotnet/arcade build 20200626.2 (dotnet#9577)

Microsoft.DotNet.Arcade.Sdk
 From Version 1.0.0-beta.20302.3 -> To Version 1.0.0-beta.20326.2

Co-authored-by: dotnet-maestro[bot] <dotnet-maestro[bot]@users.noreply.github.com>

* Improve perf for String.filter up to 3x (dotnet#9509)

* Improve perf for String.filter 2-2.5x

* Cleanup: remove "foo" etc in tests

* Add tests for new execution path for LOH in String.filter

* Change test string

* String map performance improvement (dotnet#9470)

* Simplify and improve perf of String.length

* Improve performance of String.map

* Revert "Simplify and improve perf of String.length"

* Resolves dotnet#9470 (comment)

* Lingering space

* Change `String` to use `new` to clarify use of ctor

* Add some better tests for String.map, add side-effect test

* Add tests to ensure the mapping function is called a deterministically amount of times

* Fix typo

* Remove "foo" from String.map tests

* Perf: String.replicate from O(n) to O(log(n)), up to 12x speed improvement (dotnet#9512)

* Turn String.replicate from O(n) into O(log(n))

* Cleanup String.replicate tests by removing usages of "foo"

* String.replicate: add tests for missing cases, and for the new O(log(n)) cut-off points

* Improve String.replicate algorithm further

* Add tests for String.replicate covering all lines/branches of algo

* Fix accidental comment

Co-authored-by: dotnet-maestro[bot] <42748379+dotnet-maestro[bot]@users.noreply.github.com>
Co-authored-by: dotnet-maestro[bot] <dotnet-maestro[bot]@users.noreply.github.com>
Co-authored-by: Abel Braaksma <abel.online@xs4all.nl>
…e2.fs (dotnet#9516) (dotnet#9587)

* Re-enabling tests from OperatorsModule1/2.fs (compile errors)

* Fix compile errors in OperatorsModule1/2.fs, fix tests. Note tanh test comment.

* Fix `tanh` test, ensure stable result on x86 vs x64 runtimes

* Stop using exception AssertionException, so that test window shows useful info

* Whitespace cleanup and redundant code removal

* Cleanup spelling etc

* Re-enabling int, int16, int32, int64, nativeint, incr, nullArg etc tests

* Special-case floating-point assertion messages for higher precision output

* Fix/update/add tests (some still failing)

* Separate Checked tests, add & fix others, differentiate framework/bitness for some tests

* Add branch for .NET Native (ignore cos test)

* Resorting to comparing floats with a delta using Assert.AreNearEqual

* Add some more tests

Co-authored-by: Abel Braaksma <abel.online@xs4all.nl>
…e2.fs (dotnet#9516) (dotnet#9590)

* Re-enabling tests from OperatorsModule1/2.fs (compile errors)

* Fix compile errors in OperatorsModule1/2.fs, fix tests. Note tanh test comment.

* Fix `tanh` test, ensure stable result on x86 vs x64 runtimes

* Stop using exception AssertionException, so that test window shows useful info

* Whitespace cleanup and redundant code removal

* Cleanup spelling etc

* Re-enabling int, int16, int32, int64, nativeint, incr, nullArg etc tests

* Special-case floating-point assertion messages for higher precision output

* Fix/update/add tests (some still failing)

* Separate Checked tests, add & fix others, differentiate framework/bitness for some tests

* Add branch for .NET Native (ignore cos test)

* Resorting to comparing floats with a delta using Assert.AreNearEqual

* Add some more tests

Co-authored-by: Abel Braaksma <abel.online@xs4all.nl>
@KevinRansom KevinRansom reopened this Jun 29, 2020
@KevinRansom KevinRansom merged commit 636052a into dotnet:master Jul 6, 2020
@0x53A
Copy link
Contributor Author

0x53A commented Jul 8, 2020

Thank you for taking care of this!

@abelbraaksma
Copy link
Contributor

Wow, amazing stuff! 👍

@KevinRansom
Copy link
Contributor

@0x53A , thank you for getting it done in the first place 👍

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.