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

Optimize pattern compilation #15839

Merged
merged 2 commits into from
Aug 23, 2023
Merged
Changes from all commits
Commits
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
36 changes: 20 additions & 16 deletions src/Compiler/Checking/PatternMatchCompilation.fs
Original file line number Diff line number Diff line change
Expand Up @@ -967,22 +967,26 @@ and erasePartials inps =
List.map erasePartialPatterns inps

let ReportUnusedTargets (clauses: MatchClause list) dtree =
let used = HashSet<_>(accTargetsOfDecisionTree dtree [], HashIdentity.Structural)
clauses |> List.iteri (fun i c ->
let m =
match c.BoundVals, c.GuardExpr with
| [], Some guard -> guard.Range
| [ bound ], None -> bound.Id.idRange
| [ _ ], Some guard -> guard.Range
| rest, None ->
match rest with
| [ head ] -> head.Id.idRange
| _ -> c.Pattern.Range
| _, Some guard -> guard.Range

let m = withStartEnd c.Range.Start m.End m

if not (used.Contains i) then warning (RuleNeverMatched m))
match dtree, clauses with
| TDSuccess _, [ _ ] -> ()
| _ ->
let used = HashSet<_>(accTargetsOfDecisionTree dtree [], HashIdentity.Structural)
clauses |> List.iteri (fun i c ->
if not (used.Contains i) then
let m =
match c.BoundVals, c.GuardExpr with
| [], Some guard -> guard.Range
| [ bound ], None -> bound.Id.idRange
| [ _ ], Some guard -> guard.Range
| rest, None ->
match rest with
| [ head ] -> head.Id.idRange
| _ -> c.Pattern.Range
| _, Some guard -> guard.Range

withStartEnd c.Range.Start m.End m
|> RuleNeverMatched
|> warning)

let rec isPatternDisjunctive inpPat =
match inpPat with
Expand Down