[flang] Fix template step limit issue with clang
authorJean Perier <jperier@nvidia.com>
Tue, 4 Feb 2020 18:30:16 +0000 (10:30 -0800)
committerJean Perier <jperier@nvidia.com>
Tue, 4 Feb 2020 18:30:16 +0000 (10:30 -0800)
commita8ef13ea25e9a21906aad4489f461f19cdb3fa37
tree9ab95c6168e62e89ee709ef61bb4ec958ef88fe1
parentb6363facf5fec1a6a89ea2735bdf7807df2b80b7
[flang] Fix template step limit issue with clang

While working on PR 959, I instanciated a `common::TupleToVariant`
with ~50+ types inside the tuple. Clang would then crash after
1hr compilation with message:
"constexpr evaluation hit maximum step limit; possible infinite loop"
After investigating, it turned out clang handles very badly the way
`common::AreTypesDistinctHelper` was implemented.
Its "number of steps" was exponential with the number of types.
This fix makes this number quadratic which solves the issue.

Original-commit: flang-compiler/f18@4542cb57082eaf578799c76482d4b706ae5da077
Reviewed-on: https://github.com/flang-compiler/f18/pull/968
flang/include/flang/common/template.h