Skip to content

Commit 42e4382

Browse files
committed
WIP
1 parent 5f8dc58 commit 42e4382

File tree

1 file changed

+39
-42
lines changed

1 file changed

+39
-42
lines changed

src/FSharpLint.Core/Framework/HintParserUtilities.fs

Lines changed: 39 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -275,60 +275,57 @@ module MergeSyntaxTrees =
275275
let getHints items =
276276
items |> Seq.map (fun (_, _, _, hint) -> hint) |> Seq.toList
277277

278-
let mergeHints hints =
279-
// fsharplint:disable EnsureTailCallDiagnosticsInRecursiveFunctions
280-
let rec getEdges transposed =
281-
let map =
282-
transposed
283-
|> List.choose (function
284-
| HintNode(expr, depth, rest) -> Some(getKey expr, expr, depth, rest)
285-
| EndOfHint(_) -> None)
286-
|> List.filter (isAnyMatch >> not)
287-
|> Seq.groupBy (fun (key, expr, _, _) -> Utilities.hash2 key (getHashCode expr))
288-
|> Seq.map (fun (hashcode, items) -> (hashcode, mergeHints (getHints items)))
289-
|> Map.ofSeq
290-
291-
let anyMatches =
292-
transposed
293-
|> List.choose (function
294-
| HintNode(expr, depth, rest) ->
295-
match (getKey expr, expr) with
296-
| (SyntaxHintNode.Wildcard as key), HintExpr(Expression.Wildcard)
297-
| (SyntaxHintNode.Wildcard as key), HintPat(Pattern.Wildcard)
298-
| (SyntaxHintNode.Variable as key), HintExpr(Expression.Variable(_))
299-
| (SyntaxHintNode.Variable as key), HintPat(Pattern.Variable(_)) -> Some(key, expr, depth, rest)
300-
| _ -> None
301-
| EndOfHint(_) -> None)
302-
|> Seq.groupBy (fun (_, expr, _, _) -> expr)
303-
|> Seq.choose (fun (expr, items) ->
304-
match expr with
305-
| HintPat(Pattern.Wildcard)
306-
| HintExpr(Expression.Wildcard) -> Some(None, mergeHints (getHints items))
307-
| HintPat(Pattern.Variable(var))
308-
| HintExpr(Expression.Variable(var)) -> Some(Some(var), mergeHints (getHints items))
309-
| _ -> None)
310-
|> Seq.toList
311-
312-
{ Lookup = map; AnyMatch = anyMatches }
313-
314-
and mergeHints hints =
278+
[<TailCall>]
279+
let rec private getEdges transposed =
280+
let mergeHintsInner hints =
315281
let transposed = transposeHead hints
316282

317-
let edges = getEdges transposed
318-
319283
let matchedHints =
320284
transposed
321285
|> Seq.choose (function
322286
| HintNode(_) -> None
323287
| EndOfHint(hint) -> Some(hint))
324288
|> Seq.toList
325-
289+
326290
{
327-
Edges = edges
291+
Edges = getEdges transposed
328292
MatchedHint = matchedHints
329293
}
330-
// fsharplint:enable EnsureTailCallDiagnosticsInRecursiveFunctions
331294

295+
let map =
296+
transposed
297+
|> List.choose (function
298+
| HintNode(expr, depth, rest) -> Some(getKey expr, expr, depth, rest)
299+
| EndOfHint(_) -> None)
300+
|> List.filter (isAnyMatch >> not)
301+
|> Seq.groupBy (fun (key, expr, _, _) -> Utilities.hash2 key (getHashCode expr))
302+
|> Seq.map (fun (hashcode, items) -> (hashcode, mergeHintsInner (getHints items)))
303+
|> Map.ofSeq
304+
305+
let anyMatches =
306+
transposed
307+
|> List.choose (function
308+
| HintNode(expr, depth, rest) ->
309+
match (getKey expr, expr) with
310+
| (SyntaxHintNode.Wildcard as key), HintExpr(Expression.Wildcard)
311+
| (SyntaxHintNode.Wildcard as key), HintPat(Pattern.Wildcard)
312+
| (SyntaxHintNode.Variable as key), HintExpr(Expression.Variable(_))
313+
| (SyntaxHintNode.Variable as key), HintPat(Pattern.Variable(_)) -> Some(key, expr, depth, rest)
314+
| _ -> None
315+
| EndOfHint(_) -> None)
316+
|> Seq.groupBy (fun (_, expr, _, _) -> expr)
317+
|> Seq.choose (fun (expr, items) ->
318+
match expr with
319+
| HintPat(Pattern.Wildcard)
320+
| HintExpr(Expression.Wildcard) -> Some(None, mergeHintsInner (getHints items))
321+
| HintPat(Pattern.Variable(var))
322+
| HintExpr(Expression.Variable(var)) -> Some(Some(var), mergeHintsInner (getHints items))
323+
| _ -> None)
324+
|> Seq.toList
325+
326+
{ Lookup = map; AnyMatch = anyMatches }
327+
328+
let mergeHints hints =
332329
let transposed = hints |> List.map hintToList |> transposeHead
333330

334331
getEdges transposed

0 commit comments

Comments
 (0)