Opened 3 years ago

Last modified 4 weeks ago

#10346 new bug

Cross-module SpecConstr

Reported by: simonpj Owned by:
Priority: normal Milestone: 8.6.1
Component: Compiler Version: 7.10.1
Keywords: SpecConstr, newcomer Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Runtime performance bug Test Case:
Blocked By: Blocking:
Related Tickets: #13016 Differential Rev(s):
Wiki Page:


Type-class specialisation now happens flawlessly across modules. That is, if I define

module DefineF where
   f :: Num a => a -> a
   {-# INLINEABLE f #-}
   f x = ...f x'....

then modules that import DefineF and call f at some particular type (say Int) will generate a specialised copy of f's code.

But this does not happen for SpecConstr; we only specialise a function for calls made in the same module. All the infrastructure is in place to allow cross-module SpecConstr; it just hasn't been done yet. This ticket is to record the idea.

Change History (10)

comment:1 Changed 3 years ago by Simon Peyton Jones <simonpj@…>

In b61562feb87689a202118ca08ef270422c69dcc2/ghc:

Seed SpecConstr from local calls

Seed SpecConstr based on *local* calls as well as *RHS* calls.
See Note [Seeding top-level recursive groups].  The change here
is mentioned here:

   NB: before Apr 15 we used (a) only, but Dimitrios had an example
       where (b) was  crucial, so I added that.

This is a pretty small change, requested by Dimitrios, that adds
SpecConstr call patterns from the rest of the module, as well as ones
from the RHS.

Still to come: #10346.

comment:2 Changed 2 years ago by thomie

Type of failure: None/UnknownRuntime performance bug

comment:3 Changed 13 months ago by simonpj

Keywords: SpecConstr added

comment:4 Changed 11 months ago by mpickering

Keywords: newcomer added

comment:5 Changed 9 months ago by dfeuer

Milestone: 8.4.1

comment:6 Changed 7 months ago by ak3n

Owner: set to ak3n

comment:7 Changed 7 months ago by mpickering

ak3n:I have a mostly complete patch already on phab which you might want to fi nish off and refine.

comment:8 Changed 6 months ago by ak3n

I am sorry, but what is the desired behaviour? I made a simple test with modules. The first module contains the drop function, while the second one calls it. At the current moment, both versions (ghc with the patch (D3566) and ghc 8.2.1) with enabled -O2 flag optimize the function with SpecConstr pass in the first module, and substitute the call to the optimized version into the second module.

comment:9 Changed 6 months ago by ak3n

Owner: ak3n deleted

comment:10 Changed 4 weeks ago by bgamari


This ticket won't be resolved in 8.4; remilestoning for 8.6. Do holler if you are affected by this or would otherwise like to work on it.

Note: See TracTickets for help on using tickets.