[PATCH] D37525: [docs] Add a note on iteration of unordered containers to coding standards
David Blaikie via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 6 12:04:38 PDT 2017
Might be worth pivoting this a bit differently to talk about ordering of
pointers if that's the specific niche we're going to discourage/outlaw.
(this could happen on std::set/map/etc too, when used with pointer keys)
Also "sort before iteration" is a bit too strong since it's only about when
iterating to produce an ordered result (if it's an iteration to compute,
say, a total or some order-agnostic summary/result, that's fine).
- Dave
On Wed, Sep 6, 2017 at 11:55 AM Mandeep Singh Grang via Phabricator <
reviews at reviews.llvm.org> wrote:
> mgrang created this revision.
>
> Beware of non-determinism due to iteration order of unordered containers
>
>
> Repository:
> rL LLVM
>
> https://reviews.llvm.org/D37525
>
> Files:
> docs/CodingStandards.rst
>
>
> Index: docs/CodingStandards.rst
> ===================================================================
> --- docs/CodingStandards.rst
> +++ docs/CodingStandards.rst
> @@ -811,6 +811,20 @@
> for (const auto *Ptr : Container) { observe(*Ptr); }
> for (auto *Ptr : Container) { Ptr->change(); }
>
> +Beware of non-determinism due to iteration order of unordered containers
> +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> +
> +Unordered containers like SmallPtrSet, DenseMap and DenseSet do not have
> +a defined iteration order. As a result, iteration of such containers can
> +result in non-deterministic code generation. While the generated code
> +might not necessarily be "wrong code", this non-determinism might result
> +in unexpected runtime crashes or simply hard to reproduce bugs on the
> +customer side making it harder to debug and fix.
> +
> +As a rule of thumb, remember to sort an unordered container before
> +iteration. Or try using ordered containers like SmallVector or MapVector
> +in case iteration is needed.
> +
> Style Issues
> ============
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170906/1d9017d4/attachment.html>
More information about the llvm-commits
mailing list