Opened 2 years ago

Closed 2 years ago

#14204 closed bug (fixed)

GHC bug - makeStatic: Unresolved static form at line 13, column 14.

Reported by: jchia Owned by:
Priority: normal Milestone: 8.4.1
Component: Template Haskell Version: 8.2.1
Keywords: StaticPointers Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Runtime crash Test Case: th/T14204
Blocked By: Blocking:
Related Tickets: Differential Rev(s): Phab:D3931
Wiki Page:

Description (last modified by jchia)

Building and running the attached code results in the above crash error mesage. Enabling StaticPointers in the code makes the error go away.

GHC should either reject the code or generate code that works properly at run-time, depending on the fine points of how TH is supposed to interact with the enablement of StaticPointers.

Attachments (1)

staticPointerBug.hs (343 bytes) - added by jchia 2 years ago.

Download all attachments as: .zip

Change History (8)

Changed 2 years ago by jchia

Attachment: staticPointerBug.hs added

comment:1 Changed 2 years ago by jchia

This was reproduced under stack using nightly-2017-09-07.

comment:2 Changed 2 years ago by jchia

Type of failure: None/UnknownRuntime crash

comment:3 Changed 2 years ago by jchia

Description: modified (diff)

comment:4 Changed 2 years ago by RyanGlScott

Here's a much more minimal example:

{-# LANGUAGE TemplateHaskell #-}
module Bug where

import GHC.StaticPtr
import Language.Haskell.TH

main :: IO ()
main = putStrLn (deRefStaticPtr $(pure (StaticE (LitE (StringL "wat")))))

I don't know too much about the subtleties of static pointers, but perhaps the simplest fix would be to add an extra check to see if -XStaticPointers is enabled before using them in Template Haskell?

comment:5 Changed 2 years ago by RyanGlScott

Component: CompilerTemplate Haskell
Differential Rev(s): Phab:D3931
Keywords: StaticPointers added
Status: newpatch

With Phab:D3931, the attached program now fails with a sensible error message:

staticPointerBug.hs:13:14: error:
    • Illegal static expression: static foo
        Use StaticPointers to enable this extension
    • In the untyped splice: $(cstatic 'foo)
13 |   let cl = $(cstatic 'foo)
   |              ^^^^^^^^^^^^

comment:6 Changed 2 years ago by Ryan Scott <…>

In 9ff9c35/ghc:

Check if -XStaticPointers is enabled when renaming static expressions

Trying to use `static` expressions without the `-XStaticPointers`
extension enabled can lead to runtime errors. Normally, such a situation isn't
possible, but Template Haskell provides a backdoor that allows it to happen,
as shown in #14204.

To prevent this, we ensure that `-XStaticPointers` is enabled when renaming
`static` expressions.

Test Plan: make test TEST=T14204

Reviewers: facundominguez, austin, bgamari, simonpj

Reviewed By: facundominguez, simonpj

Subscribers: simonpj, rwbarton, thomie

GHC Trac Issues: #14204

Differential Revision:

comment:7 Changed 2 years ago by RyanGlScott

Milestone: 8.4.1
Resolution: fixed
Status: patchclosed
Test Case: th/T14204
Note: See TracTickets for help on using tickets.