Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 13 additions & 0 deletions src/fsharp/ConstraintSolver.fs
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,8 @@ let IsNumericType g ty = IsNonDecimalNumericType g ty || isDecimalTy g ty

let IsRelationalType g ty = IsNumericType g ty || isStringTy g ty || isCharTy g ty || isBoolTy g ty

let IsEncodedTuple tupInfo g ty = tyconRefEq g ty (if evalTupInfoIsStruct tupInfo then g.struct_tuple8_tcr else g.ref_tuple8_tcr)

// Get measure of type, float<_> or float32<_> or decimal<_> but not float=float<1> or float32=float32<1> or decimal=decimal<1>
let GetMeasureOfType g ty =
match ty with
Expand Down Expand Up @@ -1025,6 +1027,17 @@ and SolveTypeEqualsType (csenv: ConstraintSolverEnv) ndeep m2 (trace: OptionalTr
-> SolveTypeEqualsType csenv ndeep m2 trace None ms (TType_measure Measure.One)

| TType_app (tc1, l1), TType_app (tc2, l2) when tyconRefEq g tc1 tc2 -> SolveTypeEqualsTypeEqns csenv ndeep m2 trace None l1 l2

// Catch System.Tuple<'T1,'T2,'T3,'T4,'T5,'T6,'T7,...> = 'T1*'T2*'T3*'T4*'T5*'T6*'T7*...
| TType_app (tc1, [a1;b1;c1;d1;e1;f1;g1;rest1]), TType_tuple (tupInfo, [a2;b2;c2;d2;e2;f2;g2;h2]) when IsEncodedTuple tupInfo g tc1 ->
SolveTypeEqualsTypeEqns csenv ndeep m2 trace None [a1;b1;c1;d1;e1;f1;g1;rest1] [a2;b2;c2;d2;e2;f2;g2;TType_app ((if evalTupInfoIsStruct tupInfo then g.struct_tuple1_tcr else g.ref_tuple1_tcr), [h2])]
| TType_app (tc1, [a1;b1;c1;d1;e1;f1;g1;rest1]), TType_tuple (tupInfo, a2::b2::c2::d2::e2::f2::g2::rest2) when IsEncodedTuple tupInfo g tc1 ->
SolveTypeEqualsTypeEqns csenv ndeep m2 trace None [a1;b1;c1;d1;e1;f1;g1;rest1] [a2;b2;c2;d2;e2;f2;g2;TType_tuple (tupInfo, rest2)]
| TType_tuple (tupInfo, [a1;b1;c1;d1;e1;f1;g1;h1]), TType_app (tc2, [a2;b2;c2;d2;e2;f2;g2;rest2]) when IsEncodedTuple tupInfo g tc2 ->
SolveTypeEqualsTypeEqns csenv ndeep m2 trace None [a1;b1;c1;d1;e1;f1;g1;TType_app ((if evalTupInfoIsStruct tupInfo then g.struct_tuple2_tcr else g.ref_tuple2_tcr), [h1])] [a2;b2;c2;d2;e2;f2;g2;rest2]
| TType_tuple (tupInfo, a1::b1::c1::d1::e1::f1::g1::rest1), TType_app (tc2, [a2;b2;c2;d2;e2;f2;g2;rest2]) when IsEncodedTuple tupInfo g tc2 ->
SolveTypeEqualsTypeEqns csenv ndeep m2 trace None [a1;b1;c1;d1;e1;f1;g1;TType_tuple (tupInfo, rest1)] [a2;b2;c2;d2;e2;f2;g2;rest2]

| TType_app (_, _), TType_app (_, _) -> localAbortD
| TType_tuple (tupInfo1, l1), TType_tuple (tupInfo2, l2) ->
if evalTupInfoIsStruct tupInfo1 <> evalTupInfoIsStruct tupInfo2 then ErrorD (ConstraintSolverError(FSComp.SR.tcTupleStructMismatch(), csenv.m, m2)) else
Expand Down
3 changes: 2 additions & 1 deletion src/fsharp/Optimizer.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1596,7 +1596,8 @@ let ExpandStructuralBindingRaw cenv expr =
assert cenv.settings.ExpandStructuralValues()
match expr with
| Expr.Let (TBind(v, rhs, tgtSeqPtOpt), body, m, _)
when (isRefTupleExpr rhs &&
when (isAnyTupleTy cenv.g v.Type &&
isRefTupleExpr rhs &&
CanExpandStructuralBinding v) ->
let args = tryDestRefTupleExpr rhs
if List.forall ExprIsValue args then
Expand Down
10 changes: 10 additions & 0 deletions tests/fsharp/core/csext/test.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,16 @@ module TupleSRTP =
let v1b = (^T : (member get_Item2 : unit -> _ ) (new System.Tuple<int,int>(1,3)))
let v2b = (^T : (member get_Item2 : unit -> _ ) (System.Tuple<int,int>(1,3)))
let v3b = (^T : (member get_Item2 : unit -> _ ) ((1,3)))

let areEqualT8 = System.Tuple<_,_,_,_,_,_,_,_>(1,2,3,4,5,6,7,System.Tuple<_> (8) ) = (1,2,3,4,5,6,7,8)
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.

Will this also compile for:

     let areEqualT9 = System.Tuple<_,_,_,_,_,_,_,(int * int)>(1,2,3,4,5,6,7,(8,9)) = (1,2,3,4,5,6,7,8,9) 

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I just added a commit that will allow that.

let areEqualT9 = System.Tuple<_,_,_,_,_,_,_,_>(1,2,3,4,5,6,7,System.Tuple<_,_>(8,9)) = (1,2,3,4,5,6,7,8,9)

let areEqualT9' = System.Tuple<_,_,_,_,_,_,_,(int * int)>(1,2,3,4,5,6,7,(8,9)) = (1,2,3,4,5,6,7,8,9)

let c8 = System.Tuple<int,int,int,int,int,int,int,System.Tuple<int>>(1,2,3,4,5,6,7,System.Tuple<int>(8))
let c9 = System.Tuple<int,int,int,int,int,int,int,System.Tuple<int,int>>(1,2,3,4,5,6,7,System.Tuple<int,int>(8,9))



(*--------------------*)

Expand Down