[GHC] #393: functions without implementations
GHC
ghc-devs at haskell.org
Thu Aug 25 01:46:44 UTC 2016
#393: functions without implementations
-------------------------------------+-------------------------------------
Reporter: c_maeder | Owner:
Type: feature request | Status: new
Priority: normal | Milestone: ⊥
Component: Compiler (Type | Version: None
checker) |
Resolution: | Keywords: newcomer
Operating System: Unknown/Multiple | Architecture:
| Unknown/Multiple
Type of failure: None/Unknown | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s):
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by Iceland_jack):
Probably not worth it, but fake definitions are generated for
Commentary/PrimOps
{{{#!hs
newArray# :: Int# -> a -> State# s -> (# State# s,MutableArray# s a #)
newArray# = let x = x in x
sameMutableArray# :: MutableArray# s a -> MutableArray# s a -> Int#
sameMutableArray# = let x = x in x
nullAddr# :: Addr#
nullAddr# = let x = x in x
}}}
If this feature is enabled the bodies could be omitted and if we make
holes representation-polymorphic (#12531) it's not such a reach to allow
top-level unlifted bindings as well when body is omitted:
{{{#!hs
newArray# :: Int# -> a -> State# s -> (# State# s,MutableArray# s a #)
sameMutableArray# :: MutableArray# s a -> MutableArray# s a -> Int#
nullAddr# :: NullAddr#
}}}
This might avoid hacky tests mentioned in `[Compiling GHC.Prim]`.
----
=== Note `[Placeholder declarations]` ===
> We are generating fake declarations for things in
[https://hackage.haskell.org/package/ghc-prim-0.4.0.0/candidate/docs/src
/GHC-Prim.html GHC.Prim], just to keep GHC's renamer and typechecker happy
enough for what Haddock needs. Our main plan is to say
> {{{#!hs
> foo :: <type>
> foo = foo
> }}}
> We have to silence GHC's complaints about unboxed-top-level declarations
with an ad-hoc fix in `TcBinds`: see Note `[Compiling GHC.Prim]` in
`TcBinds`.
>
>
> That works for all the primitive functions except `tagToEnum#`. If we
generate the binding
> {{{#!hs
> tagToEnum# = tagToEnum#
> }}}
> GHC will complain about "`tagToEnum#` must appear applied to one
argument". We could hack GHC to silence this complaint when compiling
`GHC.Prim`, but it seems easier to generate
> {{{#!hs
> tagToEnum# = let x = x in x
> }}}
> We don't do this for *all* bindings because for ones with an unboxed RHS
we would get other complaints (e.g.can't unify "`*`" with "`#`").
=== Note `[Compiling GHC.Prim]` ===
> Module `GHC.Prim` has no source code: it is the host module for
primitive, built-in functions and types. However, for Haddock-ing
purposes we generate (via `utils/genprimopcode`) a fake source file
`GHC/Prim.hs`, and give it to Haddock, so that it can generate
documentation. It contains definitions like
> {{{#!hs
> nullAddr# :: NullAddr#
> }}}
> which would normally be rejected as a top-level unlifted binding. But we
don't want to complain, because we are only "compiling" this fake mdule
[sic] for documentation purposes. Hence this hacky test for `gHC_PRIM` in
`checkStrictBinds`.
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/393#comment:35>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list