Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: optimized deriving BEq for enumeration types #660

Merged
merged 1 commit into from
Sep 8, 2021

Conversation

cpehle
Copy link
Contributor

@cpehle cpehle commented Sep 8, 2021

This pull request introduces an optimised code path for enumeration types for the deriving BEq elaboration.
With this commit the test case elaborates on my machine

cumulative profiling times:
        C code generation 49.6ms
        compilation 964ms
        elaboration 371ms
        import 15.2ms
        initialization 18.6ms
        interpretation 1.04ms
        parsing 3.45ms
        typeclass inference 30.4ms

without I get (after increasing set_option maxHeartbeats 10000000)

compilation of [email protected]._hyg.276.match_1 took 13.2s
compilation of [email protected]._hyg.276 took 11s
compilation of [email protected]._hyg.1659 took 824ms
elaboration took 27.9s
true
cumulative profiling times:
        C code generation 78.6ms
        compilation 25.1s
        elaboration 27.9s
        import 15ms
        initialization 18.4ms
        interpretation 1.09ms
        parsing 3.44ms
        typeclass inference 29.8ms

@leodemoura
Copy link
Member

Thanks for the PR. It is useful. I have only two minor issues.

@leodemoura leodemoura merged commit bd02f16 into leanprover:master Sep 8, 2021
@cpehle cpehle deleted the feature-opt-deriving-enum branch September 9, 2021 00:10
ChrisHughes24 pushed a commit to ChrisHughes24/lean4 that referenced this pull request Dec 2, 2022
* `@[to_additive]` will now correctly guess names with `CoeTC`, `CoeT` and `CoeHTCT` in it
* rewrite function `targetName`. 
  - It will now warn the user if it gives a composite name that can be auto-generated (before `to_additive` would never warn if a composite name was given). 
  - the logic when `allowAutoName = true` now corresponds to the docstring
  - Fix a bug where declarations were silently allowed to translate to itself (maybe because the `return` statements returned a value for the whole function?)
  - Add some more tracing
  - The behavior of namespaces when giving a composite name has been changed. It will always generate a name with the same number of components. Example:
```lean
namespace MeasureTheory.MulMeasure
@[to_additive AddMeasure.myOperation] def myOperation := ...
-- before: generates `AddMeasure.myOperation` (and never gives a warning)
-- after: generates `MeasureTheory.AddMeasure.myOperation` (and probably warns that the name can be auto-generated)
end MeasureTheory.MulMeasure
```
* This should fix all problems in leanprover#659 other than leanprover#660

Minor changes:
* When applying `@[to_additive]` to a structure, add a trace message if no translation is inserted for a field.
* Define `Name.fromComponents` and `Name.splitAt`
* Reduce transitive imports of `Tactic/toAdditive`
* Move some auxiliary declarations from `Tactic/Simps` to more appropriate places 
  - swap arguments of `String.isPrefixOf?`
  - improve `Name.getString`

Co-authored-by: Scott Morrison <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants