From fdfb3b03baaa81a532a7e4554e13ccd4d342461e Mon Sep 17 00:00:00 2001 From: Matthew Pickering Date: Fri, 15 Oct 2021 09:39:18 +0100 Subject: Make the fields of Target and TargetId strict Targets are long-lived through GHC sessions so we don't want to end up retaining In particular in 'guessTarget', the call to `unitIdOrHomeUnit` was retaining reference to an entire stale HscEnv, which in turn retained reference to a stale HomePackageTable. Making the fields strict forces that place promptly and helps ensure that mistakes like this don't happen again. --- compiler/GHC/Types/Target.hs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/compiler/GHC/Types/Target.hs b/compiler/GHC/Types/Target.hs index 6599bdac4a..191f84eb2f 100644 --- a/compiler/GHC/Types/Target.hs +++ b/compiler/GHC/Types/Target.hs @@ -21,12 +21,14 @@ import Data.Time -- module. If so, use this instead of the file contents (this -- is for use in an IDE where the file hasn't been saved by -- the user yet). +-- +-- These fields are strict because Targets are long lived. data Target = Target { - targetId :: TargetId, -- ^ module or filename - targetAllowObjCode :: Bool, -- ^ object code allowed? - targetUnitId :: UnitId, -- ^ id of the unit this target is part of - targetContents :: Maybe (InputFileBuffer, UTCTime) + targetId :: !TargetId, -- ^ module or filename + targetAllowObjCode :: !Bool, -- ^ object code allowed? + targetUnitId :: !UnitId, -- ^ id of the unit this target is part of + targetContents :: !(Maybe (InputFileBuffer, UTCTime)) -- ^ Optional in-memory buffer containing the source code GHC should -- use for this target instead of reading it from disk. -- @@ -40,9 +42,9 @@ data Target } data TargetId - = TargetModule ModuleName + = TargetModule !ModuleName -- ^ A module name: search for the file - | TargetFile FilePath (Maybe Phase) + | TargetFile !FilePath !(Maybe Phase) -- ^ A filename: preprocess & parse it to find the module name. -- If specified, the Phase indicates how to compile this file -- (which phase to start from). Nothing indicates the starting phase -- cgit v1.2.1