Personal channel of @lancern
Topics: programming, hacking, memes, life, and more. Forward anything as you wish.
Join the discussion group for more fun.
Discord: https://discord.gg/RwUx9et7
Topics: programming, hacking, memes, life, and more. Forward anything as you wish.
Join the discussion group for more fun.
Discord: https://discord.gg/RwUx9et7
Speeding up ELF relocations for store-based systems https://fzakaria.com/2024/05/03/speeding-up-elf-relocations-for-store-based-systems.html
A High-Level Technical Overview of Homomorphic Encryption https://www.jeremykun.com/2024/05/04/fhe-overview/
Flying planes in Microsoft Flight Simulator with a JavaScript autopilot (2023) https://pomax.github.io/are-we-flying/
A History of C Compilers – Part 1: Performance, Portability and Freedom https://thechipletter.substack.com/p/a-history-of-c-compilers-part-1-performance
祝各位订户五一假期快乐!✈️✈️✈️
Why SQLite Uses Bytecode https://sqlite.org/draft/whybytecode.html
A leadership crisis in the Nix community https://lwn.net/SubscriberLink/970824/0d89c6d83efad1e0/
Zed Decoded: Rope and SumTree https://zed.dev/blog/zed-decoded-rope-sumtree
TypeScript: Branded Types https://prosopo.io/articles/typescript-branding/
Borrow Checking, RC, GC, and the Eleven () Other Memory Safety Approaches https://verdagon.dev/grimoire/grimoire
今日修水管
最近一两周发现家里的水压出奇地低。我住在一栋电梯楼内的三层,照理水压不应该低。刚开始以为是市政供水的问题,但低水压情况持续了好几天没有缓解。遂前往我所在楼层的水表间尝试定位并修复该问题。
在家中水龙头全部关闭的情况下,水表没有走表。这说明家庭管路内没有漏水等情况。
我所在楼层共有四户住户,四根入户水管以并联形式直接连接到单元楼内的一根主供水管道上。在邻居用水时观察邻居的水表走表情况,发现其走表速度明显高于我用水时的走表速度。说明问题出在我家的入户水管上。这一小段入户水管上有且仅有水表以及三个阀门。这四个设备按照从上游到下游排列分别为:阀门 A、阀门 B、阀门 C 和水表。其中阀门 A 和阀门 C 上直接有可供手拧的阀门开关。尝试分别将这两个阀门拧到最大,但问题并没有消失。于是将注意力集中于阀门 B 。
阀门 B 上没有可供手拧的开关,有且仅有一个螺栓和一个压力表。经检查,在不用水时,该压力表显示读数与邻居的压力表读数一致。该读数应该就是单元楼主供水管道内的压力值。在用水时,我家的压力表读数为 0,而在邻居用水时其压力表读数并不为 0 。
上网查阅相关资料可知,阀门 B 是一个减压阀,相关资料指出减压阀上的螺栓可用于调节输出压力。遂翻出扳手等工具相应调节减压阀的螺栓。经过反复调节后,家中的水压恢复了正常。因此问题的原因是我家的减压阀因某种原因被拧了。
最近一两周发现家里的水压出奇地低。我住在一栋电梯楼内的三层,照理水压不应该低。刚开始以为是市政供水的问题,但低水压情况持续了好几天没有缓解。遂前往我所在楼层的水表间尝试定位并修复该问题。
在家中水龙头全部关闭的情况下,水表没有走表。这说明家庭管路内没有漏水等情况。
我所在楼层共有四户住户,四根入户水管以并联形式直接连接到单元楼内的一根主供水管道上。在邻居用水时观察邻居的水表走表情况,发现其走表速度明显高于我用水时的走表速度。说明问题出在我家的入户水管上。这一小段入户水管上有且仅有水表以及三个阀门。这四个设备按照从上游到下游排列分别为:阀门 A、阀门 B、阀门 C 和水表。其中阀门 A 和阀门 C 上直接有可供手拧的阀门开关。尝试分别将这两个阀门拧到最大,但问题并没有消失。于是将注意力集中于阀门 B 。
阀门 B 上没有可供手拧的开关,有且仅有一个螺栓和一个压力表。经检查,在不用水时,该压力表显示读数与邻居的压力表读数一致。该读数应该就是单元楼主供水管道内的压力值。在用水时,我家的压力表读数为 0,而在邻居用水时其压力表读数并不为 0 。
上网查阅相关资料可知,阀门 B 是一个减压阀,相关资料指出减压阀上的螺栓可用于调节输出压力。遂翻出扳手等工具相应调节减压阀的螺栓。经过反复调节后,家中的水压恢复了正常。因此问题的原因是我家的减压阀因某种原因被拧了。
2024 年 4 月 Tokyo 会议后一些频道主认为有意思的 C++ 标准提案
P1061R8: Structured Bindings can introduce a Pack
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p1061r8.html
允许结构化绑定引入 pack :
P2034R3: Partially Mutable Lambda Captures
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p2034r3.pdf
允许分别将每个 lambda 捕获声明为 mutable 了:
P2135R1: P2055R1: A Relaxed Guide to memory_order_relaxed
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p2135r1.pdf
一篇科普性质文章,介绍 C++11 relaxed 内存序的原子操作的 out-of-thin-air 现象以及 read-from-untaken-branch 现象,以及如何在已有程序中识别潜在的相关问题
P2141R2: Aggregates are named tuples
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p2141r2.html
让
P2747R2: constexpr placement new
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p2747r2.html
让 placement-new 成为 core constant expression
P2748R5: Disallow Binding a Returned Glvalue to a Temporary
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p2748r5.html
当函数返回一个引用时,不再允许这个引用绑定到临时对象上,杜绝一类 use-after-free 缺陷:
P2988R4: std::optional<T&>
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p2988r4.pdf
给
逐步氧化起来了
P3166R0: Static Exception Specifications
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p3166r0.html
又要搞大新闻,重新引入了之前被废弃的
一个亮点是允许使用
与老式
按照这样的设计编译器理论上可以把所有带有
P3176R0: The Oxford variadic comma
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p3176r0.html
不再允许不带前导逗号的 ellipsis parameter :
P1061R8: Structured Bindings can introduce a Pack
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p1061r8.html
允许结构化绑定引入 pack :
std::tuple<X, Y, Z> f();
auto [...xs] = f(); // OK
auto [x, ...rest] = f(); // OK
auto [x,y,z, ...rest] = f(); // OK
auto [x, ...rest, z] = f(); // OK
P2034R3: Partially Mutable Lambda Captures
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p2034r3.pdf
允许分别将每个 lambda 捕获声明为 mutable 了:
auto a = [mutable x, y]() {
x = 1; // OK
y = 2; // Error
};
P2135R1: P2055R1: A Relaxed Guide to memory_order_relaxed
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p2135r1.pdf
一篇科普性质文章,介绍 C++11 relaxed 内存序的原子操作的 out-of-thin-air 现象以及 read-from-untaken-branch 现象,以及如何在已有程序中识别潜在的相关问题
P2141R2: Aggregates are named tuples
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p2141r2.html
让
std::get
, std::tuple_element
以及 std::tuple_size
等实现 tuple protocol 的 STL 函数和 type traits 原生支持 aggregate 类型:struct Foo { int x; double y; std::string z; };
Foo x{1, 2.0, "3"};
std::get<1>(x); // Evaluate to 2.0
static_assert(std::is_same_v<
std::string,
typename std::tuple_element<2, Foo>::type
>); // OK
static_assert(std::tuple_size<Foo> == 3); // OK
P2747R2: constexpr placement new
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p2747r2.html
让 placement-new 成为 core constant expression
P2748R5: Disallow Binding a Returned Glvalue to a Temporary
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p2748r5.html
当函数返回一个引用时,不再允许这个引用绑定到临时对象上,杜绝一类 use-after-free 缺陷:
const int &foo() {
return 42; // Ill-formed
}
P2988R4: std::optional<T&>
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p2988r4.pdf
给
std::optional
引入 std::optional<T&>
特化,可以实现用 std::optional
上的 monadic 操作替换一堆空指针判断逐步氧化起来了
P3166R0: Static Exception Specifications
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p3166r0.html
又要搞大新闻,重新引入了之前被废弃的
throw
声明符,可以用于声明一个函数所能够抛出的所有可能的异常类型:void throws_nothing() throw(); // Effectively `noexcept`
void throws_a_b() throw(A, B); // throws_a_b can throw A or B
void throws_any() throw(...); // throws_any may throw any exception
一个亮点是允许使用
throw(auto)
自动推导函数可能抛出的异常类型集合:void foo() throw(auto) { /* ... */ }
与老式
throw
声明符的本质区别在于编译器会强制检查异常集合的正确性。如果函数带有 throw
声明符但却可能抛出没有通过 throw
声明符声明的异常,那么程序 ill-formed:void foo() throw(A) {
throws_a_b(); // Ill-formed: B is not listed above
try {
throws_a_b(); // Ill-formed: B is not caught
}
catch (A) {}
try {
throws_a_b(); // OK since B will be caught
}
catch (A) {}
catch (B) {}
}
按照这样的设计编译器理论上可以把所有带有
throw
声明符的函数的异常路径算得明明白白,可以开始优化 try-catch 路径了(例如把 throw-catch 直接优化为 goto)。P3176R0: The Oxford variadic comma
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p3176r0.html
不再允许不带前导逗号的 ellipsis parameter :
void foo(int ...); // Ill-formed