1. 22 Sep, 2000 2 commits
    • simonpj's avatar
      [project @ 2000-09-22 15:56:12 by simonpj] · 1bba522f
      simonpj authored
      --------------------------------------------------
      	Tidying up HsLit, and making it possible to define
      		your own numeric library
      
      		Simon PJ 22 Sept 00
      	--------------------------------------------------
      
      ** NOTE: I did these changes on the aeroplane.  They should compile,
      	 and the Prelude still compiles OK, but it's entirely 
      	 possible that I've broken something
      
      The original reason for this many-file but rather shallow
      commit is that it's impossible in Haskell to write your own
      numeric library.  Why?  Because when you say '1' you get 
      (Prelude.fromInteger 1), regardless of what you hide from the
      Prelude, or import from other libraries you have written.  So the
      idea is to extend the -fno-implicit-prelude flag so that 
      in addition to no importing the Prelude, you can rebind 
      	fromInteger	-- Applied to literal constants
      	fromRational	-- Ditto
      	negate		-- Invoked by the syntax (-x)
      	the (-) used when desugaring n+k patterns
      
      After toying with other designs, I eventually settled on a simple,
      crude one: rather than adding a new flag, I just extended the
      semantics of -fno-implicit-prelude so that uses of fromInteger,
      fromRational and negate are all bound to "whatever is in scope" 
      rather than "the fixed Prelude functions".  So if you say
      
      	{-# OPTIONS -fno-implicit-prelude #-}
      	module M where
       	import MyPrelude( fromInteger )
      
      	x = 3
      
      the literal 3 will use whatever (unqualified) "fromInteger" is in scope,
      in this case the one gotten from MyPrelude.
      
      
      On the way, though, I studied how HsLit worked, and did a substantial tidy
      up, deleting quite a lot of code along the way.  In particular.
      
      * HsBasic.lhs is renamed HsLit.lhs.  It defines the HsLit type.
      
      * There are now two HsLit types, both defined in HsLit.
      	HsLit for non-overloaded literals (like 'x')
      	HsOverLit for overloaded literals (like 1 and 2.3)
      
      * HsOverLit completely replaces Inst.OverloadedLit, which disappears.
        An HsExpr can now be an HsOverLit as well as an HsLit.
      
      * HsOverLit carries the Name of the fromInteger/fromRational operation,
        so that the renamer can help with looking up the unqualified name 
        when -fno-implicit-prelude is on.  Ditto the HsExpr for negation.
        It's all very tidy now.
      
      * RdrHsSyn contains the stuff that handles -fno-implicit-prelude
        (see esp RdrHsSyn.prelQual).  RdrHsSyn also contains all the "smart constructors"
        used by the parser when building HsSyn.  See for example RdrHsSyn.mkNegApp
        (previously the renamer (!) did the business of turning (- 3#) into -3#).
      
      * I tidied up the handling of "special ids" in the parser.  There's much
        less duplication now.
      
      * Move Sven's Horner stuff to the desugarer, where it belongs.  
        There's now a nice function DsUtils.mkIntegerLit which brings together
        related code from no fewer than three separate places into one single
        place.  Nice!
      
      * A nice tidy-up in MatchLit.partitionEqnsByLit became possible.
      
      * Desugaring of HsLits is now much tidier (DsExpr.dsLit)
      
      * Some stuff to do with RdrNames is moved from ParseUtil.lhs to RdrHsSyn.lhs,
        which is where it really belongs.
      
      * I also removed 
      	many unnecessary imports from modules 
      	quite a bit of dead code
        in divers places
      1bba522f
    • simonpj's avatar
      [project @ 2000-09-22 15:47:14 by simonpj] · a8e1967f
      simonpj authored
      msg1
      a8e1967f
  2. 14 Sep, 2000 2 commits
    • simonpj's avatar
      [project @ 2000-09-14 13:46:39 by simonpj] · cae34044
      simonpj authored
      ---------------------------------------
      	Simon's tuning changes: early Sept 2000
      	---------------------------------------
      
      Library changes
      ~~~~~~~~~~~~~~~
      * Eta expand PrelShow.showLitChar.  It's impossible to compile this well,
        and it makes a big difference to some programs (e.g. gen_regexps)
      
      * Make PrelList.concat into a good producer (in the foldr/build sense)
      
      
      Flag changes
      ~~~~~~~~~~~~
      * Add -ddump-hi-diffs to print out changes in interface files.  Useful
        when watching what the compiler is doing
      
      * Add -funfolding-update-in-place to enable the experimental optimisation
        that makes the inliner a bit keener to inline if it's in the RHS of
        a thunk that might be updated in place.  Sometimes this is a bad idea
        (one example is in spectral/sphere; see notes in nofib/Simon-nofib-notes)
      
      
      Tuning things
      ~~~~~~~~~~~~~
      * Fix a bug in SetLevels.lvlMFE.  (change ctxt_lvl to dest_level)
        I don't think this has any performance effect, but it saves making
        a redundant let-binding that is later eliminated.
      
      * Desugar.dsProgram and DsForeign
        Glom together all the bindings into a single Rec.  Previously the
        bindings generated by 'foreign' declarations were not glommed together, but
        this led to an infelicity (i.e. poorer code than necessary) in the modules
        that actually declare Float and Double (explained a bit more in Desugar.dsProgram)
      
      * OccurAnal.shortMeOut and IdInfo.shortableIdInfo
        Don't do the occurrence analyser's shorting out stuff for things which
        have rules.  Comments near IdInfo.shortableIdInfo.
        This is deeply boring, and mainly to do with making rules work well.
        Maybe rules should have phases attached too....
      
      * CprAnalyse.addIdCprInfo
        Be a bit more willing to add CPR information to thunks;
        in particular, if the strictness analyser has just discovered that this
        is a strict let, then the let-to-case transform will happen, and CPR is fine.
        This made a big difference to PrelBase.modInt, which had something like
      	modInt = \ x -> let r = ... -> I# v in
      			...body strict in r...
        r's RHS isn't a value yet; but modInt returns r in various branches, so
        if r doesn't have the CPR property then neither does modInt
      
      * MkId.mkDataConWrapId
        Arrange that vanilla constructors, like (:) and I#, get unfoldings that are
        just a simple variable $w:, $wI#.  This ensures they'll be inlined even into
        rules etc, which makes matching a bit more reliable.  The downside is that in
        situations like (map (:) xs), we'll end up with (map (\y ys. $w: y ys) xs.
        Which is tiresome but it doesn't happen much.
      
      * SaAbsInt.findStrictness
        Deal with the case where a thing with no arguments is bottom.  This is Good.
        E.g.   module M where { foo = error "help" }
        Suppose we have in another module
      	case M.foo of ...
        Then we'd like to do the case-of-error transform, without inlining foo.
      
      
      Tidying up things
      ~~~~~~~~~~~~~~~~~
      * Reorganised Simplify.completeBinding (again).
      
      * Removed the is_bot field in CoreUnfolding (is_cheap is true if is_bot is!)
        This is just a tidy up
      
      * HsDecls and others
        Remove the NewCon constructor from ConDecl.  It just added code, and nothing else.
        And it led to a bug in MkIface, which though that a newtype decl was always changing!
      
      * IdInfo and many others
        Remove all vestiges of UpdateInfo (hasn't been used for years)
      cae34044
    • simonmar's avatar
      [project @ 2000-09-14 09:10:35 by simonmar] · 670b00ee
      simonmar authored
      extend the scope of #ifdef GHCI so we can compile this with pre-4.08 compilers.
      670b00ee
  3. 13 Sep, 2000 1 commit
  4. 12 Sep, 2000 1 commit
    • sewardj's avatar
      [project @ 2000-09-12 10:15:09 by sewardj] · 2b4a8ed5
      sewardj authored
      Get rid of version number in the .hi-boot file, and wrap the entire
      contents of StgInterp with #ifdef GHCI, so it isn't built unless you
      want it to be.
      2b4a8ed5
  5. 11 Sep, 2000 3 commits
    • sewardj's avatar
      [project @ 2000-09-11 12:20:56 by sewardj] · 55945d0a
      sewardj authored
      First shot at a STG interpreter for GHCI.  Translates Stg syntax into a
      form convenient for interpretation, and can then run that.  Most of the
      translation stuff is there and works.  The interpreter framework is there
      and partly filled in, and seems to work.  There are still quite a lot of
      cases, etc, to fill in, but this should be straightforward given that
      the framework exists.  This interpreter cannot handle (yet?) unboxed
      tuples, but can deal with more or less everything else, including standard
      unboxed Int, Double, etc, code.
      55945d0a
    • sewardj's avatar
      [project @ 2000-09-11 11:17:09 by sewardj] · d4993e8b
      sewardj authored
      Initial primop support for the metacircular interpreter (GHCI).
      Only appears if you compile with -DGHCI; if not, the world is
      unchanged.
      
      new primops:
         indexPtrOffClosure#
         indexWordOffClosure#
      
      modified:
         dataToTag#   -- now dereferences indirections before extracting tag
      
      new entry code
         mci_constr_entry          and
         mci_constr[1..8]entry
      being the direct and vectored return code fragments for interpreter
      created constructors.  Support for static constructors is not yet
      done.
      
      New handwritten .hc functions:
         mci_make_constr*
      being code to create various flavours of constructors from args
      on the stack.  An interface file to describe these will follow in
      a later commit.
      d4993e8b
    • simonpj's avatar
      [project @ 2000-09-11 08:13:37 by simonpj] · d8e1c0a7
      simonpj authored
      Remove redundant setNoDiscardId call from Specialise.newIdSM
      d8e1c0a7
  6. 08 Sep, 2000 2 commits
  7. 07 Sep, 2000 11 commits
    • simonpj's avatar
      [project @ 2000-09-07 16:32:23 by simonpj] · 4e6d5798
      simonpj authored
      A list of simplifier-related stuff, triggered
      	by looking at GHC's performance.
      
      	I don't guarantee that this lot will lead to
      	a uniform improvement over 4.08, but it it should
      	be a bit better.  More work probably required.
      
      
      * Make the simplifier's Stop continuation record whether the expression being
        simplified is the RHS of a thunk, or (say) the body of a lambda or case RHS.
        In the thunk case we want to be a bit keener about inlining if the type of
        the thunk is amenable to update in place.
      
      * Fix interestingArg, which was being too liberal, and hence doing
        too much inlining.
      
      * Extended CoreUtils.exprIsCheap to make two more things cheap:
          - 	case (coerce x) of ...
          -   let x = y +# z
        This makes a bit more eta expansion happen.  It was provoked by
        a program of Marcin's.
      
      * MkIface.ifaceBinds.   Make sure that we emit rules for things
        (like class operations) that don't get a top-level binding in the
        interface file.  Previously such rules were silently forgotten.
      
      * Move transformRhs to *after* simplification, which makes it a
        little easier to do, and means that the arity it computes is
        readily available to completeBinding.  This gets much better
        arities.
      
      * Do coerce splitting in completeBinding. This gets good code for
      	newtype CInt = CInt Int
      
      	test:: CInt -> Int
      	test x = case x of
      	      	   1 -> 2
      	      	   2 -> 4
      	      	   3 -> 8
      	      	   4 -> 16
      	      	   _ -> 0
      
      * Modify the meaning of "arity" so that during compilation it means
        "if you apply this function to fewer args, it will do virtually
        no work".   So, for example
      	f = coerce t (\x -> e)
        has arity at least 1.  When a function is exported, it's arity becomes
        the number of exposed, top-level lambdas, which is subtly different.
        But that's ok.
      
        I removed CoreUtils.exprArity altogether: it looked only at the exposed
        lambdas.  Instead, we use exprEtaExpandArity exclusively.
      
        All of this makes I/O programs work much better.
      4e6d5798
    • simonpj's avatar
      [project @ 2000-09-07 16:31:45 by simonpj] · e9f0fa88
      simonpj authored
      * The simplifier used to glom together all the top-level bindings into
        a single Rec every time it was invoked.  The reason for this is explained
        in SimplCore.lhs, but for at least one simple program it meant that the
        simplifier never got around to unravelling the recursive group into
        non-recursive pieces.  So I've put the glomming under explicit flag
        control with a -fglom-binds simplifier pass.   A side benefit is
        that because it happens less often, the (expensive) SCC algorithm
        runs less often.
      e9f0fa88
    • simonpj's avatar
      [project @ 2000-09-07 16:29:36 by simonpj] · 0f70a20e
      simonpj authored
      Omit unnecessary import
      0f70a20e
    • simonpj's avatar
      [project @ 2000-09-07 16:28:44 by simonpj] · 2c7fe84e
      simonpj authored
      Do the begin-pass/end-pass stuff like the other core passes
      2c7fe84e
    • simonpj's avatar
      [project @ 2000-09-07 16:27:55 by simonpj] · 5439bab7
      simonpj authored
      Add comment
      5439bab7
    • simonpj's avatar
      [project @ 2000-09-07 16:25:32 by simonpj] · 17fff931
      simonpj authored
      Add an access function substEnvEnv
      17fff931
    • simonpj's avatar
      [project @ 2000-09-07 16:24:14 by simonpj] · cefef156
      simonpj authored
      Get the worker and wrapper in the right order
      cefef156
    • simonpj's avatar
      [project @ 2000-09-07 13:25:28 by simonpj] · 04a28507
      simonpj authored
      Primitives can return ThreadId# values
      04a28507
    • simonpj's avatar
      [project @ 2000-09-07 11:42:49 by simonpj] · c77080dd
      simonpj authored
      1) Fix a bad bug in Subst.lhs that made uniqAway go into an
         infinite loop when the 'hash code' in the in-scope set was
         zero.
      
      2) Rename BasicTypes.isFragileOccInfo to isFragileOcc
         Add isDeadOcc to BasisTypes
      
      
      (2) is just a tidy-up.  I have to commit it now because of (1), which
      is a bad bug.  I hope that I've committed all the files involved in (2).
      c77080dd
    • simonpj's avatar
      [project @ 2000-09-07 10:14:52 by simonpj] · 1264eac2
      simonpj authored
      Improve -ddump-types
      1264eac2
    • simonpj's avatar
      [project @ 2000-09-07 09:10:07 by simonpj] · c1994342
      simonpj authored
      * Make the desugarer use string equality for string literal
        patterns longer than 1 character.  And put a specialised
        eqString into PrelBase, with a suitable specialisation rule.
        This makes a huge difference to the size of the code generated
        by deriving(Read) notably in Time.lhs
      c1994342
  8. 06 Sep, 2000 5 commits
    • simonmar's avatar
      [project @ 2000-09-06 13:49:26 by simonmar] · 48b5a78c
      simonmar authored
      revert accidental parts of previous commit
      48b5a78c
    • simonmar's avatar
      [project @ 2000-09-06 13:29:10 by simonmar] · 2a36f904
      simonmar authored
      Generate a new unique to be used in the typedef for a f.i.d., rather
      than re-using the one from the function call, which might conflict if
      there are two similar calls in the same module.
      2a36f904
    • simonmar's avatar
      [project @ 2000-09-06 12:21:15 by simonmar] · ca3f9ad2
      simonmar authored
      When compiling code for a case where the scrutinee is a primitve
      comparison operator, we used to place the tag in a variable whose
      unique was always the same: `mkPseudoUnique1 1'.  This was mostly
      harmless but confused the Stix inliner in the NCG into generating
      slightly less efficient code when the variable was used twice in a
      basic block.
      
      This patch fixes the problem by generating a new unique by just
      changing the "tag" of an existing unique, namely the case binder.
      ca3f9ad2
    • simonmar's avatar
      [project @ 2000-09-06 10:23:52 by simonmar] · 67a402e2
      simonmar authored
      Add new PrimRep, namely PrimPtrRep, as a catch-all for the various
      boxed primitive types that currently don't have their own PrimReps.
      Use this for MVar# and MutVar#.  This fixes a crash in the code
      generator when a function returns one of these types.
      67a402e2
    • simonmar's avatar
      [project @ 2000-09-06 10:21:17 by simonmar] · 3cc69ccd
      simonmar authored
      recode primOpOkForSpeculation in terms of primOpIsCheap and primOpCanFail.
      3cc69ccd
  9. 05 Sep, 2000 3 commits
  10. 04 Sep, 2000 2 commits
  11. 01 Sep, 2000 1 commit
  12. 31 Aug, 2000 2 commits
  13. 29 Aug, 2000 1 commit
    • simonpj's avatar
      [project @ 2000-08-29 16:56:26 by simonpj] · f1e626d0
      simonpj authored
      Fix a bug reported by Jose Emilio Labra Gayo
      
      	newtype Foo a => T = MkT (out :: a)
      
      The selector 'out' was being given an incorrect RHS.
      (Core Lint spotted it.)
      f1e626d0
  14. 24 Aug, 2000 1 commit
  15. 22 Aug, 2000 3 commits