compiling-to-categories / concat

Compiling to Categories
http://conal.net/papers/compiling-to-categories
BSD 3-Clause "New" or "Revised" License
431 stars 49 forks source link

Compat ghc 8.2+warning fixes #37

Closed cartazio closed 6 years ago

cartazio commented 6 years ago

i'm taking the next day or so to see if i can embed a linear logic checker / proof generator in haskell via your concat plugin, this is the first of several change sets i'll be posting your way

one class of warning i'm ignoring for now is the following (below), but aside from that family of (slightly scary?) errors, everythign else works


src/ConCat/Deep.hs:75:14: warning: [-Wsimplifiable-class-constraints]
    • The constraint ‘Summable a’ matches an instance declaration
      instance SummableF h => Summable h -- Defined in ‘ConCat.Additive’
      This makes type inference for inner bindings fragile;
        either use MonoLocalBinds, or simplify it using the instance
    • In the type signature:
        normalize :: (Summable a, Fractional s, Additive s) => Unop (a s)
   |
75 | normalize :: (Summable a, Fractional s, Additive s) => Unop (a s)
   |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

src/ConCat/Deep.hs:80:15: warning: [-Wsimplifiable-class-constraints]
    • The constraint ‘Summable a’ matches an instance declaration
      instance SummableF h => Summable h -- Defined in ‘ConCat.Additive’
      This makes type inference for inner bindings fragile;
        either use MonoLocalBinds, or simplify it using the instance
    • In the type signature:
        dotV :: (Summable a, Additive s, Num s) => a s -> a s -> s
   |
80 | dotV,(<.>) :: (Summable a, Additive s, Num s) => a s -> a s -> s
   |               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

src/ConCat/Deep.hs:80:15: warning: [-Wsimplifiable-class-constraints]
    • The constraint ‘Summable a’ matches an instance declaration
      instance SummableF h => Summable h -- Defined in ‘ConCat.Additive’
      This makes type inference for inner bindings fragile;
        either use MonoLocalBinds, or simplify it using the instance
    • In the type signature:
        (<.>) :: (Summable a, Additive s, Num s) => a s -> a s -> s
   |
80 | dotV,(<.>) :: (Summable a, Additive s, Num s) => a s -> a s -> s
   |               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

src/ConCat/Deep.hs:104:11: warning: [-Wsimplifiable-class-constraints]
    • The constraint ‘Summable a’ matches an instance declaration
      instance SummableF h => Summable h -- Defined in ‘ConCat.Additive’
      This makes type inference for inner bindings fragile;
        either use MonoLocalBinds, or simplify it using the instance
    • In the type signature:
        linear :: (Summable a, Summable b, Additive s, Num s) =>
                  (a --* b) s -> (a s -> b s)
    |
104 | linear :: (Summable a, Summable b, Additive s, Num s)
    |           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^...

src/ConCat/Deep.hs:104:11: warning: [-Wsimplifiable-class-constraints]
    • The constraint ‘Summable b’ matches an instance declaration
      instance SummableF h => Summable h -- Defined in ‘ConCat.Additive’
      This makes type inference for inner bindings fragile;
        either use MonoLocalBinds, or simplify it using the instance
    • In the type signature:
        linear :: (Summable a, Summable b, Additive s, Num s) =>
                  (a --* b) s -> (a s -> b s)
    |
104 | linear :: (Summable a, Summable b, Additive s, Num s)
    |           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^...

src/ConCat/Deep.hs:127:11: warning: [-Wsimplifiable-class-constraints]
    • The constraint ‘Summable a’ matches an instance declaration
      instance SummableF h => Summable h -- Defined in ‘ConCat.Additive’
      This makes type inference for inner bindings fragile;
        either use MonoLocalBinds, or simplify it using the instance
    • In the type signature:
        affine :: (Summable a, Summable b, Additive s, Num s) =>
                  (a --+ b) s -> (a s -> b s)
    |
127 | affine :: (Summable a, Summable b, Additive s, Num s)
    |           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^...

src/ConCat/Deep.hs:127:11: warning: [-Wsimplifiable-class-constraints]
    • The constraint ‘Summable b’ matches an instance declaration
      instance SummableF h => Summable h -- Defined in ‘ConCat.Additive’
      This makes type inference for inner bindings fragile;
        either use MonoLocalBinds, or simplify it using the instance
    • In the type signature:
        affine :: (Summable a, Summable b, Additive s, Num s) =>
                  (a --+ b) s -> (a s -> b s)
    |
127 | affine :: (Summable a, Summable b, Additive s, Num s)
    |           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^...

src/ConCat/Deep.hs:138:12: warning: [-Wsimplifiable-class-constraints]
    • The constraint ‘Summable n’ matches an instance declaration
      instance SummableF h => Summable h -- Defined in ‘ConCat.Additive’
      This makes type inference for inner bindings fragile;
        either use MonoLocalBinds, or simplify it using the instance
    • In the type signature:
        normSqr :: (Summable n, Additive s, Num s) => n s -> s
    |
138 | normSqr :: (Summable n, Additive s, Num s) => n s -> s
    |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

src/ConCat/Deep.hs:143:12: warning: [-Wsimplifiable-class-constraints]
    • The constraint ‘Summable n’ matches an instance declaration
      instance SummableF h => Summable h -- Defined in ‘ConCat.Additive’
      This makes type inference for inner bindings fragile;
        either use MonoLocalBinds, or simplify it using the instance
    • In the type signature:
        distSqr :: (Summable n, Additive s, Num s) => n s -> n s -> s
    |
143 | distSqr :: (Summable n, Additive s, Num s) => n s -> n s -> s
    |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

src/ConCat/Deep.hs:159:12: warning: [-Wsimplifiable-class-constraints]
    • The constraint ‘Summable a’ matches an instance declaration
      instance SummableF h => Summable h -- Defined in ‘ConCat.Additive’
      This makes type inference for inner bindings fragile;
        either use MonoLocalBinds, or simplify it using the instance
    • In the type signature:
        affRelu :: (C2 Summable a b, Ord s, Additive s, Num s) =>
                   (a --+ b) s -> (a s -> b s)
    |
159 | affRelu :: (C2 Summable a b, Ord s, Additive s, Num s)
    |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^...
cartazio commented 6 years ago

One issue i hit is that FunCo and FunTy are define both by you AND by ghc, i assumed in this context you wanted to use your data type, but maybe it should move over to using the in ghc one in 8.2 onwards?

conal commented 6 years ago

Hey, great! I'm giving it a spin now.

I see that there are three resolvers listed in stack.yaml. I didn't know one can provide several resolvers. Is the idea that they all build with "stack build" etc?

cartazio commented 6 years ago

i'm actually not familiar with stack ... so i have no clue what i'm doing for that, my latest push is me trying to move to the haskell-ci style travis by @hvr et al. I dont know how to fix stack issues :)

cartazio commented 6 years ago

https://travis-ci.org/conal/concat/builds/389856296?utm_source=github_status&utm_medium=notification should be a better build matrix :)

conal commented 6 years ago

With resolver: lts-9.20 I get the following errors:

Preprocessing library concat-classes-0.3.0.0...
[1 of 6] Compiling ConCat.Misc      ( src/ConCat/Misc.hs, .stack-work/dist/x86_64-osx/Cabal-1.24.2.0/build/ConCat/Misc.o )
[2 of 6] Compiling ConCat.Orphans   ( src/ConCat/Orphans.hs, .stack-work/dist/x86_64-osx/Cabal-1.24.2.0/build/ConCat/Orphans.o )

/Users/conal/tmp/concat/classes/src/ConCat/Orphans.hs:376:24: error:
    Not in scope: type constructor or class ‘Distributive’

/Users/conal/tmp/concat/classes/src/ConCat/Orphans.hs:381:24: error:
    Not in scope: type constructor or class ‘Representable’
cartazio commented 6 years ago

woops: if you look at that code, i did a fix, but i clearly did the conditional imports wrong

cartazio commented 6 years ago

pushed a fix for that

conal commented 6 years ago

Now:

bash-3.2$ stack build

Configuring concat-plugin-0.3.0.0...
Preprocessing library concat-plugin-0.3.0.0...
[1 of 4] Compiling ConCat.Translators ( src/ConCat/Translators.hs, .stack-work/dist/x86_64-osx/Cabal-1.24.2.0/build/ConCat/Translators.o )
[2 of 4] Compiling ConCat.Rebox     ( src/ConCat/Rebox.hs, .stack-work/dist/x86_64-osx/Cabal-1.24.2.0/build/ConCat/Rebox.o )
[3 of 4] Compiling ConCat.Plugin    ( src/ConCat/Plugin.hs, .stack-work/dist/x86_64-osx/Cabal-1.24.2.0/build/ConCat/Plugin.o )

/Users/conal/tmp/concat/plugin/src/ConCat/Plugin.hs:1049:25: error:
    Not in scope: ‘OrdMap.lookupUDFM’
    Perhaps you meant one of these:
      ‘OrdMap.lookup’ (imported from Data.Map),
      ‘OrdMap.lookupGE’ (imported from Data.Map),
      ‘OrdMap.lookupGT’ (imported from Data.Map)
    Module ‘Data.Map’ does not export ‘lookupUDFM’.

/Users/conal/tmp/concat/plugin/src/ConCat/Plugin.hs:1840:16: error:
    Not in scope: ‘DFMap.listToUDFM’
    No module named ‘DFMap’ is imported.

Are you seeing this error as well?

cartazio commented 6 years ago

shoot, thats why i'm trying to fix up the CI, i'm building on 8.2 atm, but i know what mistake that is in my patch, i'll fix it now :)

conal commented 6 years ago
[3 of 4] Compiling ConCat.Plugin    ( src/ConCat/Plugin.hs, .stack-work/dist/x86_64-osx/Cabal-1.24.2.0/build/ConCat/Plugin.o )

/Users/conal/tmp/concat/plugin/src/ConCat/Plugin.hs:1840:16: error:
    Not in scope: ‘DFMap.listToUDFM’
    No module named ‘DFMap’ is imported.
conal commented 6 years ago

@kosmikus Note what @cartazio is up to. I won't merge until the gold tests work for at least 8.0.2.

cartazio commented 6 years ago

i see a missed CPP wrapping, i'll push the fix shortly

cartazio commented 6 years ago

hrmm, based on https://travis-ci.org/conal/concat/builds/389859988 it looks like language-glsl doesn't have a ghc 8.4.3 release yet

cartazio commented 6 years ago

@conal can you kill builds 81 and 82? (so the tip can be tested sooner? :) )

cartazio commented 6 years ago

i think my current version of the travis CI script probably also tests the netlist family of packages, but that should be doable to fix

cartazio commented 6 years ago

i'm gonna disable checking haddocks for now, cabal 2.2 has a bug in doc gen or two

i have a PR to cabal that fixes it, but https://github.com/haskell/cabal/pull/5269 need feedback or an owner to make it land, though it probably needs some feedback

cartazio commented 6 years ago

cabal: Tests failed for test:gold-tests from concat-examples-0.3.0.0. Tests failed for test:misc-examples from concat-examples-0.3.0.0. Tests failed for test:misc-trace from concat-examples-0.3.0.0. Tests failed for test:hardware-trace from concat-hardware-0.1.0.0.

on 8.2 on my mac :(

cartazio commented 6 years ago

ok, the travis tests failed on 8.0.2 because of the OOm killer Configuring test suite 'misc-examples' for concat-examples-0.3.0.0.. Preprocessing test suite 'misc-examples' for concat-examples-0.3.0.0.. Building test suite 'misc-examples' for concat-examples-0.3.0.0.. Configuring test suite 'gold-tests' for concat-examples-0.3.0.0.. Preprocessing test suite 'gold-tests' for concat-examples-0.3.0.0.. Building test suite 'gold-tests' for concat-examples-0.3.0.0.. cabal: Failed to build test:gold-tests from concat-examples-0.3.0.0. The build process was killed (i.e. SIGKILL). The typical reason for this is that there is not enough memory available (e.g. the OS killed a process using lots of memory).

cartazio commented 6 years ago

Preprocessing library for concat-hardware-0.1.0.0.. Building library for concat-hardware-0.1.0.0.. Configuring library for concat-graphics-0.1.0.0.. Preprocessing library for concat-graphics-0.1.0.0.. Building library for concat-graphics-0.1.0.0.. Configuring test suite 'misc-trace' for concat-examples-0.3.0.0.. Preprocessing test suite 'misc-trace' for concat-examples-0.3.0.0.. Building test suite 'misc-trace' for concat-examples-0.3.0.0.. Running 1 test suites... Test suite misc-trace: RUNNING...

misc-trace: Oops: toCcc' called Test suite misc-trace: FAIL Test suite logged to: /home/travis/build/conal/concat/dist-newstyle/build/x86_64-linux/ghc-8.0.2/concat-examples-0.3.0.0/t/misc-trace/test/concat-examples-0.3.0.0-misc-trace.log 0 of 1 test suites (0 of 1 test cases) passed. cabal: Tests failed for test:misc-trace from concat-examples-0.3.0.0.

i fixed the OOM, but still get a bug

cartazio commented 6 years ago

maybe that build failure was because i set -O0 on the test suite, trying again

cartazio commented 6 years ago

@conal is there a way to suppress all the rule firing trace data?

cartazio commented 6 years ago

figured it out i'm gonna add a -fDebugConcat flag to concat-plugin so that the Doing Macro is easy to toggle as a build flag

conal commented 6 years ago

... -fDebugConcat flag ...

Have you noticed the existing debugging flags?

cartazio commented 6 years ago

theres none in any of the concat-*.cabal files, so nope i haven't seen any.

You do use lots of CPP, but you dont expose toggling it at the cabal level

conal commented 6 years ago

@conal is there a way to suppress all the rule firing trace data?

Yes: don't turn on tracing, i.e., don't use -fplugin-opt=ConCat.Plugin:xyz, where xyz is "trace", "showResiduals", or "showCcc".

conal commented 6 years ago

maybe that build failure was because i set -O0 on the test suite, trying again

Turning off optimizations will make rewrite rules not fire, breaking the plugin.

cartazio commented 6 years ago

the DOING macro isn't controlled by those flags ...

conal commented 6 years ago

theres none in any of the concat-*.cabal files, so nope i haven't seen any.

Right. It's instead in the source files, e.g., concat/examples/test/Examples.hs .

conal commented 6 years ago

There's also the "misc-trace" target in concat-examples.cabal.

If you don't want tracing, you can use "misc-examples" instead.

cartazio commented 6 years ago

why would i be seeing the error "./gold-tests/build/gold-tests/gold-tests gold-tests: Oops: toCcc' called"

conal commented 6 years ago

the DOING macro isn't controlled by those flags ...

That macro uses dtrace, which is influenced by the flags.

cartazio commented 6 years ago

ok. My point still stands that having these be cabal visible flags :)

but lets table that for now

cartazio commented 6 years ago

@conal for local tests you may wanan revert my stack.yml edit

conal commented 6 years ago

Under GHC 8.0.2 (resolver: lts-9.20 in stack.yaml):

stack build
...
[3 of 4] Compiling ConCat.Plugin    ( src/ConCat/Plugin.hs, .stack-work/dist/x86_64-osx/Cabal-1.24.2.0/build/ConCat/Plugin.o )

/Users/conal/tmp/concat/plugin/src/ConCat/Plugin.hs:58:1: warning: [-Wdodgy-imports]
    Module ‘TyCoRep’ does not export ‘FunTy’

/Users/conal/tmp/concat/plugin/src/ConCat/Plugin.hs:58:1: warning: [-Wdodgy-imports]
    Module ‘TyCoRep’ does not export ‘FunCo’
cartazio commented 6 years ago

yup, on newer ghc it exports that, so i chose correctly it sounds like

conal commented 6 years ago

Ah, I see. Just a warning, to be fixed via another CPP conditional I guess.

cartazio commented 6 years ago

Building library for concat-graphics-0.1.0.0.. Running 1 test suites... Test suite misc-examples: RUNNING...

misc-examples: Oops: toCcc' called Test suite misc-examples: FAIL Test suite logged to: /Users/carter/WorkSpace/projects/active/concat-linear-work/dist-newstyle/build/x86_64-osx/ghc-8.2.2/concat-examples-0.3.0.0/t/misc-examples/test/concat-examples-0.3.0.0-misc-examples.log 0 of 1 test suites (0 of 1 test cases) passed. Running 1 test suites... Test suite misc-trace: RUNNING...

misc-trace: Oops: toCcc' called Test suite misc-trace: FAIL Test suite logged to: /Users/carter/WorkSpace/projects/active/concat-linear-work/dist-newstyle/build/x86_64-osx/ghc-8.2.2/concat-examples-0.3.0.0/t/misc-trace/test/concat-examples-0.3.0.0-misc-trace.log 0 of 1 test suites (0 of 1 test cases) passed. Configuring test suite 'gold-tests' for concat-examples-0.3.0.0.. Preprocessing test suite 'gold-tests' for concat-examples-0.3.0.0.. Building test suite 'gold-tests' for concat-examples-0.3.0.0.. Running 1 test suites... Test suite gold-tests: RUNNING... gold-tests: Oops: toCcc' called Test suite gold-tests: FAIL Test suite logged to: /Users/carter/WorkSpace/projects/active/concat-linear-work/dist-newstyle/build/x86_64-osx/ghc-8.2.2/concat-examples-0.3.0.0/t/gold-tests/test/concat-examples-0.3.0.0-gold-tests.log 0 of 1 test suites (0 of 1 test cases) passed. cabal: Tests failed for test:gold-tests from concat-examples-0.3.0.0. Tests failed for test:misc-examples from concat-examples-0.3.0.0. Tests failed for test:misc-trace from concat-examples-0.3.0.0.

cartazio commented 6 years ago

somehow the way / order of toCCC being invoked isn't working?

conal commented 6 years ago

Which compiler version?

cartazio commented 6 years ago

ghc 8.2.2

conal commented 6 years ago

Got it. Thanks. I just confirmed that the gold tests are working fine with your tweaked concat under 8.0.2. That's great! Now I can accept the PR and start investigating the 8.2 issues.

conal commented 6 years ago

Do you want to make any more tweaks to your PR before I merge?

cartazio commented 6 years ago

nah this is great :)

cartazio commented 6 years ago

you may wanna move the tracing flags into concat-plugin btw :)

cartazio commented 6 years ago

.cabal

cartazio commented 6 years ago

(or .... at least document them in the top level)

conal commented 6 years ago

Hm. I don't think I know what you mean. The tracing flags are plugin flags, given for plugin clients rather than for the plugin itself.

cartazio commented 6 years ago

gotcha.

where are they currently documented :)

conal commented 6 years ago

Nowhere, I'm afraid.

cartazio commented 6 years ago

could you tell me ? or add it to the readme.md at the top?