Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC Commits: c786065e by sheaf at 2026-10-09T20:28:20-04:00 Use an explicit pattern match in toIfaceIdDetails The old wildcard pattern let this code bit rot: it did not properly account for recently added 'IdDetails' such as 'RepPolyId', which resulted in spurious 'pprTrace' messages that could even pollute HLS sessions. Fixes #23785 - - - - - 3 changed files: - + changelog.d/T23785 - compiler/GHC/CoreToIface.hs - compiler/GHC/Iface/Decl.hs Changes: ===================================== changelog.d/T23785 ===================================== @@ -0,0 +1,7 @@ +section: compiler +issues: #23785 +mrs: !16784 +synopsis: + Silence 'toIfaceIdDetails' debug messages. +description: + GHC no longer emits spurious 'toIfaceIdDetails' warnings. ===================================== compiler/GHC/CoreToIface.hs ===================================== @@ -447,26 +447,45 @@ toIfaceTopBndr id = if isExternalName name then IfGblTopBndr name else IfLclTopBndr (mkIfLclName (occNameFS (getOccName id))) (toIfaceType (idType id)) - (toIfaceIdInfo (idInfo id)) (toIfaceIdDetails (idDetails id)) + (toIfaceIdInfo (idInfo id)) (toIfaceIdDetails name (idDetails id)) where name = getName id -toIfaceIdDetails :: IdDetails -> IfaceIdDetails -toIfaceIdDetails VanillaId = IfVanillaId -toIfaceIdDetails (WorkerLikeId dmds) = IfWorkerLikeId dmds -toIfaceIdDetails (DFunId {}) = IfDFunId -toIfaceIdDetails (RecSelId { sel_naughty = n - , sel_tycon = tc - , sel_fieldLabel = fl }) = +toIfaceIdDetails :: Name -- ^ for trace/panic messages only + -> IdDetails -> IfaceIdDetails +toIfaceIdDetails _ VanillaId = IfVanillaId +toIfaceIdDetails _ (WorkerLikeId dmds) = IfWorkerLikeId dmds +toIfaceIdDetails _ (DFunId {}) = IfDFunId +toIfaceIdDetails _ (RecSelId { sel_naughty = n + , sel_tycon = tc + , sel_fieldLabel = fl }) = let (iface, first_con) = case tc of RecSelData ty_con -> ( Left (toIfaceTyCon ty_con), dataConName $ head $ tyConDataCons ty_con) RecSelPatSyn pat_syn -> ( Right (patSynToIfaceDecl pat_syn), patSynName pat_syn) in IfRecSelId iface first_con n fl - -- The remaining cases are all "implicit Ids" which don't - -- appear in interface files at all -toIfaceIdDetails other = pprTrace "toIfaceIdDetails" (ppr other) - IfVanillaId -- Unexpected; the other + -- NB: we deliberately handle every remaining 'IdDetails' constructor below, + -- so that anyone adding a new 'IdDetails' constructor gets an incomplete + -- pattern match warning telling them to update this code. See also #23785. + +toIfaceIdDetails _ (PrimOpId {}) = IfVanillaId -- Only reachable via 'pprTyThing' +toIfaceIdDetails _ (ClassOpId {}) = IfVanillaId -- (e.g. GHCi :browse!) +toIfaceIdDetails _ (RepPolyId {}) = IfVanillaId + -- Reachable via 'pprTyThing', but also with 'unsafeCoerce#' due to the + -- specific way it is wired-in. Otherwise we should never hit this, because + -- 'RepPolyId's are wired-in (and hence don't make it into interface files). + +-- Other cases should never occur (not even via 'pprTyThing'). +toIfaceIdDetails nm dets@(DataConWorkId {}) = not_iface_details nm dets +toIfaceIdDetails nm dets@(DataConWrapId {}) = not_iface_details nm dets +toIfaceIdDetails nm dets@(FCallId {}) = not_iface_details nm dets +toIfaceIdDetails nm dets@(TickBoxOpId {}) = not_iface_details nm dets +toIfaceIdDetails nm dets@(CoVarId {}) = not_iface_details nm dets +toIfaceIdDetails nm dets@(JoinId {}) = not_iface_details nm dets + +not_iface_details :: HasDebugCallStack => Name -> IdDetails -> a +not_iface_details nm details + = pprPanic "toIfaceIdDetails" (ppr nm <+> parens (ppr details)) toIfaceIdInfo :: IdInfo -> IfaceIdInfo toIfaceIdInfo id_info ===================================== compiler/GHC/Iface/Decl.hs ===================================== @@ -68,7 +68,7 @@ idToIfaceDecl :: Id -> IfaceDecl idToIfaceDecl id = IfaceId { ifName = getName id, ifType = toIfaceType (idType id), - ifIdDetails = toIfaceIdDetails (idDetails id), + ifIdDetails = toIfaceIdDetails (getName id) (idDetails id), ifIdInfo = toIfaceIdInfo (idInfo id) } -------------------------- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/c786065eda8b23b9ccc6d8da9fcbdb63... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/c786065eda8b23b9ccc6d8da9fcbdb63... 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