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

[WIP, RFC FS-1043] Extension members visible to trait constraints #6286

Closed
wants to merge 69 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
7822a13
First attempt
Aug 17, 2017
f977d3f
add testfile
TobyShaw Aug 18, 2017
898d97b
First draft, messy solution
Sep 14, 2017
888f1cf
Merge branch 'extensionconstraints' of https://github.com/TobyShaw/vi…
Sep 14, 2017
1b41d93
merge with master
dsyme Sep 25, 2017
9efe7ef
merge with master
dsyme Sep 25, 2017
7121bc3
work towards freshening things correctly
Sep 25, 2017
bdfa7b3
fix build
Sep 25, 2017
1fa2326
prototype for extension solutions to trait constraints
Sep 25, 2017
baf3f15
Merge branch 'master' of http://github.com/Microsoft/visualfsharp int…
dsyme Sep 27, 2017
db3f298
resolve
dsyme Sep 27, 2017
b8c95f4
resolve and merge
dsyme Sep 27, 2017
f75a2ab
resolve and merge
dsyme Sep 27, 2017
072cbbb
minor cleanup
dsyme Sep 27, 2017
2e78b58
merge
Sep 27, 2017
9bdfb21
it works
Sep 27, 2017
96502ea
minor cleanup
dsyme Sep 27, 2017
f287f20
various fixes
Sep 29, 2017
100ff18
Merge branch 'master' of http://github.com/Microsoft/visualfsharp int…
Oct 2, 2017
91d1a35
support extenstion properties on generic types
Oct 2, 2017
7513645
range of fixes to freshening and trait printing
Oct 2, 2017
010bf0f
fix build
Oct 2, 2017
d0bc0b3
Merge branch 'master' of http://github.com/Microsoft/visualfsharp int…
Oct 2, 2017
36d26e7
reduce diff
Oct 2, 2017
434b095
merge with master
Oct 2, 2017
000e34d
Merge branch 'master' into extensionconstraints
dsyme Oct 3, 2017
8b601f2
Fix Oddities in statically resolved method constraints and method ove…
Nov 17, 2017
77447d6
no return type needed before proceeding to overload resolution
dsyme Nov 18, 2017
c67437d
fix tests
dsyme Nov 18, 2017
827f38a
Merge branch 'master' of http://github.com/Microsoft/visualfsharp int…
Dec 1, 2017
dbe243c
Merge branch 'fix-3814' of https://github.com/dsyme/visualfsharp into…
Dec 1, 2017
ec80c48
integrate master
Dec 1, 2017
4e7183e
minimize diff and integrate fix
Dec 1, 2017
4ca7ea8
minimize diff
Dec 1, 2017
fa31367
minimize diff
Dec 1, 2017
281e1f0
minimize diff
Dec 1, 2017
58787bd
minimize diff
Dec 1, 2017
3316850
integrate master
dsyme Feb 26, 2019
1f325a8
reduce diff
dsyme Feb 26, 2019
bd86a8f
fix build
dsyme Feb 27, 2019
261d654
update baselines
dsyme Feb 27, 2019
8070d9d
update baseline
dsyme Feb 28, 2019
6c3df9f
Merge branch 'master' of http://github.com/Microsoft/visualfsharp int…
dsyme Mar 1, 2019
cbb001d
Merge branch 'master' of https://github.com/Microsoft/visualfsharp in…
dsyme Mar 2, 2019
b0fc19f
Merge branch 'ext' of https://github.com/dsyme/visualfsharp into ext
dsyme Mar 2, 2019
2f14b5d
resolve conflicts
dsyme Mar 3, 2019
fe65783
Merge branch 'ext' of https://github.com/dsyme/visualfsharp into ext
dsyme Mar 3, 2019
4d45e03
integrate master
dsyme Mar 9, 2019
d1b1389
add diagnostics
dsyme Mar 10, 2019
0f89711
add diagnostics
dsyme Mar 10, 2019
7da6aff
diagnostics
dsyme Mar 11, 2019
871489b
diagnostics
dsyme Mar 11, 2019
27d00a0
diagnostics
dsyme Mar 11, 2019
7d98d16
add diagnostics and possible fix for tp smoke tests
dsyme Mar 11, 2019
cc6e992
fix build
dsyme Mar 11, 2019
e13b385
fix build
dsyme Mar 11, 2019
d16e49b
Merge branch 'diag4' into ext
dsyme Mar 11, 2019
119f1a7
integrate master
dsyme Mar 11, 2019
42b1f1d
append extension methods in GetRelevantMethodsForTrait
kevmal Mar 15, 2019
e11da64
Merge pull request #13 from kevmal/ext1
dsyme Mar 15, 2019
23b8296
integrate master
dsyme Mar 20, 2019
5fef227
Merge branch 'master' of https://github.com/Microsoft/visualfsharp in…
dsyme Mar 21, 2019
997d7eb
Merge branch 'master' of http://github.com/Microsoft/visualfsharp int…
dsyme Mar 22, 2019
b5365ba
fix tests
dsyme Mar 22, 2019
2605751
merge master
dsyme Mar 26, 2019
b27315a
Merge branch 'master' of http://github.com/Microsoft/visualfsharp int…
dsyme Apr 1, 2019
2c8a378
Merge branch 'master' of http://github.com/Microsoft/visualfsharp int…
dsyme Apr 14, 2019
088a7d5
merge master
dsyme Apr 16, 2019
0450da8
fix build
dsyme Apr 16, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/fsharp/AccessibilityLogic.fs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ type AccessorDomain =
/// An AccessorDomain which returns all items
| AccessibleFromSomewhere

interface TraitAccessorDomain

// Hashing and comparison is used for the memoization tables keyed by an accessor domain.
// It is dependent on a TcGlobals because of the TyconRef in the data structure
static member CustomGetHashCode(ad:AccessorDomain) =
Expand All @@ -45,6 +47,7 @@ type AccessorDomain =
| AccessibleFromEverywhere -> 2
| AccessibleFromSomeFSharpCode -> 3
| AccessibleFromSomewhere -> 4

static member CustomEquals(g:TcGlobals, ad1:AccessorDomain, ad2:AccessorDomain) =
match ad1, ad2 with
| AccessibleFrom(cs1, tc1), AccessibleFrom(cs2, tc2) -> (cs1 = cs2) && (match tc1, tc2 with None, None -> true | Some tc1, Some tc2 -> tyconRefEq g tc1 tc2 | _ -> false)
Expand Down
2 changes: 1 addition & 1 deletion src/fsharp/CheckFormatStrings.fs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ open FSharp.Compiler.NameResolution
type FormatItem = Simple of TType | FuncAndVal

let copyAndFixupFormatTypar m tp =
let _,_,tinst = FreshenAndFixupTypars m TyparRigidity.Flexible [] [] [tp]
let _,_,tinst = FreshenAndFixupTypars None m TyparRigidity.Flexible [] [] [tp]
List.head tinst

let lowestDefaultPriority = 0 (* See comment on TyparConstraint.DefaultsTo *)
Expand Down
1 change: 0 additions & 1 deletion src/fsharp/CompileOptions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1681,7 +1681,6 @@ let ApplyAllOptimizations (tcConfig:TcConfig, tcGlobals, tcVal, outfile, importM
let optSettings = tcConfig.optSettings
let optSettings = { optSettings with abstractBigTargets = tcConfig.doTLR }
let optSettings = { optSettings with reportingPhase = true }

let results, (optEnvFirstLoop, _, _, _) =
((optEnv0, optEnv0, optEnv0, SignatureHidingInfo.Empty), implFiles)

Expand Down
183 changes: 119 additions & 64 deletions src/fsharp/ConstraintSolver.fs

Large diffs are not rendered by default.

96 changes: 63 additions & 33 deletions src/fsharp/ConstraintSolver.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ open FSharp.Compiler
open FSharp.Compiler.AccessibilityLogic
open FSharp.Compiler.Ast
open FSharp.Compiler.ErrorLogger
open FSharp.Compiler.NameResolution
open FSharp.Compiler.Tast
open FSharp.Compiler.Range
open FSharp.Compiler.Import
Expand Down Expand Up @@ -34,47 +35,70 @@ val NewErrorMeasure : unit -> Measure
/// Create a list of inference type variables, one for each element in the input list
val NewInferenceTypes : 'a list -> TType list

/// Freshen a trait for use at a particular location
type TraitFreshener = (TraitConstraintInfo -> TraitPossibleExtensionMemberSolutions * TraitAccessorDomain)

/// Given a set of formal type parameters and their constraints, make new inference type variables for
/// each and ensure that the constraints on the new type variables are adjusted to refer to these.
val FreshenAndFixupTypars : range -> TyparRigidity -> Typars -> TType list -> Typars -> Typars * TyparInst * TType list
val FreshenAndFixupTypars : TraitFreshener option -> range -> TyparRigidity -> Typars -> TType list -> Typars -> Typars * TyparInst * TType list

/// Make new type inference variables for the use of a generic construct at a particular location
val FreshenTypeInst : TraitFreshener option -> range -> Typars -> Typars * TyparInst * TType list

val FreshenTypeInst : range -> Typars -> Typars * TyparInst * TType list
/// Make new type inference variables for the use of a generic construct at a particular location
val FreshenTypars : TraitFreshener option -> range -> Typars -> TType list

val FreshenTypars : range -> Typars -> TType list
/// Make new type inference variables for the use of a method at a particular location
val FreshenMethInfo : TraitFreshener option -> range -> MethInfo -> TType list

val FreshenMethInfo : range -> MethInfo -> TType list
/// Get the trait freshener for a particular location
val GetTraitFreshner : AccessorDomain -> NameResolutionEnv -> TraitFreshener

[<RequireQualifiedAccess>]
/// Information about the context of a type equation.
/// Information about the context of a type equation, for better error reporting
type ContextInfo =
/// No context was given.
| NoContext
/// The type equation comes from an IF expression.
| IfExpression of range
/// The type equation comes from an omitted else branch.
| OmittedElseBranch of range
/// The type equation comes from a type check of the result of an else branch.
| ElseBranchResult of range
/// The type equation comes from the verification of record fields.
| RecordFields
/// The type equation comes from the verification of a tuple in record fields.
| TupleInRecordFields
/// The type equation comes from a list or array constructor
| CollectionElement of bool * range
/// The type equation comes from a return in a computation expression.
| ReturnInComputationExpression
/// The type equation comes from a yield in a computation expression.
| YieldInComputationExpression
/// The type equation comes from a runtime type test.
| RuntimeTypeTest of bool
/// The type equation comes from an downcast where a upcast could be used.
| DowncastUsedInsteadOfUpcast of bool
/// The type equation comes from a return type of a pattern match clause (not the first clause).
| FollowingPatternMatchClause of range
/// The type equation comes from a pattern match guard.
| PatternMatchGuard of range
/// The type equation comes from a sequence expression.
| SequenceExpression of TType

/// No context was given.
| NoContext

/// The type equation comes from an IF expression.
| IfExpression of range

/// The type equation comes from an omitted else branch.
| OmittedElseBranch of range

/// The type equation comes from a type check of the result of an else branch.
| ElseBranchResult of range

/// The type equation comes from the verification of record fields.
| RecordFields

/// The type equation comes from the verification of a tuple in record fields.
| TupleInRecordFields

/// The type equation comes from a list or array constructor
| CollectionElement of bool * range

/// The type equation comes from a return in a computation expression.
| ReturnInComputationExpression

/// The type equation comes from a yield in a computation expression.
| YieldInComputationExpression

/// The type equation comes from a runtime type test.
| RuntimeTypeTest of bool

/// The type equation comes from an downcast where a upcast could be used.
| DowncastUsedInsteadOfUpcast of bool

/// The type equation comes from a return type of a pattern match clause (not the first clause).
| FollowingPatternMatchClause of range

/// The type equation comes from a pattern match guard.
| PatternMatchGuard of range

/// The type equation comes from a sequence expression.
| SequenceExpression of TType

exception ConstraintSolverTupleDiffLengths of DisplayEnv * TType list * TType list * range * range
exception ConstraintSolverInfiniteTypes of ContextInfo * DisplayEnv * TType * TType * range * range
Expand Down Expand Up @@ -115,7 +139,10 @@ type OptionalTrace =
val SimplifyMeasuresInTypeScheme : TcGlobals -> bool -> Typars -> TType -> TyparConstraint list -> Typars
val SolveTyparEqualsType : ConstraintSolverEnv -> int -> range -> OptionalTrace -> TType -> TType -> OperationResult<unit>
val SolveTypeEqualsTypeKeepAbbrevs : ConstraintSolverEnv -> int -> range -> OptionalTrace -> TType -> TType -> OperationResult<unit>

/// Canonicalize constraints prior to generalization
val CanonicalizeRelevantMemberConstraints : ConstraintSolverEnv -> int -> OptionalTrace -> Typars -> OperationResult<unit>

val ResolveOverloading : ConstraintSolverEnv -> OptionalTrace -> string -> ndeep: int -> TraitConstraintInfo option -> int * int -> AccessorDomain -> CalledMeth<Expr> list -> bool -> TType option -> CalledMeth<Expr> option * OperationResult<unit>
val UnifyUniqueOverloading : ConstraintSolverEnv -> int * int -> string -> AccessorDomain -> CalledMeth<SynExpr> list -> TType -> OperationResult<bool>
val EliminateConstraintsForGeneralizedTypars : ConstraintSolverEnv -> OptionalTrace -> Typars -> unit
Expand Down Expand Up @@ -144,4 +171,7 @@ val CodegenWitnessThatTypeSupportsTraitConstraint : TcValF -> TcGlobals -> Impor

val ChooseTyparSolutionAndSolve : ConstraintSolverState -> DisplayEnv -> Typar -> unit

/// Get the type variables that may help provide solutions to a statically resolved member trait constraint
val GetSupportOfMemberConstraint : ConstraintSolverEnv -> TraitConstraintInfo -> Typar list

val IsApplicableMethApprox : TcGlobals -> ImportMap -> range -> MethInfo -> TType -> bool
2 changes: 1 addition & 1 deletion src/fsharp/FSComp.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1075,7 +1075,7 @@ lexIndentOffForML,"Consider using a file with extension '.ml' or '.mli' instead"
1212,tcOptionalArgsMustComeAfterNonOptionalArgs,"Optional arguments must come at the end of the argument list, after any non-optional arguments"
1213,tcConditionalAttributeUsage,"Attribute 'System.Diagnostics.ConditionalAttribute' is only valid on methods or attribute classes"
#1214,monoRegistryBugWorkaround,"Could not determine highest installed .NET framework version from Registry keys, using version 2.0"
1215,tcMemberOperatorDefinitionInExtrinsic,"Extension members cannot provide operator overloads. Consider defining the operator as part of the type definition instead."
#1215,tcMemberOperatorDefinitionInExtrinsic,"Extension members cannot provide operator overloads. Consider defining the operator as part of the type definition instead."
1216,ilwriteMDBFileNameCannotBeChangedWarning,"The name of the MDB file must be <assembly-file-name>.mdb. The --pdb option will be ignored."
1217,ilwriteMDBMemberMissing,"MDB generation failed. Could not find compatible member %s"
1218,ilwriteErrorCreatingMdb,"Cannot generate MDB debug information. Failed to load the 'MonoSymbolWriter' type from the 'Mono.CompilerServices.SymbolWriter.dll' assembly."
Expand Down
2 changes: 1 addition & 1 deletion src/fsharp/FindUnsolved.fs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ and accOp cenv env (op, tyargs, args, _m) =
accTypeInst cenv env enclTypeArgs
accTypeInst cenv env methTypeArgs
accTypeInst cenv env tys
| TOp.TraitCall (TTrait(tys, _nm, _, argtys, rty, _sln)) ->
| TOp.TraitCall (TTrait(tys, _nm, _, argtys, rty, _sln, _extSlns, _ad)) ->
argtys |> accTypeInst cenv env
rty |> Option.iter (accTy cenv env)
tys |> List.iter (accTy cenv env)
Expand Down
2 changes: 1 addition & 1 deletion src/fsharp/InfoReader.fs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ open FSharp.Compiler.Tastops
open FSharp.Compiler.TcGlobals

/// Use the given function to select some of the member values from the members of an F# type
let private SelectImmediateMemberVals g optFilter f (tcref: TyconRef) =
let SelectImmediateMemberVals g optFilter f (tcref: TyconRef) =
let chooser (vref: ValRef) =
match vref.MemberInfo with
// The 'when' condition is a workaround for the fact that values providing
Expand Down
26 changes: 17 additions & 9 deletions src/fsharp/MethodCalls.fs
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,9 @@ type CalledMeth<'T>

member x.TotalNumAssignedNamedArgs = x.ArgSets |> List.sumBy (fun x -> x.NumAssignedNamedArgs)

override x.ToString() = "call to " + minfo.ToString()


let NamesOfCalledArgs (calledArgs: CalledArg list) =
calledArgs |> List.choose (fun x -> x.NameOpt)

Expand Down Expand Up @@ -676,12 +679,12 @@ let BuildFSharpMethodApp g m (vref: ValRef) vexp vexprty (args: Exprs) =
retTy

/// Build a call to an F# method.
let BuildFSharpMethodCall g m (ty, vref: ValRef) valUseFlags minst args =
let BuildFSharpMethodCall g m (vref: ValRef) valUseFlags declaringTypeInst minst args =
let vexp = Expr.Val (vref, valUseFlags, m)
let vexpty = vref.Type
let tpsorig, tau = vref.TypeScheme
let vtinst = argsOfAppTy g ty @ minst
if tpsorig.Length <> vtinst.Length then error(InternalError("BuildFSharpMethodCall: unexpected List.length mismatch", m))
let tpsorig,tau = vref.TypeScheme
let vtinst = declaringTypeInst @ minst
if tpsorig.Length <> vtinst.Length then error(InternalError("BuildFSharpMethodCall: unexpected typar length mismatch",m))
let expr = mkTyAppExpr m (vexp, vexpty) vtinst
let exprty = instType (mkTyparInst tpsorig vtinst) tau
BuildFSharpMethodApp g m vref expr exprty args
Expand All @@ -691,15 +694,20 @@ let BuildFSharpMethodCall g m (ty, vref: ValRef) valUseFlags minst args =
/// calls to the type-directed solutions to member constraints.
let MakeMethInfoCall amap m minfo minst args =
let valUseFlags = NormalValUse // correct unless if we allow wild trait constraints like "T has a ctor and can be used as a parent class"

match minfo with
| ILMeth(g, ilminfo, _) ->

| ILMeth(g,ilminfo,_) ->
let direct = not minfo.IsVirtual
let isProp = false // not necessarily correct, but this is only used post-creflect where this flag is irrelevant
BuildILMethInfoCall g amap m isProp ilminfo valUseFlags minst direct args |> fst
| FSMeth(g, ty, vref, _) ->
BuildFSharpMethodCall g m (ty, vref) valUseFlags minst args |> fst
| DefaultStructCtor(_, ty) ->
mkDefault (m, ty)

| FSMeth(g, _, vref, _) ->
BuildFSharpMethodCall g m vref valUseFlags minfo.DeclaringTypeInst minst args |> fst

| DefaultStructCtor(_,ty) ->
mkDefault (m,ty)

#if !NO_EXTENSIONTYPING
| ProvidedMeth(amap, mi, _, m) ->
let isProp = false // not necessarily correct, but this is only used post-creflect where this flag is irrelevant
Expand Down
Loading