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

Commit411992c

Browse files
dsymeKevinRansom
authored andcommitted
Fix for 2937 - Don't detuple lambdas during optimization based on types only (#3282)
* don't detuple lambdas during optimization based on types only* update comment* update baselines
1 parentf180548 commit411992c

File tree

15 files changed

+181
-3080
lines changed

15 files changed

+181
-3080
lines changed

‎src/fsharp/IlxGen.fs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1366,7 +1366,7 @@ type CodeGenBuffer(m:range,
13661366
// Save the last sequence point away so we can make a decision graph look consistent (i.e. reassert the sequence point at each target)
13671367
lastSeqPoint<- Some src
13681368

1369-
// For debug code, emit FeeFee breakpoints for hidden code, seehttp://blogs.msdn.com/jmstall/archive/2005/06/19/FeeFee_SequencePoints.aspx
1369+
// For debug code, emit FeeFee breakpoints for hidden code, seehttps://blogs.msdn.microsoft.com/jmstall/2005/06/19/line-hidden-and-0xfeefee-sequence-points/
13701370
membercgbuf.EmitStartOfHiddenCode()=
13711371
if mgbuf.cenv.opts.generateDebugSymbols&&not mgbuf.cenv.opts.localOptimizationsAreOnthen
13721372
letdoc= mgbuf.cenv.g.memoize_file m.FileIndex

‎src/fsharp/InnerLambdasToTopLevelFuncs.fs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -972,7 +972,7 @@ module Pass4_RewriteAssembly =
972972

973973
letConvertBind g(TBind(v,repr,_)as bind)=
974974
match v.ValReprInfowith
975-
| None-> v.SetValReprInfo(Some(InferArityOfExprBinding g v repr))
975+
| None-> v.SetValReprInfo(Some(InferArityOfExprBinding gAllowTypeDirectedDetupling.Yesv repr))
976976
| Some_->()
977977

978978
bind

‎src/fsharp/Optimizer.fs‎

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2920,23 +2920,24 @@ and OptimizeSwitchFallback cenv env (e', einfo, cases,dflt,m) =
29202920
letinfo={ infowith TotalSize= info.TotalSize+ size; FunctionSize= info.FunctionSize+ size;}
29212921
TDSwitch(e',cases',dflt',m),info
29222922

2923-
andOptimizeBinding cenv isRec env(TBind(v,e,spBind))=
2923+
andOptimizeBinding cenv isRec env(TBind(vref,expr,spBind))=
29242924
try
29252925

29262926
// The aim here is to stop method splitting for direct-self-tailcalls. We do more than that: if an expression
29272927
// occurs in the body of recursively defined values RVS, then we refuse to split
29282928
// any expression that contains a reference to any value in RVS.
29292929
// This doesn't prevent splitting for mutually recursive references. See FSharp 1.0 bug 2892.
29302930
letenv=
2931-
if isRecthen{ envwith dontSplitVars= env.dontSplitVars.Addv()}
2931+
if isRecthen{ envwith dontSplitVars= env.dontSplitVars.Addvref()}
29322932
else env
29332933

2934-
letrepr',einfo=
2935-
letenv=if v.IsCompilerGenerated&& Option.isSome env.latestBoundIdthen envelse{envwith latestBoundId=Some v.Id}
2936-
letcenv=if v.InlineInfo= ValInline.PseudoValthen{ cenvwith optimizing=false}else cenv
2937-
lete',einfo= OptimizeLambdas(Some v) cenv env(InferArityOfExprBinding cenv.g v e) e v.Type
2934+
letexprOptimized,einfo=
2935+
letenv=if vref.IsCompilerGenerated&& Option.isSome env.latestBoundIdthen envelse{envwith latestBoundId=Some vref.Id}
2936+
letcenv=if vref.InlineInfo= ValInline.PseudoValthen{ cenvwith optimizing=false}else cenv
2937+
letarityInfo= InferArityOfExprBinding cenv.g AllowTypeDirectedDetupling.No vref expr
2938+
letexprOptimized,einfo= OptimizeLambdas(Some vref) cenv env arityInfo expr vref.Type
29382939
letsize= localVarSize
2939-
e',{einfowith FunctionSize=einfo.FunctionSize+size; TotalSize= einfo.TotalSize+size}
2940+
exprOptimized,{einfowith FunctionSize=einfo.FunctionSize+size; TotalSize= einfo.TotalSize+size}
29402941

29412942
// Trim out optimization information for large lambdas we'll never inline
29422943
// Trim out optimization information for expressions that call protected members
@@ -2960,18 +2961,18 @@ and OptimizeBinding cenv isRec env (TBind(v,e,spBind)) =
29602961
| UnionCaseValue(a,b)-> UnionCaseValue(a,Array.map cut b)
29612962
| UnknownValue| ConstValue_| ConstExprValue_-> ivalue
29622963
| SizeValue(_,a)-> MakeSizedValueInfo(cut a)
2963-
leteinfo=ifv.MustInlinethen einfoelse{einfowith Info= cut einfo.Info}
2964+
leteinfo=ifvref.MustInlinethen einfoelse{einfowith Info= cut einfo.Info}
29642965
leteinfo=
2965-
if(notv.MustInline&&not(cenv.settings.KeepOptimizationValues()))||
2966+
if(notvref.MustInline&&not(cenv.settings.KeepOptimizationValues()))||
29662967

29672968
// Bug 4916: do not record inline data for initialization trigger expressions
29682969
// Note: we can't eliminate these value infos at the file boundaries because that would change initialization
29692970
// order
2970-
IsCompiledAsStaticPropertyWithField cenv.gv||
2971+
IsCompiledAsStaticPropertyWithField cenv.gvref||
29712972

2972-
(v.InlineInfo= ValInline.Never)||
2973+
(vref.InlineInfo= ValInline.Never)||
29732974
// MarshalByRef methods may not be inlined
2974-
(matchv.ActualParentwith
2975+
(matchvref.ActualParentwith
29752976
| Parent tcref->
29762977
match cenv.g.system_MarshalByRefObject_tcrefwith
29772978
| None->false
@@ -2980,15 +2981,15 @@ and OptimizeBinding cenv isRec env (TBind(v,e,spBind)) =
29802981
if mbrTyconRef.TryDeref.IsSomethen
29812982
// Check if this is a subtype of MarshalByRefObject
29822983
assert(cenv.g.system_MarshalByRefObject_typ.IsSome)
2983-
ExistsSameHeadTypeInHierarchy cenv.g cenv.amapv.Range(generalizedTyconRef tcref) cenv.g.system_MarshalByRefObject_typ.Value
2984+
ExistsSameHeadTypeInHierarchy cenv.g cenv.amapvref.Range(generalizedTyconRef tcref) cenv.g.system_MarshalByRefObject_typ.Value
29842985
else
29852986
false
29862987
| ParentNone->false)||
29872988

29882989
// These values are given a special going-over by the optimizer and
29892990
// ilxgen.fs, hence treat them as if no-inline (when preparing the inline information for
29902991
// FSharp.Core).
2991-
(letnvref= mkLocalValRefv
2992+
(letnvref= mkLocalValRefvref
29922993
cenv.g.compilingFslib&&
29932994
(valRefEq cenv.g nvref cenv.g.seq_vref||
29942995
valRefEq cenv.g nvref cenv.g.seq_generated_vref||
@@ -3009,13 +3010,13 @@ and OptimizeBinding cenv isRec env (TBind(v,e,spBind)) =
30093010
valRefEq cenv.g nvref cenv.g.generic_hash_inner_vref))
30103011
then{einfowith Info=UnknownValue}
30113012
else einfo
3012-
ifv.MustInline&& IsPartialExprVal einfo.Infothen
3013-
errorR(InternalError("the mustinline value '"+v.LogicalName+"' was not inferred to have a known value",v.Range))
3013+
ifvref.MustInline&& IsPartialExprVal einfo.Infothen
3014+
errorR(InternalError("the mustinline value '"+vref.LogicalName+"' was not inferred to have a known value",vref.Range))
30143015

3015-
letenv= BindInternalLocalVal cenvv(mkValInfo einfov) env
3016-
(TBind(v,repr',spBind), einfo), env
3016+
letenv= BindInternalLocalVal cenvvref(mkValInfo einfovref) env
3017+
(TBind(vref,exprOptimized,spBind), einfo), env
30173018
with exn->
3018-
errorRecovery exnv.Range
3019+
errorRecovery exnvref.Range
30193020
raise(ReportedError(Some exn))
30203021

30213022
andOptimizeBindings cenv isRec env xs= List.mapFold(OptimizeBinding cenv isRec) env xs

‎src/fsharp/TastOps.fs‎

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4385,9 +4385,12 @@ let stripTopLambda (e,ty) =
43854385
letvs,body,rty= stripLambda(taue,tauty)
43864386
tps,vs,body,rty
43874387

4388+
[<RequireQualifiedAccess>]
4389+
typeAllowTypeDirectedDetupling= Yes| No
4390+
43884391
// This is used to infer arities of expressions
43894392
// i.e. base the chosen arity on the syntactic expression shape and type of arguments
4390-
letInferArityOfExpr g ty partialArgAttribsL retAttribs e=
4393+
letInferArityOfExpr gallowTypeDirectedDetuplingty partialArgAttribsL retAttribs e=
43914394
let recstripLambda_notypes e=
43924395
match ewith
43934396
| Expr.Lambda(_,_,_,vs,b,_,_)->
@@ -4410,7 +4413,12 @@ let InferArityOfExpr g ty partialArgAttribsL retAttribs e =
44104413
letcurriedArgInfos=
44114414
(List.zip vsl dtys)|> List.mapi(fun i(vs,ty)->
44124415
letpartialAttribs=if i< partialArgAttribsL.Lengththen partialArgAttribsL.[i]else[]
4413-
lettys=if(i=0&& isUnitTy g ty)then[]else tryDestRefTupleTy g ty
4416+
lettys=
4417+
match allowTypeDirectedDetuplingwith
4418+
| AllowTypeDirectedDetupling.No->[ty]
4419+
| AllowTypeDirectedDetupling.Yes->
4420+
if(i=0&& isUnitTy g ty)then[]
4421+
else tryDestRefTupleTy g ty
44144422
letids=
44154423
if vs.Length= tys.Lengththen vs|> List.map(fun v-> Some v.Id)
44164424
else tys|> List.map(fun _-> None)
@@ -4421,10 +4429,10 @@ let InferArityOfExpr g ty partialArgAttribsL retAttribs e =
44214429
letretInfo:ArgReprInfo={ Attribs= retAttribs; Name= None}
44224430
ValReprInfo(ValReprInfo.InferTyparInfo tps, curriedArgInfos, retInfo)
44234431

4424-
letInferArityOfExprBinding g(v:Val)e=
4432+
letInferArityOfExprBinding gallowTypeDirectedDetupling(v:Val)e=
44254433
match v.ValReprInfowith
44264434
| Some info-> info
4427-
| None-> InferArityOfExpr g v.Type[][] e
4435+
| None-> InferArityOfExpr gallowTypeDirectedDetuplingv.Type[][] e
44284436

44294437
//-------------------------------------------------------------------------
44304438
// Check if constraints are satisfied that allow us to use more optimized
@@ -6942,8 +6950,8 @@ let LinearizeTopMatchAux g parent (spBind,m,tree,targets,m2,ty) =
69426950
vs|> List.mapi(fun i v->
69436951
letty= v.Type
69446952
letrhs= etaExpandTypeLambda g m v.Typars(itemsProj vtys i tmpe, ty)
6945-
(* update the arity of the value*)
6946-
v.SetValReprInfo(Some(InferArityOfExpr g ty[][] rhs))
6953+
// update the arity of the value
6954+
v.SetValReprInfo(Some(InferArityOfExpr gAllowTypeDirectedDetupling.Yesty[][] rhs))
69476955
mkInvisibleBind v rhs)in(* vi = proj tmp*)
69486956
mkCompGenLet m
69496957
tmp(primMkMatch(spBind,m,tree,targets,m2,tmpTy))(* note, probably retyped match, but note, result still has same type*)

‎src/fsharp/TastOps.fsi‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -740,9 +740,12 @@ val tyOfExpr : TcGlobals -> Expr -> TType
740740
// Top expressions to implement top types
741741
//-------------------------------------------------------------------------
742742

743+
[<RequireQualifiedAccess>]
744+
type AllowTypeDirectedDetupling= Yes| No
745+
743746
valstripTopLambda:Expr* TType-> Typars* Val list list* Expr* TType
744-
val InferArityOfExpr: TcGlobals-> TType-> Attribs list list-> Attribs-> Expr-> ValReprInfo
745-
val InferArityOfExprBinding: TcGlobals-> Val-> Expr-> ValReprInfo
747+
val InferArityOfExpr: TcGlobals->AllowTypeDirectedDetupling->TType-> Attribs list list-> Attribs-> Expr-> ValReprInfo
748+
val InferArityOfExprBinding: TcGlobals->AllowTypeDirectedDetupling->Val-> Expr-> ValReprInfo
746749

747750
//-------------------------------------------------------------------------
748751
// Copy expressions and types

‎src/fsharp/TypeChecker.fs‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1762,7 +1762,7 @@ let CombineSyntacticAndInferredArities g declKind rhsExpr prelimScheme =
17621762
else
17631763

17641764
let (ValReprInfo (_,curriedArgInfosFromExpression,_)) =
1765-
InferArityOfExpr g (GeneralizedTypeForTypeScheme typeScheme) argAttribs retAttribs rhsExpr
1765+
InferArityOfExpr gAllowTypeDirectedDetupling.Yes(GeneralizedTypeForTypeScheme typeScheme) argAttribs retAttribs rhsExpr
17661766

17671767
// Choose between the syntactic arity and the expression-inferred arity
17681768
// If the syntax specifies an eliminated unit arg, then use that
@@ -3811,12 +3811,12 @@ let EliminateInitializationGraphs
38113811
let fty = (g.unit_ty --> ty)
38123812
let flazy,felazy = Tastops.mkCompGenLocal m v.LogicalName fty
38133813
let frhs = mkUnitDelayLambda g m e
3814-
if mustHaveArity then flazy.SetValReprInfo (Some(InferArityOfExpr g fty [] [] frhs))
3814+
if mustHaveArity then flazy.SetValReprInfo (Some(InferArityOfExpr gAllowTypeDirectedDetupling.Yesfty [] [] frhs))
38153815

38163816
let vlazy,velazy = Tastops.mkCompGenLocal m v.LogicalName vty
38173817
let vrhs = (mkLazyDelayed g m ty felazy)
38183818

3819-
if mustHaveArity then vlazy.SetValReprInfo (Some(InferArityOfExpr g vty [] [] vrhs))
3819+
if mustHaveArity then vlazy.SetValReprInfo (Some(InferArityOfExpr gAllowTypeDirectedDetupling.Yesvty [] [] vrhs))
38203820
fixupPoints |> List.iter (fun (fp,_) -> fp := mkLazyForce g (!fp).Range ty velazy)
38213821

38223822
[mkInvisibleBind flazy frhs; mkInvisibleBind vlazy vrhs],
@@ -10716,7 +10716,7 @@ and TcLetBinding cenv isUse env containerInfo declKind tpenv (binds,bindsm,scope
1071610716
// type checker that anything related to binding module-level values is marked with an
1071710717
// val_repr_info, val_actual_parent and is_topbind
1071810718
if (DeclKind.MustHaveArity declKind) then
10719-
AdjustValToTopVal tmp altActualParent (InferArityOfExprBinding cenv.g tmp rhsExpr)
10719+
AdjustValToTopVal tmp altActualParent (InferArityOfExprBinding cenv.gAllowTypeDirectedDetupling.Yestmp rhsExpr)
1072010720
tmp,pat'
1072110721

1072210722
let mkRhsBind (bodyExpr,bodyExprTy) =
@@ -12257,7 +12257,7 @@ module IncrClassChecking =
1225712257
if isUnitTy cenv.g v.Type then
1225812258
false
1225912259
else
12260-
let arity = InferArityOfExprBinding cenv.g v bind.Expr
12260+
let arity = InferArityOfExprBinding cenv.gAllowTypeDirectedDetupling.Yesv bind.Expr
1226112261
not arity.HasNoArgs && not v.IsMutable
1226212262

1226312263

@@ -12295,7 +12295,7 @@ module IncrClassChecking =
1229512295
warning (Error(FSComp.SR.chkUnusedValue(v.DisplayName), v.Range))
1229612296

1229712297
let repr =
12298-
match InferArityOfExprBinding g v bind.Expr with
12298+
match InferArityOfExprBinding gAllowTypeDirectedDetupling.Yesv bind.Expr with
1229912299
| arity when arity.HasNoArgs || v.IsMutable ->
1230012300
// all mutable variables are forced into fields, since they may escape into closures within the implicit constructor
1230112301
// e.g.

‎src/fsharp/symbols/Exprs.fs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1060,7 +1060,7 @@ and FSharpImplementationFileContents(cenv, mimpl) =
10601060
andgetBind(bind:Binding)=
10611061
letv= bind.Var
10621062
assert v.IsCompiledAsTopLevel
1063-
lettopValInfo= InferArityOfExprBinding cenv.g v bind.Expr
1063+
lettopValInfo= InferArityOfExprBinding cenv.gAllowTypeDirectedDetupling.Yesv bind.Expr
10641064
lettps,_ctorThisValOpt,_baseValOpt,vsl,body,_bodyty= IteratedAdjustArityOfLambda cenv.g cenv.amap topValInfo bind.Expr
10651065
letv= FSharpMemberOrFunctionOrValue(cenv, mkLocalValRef v)
10661066
letgps= v.GenericParameters

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp