HNHacker News
TopNewBestAskShowJobs

jcranmer

36,256 karma · joined November 17, 2014

submissionscomments
jcranmer··on Looking forward to Git 2.56 – and 3.0
Sure, we can write a binary file format parser in C. We just can't figure out how to write one that isn't buggy and lets someone infect your computer if you give it sufficiently inventive garbage.
jcranmer··on Looking forward to Git 2.56 – and 3.0
The comments gives a link to a recent talk about the motivation for using Rust in Git: https://github.com/bk2204/talk-rust-in-git/blob/dev/presenta...

I wouldn't agree with all of those reasons, but it's very definitely not "just for the sake of it." One of the better reasons so many people look to writing some things in Rust is that we now have pretty ample evidence than trying to write a binary file format parser in C is a cornucopia of CVEs that are just simply absent in Rust, and the excuse of "well, but a sufficiently smart programmer doesn't write bugs in C" doesn't cut it anymore.

jcranmer··on US halts flights at busy East Coast airports, says fiber line cut
Over the weekend, I got linked to https://admiralcloudberg.medium.com/reaping-the-whirlwind-in..., which is an exhaustive look at the causes of the first airspace collision in the US in several decades. After reading that, my conclusion is that, if the software being rolled out is what I think it is, it would be a borderline impeachable offense to not first trying it out in the DC airspace.

The fundamental problem with DCA, and one of the two main causes of the crash [1], is that they are required by political pressure to operate at a higher operational tempo than they can safely operate at. DCA has essentially 1½ usable runaways--large planes can only use the larger runway, and given the capacity restrictions, airlines have been pushing to use fewer small planes at the airport. This shift in plane size means the effective safe slot capacity has gone down, but people still keep citing the same number as justification for safe numbers, and the politicization of the issue has shut down everyone who complained that the actual traffic just couldn't be safely handled.

If DCA's theoretical slot capacity (36 landings and takeoffs each per hour) is to be reached one just one runway, you have about 100 seconds to go from plane 1 touchdown; exit the runway, letting plane 2 on to take off; plane 2's wheel leaving the runway, clearing plane 3 touchdown. That's doable, but with essentially 0 margin for error. Alternating the runways used for each landing would give you closer to 30s of margin, but if only 10-20% of the planes can use the alternate runway, you can't divert enough planes to use the alternate runway.

Now DCA and the FAA aren't stupid enough to actually schedule 36 landing slots every hour, but the problem is that because of a few various factors, what was scheduled as, say, 30 slots for an hour (giving 120 seconds between landings, probably sufficient margin) ends up being 12 slots used in the first half-hour and 18 slots used in the second half-hour, which means a lot of the actual operation ends up having no safety margin even though on paper you have sufficient margin.

One of the ways you can rectify that is to assign slots further in advance so that you don't get the bunching. Effectively saying "oh, if you leave right now, you'll arrive at 3:30 with three other planes, but if I hold you for 10 minutes, I can push you into a less busy arrival time." Doing this requires good, accurate prediction of the actual flight travel times, and my understanding is that this is what the new software is meant to provide.

[1] The other main cause is essentially that the DoD's aviation practices in the area is a giant clusterfuck that endangers lives, and unfortunately that sentence is not relegated to the past tense.

jcranmer··on Uber arbitration award over Emily Normandin-Parker’s death
Where is the power of the state involved here?
jcranmer··on What Zig felt like, coming from Rust
I'd word it slightly differently, as something like the Allocator Effect System obsession. It's not so much that allocator tricks don't have a role in modern software--all of the large applications I've worked on rely on things like arena allocation at least some of the time--but rather that things like making container types generic over allocators seems to be more trouble than it's worth. I've never seen anyone use anything other than the default allocator for STL types, for example.
jcranmer··on Why building a Rust LSP is hard
That doesn't really fix anything. The filesystem is fundamentally a racy shared data structure. If you made the entrypoint API synchronous, any half-way decent editor would shove the LSP queries to the synchronous API into a different thread, because "Do Not Block the UI Thread" is a fundamental principle of good UI programming.

Once you get past that, JSON-over-TCP is just another kind of asynchronous RPC mechanism, one that has the advantage that you can build it in just about any language with out-of-the-box tools. Trying to make a plugin system or a COM or CORBA or OLE based system really cuts out the ability to build language servers in most languages, because you have to be able to build the code in just the right way.

jcranmer··on BeanShell3 in Development
jEdit uses BeanShell and appears to still be alive.
jcranmer··on The scourge of x86 emulation
The C/C++ memory model starts with Java's data-race free memory model, but makes data races fully UB. Atomics are introduced into C/C++ that allows fine-grained definition of synchronization, with four different models of atomics: sequentially-consistent (equivalent to Java's volatile), release-acquire, release-consume, and relaxed (which are not synchronizing and are therefore closer to a defined data race than proper atomics). The Java 5 memory model doesn't have the concept of atomics, except that volatile variables act like C/C++ sequentially-consistent atomics.

Relaxed atomics took a couple of tries to specify, and still have a known out-of-thin-air hole that people are still struggling to solve. But the problem with relaxed atomics is that the practical operational semantics are pretty clear, but the formal model is quite tricky for various reasons.

Sequentially-consistent matches the model that most people naively think is going on in hardware (execute a single instruction at a time from a random thread). Release-acquire is a slight relaxation of that model that works well most of the time; the main difference between sequentially-consistent and release-acquire is that release-acquire requires you to specifically release and acquire on the same memory location to get the synchronization, whereas sequentially-consistent synchronizes across different memory locations. Since most multithreaded code tends to have a concept of something like a lock or mutex that is guarding access to a particular region of memory, release-acquire is usually sufficient.

Release-consume is supposed to be release-acquire, but only for data-dependent loads of the consume. This is the only part of the memory model that has really failed, and that's because compilers cannot really guarantee preservation of data dependence in the optimizer. (This also comes up with pointer provenance, FWIW).

jcranmer··on Subnormal floating-point numbers are expensive on Intel processors
Binary floating-point numbers are scientific notation except the pieces are all in binary. In proper scientific notation, the only time the digit before the decimal point can be 0 is when the number itself is 0. Since the only other digit in binary notation is 1, there is no need to store the digit before the decimal point, since it's always 1... except now you can't store 0.

This problem is fixed by reserving one of the exponents for the representation of 0. Some of the formats (e.g. VAX floating point) that introduced this implicit-1-bit for the binary format said that every number with this special-0-exponent was a zero. But IEEE 754 introduced the concept of gradual underflow, and says instead that it is a bit string with the implicit digit before the decimal point as a 0 instead of 1.

Putting it differently and more succinctly: a subnormal number is a number that has fewer digits of precision than is normally implied by the format. Which numbers are subnormal numbers is entirely dependent on the floating-point format.

jcranmer··on Subnormal floating-point numbers are expensive on Intel processors
If you use -ffast-math when linking an executable but not a shared library, both gcc and clang will link in crtfastmath.o which has the bit of code to set the DAZ/FTZ flags.
jcranmer··on The scourge of x86 emulation
No, they don't. x86 is a superscalar processor, and it does what all superscalar processors do--translate the instructions into µops for execution and dispatch to the various execution units, with the µops not being 1-1 with the original instructions. However, it was supposed to be impossible for a CISC architecture to be superscalar, so this is what spawns the myth that it's somehow cheating by executing a RISC architecture under the hood.
jcranmer··on The scourge of x86 emulation
DOS interrupts, for starters.
jcranmer··on Small programming tricks
C added it to the C2y draft about a year ago (so not in any actual released version of C). C++ is still working on adding it to the C++ draft.
jcranmer··on How much oil-market buffer is left?
Venezuelan oil production has declined by about half since Chavez took power. Given the losses they suffered from expropriation, the oil majors aren't particularly keen on returning to Venezuela without stronger guarantees, and oil executives aren't idiot--they understand that Trump is not a reliable partner and that there's a good chance that any deal he strikes with Venezuela will fail to be honored past 2028 (or possibly even before then).

There's also the fact that Venezuelan crude oil is basically among the worst grades of crude oil, the sort of stuff that the refineries don't want to use unless they have no other options. Which also means that as global oil demand hits its maximum (likely within decades), this is also going to be some of the first oil production to be permanently mothballed. With massive necessary investment to get anything running, subpar product, and a very uncertain political situation for the necessary long-term investment, most oil companies are reluctant to invest.

As a result, the only major oil company to have really been contemplating investing in Venezuela is Chevron (which itself appears to be mostly hedging its bets); Trump more recently announced another deal with a supposed major investment in an unnamed operator to extract oil from Venezuela, but without any companies being named, I'm skeptical of how real it is as opposed to merely being a vehicle for graft.

As AnimalMuppet says, if anything does get built, it's on the order of years before anything starts flowing.

jcranmer··on Oil Executives Say the Great Fuel Crisis Is Here
I can't read the article either, but my understanding of the various factors is this:

* Houthis have taken control of all of the Yemeni coastline along the Bab-el-Mandeb Strait (and an island in the middle of it), which gives them the ability to effectively interdict trade through the Red Sea and the Suez Canal, just as Iran has shut down the Strait of Hormuz.

* Not that it matters that much, because the Saudi pipeline that lets it export crude via Yanbu, in the Red Sea, has been disabled, and current estimates suggest that the recovery time is in weeks-to-months. That's about 4-5mbpd of crude oil that's down for the near feature, or about 4% of global crude oil production.

* Now that the summer driving season is over, US refineries are starting to switch from summer blends to winter blends, and this is one of the periods that refineries go down for maintenance. So US refinery capacity is down.

* The supply shock has been mitigated for the past several months by drawing down reserves (note that reserves were relatively high when the war started). This includes both national strategic petroleum reserves, but also corporate reserves (e.g., tanks on-site at refineries). It seems some of these reserves are starting to hit effective 0.

* On top of this, Trump is making it more and more clear that he has no intention of actually doing anything to end to the crisis. For example, he's effectively said that he's not going to do anything before the midterm elections, two months away. Which means the market optimism that the war is going to be over, like, tomorrow is fading.

jcranmer··on Dario, Please
I've seen two theories as to what's going on. One is the theory you've espoused, that AI companies are trying to do regulatory capture. The other theory is that they're starting to worry about running out of cash, so they want to do a Washington Naval Treaty-style pause to lower the amount of money they have to shovel at model development to stay competitive.

These theories aren't entirely incompatible with each other, so both could be true at the same time.

jcranmer··on Microcode in Intel's 8087 floating-point chip: the scale instruction
> But for a compiler to target, it's just so painful. It's so different from almost all other ways CPUs work. There's a reason both CPU and compilers prefer to avoid x87 when possible and use regular SIMD (SSE/AVX) instead.

The x87 ISA is essentially a one-address stack-based ISA (so unlike a pure stack ISA, you can reference another value on the stack without having to introduce something like a dup instruction). Which honestly isn't particularly painful to work with for a compiler; it's not usual, but there are other ISAs that are also stack-based (the JVM bytecode is the one that most immediately comes to mind).

The actual weirdness of x87, what makes all the compilers run away from it, is that the only values you can have on the stack are 80-bit extended-precision types. But people don't use those types in their code, they use 32-bit and 64-bit single and double precision, and compilers largely implemented these types by pretending that the x87 just used those value sizes in the first type (the only ones to actually get it correct that I'm aware of are Java's strictfp and Intel's icc, although the latter is merely just correctly implementing FLT_EVAL_METHOD==2). The end result is that compilers caused code to have essentially random and largely uncontrollable precision changes, which pissed a lot of users off, and the SSE units having regular scalar proper single and double precision types made it easier for compilers to switch to that rather than introducing the proper sequences to compile for x87.

jcranmer··on A Design Space Exploration of Async/Await
> Elsewhere on HA you’ll find my extended rant about how strange it is that we don't have a language that elegantly abstracts computation over threads, SIMD, GPUs etc. Compilers can do this sort of thing now, just not optimally.

Autoparallelization has been a hot topic for literally decades, quite possibly longer than you've been alive.

The problem is that the techniques you need to do to write good SIMD code versus good GPU code versus good multithreaded code versus distributed computation are all different. Taking just memory concerns: a SIMD code needs you to carefully arrange memory so that every thread is accessing an adjacent memory location. GPU code likes locality, but you have large group sizes that can share all the local memory pretty cheaply, and loading from global memory to local memory is relatively expensive, so now you have to do a lot of tuned blocking. With multithreaded code, you now want to avoid sharing between different threads (which generally requires distributing loop iterations among threads very differently). And with a distributed platform, now you're primarily worrying about the overhead of communication of data between different nodes, and you're trying to minimize that.

jcranmer··on Houthis 'take control' of key island in global shipping route
VLCCs are too large to fit through the Suez Canal. I don't know how much of Saudi export is using VLCCs versus Suezmax or smaller tankers, but I've heard that much of the Red Sea oil export is currently going through Bab al-Mandab, not that I have a source on hand.
jcranmer··on OpenAI’s Navier-Stokes release included a Lean 4 formal proof
Newspapers are not above printing rumors.

See, e.g., Barak Ravid regularly reporting in Axios the impending ceasefire negotiation progress in the Iran War, which largely have failed to come to pass.

jcranmer··on Implementation of GCC's Nested Functions (vs. C++ Lambdas)
> The advantage of being compatible to other languages is because if we would use a common ABI that many other languages also use: Ada, Go, D, etc.

I have looked it up and I can already tell you that Go is not using the ABI you would be proposing. I cannot speak for the other languages.

> But I fully realize that the opposition for everything that looks different to C++ from the clang side comes from the perception that it is more work on your side.

That is not where the opposition comes from, and for as long as you continue to believe that, you will fail to understand the opposition at all.

jcranmer··on Growing proof that autonomous cars save lives
As a point of evidence in favor of this viewpoint:

Multi-dozen car pileups aren't particularly rare, with the common cause for a lot of these being "one car hits an icy patch, hits another car, car behind them tries but fails to stop in time due to the ice, rinse and repeat a few dozen times". And the root cause of that is every single driver in that collision driving too fast for conditions and unable to make the requisite emergency stop in time.

jcranmer··on Implementation of GCC's Nested Functions (vs. C++ Lambdas)
An example showing nonequivalency is this: https://godbolt.org/z/PxP4vrfM1

Showing things that are optimized by fully inlining into one function don't actually demonstrate equivalency, because you end up omitting anything that might actually evidence a difference in the semantics. And I get that, for your use cases, those differences might not matter. But as a compiler engineer, I can't say that only those use cases matter and therefore they're equivalent for all practical purposes.

It is also very unhelpful when you insist that this is "compatible" with other languages, where "compatible" actually means "compatible, if you put in a bunch of work in both languages to make something that makes them compatible, none of which I'm actually describing." Especially when there are competing proposals that do have compatibility in the sense of "I don't have to modify the C++ compiler to let it use this thing."

jcranmer··on Implementation of GCC's Nested Functions (vs. C++ Lambdas)
Okay, so you accept that nested functions have a different ABI than C++ lambdas. And it looks like you accept that neither ABI is going to change. So long as the two features have different ABIs, they cannot be compatible with one another.

> And this question is relevant only if one allows taking the address of a nested function

And that question is very relevant since taking the address of such functions (to pass to other functions, e.g., qsort) is one of the main use cases for their existence.

jcranmer··on Implementation of GCC's Nested Functions (vs. C++ Lambdas)
C++, C#, Java, JavaScript, Rust, Go, Julia, Nim, Zig.

I'm shocked that you didn't even pick up Rust, given how frequently I mention it on the WG14 reflector.

jcranmer··on Implementation of GCC's Nested Functions (vs. C++ Lambdas)
I can write the signature of the generated function of a C++ lambda as a C function. I cannot write the signature of a generated GCC nested function as a C function.

If your argument is that ABI doesn't matter, then by all means, propose a patch to GCC to change the ABI and see if it gets accepted.

jcranmer··on Implementation of GCC's Nested Functions (vs. C++ Lambdas)
Yes, it does. The lambda still needs to follow the C++ object model in case someone might use it like a regular C++ object. It's possible to change the ABI with escape analysis that proves you know all of the uses of the lambda to change the ABI, but a) that escape analysis is surprisingly easily defeated [1] and b) ABI-changing optimizations tend to be much more common in research papers than production compilers because getting them right on real code is a lot more difficult than it looks.

[1] The lambda function probably has the same linkage as the function the lambda is contained in, which likely isn't "the only copy of this function is in this TU" but rather "this function may appear in several TUs, but all of these copies are equivalent and you can pick whichever one you like as the actual body." Very different opportunities there!

jcranmer··on “Tweet” and the bird logo apparently enter the public domain
No, there is an amount of legal reality built into it. With copyright and patents, once you obtain the intellectual property, you keep it for the rest of the term no matter what you do. But with trademarks, your actions (or inaction) can cause you to lose the trademark.

The legal purpose of the trademark is to protect identifying marks for the purposes of conducting business (trade)--literally its name. The subsidiary public interest of attaching trust to that mark isn't directly protected, but failing to police the use of trademark is sufficient grounds to lose the trademark, which is why companies tend to be overly aggressive in suing people for violating the trademark.

jcranmer··on Implementation of GCC's Nested Functions (vs. C++ Lambdas)
In the nested function, the variable x is passed in edi, and the pointer to the nested stack frame is passed in r10. In the lambda, the variable x is passed in esi, and the 'this' pointer for the lambda is passed in rdi. The function-level ABIs end up being quite different.
jcranmer··on Implementation of GCC's Nested Functions (vs. C++ Lambdas)
> Generally this is a bit nicer than having explicit lambdas, but I thought the 'best-case' scenario would be if GCC saw into the stack layout of the calling function and could manipulate the calling functions stored stack variables (and saved registers).

A modern compiler IR is probably going to be an SSA-based infinite virtual register set model. In such a model, any variable without its address taken ends up being a register (which may happen to be spilled to the stack). Referencing the variable via a nested function means its a local variable whose address escapes, which kills a lot of optimization potential. It's probably possible to adjust SSA to handle this, but it's a lot of work for little benefit, especially since closure models (closures being regular objects with an unnameable type and an overloaded call operator) have taken over nested functions in language design and thus it isn't really applicable for modern languages.

> After all, a debugger can track what variable goes where at every line of code, so this can be done.

Variable value tracking breaks down pretty much the moment any optimization happens.

← PreviousPage 5 of 34Next →