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

Commit931f546

Browse files
forkiKevinRansom
authored andcommitted
Remove double lookups from TastOps (dotnet#4747)
1 parent3a0f5d6 commit931f546

File tree

3 files changed

+32
-31
lines changed

3 files changed

+32
-31
lines changed

‎src/fsharp/IlxGen.fs‎

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2474,27 +2474,27 @@ and GenUntupledArgExpr cenv cgbuf eenv m argInfos expr sequel =
24742474
andGenApp cenv cgbuf eenv(f,fty,tyargs,args,m)sequel=
24752475
match(f,tyargs,args)with
24762476
(* Look for tailcall to turn into branch*)
2477-
|(Expr.Val(v,_,_),_,_)when
2478-
((ListAssoc.containsKey cenv.g.valRefEq v eenv.innerVals)&&
2479-
not v.IsConstructor&&
2480-
let(kind,_)= ListAssoc.find cenv.g.valRefEq v eenv.innerVals
2481-
(* when branch-calling methods we must have the right type parameters*)
2482-
beginmatch kindwith
2483-
| BranchCallClosure_->true
2484-
| BranchCallMethod(_,_,tps,_,_)->
2485-
(List.lengthsEqAndForall2(fun ty tp-> typeEquiv cenv.g ty(mkTyparTy tp)) tyargs tps)
2486-
end&&
2487-
(* must be exact #args, ignoring tupling - we untuple if needed below*)
2488-
(letarityInfo=
2489-
match kindwith
2490-
| BranchCallClosure arityInfo
2491-
| BranchCallMethod(arityInfo,_,_,_,_)-> arityInfo
2492-
arityInfo.Length= args.Length
2493-
)&&
2494-
(* no tailcall out of exception handler, etc.*)
2495-
(match sequelIgnoringEndScopesAndDiscard sequelwith Return| ReturnVoid->true|_->false))
2477+
|(Expr.Val(v,_,_),_,_)when
2478+
matchListAssoc.tryFind cenv.g.valRefEq v eenv.innerValswith
2479+
| Some(kind,_)->
2480+
(not v.IsConstructor&&
2481+
(* when branch-calling methods we must have the right type parameters*)
2482+
(match kindwith
2483+
| BranchCallClosure_->true
2484+
| BranchCallMethod(_,_,tps,_,_)->
2485+
(List.lengthsEqAndForall2(fun ty tp-> typeEquiv cenv.g ty(mkTyparTy tp)) tyargs tps))&&
2486+
(* must be exact #args, ignoring tupling - we untuple if needed below*)
2487+
(letarityInfo=
2488+
match kindwith
2489+
| BranchCallClosure arityInfo
2490+
| BranchCallMethod(arityInfo,_,_,_,_)-> arityInfo
2491+
arityInfo.Length= args.Length
2492+
)&&
2493+
(* no tailcall out of exception handler, etc.*)
2494+
(match sequelIgnoringEndScopesAndDiscard sequelwith Return| ReturnVoid->true|_->false))
2495+
| None->false
24962496
->
2497-
let(kind,mark)= ListAssoc.find cenv.g.valRefEq v eenv.innerVals
2497+
let(kind,mark)= ListAssoc.find cenv.g.valRefEq v eenv.innerVals// already checked above in when guard
24982498
letntmargs=
24992499
match kindwith
25002500
| BranchCallClosure arityInfo->

‎src/fsharp/TastOps.fs‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,13 +212,14 @@ and remapMeasureAux tyenv unt =
212212
| Measure.RationalPower(u, q)-> Measure.RationalPower(remapMeasureAux tyenv u, q)
213213
| Measure.Inv u-> Measure.Inv(remapMeasureAux tyenv u)
214214
| Measure.Var tpas unt->
215-
match tp.Solutionwith
215+
match tp.Solutionwith
216216
| None->
217-
if ListAssoc.containsKey typarEq tp tyenv.tpinstthen
218-
match ListAssoc.find typarEq tp tyenv.tpinstwith
217+
match ListAssoc.tryFind typarEq tp tyenv.tpinstwith
218+
| Some v->
219+
match vwith
219220
| TType_measure unt-> unt
220221
|_-> failwith"remapMeasureAux: incorrect kinds"
221-
else unt
222+
| None-> unt
222223
| Some(TType_measure unt)-> remapMeasureAux tyenv unt
223224
| Some ty-> failwithf"incorrect kinds:%A" ty
224225

‎src/fsharp/lib.fs‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ module IntMap =
155155
// Library: generalized association lists
156156
//------------------------------------------------------------------------
157157

158-
moduleListAssoc=
158+
moduleListAssoc=
159159

160160
/// Treat a list of key-value pairs as a lookup collection.
161161
/// This function looks up a value based on a match from the supplied
@@ -166,12 +166,12 @@ module ListAssoc =
166166
|(x',y)::t->if f x x'then yelse find f x t
167167

168168
/// Treat a list of key-value pairs as a lookup collection.
169-
/// This functionreturns true if two keys are the same according tothepredicate
170-
/// functionpassed in.
171-
let reccontainsKey(f:'key->'key->bool)(x:'key)(l:('key*'value)list):bool=
172-
match lwith
173-
|[]->false
174-
|(x',_y)::t-> f x x'|| containsKey f x t
169+
/// This functionlooks up a value based on a match fromthesupplied
170+
///predicatefunctionand returns None if value does not exist.
171+
let rectryFind(f:'key->'key->bool)(x:'key)(l:('key*'value)list):'value option=
172+
match lwith
173+
|[]->None
174+
|(x',y)::t->iff x x'then Some yelse tryFind f x t
175175

176176
//-------------------------------------------------------------------------
177177
// Library: lists as generalized sets

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp