[Git][ghc/ghc][master] Ignore ticks in the pattern-match term oracle
Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC Commits: b388d093 by Brian McKenna at 2026-07-18T17:51:50-04:00 Ignore ticks in the pattern-match term oracle The term-oracle in the pattern-match checker is keyed by a canonical form of the scrutinee, computed by `makeDictsCoherent`. That canonical form was tick-sensitive: two occurrences of an otherwise identical expression that happened to carry different ticks were treated as distinct values, breaking long-distance information. This shows up in practice under `-finfo-table-map`, because the desugarer wraps every record-selector use site in a `SourceNote` carrying that site's span. For example: data Box = Box { unBox :: Maybe Int } f b = case unBox b of Nothing -> 0 Just _ -> let Just x = unBox b in x The two `unBox b` expressionss carry different SourceNote spans, the pattern-match checker sees them as different, the long-distance information from the outer `Just _` branch never reaches the let-pattern, and `Just x = unBox b` is wrongly reported as non-exhaustive. We now strip all ticks in `makeDictsCoherent`. This is documented as Wrinkle (UD1) of Note [Unique dictionaries in the TmOracle CoreMap]. Fixes #27314 - - - - - 4 changed files: - + changelog.d/T27314.md - compiler/GHC/HsToCore/Pmc/Solver.hs - + testsuite/tests/pmcheck/should_compile/T27314.hs - testsuite/tests/pmcheck/should_compile/all.T Changes: ===================================== changelog.d/T27314.md ===================================== @@ -0,0 +1,10 @@ +section: compiler +issues: #27314 +mrs: !16118 +synopsis: + Fix spurious ``-Wincomplete-uni-patterns`` warning under ``-finfo-table-map``. +description: + The pattern-match checker now ignores ticks when comparing scrutinees in + its CoreMap, so long-distance information is no longer lost across + function-application scrutinees because debug source annotations + (e.g. SourceNotes added by ``-finfo-table-map``) were inserted. ===================================== compiler/GHC/HsToCore/Pmc/Solver.hs ===================================== @@ -1000,8 +1000,9 @@ makeDictsCoherent (Case scrut bndr ty alts) , let expr' = makeDictsCoherent expr ] makeDictsCoherent (Cast expr co) = Cast (makeDictsCoherent expr) co -makeDictsCoherent (Tick tick expr) - = Tick tick (makeDictsCoherent expr) +makeDictsCoherent (Tick _tick expr) + -- See Wrinkle (UD1) in Note [Unique dictionaries in the TmOracle CoreMap] + = makeDictsCoherent expr makeDictsCoherent ty@(Type {}) = ty makeDictsCoherent co@(Coercion {}) @@ -1061,6 +1062,25 @@ In the end, replacing dictionaries with an error value in the pattern-match checker was the most self-contained, although we might want to revisit once we implement a more robust approach to computing equality in the pattern-match checker (see #19272). + +Wrinkle (UD1): ticks +-------------------- +'makeDictsCoherent' also drops all ticks. The CoreMap key represents +value-level equality, which ticks never affect. + +Example (#27314): with -finfo-table-map every record-selector use site is +wrapped in a 'SourceNote' carrying that site's span (see +Note [Record-selector ticks] in GHC.HsToCore.Ticks). Given + + data Box = Box { unBox :: Maybe Int } + f b = case unBox b of + Nothing -> 0 + Just _ -> let Just x = unBox b in x + +the two `unBox b`s carry different SourceNote spans. Without tick stripping +the CoreMap treats them as distinct expressions. Long-distance information +from the outer `Just _` branch therefore never reaches the let-pattern, and +`Just x = unBox b` is wrongly reported as non-exhaustive. -} {- Note [The Pos/Neg invariant] ===================================== testsuite/tests/pmcheck/should_compile/T27314.hs ===================================== @@ -0,0 +1,8 @@ +module T27314 where + +data Box = Box { unBox :: Maybe Int } + +f :: Box -> Int +f b = case unBox b of + Nothing -> 0 + Just _ -> let Just x = unBox b in x ===================================== testsuite/tests/pmcheck/should_compile/all.T ===================================== @@ -93,6 +93,14 @@ test('T21360', normal, compile, [overlapping_incomplete+'-Wincomplete-record-upd test('T21360b', normal, compile, [overlapping_incomplete+'-Wincomplete-record-updates']) test('T23520', normal, compile, [overlapping_incomplete+'-Wincomplete-record-updates']) test('T25164', [extra_files(['T25164_aux.hs']), req_th], multimod_compile, ['T25164', '-v0']) +test( + 'T27314', + [ omit_ways(llvm_ways), # -finfo-table-map does not work with -fllvm (#26435) + when(js_arch(), skip) # javascript doesn't support -finfo-table-map yet and yields a warning we don't want to handle here + ], + compile, + ['-Wincomplete-uni-patterns -finfo-table-map'] +) # Other tests test('pmc001', [], compile, [overlapping_incomplete]) View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/b388d0934c0933c1cdb47226489634e2... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/b388d0934c0933c1cdb47226489634e2... You're receiving this email because of your account on gitlab.haskell.org. Manage all notifications: https://gitlab.haskell.org/-/profile/notifications | Help: https://gitlab.haskell.org/help
participants (1)
-
Marge Bot (@marge-bot)