Skip to content

Switch from template-haskell to template-haskell-lift#717

Merged
Bodigrim merged 1 commit into
haskell:masterfrom
TeofilC:wip/th-lift
May 29, 2026
Merged

Switch from template-haskell to template-haskell-lift#717
Bodigrim merged 1 commit into
haskell:masterfrom
TeofilC:wip/th-lift

Conversation

@TeofilC

@TeofilC TeofilC commented Oct 10, 2025

Copy link
Copy Markdown
Member

We switch our dependency on template-haskell to a dependency on template-haskell-lift. This smaller library is more stabler. If we can remove the template-haskell dependency from all boot libraries then template-haskell will be much easier to re-install since it no longer needs to be in GHC's dependency closure.

For more information see the GHC proposal that introduced this library: ghc-proposals/ghc-proposals#696

This GHC MR tests this PR against GHC-HEAD: https://gitlab.haskell.o

@TeofilC TeofilC changed the title Wip/th lift Switch from template-haskell to template-haskell-lift Oct 10, 2025
@TeofilC TeofilC force-pushed the wip/th-lift branch 4 times, most recently from 54ef253 to d85e62d Compare October 10, 2025 17:40
@Bodigrim

Copy link
Copy Markdown
Contributor

We strive for new releases to be backportable to older GHC major series, which do not yet have template-haskell-lift as a boot library. To keep it possible, I imagine you need something like

if impl(ghc>9.15)
  build-depends: template-haskell-lift
else 
  build-depends: template-haskell 

@TeofilC

TeofilC commented Oct 10, 2025

Copy link
Copy Markdown
Member Author

Good point. template-haskell-lift itself is buildable with older major versions (where it just re exports tenplate-haskell) but unless we backport it as a boot library to those versions then indeed you wouldn't be able to use the new bytestring as a boot library.

I'll implement what you suggest

@TeofilC TeofilC force-pushed the wip/th-lift branch 3 times, most recently from e1fb704 to 800ee4c Compare October 12, 2025 11:22
@Bodigrim

Copy link
Copy Markdown
Contributor

@TeofilC please rebase.

@Bodigrim

Copy link
Copy Markdown
Contributor

@TeofilC could you please raise a draft GHC MR, which updates bytestring submodule to your commit? Otherwise I cannot test it.

@TeofilC TeofilC force-pushed the wip/th-lift branch 2 times, most recently from afc9dd0 to 99ec2e9 Compare October 16, 2025 22:58
@TeofilC

TeofilC commented Jan 10, 2026

Copy link
Copy Markdown
Member Author

Since I last looked at this, bytestring has gained a dependency on liftCode. This is not exposed by template-haskell-lift, so for now this PR is stalled.

This shows a gap in the interface of template-haskell-lift. Exporting unsafeCodeCoerce from template-haskell-lift should allow this code to be written. I didn't spot this when designing the interface since so few people use the typed TH API, but this is a reasonable thing to want.

@TeofilC

TeofilC commented Jan 10, 2026

Copy link
Copy Markdown
Member Author

Actually we can just use error and we get a similar message!

@TeofilC TeofilC force-pushed the wip/th-lift branch 4 times, most recently from 754b7a7 to ee19745 Compare January 10, 2026 22:06
@TeofilC

TeofilC commented Jan 10, 2026

Copy link
Copy Markdown
Member Author

Not sure about the CI failure on 9.0. I can't reproduce it locally

@TeofilC TeofilC marked this pull request as ready for review January 10, 2026 22:14
@Bodigrim

Copy link
Copy Markdown
Contributor

Not sure about the CI failure on 9.0. I can't reproduce it locally

It's unrelated to your changes, I have the same failure in #718 (comment).

@TeofilC

TeofilC commented Mar 10, 2026

Copy link
Copy Markdown
Member Author

Anything I can do to move this along ?

@Bodigrim

Copy link
Copy Markdown
Contributor

@TeofilC if you have time to figure out what’s up with the CI, it would help to speed things up.

@TeofilC

TeofilC commented Apr 3, 2026

Copy link
Copy Markdown
Member Author

I tried to have a quick look but had little luck. I tried building locally with GHC-9.0.2 and it seems to run the test suite fine.

Perhaps it's something like a broken cache or some oddness about the github runner env?

@Bodigrim

Bodigrim commented Apr 3, 2026

Copy link
Copy Markdown
Contributor

Could you rebase and trigger a fresh CI run?

@TeofilC

TeofilC commented Apr 3, 2026

Copy link
Copy Markdown
Member Author

Interesting now we are getting this failure on 9.2. When running it locally, I was getting this too:

 *** Failed! Exception: './lazy-hclose-test7457-300.tmp: withFile: resource busy (file is locked)' 

@TeofilC

TeofilC commented Apr 3, 2026

Copy link
Copy Markdown
Member Author

I see fixed on the other PR

@Bodigrim

Bodigrim commented Apr 3, 2026

Copy link
Copy Markdown
Contributor

There seems to be a bunch of warnings "The import of ‘Language.Haskell.TH.Syntax’ is redundant" for GHC < 9.14.

@TeofilC

TeofilC commented Apr 3, 2026

Copy link
Copy Markdown
Member Author

There seems to be a bunch of warnings "The import of ‘Language.Haskell.TH.Syntax’ is redundant" for GHC < 9.14.

Fixed now, we only needed that import before <9.0

@Bodigrim Bodigrim requested review from clyring, hsyl20 and sjakobi April 12, 2026 17:09
Comment thread Data/ByteString/Internal/Type.hs Outdated
Comment thread Data/ByteString/Short/Internal.hs
Comment thread bytestring.cabal
@TeofilC TeofilC force-pushed the wip/th-lift branch 2 times, most recently from 8531463 to a80d05c Compare April 13, 2026 10:32

@hsyl20 hsyl20 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Comment thread Data/ByteString/Internal/Type.hs Outdated
#endif

import qualified Language.Haskell.TH.Lib as TH
#if __GLASGOW_HASKELL__ >= 914

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a roundabout way to express the idea. Could we use #ifdef MIN_VERSION_template_haskell_lift instead? And then it's up to bytestring.cabal whether template-haskell-lift is available in a given build configuration.

Similar below, and I'd prefer #if MIN_VERSION_template_haskell(2,16,0) || defined(MIN_VERSION_template_haskell_lift) to __GLASGOW_HASKELL__ >= 810.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TeofilC just a gentle reminder.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the ping. I had completely forgotten about this!

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've implemented this in a slightly different way to what you suggest. Hopefully it's a bit simpler

This new boot library should be more stable than template-haskell and
should eventually allow us to remove much of the CPP around TH.

It will also make it easier for end-users to reinstall template-haskell
as it will no longer be used by any boot libraries
@Bodigrim Bodigrim merged commit 2426ece into haskell:master May 29, 2026
28 of 29 checks passed
@Bodigrim

Copy link
Copy Markdown
Contributor

Thanks @TeofilC!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants