C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Efficient and silent bounds checking with silent_at()

From: Sebastian Wittmeier <wittmeier_at_[hidden]>
Date: Thu, 6 Jul 2023 04:34:35 +0200
Dear Shengdun Wang, you are proposing a member function, which does bounds checking, but instead of throwing an exception, would be aborting the program.   You state, the optimizer can reorder instructions better this way.   Could you please clarify the reason for it? Is it, because no exceptions are thrown or because no output is made to the console? Is it because of the specific implementation within libstdc++ or because of the standardized behavior of .at()? Could this in theory also be solved with improvements to the optimizer?   The comparison to the upcoming (not current yet) contracts feature of C++ is important, as bounds-checking is a prime example for checking a pre-condition. One would expect to get a good compromise between safety and performance for contracts, too. Either the contracts proposal can learn from your findings to get it done the right way from the start and/or your proposal can be subsumed within the existing .at() configured by a suitable 'contracts configuration' without the need for introducing a new member function and being more compatible with existing code.   So it is very important, what the reason for the performance loss actually is, and what the minimum change for solving it is. E.g. can exceptions be kept, even if _you_ do not use them? If exceptions are the absolute reason for the performance loss in this case, can they be implemented in a different way to prevent it? There are also proposals to change the C++ exception mechanism with a simpler alternative, which is acceptable to a broader range of C++ programmers.   Best, Sebastian   -----Ursprüngliche Nachricht----- Von:trtaab trtaab via Std-Proposals <std-proposals_at_[hidden]> Gesendet:Do 06.07.2023 01:38 Betreff:[std-proposals] Efficient and silent bounds checking with silent_at() An:std-proposals_at_[hidden]; CC:trtaab trtaab <tvfvof_at_[hidden]>; Dear ISO C++ Committee,   I am writing to propose the addition of a new method, "reference silent_at(size_type index) noexcept," to all random access containers in C++. This proposal aims to address the concern of bounds checking in a manner that balances efficiency and safety.   To provide further clarity and support for this proposal, I would like to share some code references that demonstrate the proposed silent_at() method and its benefits.   By studying these code references, it becomes evident that the proposed silent_at() method can offer a pragmatic compromise between the unchecked operator[] and the exception-throwing at() methods. It enables efficient bounds checking while ensuring controlled program termination without producing any output.   I sincerely appreciate your consideration of this proposal and the opportunity to contribute to the ongoing development of the C++ language. I eagerly await your feedback and the possibility of engaging in further discussions regarding this idea.   Thank you for your time and attention.   References: silent_at: https://godbolt.org/z/4v7Eo3ce9   at with supposed implementation: https://godbolt.org/z/soK98Prjh   libstdc++ with _GLIBCXX_ASSERTIONS : https://godbolt.org/z/vWzsxshGv   Rust Inefficiency due to too much debugging output: https://godbolt.org/z/M455GqsE6     Sincerely,   Shengdun Wang tvfvof_at_[hidden]   Sent from Mail for Windows   -- Std-Proposals mailing list Std-Proposals_at_[hidden] https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals

Received on 2023-07-06 02:34:37