Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8336519

Browse files
forkiKevinRansom
authored andcommitted
Don't call isSome and .Value (#3126)
* Don't call isSome and .Value* Use hasOrigExpr in order to reduce checks and move filter up
1 parent545197e commit8336519

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

‎src/fsharp/TypeChecker.fs‎

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6769,6 +6769,8 @@ and TcRecdExpr cenv overallTy env tpenv (inherits, optOrigExpr, flds, mWholeExpr
67696769
let oldv,oldve = mkCompGenLocal mWholeExpr "inputRecord" overallTy
67706770
Some (olde,oldv,oldve), tpenv
67716771

6772+
let hasOrigExpr = Option.isSome optOrigExpr
6773+
67726774
let fldsList =
67736775
let flds =
67746776
[
@@ -6781,15 +6783,20 @@ and TcRecdExpr cenv overallTy env tpenv (inherits, optOrigExpr, flds, mWholeExpr
67816783

67826784
yield (List.frontAndBack lidwd.Lid, v)
67836785
]
6786+
67846787
match flds with
67856788
| [] -> []
67866789
| _ ->
6787-
let tcref,_,fldsList = BuildFieldMap cenv env(Option.isSome optOrigExpr) overallTy flds mWholeExpr
6790+
let tcref,_,fldsList = BuildFieldMap cenv envhasOrigExpr overallTy flds mWholeExpr
67886791
let _,_,_,gtyp = infoOfTyconRef mWholeExpr tcref
6789-
UnifyTypes cenv env mWholeExpr overallTy gtyp
6790-
fldsList
6792+
UnifyTypes cenv env mWholeExpr overallTy gtyp
6793+
6794+
[ for n, v in fldsList do
6795+
match v with
6796+
| Some v -> yield n, v
6797+
| None -> () ]
67916798

6792-
ifOption.isSome optOrigExpr && not (isRecdTy cenv.g overallTy) then
6799+
ifhasOrigExpr && not (isRecdTy cenv.g overallTy) then
67936800
errorR(Error(FSComp.SR.tcExpressionFormRequiresRecordTypes(),mWholeExpr))
67946801

67956802
if requiresCtor || haveCtor then
@@ -6800,9 +6807,7 @@ and TcRecdExpr cenv overallTy env tpenv (inherits, optOrigExpr, flds, mWholeExpr
68006807
errorR(Error(FSComp.SR.tcObjectConstructionExpressionCanOnlyImplementConstructorsInObjectModelTypes(),mWholeExpr))
68016808
else
68026809
if isNil flds then
6803-
let errorInfo =
6804-
if Option.isSome optOrigExpr then FSComp.SR.tcEmptyCopyAndUpdateRecordInvalid()
6805-
else FSComp.SR.tcEmptyRecordInvalid()
6810+
let errorInfo = if hasOrigExpr then FSComp.SR.tcEmptyCopyAndUpdateRecordInvalid() else FSComp.SR.tcEmptyRecordInvalid()
68066811
error(Error(errorInfo,mWholeExpr))
68076812

68086813
if isFSharpObjModelTy cenv.g overallTy then errorR(Error(FSComp.SR.tcTypeIsNotARecordTypeNeedConstructor(),mWholeExpr))
@@ -6824,9 +6829,7 @@ and TcRecdExpr cenv overallTy env tpenv (inherits, optOrigExpr, flds, mWholeExpr
68246829
errorR(InternalError("Unexpected failure in getting super type",mWholeExpr))
68256830
None,tpenv
68266831

6827-
let expr,tpenv =
6828-
let fldsList = fldsList |> List.choose (fun (n, v) -> if v.IsSome then Some (n, v.Value) else None)
6829-
TcRecordConstruction cenv overallTy env tpenv optOrigExpr overallTy fldsList mWholeExpr
6832+
let expr,tpenv = TcRecordConstruction cenv overallTy env tpenv optOrigExpr overallTy fldsList mWholeExpr
68306833

68316834
let expr =
68326835
match superTy with

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp