Introduce ConApp to Core
AbandonedPublic

Authored by nomeata on Oct 3 2016, 4:39 PM.

Details

Reviewers
simonmar
simonpj
goldfire
hvr
austin
bgamari
Commits
rGHC65ba986828ab: Use ConApp when creating True resp. False
rGHCef7fc1a15bc6: Deserialize interface tuples to ConApp
rGHC3733c4dfc50d: Get rid of unitDataConId (use ConApp instead)
rGHC67814af6d687: Introduce ConApp to Core (dead code as of yet)
rGHCd1922185829f: Handle ConApp in "Eliminate Identity Case"
rGHCe7d8c5a71321: ConApp bytecode: Add more ASSERT
rGHC36143d401423: CorePrep: Stop creating weird bindings for data constructor workers
rGHCf10cbcb7aab8: mkDataConRep: Do not interleave applying arguments and unboxers
rGHC48877dad6bfd: mkSimpleDataConRep: No wrapper for newtypes
rGHC1c4c64385bbc: Squashed commit of adding ConApp
rGHC5a7d036452d8: ConApp: Include dc worker id in free variables
rGHC6ef0f7e8dda3: Introduce ConApp to Core
rGHC4dcdb0faead6: Introduce ConApp to Core
rGHCa875ab3b4c3b: Compress arguments to ConApp
rGHC39185a4af6d8: Always build a wrapper for data types
rGHC38dbcb17800d: Squached ConApp commit
rGHC6c7668e65cc1: mkCoreConApps: Warn about unsaturated use
rGHCba8341c129bb: mkCoreConApps: Do not use ConApp for newtypes
rGHCa40b10315ca7: Lint: Complain about saturated uses of the data con worker
rGHC916c15272fff: Reserve a unique for the wrapper of a wired in DataCon
rGHC70e58e8316a1: New Lint Check: No data con workers any more, please
rGHC8fa24208a732: ConApp: Include dc worker id in dffvExpr
rGHC5be97a0c7aec: Desugar: Use Coercible worker, not wrapper
rGHCf17b59ef0061: Actually desugar to ConApp
rGHCb486662d3c75: DataCon wrapper: Use ConApp in the body
rGHC1aa69bff3624: Use dataConWrapId in unsaturated uses of mkCoreConApps
rGHC3f42e87964b3: ConApp: More Linting
rGHC32b47198c2f6: Always use ConApp in CoreSyn
rGHC395db23544db: Create a simple wrapper for built-in types as well
rGHCc3e1cb0b94f5: knownCon: Use ConApp in unfolding of scrutinee
rGHC8399e73a4428: Use ConApp in tagToEnumRule
Trac Issues
#12618
Summary

Work in progress, no need for proper review yet! (But helpful hints are welcome, of course.)

This is my work-in-progress towards Trac #12618. It is not ready for review yet; I
create this DR mainly to get Harbormaster run it, because it crashes on my
computer, but works in Travis, and I need a third opinion.

Test Plan

validate

There are a very large number of changes, so older changes are hidden. Show Older Changes
nomeata updated this revision to Diff 8944.Oct 8 2016, 3:09 PM
nomeata edited edge metadata.

Suddenly no linker errors here any more. Is the DR up-to-date? Syncing with local branch…

nomeata updated this revision to Diff 8946.Oct 8 2016, 4:00 PM
nomeata edited edge metadata.

A stab in the dark:

  • coreToStgExpr: add con worker to free variables reported

I think I could use some help here. The support for saturated uses of constructors via ConApp seems to be roughly complete, but I must have messed something up revolving around code generation or linking, because the resulting stage2 GHC binary crashes, and I could not yet figure out the cause.

I have a hunch that it is related to static constructors (i.e. those that do not have parameters). At one point, I got linker errors about them, but it seems that I got that fixed somehow.

I compared the Cmm output of a very simple module before and after this change, and there is no notable difference. Maybe the problem is transitive imports. Or maybe I am barking up the wrong tree.

nomeata updated this revision to Diff 8948.Oct 8 2016, 9:58 PM
nomeata edited edge metadata.
  • Handle ConApp in inlineBoringOk
nomeata updated this revision to Diff 8950.Oct 9 2016, 11:09 AM
nomeata edited edge metadata.
  • cpe_ExprIsTrivial: Nullary Constructors are trivial
nomeata updated this revision to Diff 8951.Oct 9 2016, 11:52 AM
nomeata edited edge metadata.

Whooho, it compiles and runs finally! The cpe_ExprIsTrivial change was important, it seems.

  • Handle nullary Cons in myCollectArgs

I think I could use some help here. The support for saturated uses of constructors via ConApp seems to be roughly complete, but I must have messed something up revolving around code generation or linking, because the resulting stage2 GHC binary crashes, and I could not yet figure out the cause.

I have a hunch that it is related to static constructors (i.e. those that do not have parameters). At one point, I got linker errors about them, but it seems that I got that fixed somehow.

It seems I cracked it, and am unblocked.

nomeata updated this revision to Diff 8952.Oct 9 2016, 12:48 PM
nomeata edited edge metadata.
  • Handle nullary constructors in the byte code generator.
  • getIdFromTrivialExpr_maybe: Return dataConWorkId for nullary data cons
  • Avoid invalid haddock synatx
nomeata updated this revision to Diff 8953.Oct 9 2016, 1:47 PM
nomeata edited edge metadata.

Only 27 failing test cases.

  • No lint warning about staticPtr data con worker
  • Update some test output
nomeata updated this revision to Diff 8955.Oct 9 2016, 4:58 PM
nomeata edited edge metadata.
  • SetLevels: Do not float nullary data constructors
  • Update debugger test output
nomeata updated this revision to Diff 8964.Oct 10 2016, 4:40 PM
nomeata edited edge metadata.

Down to three non-perf test case failures, at least here.

  • Update some test output
  • SetLevels: Do not float nullary data constructors
  • Update debugger test output
  • Move zonking out of tcFamTyPats
  • Nullary data constructors are trivial
  • sptModuleInitCode: Look for ConApp
  • Have a compulary unfolding for unboxed tuple wrappers
nomeata updated this revision to Diff 8967.Oct 11 2016, 10:04 AM
nomeata edited edge metadata.
  • Fix instance Eq (DeBruijn CoreExpr) for ConApp
  • Adjust exprIsCheap
  • SpecConstr.isValue: Handle ConApp
bgamari edited edge metadata.Oct 11 2016, 2:19 PM

Whooho, it compiles and runs finally! The cpe_ExprIsTrivial change was important, it seems.

Do you know why this is? There are actually two implementations of exprIsTrivial in GHC which at one point I attempted to merge (see Trac #11158). This attempt was frustrated by a small semantic difference between the two which I never did quite understand.

Whooho, it compiles and runs finally! The cpe_ExprIsTrivial change was important, it seems.

Do you know why this is? There are actually two implementations of exprIsTrivial in GHC which at one point I attempted to merge (see Trac #11158). This attempt was frustrated by a small semantic difference between the two which I never did quite understand.

Ah, I worried that someone would ask that question…

Here is my theory. Because of the mistake before, nullary constructors would get their own binding in CorePrep. This means that at run time, they would be allocated, instead of just the single global instance being used. And I assume that the code generator assumes that these are never allocated.

Do you know why this is? There are actually two implementations of exprIsTrivial in GHC which at one point I attempted to merge (see Trac #11158). This attempt was frustrated by a small semantic difference between the two which I never did quite understand.

Ah, I worried that someone would ask that question…

Here is my theory. Because of the mistake before, nullary constructors would get their own binding in CorePrep. This means that at run time, they would be allocated, instead of just the single global instance being used. And I assume that the code generator assumes that these are never allocated.

I doubt that theory... the only difference between the two impls of exprIsTrivial is in their handling of literals.

It would be REALLY good to understand Trac #11158, if you have a moment to investigate.

nomeata updated this revision to Diff 8984.Oct 13 2016, 2:25 PM
nomeata edited edge metadata.

Try to make rules working for DataCon. Not pretty so far.

  • Add test case for Trac #12689
  • Add a broken test case for Trac #12689
  • Make data con wrappers ConLike (and see what happens)
  • Revert "Make data con wrappers ConLike (and see what happens)"
  • Use mkSimpleDataConRep in mkDataConRep if nothing fancy goes on
  • Extend test for Trac #12689 with rule matching late on normal data con
  • Make simple DataCon wrappers complusary unfoldings
  • Try to apply rules that match a data con
nomeata updated this revision to Diff 9008.Oct 14 2016, 2:54 PM
nomeata edited edge metadata.
  • Make simple DataCon wrappers complusary unfoldings
  • Try to apply rules that match a data con
  • Have SimpleWrapperUnfoldings
nomeata updated this revision to Diff 9009.Oct 14 2016, 3:44 PM
nomeata edited edge metadata.
  • Have SimpleWrapperUnfoldings
nomeata updated this revision to Diff 9010.Oct 14 2016, 10:34 PM
nomeata edited edge metadata.
  • magictDict built-in rule: Also match ConApp
nomeata updated this revision to Diff 9061.Oct 18 2016, 2:36 PM
nomeata edited edge metadata.
  • Handle ConApp in more points in the Specializer
  • specExpr: Reverse ConArg traversal, to reduce diff
  • Add eta-expanded variants of RULE foldr/id and foldr/app
nomeata updated this revision to Diff 9087.Oct 19 2016, 3:17 PM
nomeata edited edge metadata.
  • Update Test output
nomeata updated this revision to Diff 9088.Oct 19 2016, 3:18 PM
nomeata edited edge metadata.

Push again (for Harbormaster)

thomie added inline comments.Oct 19 2016, 5:11 PM
testsuite/tests/simplCore/should_compile/T8832.stdout
10

Be careful: there is a also a T8832.stdout-ws32 for 32-bit platforms. Without any other changes, this test (and maybe others) will no longer validate on 32-bit.

nomeata added inline comments.Oct 19 2016, 5:19 PM
testsuite/tests/simplCore/should_compile/T8832.stdout
10

Thanks. This branch is far from being merged, I’ll try to remember then.

nomeata updated this revision to Diff 9102.Oct 20 2016, 6:15 PM
nomeata edited edge metadata.

Now we are tackling the real thing.

  • Compress arguments to ConApp
nomeata updated this revision to Diff 9105.Oct 20 2016, 11:29 PM
nomeata edited edge metadata.

Turn a WARN into an ASSERT

nomeata updated this revision to Diff 9106.Oct 21 2016, 2:27 PM
nomeata edited edge metadata.
  • Compress arguments to ConApp
  • Fix calculation of res_ty in CoreFVs
nomeata updated this revision to Diff 9108.Oct 21 2016, 4:19 PM
nomeata edited edge metadata.
  • Update some test output
nomeata updated this revision to Diff 9113.Oct 21 2016, 7:21 PM
nomeata edited edge metadata.
  • Cache the analysis of the data con type
bgamari abandoned this revision.Dec 9 2016, 10:01 PM

@nomeata, I'm assuming this has lived it's useful life? If so, perhaps you could abandon it?

Quite right.