Safe Static Initialization, No Destruction

Since I joined Google Brain, I brought PyTorch to Google's internal infra and owned its maintenance. Being a "tech island", it's well known that almost everything in Google works differently from the outside world, and that creates many challenges when building a massive library like PyTorch.

Among those challenges, there are a few tricky bugs related to static initialization order fiasco (SIOF) and their destructions. This time I was forced to learn a lot more details than I'd like to know about these topics, so it's good to write them down before I forget.

Read more

Patching STB_GNU_UNIQUE of Buggy Binaries

开源工具链里有很多陈年小 "feature", 最初由于各种原因 (例如作为 workaround) 实现了之后, 即使语义模糊或设计不合理, 也因为兼容性被留到了今天.

Read more

Explode Tuple in C++11

std::tuple 是 C++11 中的一个好东西. 它功能上算是std::pair 的扩展, 但有一些其他的用法.

例如, 可以借用 tuple 来模拟多值返回 (Python 中也是这样), SugarCpp 中就是使用 tuple 实现了简洁的多值返回语法:

tuple<T, T> sort<T>(a: T, b: T)
    return a < b ? (a, b) : (b, a)

tuple 也可以用于模拟 Python 中的 Parallel Assignment:

Read more