Desugar: Refactor initDs
ClosedPublic

Authored by bgamari on Feb 27 2017, 2:39 PM.

Details

Summary

As far as I can tell we were unnecessarily building a new TcgEnv when we already
had one on hand. TcRnMonad now sports an initTcWithGbl function, which allows us
to run a TcM monad in the context of this TcgEnv. This appears to simplify
things nicely.

Test Plan

Validate

Diff Detail

Repository
rGHC Glasgow Haskell Compiler
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
bgamari created this revision.Feb 27 2017, 2:39 PM
bgamari added inline comments.Feb 27 2017, 2:53 PM
compiler/deSugar/Desugar.hs
121

This (and Vectorise.Monad) is the only slight compromise here; initTc wants a RealSrcSpan, but we can only produce an UnhelpfulSpan here. Thankfully, this doesn't seem to cause trouble (although I'm not confident that this won't break at some inconvenient point).

Perhaps we should just allow the span in TcGblEnv to be a SrcSpan.

@simonpj, what do you think about this (in particular the comment inline regarding the use of RealSrcSpan in TcGblEnv?

This is great. But could be better.

In particular initTc blah (initDsTc go) does a whole lot of work in initTc on the TcLclEnv that initDsTc entirely discards.

Maybe just initDsWithGbl :: TcGlbEnv -> DsM a -> IOEnv glb lcl a?

bgamari retitled this revision from Desugar: Drop initDs to Desugar: Refactor initDs.Mar 4 2017, 12:15 PM
bgamari updated this revision to Diff 11558.Mar 4 2017, 12:18 PM

More refactoring

bgamari updated this revision to Diff 11560.Mar 4 2017, 12:27 PM
bgamari marked an inline comment as done.

Separate out DPH changes

This is great. But could be better.

In particular initTc blah (initDsTc go) does a whole lot of work in initTc on the TcLclEnv that initDsTc entirely discards.

That isn't *quite* true; initDsTc uses tcl_errs.

It turns out that refactoring this taking this into account was not entirely trivial. Unfortunately, the patch actually ends up adding lines of code. However, I still think that the result is worth merging. In particular, breaking up initTcWithGbl seems like a marginal improvement in readability, and pulling out initDsWithModGuts seems like it may be useful elsewhere.

Maybe just initDsWithGbl :: TcGlbEnv -> DsM a -> IOEnv glb lcl a?

bgamari updated this revision to Diff 11562.Mar 4 2017, 12:48 PM

Ensure HPT complete matches are accounted for

dfeuer added a subscriber: dfeuer.Mar 6 2017, 1:00 PM
dfeuer added inline comments.
compiler/deSugar/DsMonad.hs
167

thing_inside doesn't look like the clearest possible name.

This revision was automatically updated to reflect the committed changes.