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

[RFC FS-1093] Additional type directed conversions #10884

Merged
merged 78 commits into from
Aug 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
3bc197c
merge main
Jan 15, 2021
722bd32
merge main
Jan 15, 2021
983c71b
fix some misc bits and pieces
Jan 15, 2021
265b14f
fix bug
Jan 15, 2021
28c2525
assert constructor return type
Jan 15, 2021
5fcb36f
no subsumption for type-directed records
Jan 15, 2021
b67d861
fix bootstrap build
Jan 16, 2021
1a630b9
fix test
Jan 16, 2021
163e707
fix test baselines
Jan 18, 2021
3eea4d5
respect rigid type annotations within expressions
Jan 18, 2021
874f8a4
respect rigid type annotations within expressions
Jan 18, 2021
b34e4de
reenable rigid type annotations within expressions
Jan 18, 2021
266e9a1
update baseline
Jan 18, 2021
ef9fd65
Merge branch 'main' of https://github.com/dotnet/fsharp into feature/…
Jan 19, 2021
99aa42d
add language version check
Jan 19, 2021
1092a80
Merge branch 'main' of https://github.com/dotnet/fsharp into feature/…
Jan 20, 2021
0a30a3b
adjust test baseline for better error recovery
Jan 21, 2021
b6211a1
adjust test baseline for better error recovery
Jan 21, 2021
b03c6a3
Merge branch 'main' of https://github.com/dotnet/fsharp into feature/…
Jan 21, 2021
326b7d5
Merge main to feature/auto-widen (#10918)
dotnet-bot Jan 22, 2021
a5fb84c
fixes for type directed conversion for optional args, backwards compa…
Jan 25, 2021
8c60247
Merge branch 'feature/auto-widen' of https://github.com/dotnet/fsharp…
Jan 25, 2021
3c0bb24
op_Implicit support
Jan 26, 2021
0fb65fa
merge
Jan 26, 2021
d20062b
update baselines
Jan 26, 2021
efb4e7e
fix bug in nullable codegen
Jan 26, 2021
9535615
fix tests
Jan 27, 2021
22665d0
fix unions and records
Jan 27, 2021
9c46f99
ignore hanging test for now
Jan 28, 2021
e0db898
fix hang
Jan 28, 2021
b5feadf
update baseline
Jan 30, 2021
4347437
merge main
Feb 3, 2021
79269e2
Merge pull request #11003 from dotnet/merges/main-to-feature/auto-widen
KevinRansom Feb 3, 2021
17a0e0b
merge main
Feb 4, 2021
dd60c07
Merge pull request #11012 from dotnet/merges/main-to-feature/auto-widen
KevinRansom Feb 5, 2021
39c4a90
Merge pull request #11036 from dotnet/merges/main-to-feature/auto-widen
cartermp Feb 6, 2021
5066a2e
Merge pull request #11051 from dotnet/merges/main-to-feature/auto-widen
KevinRansom Feb 8, 2021
bd23f78
Merge pull request #11062 from dotnet/merges/main-to-feature/auto-widen
KevinRansom Feb 9, 2021
ac263cf
Merge pull request #11079 from dotnet/merges/main-to-feature/auto-widen
KevinRansom Feb 11, 2021
efa0674
Merge pull request #11093 from dotnet/merges/main-to-feature/auto-widen
KevinRansom Feb 12, 2021
b7cdcdf
integrate main
Mar 29, 2021
8d53258
merge main
May 24, 2021
9aba0c0
Merge branch 'main' of https://github.com/dotnet/fsharp into feature/…
May 25, 2021
19ed0e6
trim trailing spaces
May 25, 2021
27e7911
simplify expression leaf logic and make regular
May 25, 2021
4e1e621
fix build
May 25, 2021
bf35f40
update testing
May 25, 2021
6de01a6
update baselines
May 25, 2021
4dc59bf
Merge branch 'main' of https://github.com/dotnet/fsharp into feature/…
May 26, 2021
85c0117
cache implicit operator lookup
May 26, 2021
8056d38
Merge branch 'main' of https://github.com/dotnet/fsharp into feature/…
May 27, 2021
57afe7d
Merge branch 'main' into feature/auto-widen
dsyme Jun 4, 2021
8bb487c
add op_Implicit tests: checks, options, ambiguities, extrinsic extens…
Jun 7, 2021
c168fc5
Merge branch 'main' of https://github.com/dotnet/fsharp into feature/…
Jun 8, 2021
cfb69c4
remove int32 --> float32 and floar32 --> float64, improve error messages
Jun 8, 2021
b4d1e96
Merge branch 'main' of https://github.com/dotnet/fsharp into feature/…
dsyme Jun 9, 2021
73f3129
Merge branch 'main' of https://github.com/dotnet/fsharp into feature/…
Jun 24, 2021
e92215d
Merge branch 'main' of https://github.com/dotnet/fsharp into feature/…
Jun 25, 2021
f2b0357
integrate main
Jul 5, 2021
5152b79
update baseline and improve errors
Jul 6, 2021
a541448
Merge branch 'main' into feature/auto-widen
vzarytovskii Jul 12, 2021
e541c7e
Merge branch 'main' of https://github.com/dotnet/fsharp into feature/…
Jul 14, 2021
e94d6da
Merge branch 'main' into feature/auto-widen
vzarytovskii Jul 16, 2021
e8b8986
Merge branch 'main' into feature/auto-widen
vzarytovskii Jul 16, 2021
d90a828
merge main
Jul 23, 2021
59e7d48
update message
Jul 24, 2021
b5c1121
Merge branch 'main' of https://github.com/dotnet/fsharp into feature/…
Jul 25, 2021
ba289f1
adjust mechanism and policy for warnings
Jul 26, 2021
8a30060
adjust warnings implementation and policy
Jul 26, 2021
fca3375
Merge branch 'main' into feature/auto-widen
vzarytovskii Aug 2, 2021
6a97c66
resolve conflict
Aug 9, 2021
17713a1
Update FSharp.Test.Utilities.fsproj
dsyme Aug 9, 2021
d2c3a33
Update FSharp.Compiler.Service.Tests.fsproj
dsyme Aug 9, 2021
fea36b9
Merge branch 'main' of https://github.com/dotnet/fsharp into fix_test…
KevinRansom Aug 9, 2021
c29bf2b
Fix merge issue
KevinRansom Aug 9, 2021
3ad080d
Merge pull request #11944 from KevinRansom/fix_tests_for_auto_widen
KevinRansom Aug 9, 2021
214876f
Merge branch 'main' into feature/auto-widen
dsyme Aug 10, 2021
0147f34
Update CheckExpressions.fs
dsyme Aug 10, 2021
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
43 changes: 23 additions & 20 deletions src/fsharp/CheckComputationExpressions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,9 @@ let RecordNameAndTypeResolutions_IdeallyWithoutHavingOtherEffects cenv env tpenv
with e -> ())

/// Used for all computation expressions except sequence expressions
let TcComputationExpression cenv env overallTy tpenv (mWhole, interpExpr: Expr, builderTy, comp: SynExpr) =

let TcComputationExpression cenv env (overallTy: OverallTy) tpenv (mWhole, interpExpr: Expr, builderTy, comp: SynExpr) =
let overallTy = overallTy.Commit

//dprintfn "TcComputationExpression, comp = \n%A\n-------------------\n" comp
let ad = env.eAccessRights

Expand Down Expand Up @@ -1642,7 +1643,7 @@ let TcComputationExpression cenv env overallTy tpenv (mWhole, interpExpr: Expr,
| SynExpr.YieldOrReturn ((_, true), _, _) -> { env with eContextInfo = ContextInfo.ReturnInComputationExpression }
| _ -> env

let lambdaExpr, tpenv= TcExpr cenv (builderTy --> overallTy) env tpenv lambdaExpr
let lambdaExpr, tpenv= TcExpr cenv (MustEqual (builderTy --> overallTy)) env tpenv lambdaExpr
// beta-var-reduce to bind the builder using a 'let' binding
let coreExpr = mkApps cenv.g ((lambdaExpr, tyOfExpr cenv.g lambdaExpr), [], [interpExpr], mBuilderVal)

Expand Down Expand Up @@ -1704,10 +1705,10 @@ let compileSeqExprMatchClauses (cenv: cenv) env inputExprMark (pat: Pattern, vsp
/// These are later detected by state machine compilation.
///
/// Also "ienumerable extraction" is performed on arguments to "for".
let TcSequenceExpression (cenv: cenv) env tpenv comp overallTy m =
let TcSequenceExpression (cenv: cenv) env tpenv comp (overallTy: OverallTy) m =

let genEnumElemTy = NewInferenceType ()
UnifyTypes cenv env m overallTy (mkSeqTy cenv.g genEnumElemTy)
UnifyTypes cenv env m overallTy.Commit (mkSeqTy cenv.g genEnumElemTy)

// Allow subsumption at 'yield' if the element type is nominal prior to the analysis of the body of the sequence expression
let flex = not (isTyparTy cenv.g genEnumElemTy)
Expand Down Expand Up @@ -1765,7 +1766,7 @@ let TcSequenceExpression (cenv: cenv) env tpenv comp overallTy m =
Some(tcSequenceExprBody env genOuterTy tpenv (elimFastIntegerForLoop (spBind, id, start, dir, finish, innerComp, m)))

| SynExpr.While (spWhile, guardExpr, innerComp, _m) ->
let guardExpr, tpenv = TcExpr cenv cenv.g.bool_ty env tpenv guardExpr
let guardExpr, tpenv = TcExpr cenv (MustEqual cenv.g.bool_ty) env tpenv guardExpr
let innerExpr, tpenv = tcSequenceExprBody env genOuterTy tpenv innerComp

let guardExprMark = guardExpr.Range
Expand All @@ -1782,7 +1783,7 @@ let TcSequenceExpression (cenv: cenv) env tpenv comp overallTy m =

| SynExpr.TryFinally (innerComp, unwindExpr, mTryToLast, spTry, spFinally) ->
let innerExpr, tpenv = tcSequenceExprBody env genOuterTy tpenv innerComp
let (unwindExpr: Expr), tpenv = TcExpr cenv cenv.g.unit_ty env tpenv unwindExpr
let unwindExpr, tpenv = TcExpr cenv (MustEqual cenv.g.unit_ty) env tpenv unwindExpr

// We attach the debug points to the lambda expressions so we can fetch it out again in LowerComputedListOrArraySeqExpr
let mTry =
Expand Down Expand Up @@ -1823,7 +1824,7 @@ let TcSequenceExpression (cenv: cenv) env tpenv comp overallTy m =
Some(Expr.Sequential(stmt1, innerExpr2, NormalSeq, sp, m), tpenv)

| SynExpr.IfThenElse (_, _, guardExpr, _, thenComp, _, elseCompOpt, spIfToThen, _isRecovery, mIfToThen, mIfToEndOfElseBranch) ->
let guardExpr', tpenv = TcExpr cenv cenv.g.bool_ty env tpenv guardExpr
let guardExpr', tpenv = TcExpr cenv (MustEqual cenv.g.bool_ty) env tpenv guardExpr
let thenExpr, tpenv = tcSequenceExprBody env genOuterTy tpenv thenComp
let elseComp = (match elseCompOpt with Some c -> c | None -> SynExpr.ImplicitZero mIfToThen)
let elseExpr, tpenv = tcSequenceExprBody env genOuterTy tpenv elseComp
Expand All @@ -1832,7 +1833,7 @@ let TcSequenceExpression (cenv: cenv) env tpenv comp overallTy m =
// 'let x = expr in expr'
| SynExpr.LetOrUse (_, false (* not a 'use' binding *), _, _, _) ->
TcLinearExprs
(fun ty envinner tpenv e -> tcSequenceExprBody envinner ty tpenv e)
(fun overallTy envinner tpenv e -> tcSequenceExprBody envinner overallTy.Commit tpenv e)
cenv env overallTy
tpenv
true
Expand All @@ -1846,7 +1847,7 @@ let TcSequenceExpression (cenv: cenv) env tpenv comp overallTy m =
let inputExprTy = NewInferenceType ()
let pat', _, vspecs, envinner, tpenv = TcMatchPattern cenv bindPatTy env tpenv (pat, None)
UnifyTypes cenv env m inputExprTy bindPatTy
let (inputExpr: Expr), tpenv = TcExpr cenv inputExprTy env tpenv rhsExpr
let inputExpr, tpenv = TcExpr cenv (MustEqual inputExprTy) env tpenv rhsExpr
let innerExpr, tpenv = tcSequenceExprBody envinner genOuterTy tpenv innerComp
let mBind =
match spBind with
Expand Down Expand Up @@ -1897,7 +1898,7 @@ let TcSequenceExpression (cenv: cenv) env tpenv comp overallTy m =

| _ -> None

and tcSequenceExprBody env genOuterTy tpenv comp =
and tcSequenceExprBody env (genOuterTy: TType) tpenv comp =
let res, tpenv = tcSequenceExprBodyAsSequenceOrStatement env genOuterTy tpenv comp
match res with
| Choice1Of2 expr ->
Expand Down Expand Up @@ -1927,11 +1928,11 @@ let TcSequenceExpression (cenv: cenv) env tpenv comp overallTy m =
let stmt, tpenv = TcStmtThatCantBeCtorBody cenv env tpenv comp
Choice2Of2 stmt, tpenv

let coreExpr, tpenv = tcSequenceExprBody env overallTy tpenv comp
let coreExpr, tpenv = tcSequenceExprBody env overallTy.Commit tpenv comp
let delayedExpr = mkDelayedExpr coreExpr.Range coreExpr
delayedExpr, tpenv

let TcSequenceExpressionEntry (cenv: cenv) env overallTy tpenv (isArrayOrList, isNotNakedRefCell, comp) m =
let TcSequenceExpressionEntry (cenv: cenv) env (overallTy: OverallTy) tpenv (isArrayOrList, isNotNakedRefCell, comp) m =
let implicitYieldEnabled = cenv.g.langVersion.SupportsFeature LanguageFeature.ImplicitYield
let validateObjectSequenceOrRecordExpression = not implicitYieldEnabled
if not isArrayOrList then
Expand Down Expand Up @@ -1977,16 +1978,18 @@ let TcArrayOrListSequenceExpression (cenv: cenv) env overallTy tpenv (isArray, c
TcExprUndelayed cenv overallTy env tpenv replacementExpr
| _ ->

let genCollElemTy = NewInferenceType ()
let genCollElemTy = NewInferenceType ()

let genCollTy = (if isArray then mkArrayType else mkListTy) cenv.g genCollElemTy

UnifyTypes cenv env m overallTy genCollTy
let genCollTy = (if isArray then mkArrayType else mkListTy) cenv.g genCollElemTy

// Propagating type directed conversion, e.g. for
// let x : seq<int64> = [ yield 1; if true then yield 2 ]
TcPropagatingExprLeafThenConvert cenv overallTy genCollTy env (* canAdhoc *) m (fun () ->

let exprty = mkSeqTy cenv.g genCollElemTy

// Check the comprehension
let expr, tpenv = TcExpr cenv exprty env tpenv comp
let expr, tpenv = TcExpr cenv (MustEqual exprty) env tpenv comp

let expr = mkCoerceIfNeeded cenv.g exprty (tyOfExpr cenv.g expr) expr

Expand All @@ -1999,12 +2002,12 @@ let TcArrayOrListSequenceExpression (cenv: cenv) env overallTy tpenv (isArray, c
// comprehension. But don't do this in FSharp.Core.dll since 'seq' may not yet be defined.
mkCallSeq cenv.g m genCollElemTy expr

let expr = mkCoerceExpr(expr, exprty, expr.Range, overallTy)
let expr = mkCoerceExpr(expr, exprty, expr.Range, overallTy.Commit)

let expr =
if isArray then
mkCallSeqToArray cenv.g m genCollElemTy expr
else
mkCallSeqToList cenv.g m genCollElemTy expr

expr, tpenv
expr, tpenv)
7 changes: 4 additions & 3 deletions src/fsharp/CheckComputationExpressions.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
module internal FSharp.Compiler.CheckComputationExpressions

open FSharp.Compiler.CheckExpressions
open FSharp.Compiler.ConstraintSolver
open FSharp.Compiler.Syntax
open FSharp.Compiler.Text
open FSharp.Compiler.TypedTree

val TcSequenceExpressionEntry: cenv:TcFileState -> env:TcEnv -> overallTy:TType -> tpenv:UnscopedTyparEnv -> isArrayOrList:bool * isNotNakedRefCell:bool ref * comp:SynExpr -> m:range -> Expr * UnscopedTyparEnv
val TcSequenceExpressionEntry: cenv:TcFileState -> env:TcEnv -> overallTy:OverallTy -> tpenv:UnscopedTyparEnv -> isArrayOrList:bool * isNotNakedRefCell:bool ref * comp:SynExpr -> m:range -> Expr * UnscopedTyparEnv

val TcArrayOrListSequenceExpression: cenv:TcFileState -> env:TcEnv -> overallTy:TType -> tpenv:UnscopedTyparEnv -> isArray:bool * comp:SynExpr -> m:range -> Expr * UnscopedTyparEnv
val TcArrayOrListSequenceExpression: cenv:TcFileState -> env:TcEnv -> overallTy:OverallTy -> tpenv:UnscopedTyparEnv -> isArray:bool * comp:SynExpr -> m:range -> Expr * UnscopedTyparEnv

val TcComputationExpression: cenv:TcFileState -> env:TcEnv -> overallTy:TType -> tpenv:UnscopedTyparEnv -> mWhole:range * interpExpr:Expr * builderTy:TType * comp:SynExpr -> Expr * UnscopedTyparEnv
val TcComputationExpression: cenv:TcFileState -> env:TcEnv -> overallTy:OverallTy -> tpenv:UnscopedTyparEnv -> mWhole:range * interpExpr:Expr * builderTy:TType * comp:SynExpr -> Expr * UnscopedTyparEnv

2 changes: 1 addition & 1 deletion src/fsharp/CheckDeclarations.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1874,7 +1874,7 @@ module MutRecBindingChecking =
let ty = generalizedTyconRef tcref
let ad = envNonRec.AccessRights
match TryFindIntrinsicMethInfo cenv.infoReader bind.Var.Range ad nm ty,
TryFindPropInfo cenv.infoReader bind.Var.Range ad nm ty with
TryFindIntrinsicPropInfo cenv.infoReader bind.Var.Range ad nm ty with
| [], [] -> ()
| _ -> errorR (Error(FSComp.SR.tcMemberAndLocalClassBindingHaveSameName nm, bind.Var.Range))

Expand Down
Loading