Or, even better, use value semantics and pass things by value. Imho that's the best way for you and your compiler to reason about what can change when and where.
-
-
Replying to @timur_audio @hankadusikova
That's not really an option for much of what I'm working on (largely RDBMs), unfortunately. E.g. I hardly can do that for a database's buffer cache - but I can guarantee there are no modifications on a page while holding a lock.
1 reply 0 retweets 1 like -
Passing a query execution plan by value would be way too expensive. There's a lot of query execution time datastructures that should not be copied, and need to be mutable, but there are sections where we know they can't change.
1 reply 0 retweets 0 likes -
And const [references] doesn't do much for my cases (see upthread). I agree that assume seems like a poor fit, it seems more like a type system level issue. But I'd take anything :)
1 reply 0 retweets 0 likes -
Replying to @AndresFreundTec @hankadusikova
I think I understand where you're coming from, but assumptions are not for that. Assumptions are for local things. They are there to trigger certain optimisations in a certain line of code, not to reason about functions across different TUs. I think you need another feature.
1 reply 0 retweets 0 likes -
If you want to be sure a func won't change an object, keep a copy, or make sure the obj itself is const in the context of that func. If the compiler can't see inside the func, & the func can access the obj through a non-const reference, there is no way of knowing it won't change.
2 replies 0 retweets 0 likes -
Replying to @timur_audio @AndresFreundTec
but it would be nice to be able to tell compiler "hey, I'm really sure it won't change, because I'm writing a database, and actually there is a database level lock over this resource"
1 reply 0 retweets 0 likes -
Replying to @hankadusikova @AndresFreundTec
Yeah. Maybe this could be done by inventing some magic function std::assume_const... it feels somewhat similar to std::assume_aligned. But before proposing sth like that, I would ask compiler engineers whether such an assumption is even implementable?
4 replies 0 retweets 0 likes -
Replying to @timur_audio @hankadusikova
Something like std::assume_aligned would be very helpful. Given that, WRT compiler optimizations, const guarantees in C[++] are pretty weak (i.e. ptr-to-const doesn't allow compiler to assume memory won't change on its own), I'm a bit hesitant to reuse 'const' for it though.
1 reply 0 retweets 0 likes -
Replying to @AndresFreundTec @hankadusikova
Yeah that was just a spontaneous idea. Probably better to call it something long and ugly like std::assume_value_unchanged? But again, before spending time on such a proposal, I would be interested in any existing practice and implementability
1 reply 0 retweets 0 likes
I looked at gcc and clang, and neither currently expose it as intrinsics/builtins as far as I am aware. I have successfully used LLVM's IR invariant builtin as part of JIT codegen though.
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.