Commit c4a120e7 authored by Simon Marlow's avatar Simon Marlow
Browse files

Re-read pragmas after preprocessing (#2464, #3674, #3457)

This was a lot easier than I imagined.
parent 990171bf
......@@ -696,19 +696,30 @@ runPhase (Unlit sf) _stop hsc_env _basename _suff input_fn get_output_fn maybe_l
runPhase (Cpp sf) _stop hsc_env _basename _suff input_fn get_output_fn maybe_loc
= do let dflags0 = hsc_dflags hsc_env
src_opts <- liftIO $ getOptionsFromFile dflags0 input_fn
(dflags, unhandled_flags, warns)
(dflags1, unhandled_flags, warns)
<- liftIO $ parseDynamicNoPackageFlags dflags0 src_opts
handleFlagWarnings dflags warns
checkProcessArgsResult unhandled_flags
if not (dopt Opt_Cpp dflags) then
if not (dopt Opt_Cpp dflags1) then do
-- we have to be careful to emit warnings only once.
unless (dopt Opt_Pp dflags1) $ handleFlagWarnings dflags1 warns
-- no need to preprocess CPP, just pass input file along
-- to the next phase of the pipeline.
return (HsPp sf, dflags, maybe_loc, input_fn)
return (HsPp sf, dflags1, maybe_loc, input_fn)
else do
output_fn <- liftIO $ get_output_fn dflags (HsPp sf) maybe_loc
liftIO $ doCpp dflags True{-raw-} False{-no CC opts-} input_fn output_fn
return (HsPp sf, dflags, maybe_loc, output_fn)
output_fn <- liftIO $ get_output_fn dflags1 (HsPp sf) maybe_loc
liftIO $ doCpp dflags1 True{-raw-} False{-no CC opts-} input_fn output_fn
-- re-read the pragmas now that we've preprocessed the file
-- See #2464,#3457
src_opts <- liftIO $ getOptionsFromFile dflags0 output_fn
(dflags2, unhandled_flags, warns)
<- liftIO $ parseDynamicNoPackageFlags dflags0 src_opts
unless (dopt Opt_Pp dflags2) $ handleFlagWarnings dflags2 warns
-- the HsPp pass below will emit warnings
checkProcessArgsResult unhandled_flags
return (HsPp sf, dflags2, maybe_loc, output_fn)
-------------------------------------------------------------------------------
-- HsPp phase
......@@ -730,7 +741,15 @@ runPhase (HsPp sf) _stop hsc_env basename suff input_fn get_output_fn maybe_loc
] ++
map SysTools.Option hspp_opts
)
return (Hsc sf, dflags, maybe_loc, output_fn)
-- re-read pragmas now that we've parsed the file (see #3674)
src_opts <- liftIO $ getOptionsFromFile dflags output_fn
(dflags1, unhandled_flags, warns)
<- liftIO $ parseDynamicNoPackageFlags dflags src_opts
handleFlagWarnings dflags1 warns
checkProcessArgsResult unhandled_flags
return (Hsc sf, dflags1, maybe_loc, output_fn)
-----------------------------------------------------------------------------
-- Hsc phase
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment