camfort / fortran-src

Fortran parsing and static analysis infrastructure
https://hackage.haskell.org/package/fortran-src
Other
48 stars 20 forks source link

use generic-optics to define First,SecondParameter #218

Closed raehik closed 2 years ago

raehik commented 2 years ago

Our generics code was unsafe in that if you tried to derive an instance which was invalid (e.g. you say an a is the first parameter in each constructor, but it isn't), it would still derive an instance, but give you an undefined runtime error upon using it. Pushing that error to compile time is complex, but it's a solved problem by kcsongor's in his wonderful generic-lens library.

This change adds generic-optics and optics-core to dependencies. They're very lightweight. Performance should be the same; compile time should most likely increase.

raehik commented 2 years ago

Looks like the compile time increase is much bigger than I thought, and memory usage too. The main module it should affect is Language.Fortran.AST. Running stack ghci on master and this branch and timing that module (mem% is from htop) shows:

Bit unsure now. I wonder if it would improve if Expression weren't so mutually recursive.

raehik commented 2 years ago

The extra work generic-lens has to do for safe derivations is just too much. At least it's shown me another questionable instance to remove. I'm replacing this PR with one which doesn't alter the generic derivation over here: https://github.com/camfort/fortran-src/pull/219