|
steckles posted:Request denied. Reason: The old code is “burnt in”. I’ve heard that one used a few times to justify the continued existence of some of the deeper, stranger places in our codebase. I've had this happen with date-handling code a couple times. "Luckily" everything will be "okay" as long as we never ever have code or a database running west of central time
|
# ? Mar 24, 2019 03:31 |
|
|
# ? May 21, 2024 03:58 |
|
Magissima posted:I've had this happen with date-handling code a couple times. "Luckily" everything will be "okay" as long as we never ever have code or a database running west of central time It could be worse, like that bug with the F-22 where all the electronics crashed when they crossed the international date line.
|
# ? Mar 24, 2019 07:01 |
|
RPATDO_LAMD posted:You're allowed to have a constexpr function that returns a compile-time constant if passed compile-time-constant arguments but just gets called normally if passed variable / runtime values. This was a fancy algorithm which gcc executed at compile time but MSVC had a tougher time with it and bailed.
|
# ? Mar 24, 2019 10:00 |
|
FWIW you can force compile-time evaluation by using the result in a place that requires compile-time evaluation, like a static_assert. Buy yeah, without that the compiler has full liberty to just defer the evaluation, and it is (was) a feature -- the original constexpr specification was extremely limited to avoid implementation problems.
|
# ? Mar 24, 2019 14:26 |
|
That Dang Lizard posted:It could be worse, like that bug with the F-22 where all the electronics crashed when they crossed the international date line. This is somehow not surprising to me
|
# ? Mar 24, 2019 15:37 |
|
Suspicious Dish posted:Today I discovered that there's no guarantee for constexpr to be actually computed at compile time and MSVC will just give up and compute it at runtime if it's too hard. No way to turn that into an error afaict though. whitelist ctors
|
# ? Mar 24, 2019 15:40 |
|
Xarn posted:FWIW you can force compile-time evaluation by using the result in a place that requires compile-time evaluation, like a static_assert. Buy yeah, without that the compiler has full liberty to just defer the evaluation, and it is (was) a feature -- the original constexpr specification was extremely limited to avoid implementation problems. That sort of raises the question of what it was supposed to achieve...
|
# ? Mar 24, 2019 20:10 |
|
feedmegin posted:That sort of raises the question of what it was supposed to achieve... Isn't it essentially a termination checking issue? Compilers may reasonably want to avoid trying to fully evaluate arbitrary expressions that they cannot guarantee terminate at compile time, which means that either constexpr needs to be a non-Turing complete subset of the language where termination can always be validated or implementations must be able to defer evaluation when they're unsure if an expression terminates. The MSVC implementation is apparently to speculatively evaluate the expression to some configured recursion depth and instruction count (set with /constexpr ), and defer the evaluating a constexpr to runtime if the compile time evaluation fails to terminate within those constraints. This seems pretty reasonable to me; I am not sure if clang or gcc do something fundamentally different. Doing algorithmic termination checking of C++ instead of speculative execution seems like it would be hard, even ignoring that it's in some cases fundamentally impossible.
|
# ? Mar 24, 2019 20:41 |
|
feedmegin posted:That sort of raises the question of what it was supposed to achieve...
|
# ? Mar 24, 2019 20:55 |
|
Xerophyte posted:Isn't it essentially a termination checking issue? Compilers may reasonably want to avoid trying to fully evaluate arbitrary expressions that they cannot guarantee terminate at compile time, I don't see why this is. If I put a constant equation in that is `while (1);`, then I expect the compiler to hang forever.
|
# ? Mar 24, 2019 21:05 |
|
xtal posted:I don't see why this is. If I put a constant equation in that is `while (1);`, then I expect the compiler to hang forever. Unless I'm missing a joke. Xerophyte posted:constexpr needs to be a non-Turing complete subset of the language where termination can always be validated or implementations must be able to defer evaluation when they're unsure if an expression terminates
|
# ? Mar 24, 2019 23:10 |
|
Dylan16807 posted:Most people don't want their compilers to crash or hang. In order of preference, when I write broken code (such as an infinite loop in a compile-time evaluated expression):
Absolutely no where on the list is
|
# ? Mar 25, 2019 01:39 |
|
Dylan16807 posted:Most people don't want their compilers to crash or hang. When you write compile-time code that crashes or hangs, you certainly do want the compiler to crash or hang.
|
# ? Mar 25, 2019 03:38 |
|
Ideally the compiler would give you an error instead of crashing or taking unusually long to run.
|
# ? Mar 25, 2019 04:10 |
|
Jabor posted:Ideally the compiler would give you an error instead of crashing or taking unusually long to run. It's not an unusually long time if it's doing exactly what you wrote imho. The code you write is what should run. That's what we think about runtime, so why think differently for compile time?
|
# ? Mar 25, 2019 04:22 |
|
Because I write code to actually accomplish useful tasks, not to have some moron tool developer tut-tut about how I wrote something wrong so they're going to waste my time accomplishing nothing until I manually figure out what happened. By a similar token, I also like having automated analyses that tell me when runtime code is (or could be) problematically slow. These are good things.
|
# ? Mar 25, 2019 04:28 |
|
Keep in mind that I'm talking about what is apparently an MSVC bug. gcc and clang successfully compile it at compile time without concern. MSVC decides that it is too complicated and unhelpfully shoves the computation to runtime. Someone else suggested using an enum instead of a constexpr variable, which actually provides the error I want.
|
# ? Mar 25, 2019 05:11 |
|
feedmegin posted:That sort of raises the question of what it was supposed to achieve... It was supposed to let you write functions which can be used in places which require constant expressions (hence "constexpr") without having to do ridiculous metaprogramming things. It does a perfectly good job of this. This was probably not the right choice of thing to put into the language, but the intended usecase for it really isn't that weird or confusing.
|
# ? Mar 25, 2019 07:57 |
|
xtal posted:you certainly do want the compiler to crash or hang.
|
# ? Mar 25, 2019 11:19 |
|
Spatial posted:It's coming from inside the thread! As noted, while that's worse than producing an error message it's definitely better than silently emitting invalid code. IMO, silently doing the wrong thing is the worst possible failure mode for a compiler.
|
# ? Mar 25, 2019 13:31 |
|
ToxicFrog posted:As noted, while that's worse than producing an error message it's definitely better than silently emitting invalid code. IMO, silently doing the wrong thing is the worst possible failure mode for a compiler. Right, but in Suspicious Dish's case, it didn't emit invalid code, it just didn't do exactly what they thought it would do because the feature spec is slightly confusing.
|
# ? Mar 25, 2019 14:18 |
|
Just to clarify again because it seems that a lot of people misunderstand what constexpr does: it does not make code execute at compile time. It makes code able to be executed at compile time. Whether it is executed at compile-time or at runtime depends entirely on where it is called from, and not solely whether the function is marked constexpr. The compiler emitting a runtime function call when you call a function (constexpr or not) in a runtime context is not a compiler bug. At worst, it's a dropped optimization opportunity. The only way to force something to be called at compile time is to call it from a compile-time context, such as in the value of an enum or inside a static assert. You're perfectly free to use while (1) inside a compile-time-executed constexpr and the compiler will hang forever*. (*until it gets killed for exceeding the maximum number of steps). code:
Notice that the compiler emits a call to compute() for the third printf argument, but the first two are pre-computed. Play around with the following things:
edit: whoops should have used PRId64 instead of PRIu64 but I'm too lazy to update the godbolt link Volte fucked around with this message at 15:05 on Mar 25, 2019 |
# ? Mar 25, 2019 14:51 |
|
It is important to remember that the compiler has to interpret the C++ code for constexpr contexts, which is a lot slower than compiling it into something sane and then running that, which is why it is allowed to defer to runtime if the compilation would take too long and the result is only needed at runtime.
|
# ? Mar 25, 2019 15:02 |
|
Xarn posted:It is important to remember that the compiler has to interpret the C++ code for constexpr contexts, which is a lot slower than compiling it into something sane and then running that, which is why it is allowed to defer to runtime if the compilation would take too long and the result is only needed at runtime. Volte fucked around with this message at 15:45 on Mar 25, 2019 |
# ? Mar 25, 2019 15:42 |
|
At -O2, the compiler's optimizer is probably just discovering the closed-form solution for that loop either before or after inlining it.
|
# ? Mar 25, 2019 16:05 |
|
rjmccall posted:At -O2, the compiler's optimizer is probably just discovering the closed-form solution for that loop either before or after inlining it.
|
# ? Mar 25, 2019 16:17 |
Plorkyeran posted:It was supposed to let you write functions which can be used in places which require constant expressions (hence "constexpr") without having to do ridiculous metaprogramming things. It does a perfectly good job of this. C++: This was probably not the right choice of thing to put into the language
|
|
# ? Mar 25, 2019 17:06 |
|
Volte posted:Indeed - the point being that just because something can be done at compile-time doesn't mean that adding constexpr is going to force it to happen, or that not adding constexpr is going to force it not to happen. I find this kind of thing annoying. Compilers these days use a lot of heuristics, and while they're quite good, heuristics by their nature can't account for every possible situation. That's why it's nice when you can override the heuristic and force the compiler to do something when you really need it to. The problem I find is that while c++ often appears to give you this kind of control (such as with inline or constexpr), the reality is you're just providing hints and hoping the compiler guesses correctly.
|
# ? Mar 25, 2019 19:44 |
|
RPATDO_LAMD posted:In order of preference, when I write broken code (such as an infinite loop in a compile-time evaluated expression):
|
# ? Mar 25, 2019 19:52 |
|
xtal posted:It's not an unusually long time if it's doing exactly what you wrote imho. The code you write is what should run. That's what we think about runtime, so why think differently for compile time? At compile time that purpose goes away and there's no reason to hang.
|
# ? Mar 25, 2019 20:41 |
|
Sure, I think everyone would love it if the compiler always gave an error for invalid compile-time expressions and always accepted valid ones. The problem is that a compiler cannot know that an expression will terminate without solving the halting problem. Since it definitely can't solve the halting problem the compiler has to do at least one of: 1. Sometimes hang indefinitely while it waits for your ill-formed expression to maybe hopefully terminate. 2. Sometimes reject well-formed expressions that it cannot successfully determine will terminate. 3. Reduce the generality of constant expressions so they're in some incomplete subset of the language where expressions are guaranteed to always terminate. C++ went with 2, and a requirement in the standard for core constant expressions is that they will not "exceed the implementation-defined limits" which seems fine to me since the alternatives are worse. There's additionally the question to do when the compile time evaluation fails. constexpr took the view that it is there to help you write better code, not guarantee evaluation. It's like const: it makes the typechecker more restrictive to stop you from doing things that have side effects. constexpr functions may still be emitted into the binary, may be used on variables, and marking appropriate pre-existing code as constexpr will not change the result of your program. consteval instead gives a hard guarantee that "every call to the function must produce a compile-time constant". consteval functions may never be called with variables as parameters, and allow compilers to fail on well-formed code if it's over some implementation-specific complexity level. Both of these are mildly annoying. I'd think there could have been some way of forcing a constexpr call to be evaluated at compile time or fail, rather than adding consteval and its very strict no-variables-ever policy, but since it's C++ I am probably missing some fun other corner case.
|
# ? Mar 25, 2019 23:47 |
|
Xerophyte posted:Sure, I think everyone would love it if the compiler always gave an error for invalid compile-time expressions and always accepted valid ones. The problem is that a compiler cannot know that an expression will terminate without solving the halting problem. Well now! Assuming it is possible to statically check that a C++ expression does not have side effects, then solving the halting problem is not necessary. As far as I know, the pure subset of C is Turing-incomplete for pedantic reasons, because it requires all objects to be uniquely identifiable with a finitely-sized integer (everything must potentially have an address), and so the total number of objects that can exist at once is limited. Unless C++ changed some of these details, I believe the same restriction must apply. The restriction to pure expressions is that I'm not sure if you can use the file system functions to access potentially unbounded storage. Anyway, this would imply that pure C++ expressions embody a linear bounded automaton, not a full Turing machine, and you can verify termination of an LBA simply by tracking all intermediate evaluation states and constantly checking whether you've reached a state you've seen before. Clearly this was the intended implementation strategy.
|
# ? Mar 26, 2019 07:26 |
|
of course going back to the date thing, the islamic calendar is simple 30,29,30,29,30,29,30,29,30,29,30,29
|
# ? Mar 26, 2019 07:46 |
|
Why don't we just push the earth towards the sun a tiny bit so we get 360 days a year? Then this problem goes away.
|
# ? Mar 26, 2019 09:10 |
|
NtotheTC posted:Why don't we just push the earth towards the sun a tiny bit so we get 360 days a year? Then this problem goes away. 360 official days, plus 5.2422 days of planned downtime.
|
# ? Mar 26, 2019 10:23 |
|
|
# ? Mar 31, 2019 00:39 |
|
Cursed
|
# ? Mar 31, 2019 01:06 |
huh elon's program crashed weird
|
|
# ? Mar 31, 2019 01:15 |
|
r/fellowdevelopers
|
# ? Mar 31, 2019 10:51 |
|
|
# ? May 21, 2024 03:58 |
|
while (firetruck.isVisible()) speed++;
|
# ? Mar 31, 2019 12:22 |