@foonathan@fosstodon.org
@foonathan@fosstodon.org avatar

foonathan

@foonathan@fosstodon.org

C++, compilers, and programming languages. Library developer @ think-cell, assistant chair for std::ranges @ C++ standardization committee.

This profile is from a federated server and may be incomplete. Browse more on the original instance.

foonathan, to random
@foonathan@fosstodon.org avatar

The control flow graph is an arbitrary graph with cycles, but if you create it from a source language with structured control flow, you can assign each basic block a lexical parent based on the lexical nesting in the source code. The result is a tree where parent blocks can contain variables the child blocks can access (assuming normal lookup rules) which can help with e.g. borrow checking (only borrows in the parent scope need to be considered).

Is this "control flow tree" a thing?

foonathan, to random
@foonathan@fosstodon.org avatar

I was talking with a friend who's a science advisor to a German MP. He was complaining about issues with old Soviet contracts that are still in effect with Russia that prevents them from doing stuff under international law.

I told him: "Oh, in the C++ committee we have a similar problem with old IBM computers".

foonathan,
@foonathan@fosstodon.org avatar

@deepbluev7 The government wants to seize the German branches of Russian gas companies but according to trade treaties with the Soviet Union or sth Russia would be entitled to compensation.

foonathan,
@foonathan@fosstodon.org avatar

@deepbluev7 Don't worry, they found some legal workaround.

foonathan, to random
@foonathan@fosstodon.org avatar

If you're in Berlin, I'll be giving my talk "A deep dive into dispatching techniques" as part of the Humboldt university's Programming in C lecture on Thursday 15:00!

The event is free to attend, but register here: https://forms.office.com/e/8Br6nV99TA

More info: https://www.linkedin.com/posts/think-cell_on-may-30-2024-we-are-thrilled-to-return-activity-7200786899190333440-tcYD?utm_source=share&utm_medium=member_android

foonathan,
@foonathan@fosstodon.org avatar

@jeslas It's about optimizing switch statements.

pervognsen, to random
@pervognsen@mastodon.social avatar

There's a bunch of C-like successor languages that say they want to eliminate undefined behavior. I've never been able to figure out how they intend to deal with reads and writes to memory since a lot of these languages take what I would call the "naive" machine-centric view of memory which is hard to reconcile with source-level semantics for variables, etc. You can't really rename all of this stuff as "implementation-defined" and get out of jail for free.

foonathan,
@foonathan@fosstodon.org avatar

@pervognsen I think some of them just use "undefined behavior" to mean "compiler optimizes away overflow checks", and don't consider basic load/store elimination to leverage UB.

foonathan,
@foonathan@fosstodon.org avatar

@pervognsen I think it's also just a lot of semantic arguing about the meaning of undefined behavior, see e.g. my Twitter conversation here: https://x.com/Jonathan_Blow/status/1696277362529485112?t=9t95NOQKoz1_GGGop7f9fg&s=19

pervognsen, (edited ) to random
@pervognsen@mastodon.social avatar

Just ran the yyjson benchmark on my laptop (AMD Ryzen 9 5900HX). I've looked a little bit at its code and on the surface it really has no business being this fast considering it uses very few tricks. Time for some careful study...

foonathan,
@foonathan@fosstodon.org avatar

@pervognsen I love how there is just this corpus of random JSON files everybody uses for benchmarks :D

pervognsen, (edited ) to random
@pervognsen@mastodon.social avatar

For people who've been around much longer, has there been any retrospectives on Rust's decision to allow panics to unwind rather than abort? I've mostly come to terms with it in a practical sense but it's something that really "infects" the language and library ecosystem at a deep level, e.g. fn(&mut T) isn't "the same" as fn(T) -> T and it's especially troublesome if you're writing unsafe library code and dynamically calling code through closures or traits that could potentially panic.

foonathan,
@foonathan@fosstodon.org avatar
chandlerc, to random
@chandlerc@hachyderm.io avatar

C++ data structure API design question...

What are folks favorite ways to design a data structure that supports users providing two closely coupled custom functions? Why that pattern?

Specifically, imagine a hash table data structure that wants to allow users to deeply customize both the hash function and the equality comparison.

Current ideas, w/o ranking or even saying I like them, and interested in others:

  • A type parameter with static functions
  • two lambda template parameters
  • CRTP
foonathan,
@foonathan@fosstodon.org avatar

@chandlerc I wouldn't go with CRTP for that as it's kind of the wrong way around. I use CRTP when I want to get some boilerplate implementation for my type, not to customize something in a different type. This is especially true if the customization doesn't inject state as I assume is the case here.

So I'd go with a HashPolicy template parameter and static functions in there.

foonathan,
@foonathan@fosstodon.org avatar

@chandlerc I just find inheritance annoying to deal with. You have to manually pull in the constructor, write a protected destructor, name lookup is annoying when everything is templated and you call stuff from the base etc.

If you need state, you can also store the Policy class as a member.

foonathan,
@foonathan@fosstodon.org avatar

@chandlerc CRTP is getting a lot nicer with deducing this at least, then you don't need the Derived template parameter anymore.

There are still problems with getting typedefs from the Derived type, since it is incomplete in during the signatures and stuff...

zwarich, to random
@zwarich@hachyderm.io avatar

The worst realization that you’re aging is searching for something on Math Overflow and realizing that you answered it 8 years ago.

foonathan,
@foonathan@fosstodon.org avatar

@zwarich A couple days ago I've watched a lightning talk I gave in 2018.

Learned something new.

pervognsen, (edited ) to random
@pervognsen@mastodon.social avatar

How much RAM do you have in your dev workstation/laptop?

foonathan,
@foonathan@fosstodon.org avatar

@pervognsen 512GB, but I also have 128 cores or so.

foonathan,
@foonathan@fosstodon.org avatar

@pervognsen (because compiling C++ is slow...)

foonathan,
@foonathan@fosstodon.org avatar

@vitaut @pervognsen I have seen "compiler is out of heap space" error messages with MSVC.

foonathan, to cpp
@foonathan@fosstodon.org avatar

I've written a trip report for C++Now 2024, one of the best conferences I've ever attended: https://www.think-cell.com/en/career/devblog/trip-report-cpp-now-2024

vitaut, to random
@vitaut@mastodon.social avatar

Me waiting for Cassio Neri's C++ Now talk about the new FP to string conversion algorithm to be published.

foonathan,
@foonathan@fosstodon.org avatar
foonathan,
@foonathan@fosstodon.org avatar

@dougmerritt @vitaut Yes, the algorithm is a lot simpler than I thought as well!

lesley, to rust
@lesley@mastodon.gamedev.place avatar

#rust noob question: is there a way to "catch one kind of error and propagate the other" with something cleaner than this?

#rustlang

foonathan,
@foonathan@fosstodon.org avatar

@lesley You generally want to stay in the monad if you want to avoid manual matching: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=1b795b9c952fcec028b82e5384cc55fe

foonathan, to random
@foonathan@fosstodon.org avatar
foonathan,
@foonathan@fosstodon.org avatar

@vitaut Not yet, he'll also open source it soon.

But it's really really simple, I almost could re-derive it once after watching his talk.

foonathan, (edited ) to random
@foonathan@fosstodon.org avatar

Hypothetically, consider the following pattern matching syntax in C++:

expr match {
x => ...
}

What should this mean?
A - match expr against the existing constant x
B - match everything and introduce the name x for expr

foonathan,
@foonathan@fosstodon.org avatar

@pervognsen That's also what I prefer, but the committee didn't like that (not my paper).

foonathan,
@foonathan@fosstodon.org avatar

@thibault There is going to be syntax to match against types, yes.

  • All
  • Subscribed
  • Moderated
  • Favorites
  • megavids
  • thenastyranch
  • rosin
  • GTA5RPClips
  • osvaldo12
  • love
  • Youngstown
  • slotface
  • khanakhh
  • everett
  • kavyap
  • mdbf
  • DreamBathrooms
  • ngwrru68w68
  • provamag3
  • magazineikmin
  • InstantRegret
  • normalnudes
  • tacticalgear
  • cubers
  • ethstaker
  • modclub
  • cisconetworking
  • Durango
  • anitta
  • Leos
  • tester
  • JUstTest
  • All magazines