ralf-jung
12 articles
如何用“讲故事”模型将内联汇编融入 Rust
Translated
AI Summary
eng
[AI 摘要] 本文提出了“讲故事”模型,通过要求内联汇编提供对应的Rust代码描述来将其融入Rust的抽象机语义,以确保与优化和安全性兼容。
View content
<p>Rust 抽象机中充满了在<a href="/blog/2020/12/14/provenance.html">实际硬件上不存在</a>的<a href="/blog/2019/07/14/uninit.html">奇妙细节</a>。不可避免地,每次讨论这些时,总会有人问:“但如果我使用内联汇编呢?那指针来源、未初始化内存、树形借用以及你们发明的这些实际不存在的‘有趣’东西会怎样?”</p>
<p>这是个好问题,但要正确回答需要一些功夫。在这篇文章中,我将通过提出一个<em>通用原则</em>来阐述当前对内联汇编如何融入 Rust 抽象机的思考:该原则解释了我们对纯 Rust 语义的任何决定如何影响内联汇编可以或不可以做什么。</p>
<!-- MORE -->
<p>请注意,我在这里讨论的所有内容同样适用于外部函数接口调用,就像适用于内联汇编一样。这两种机制本质上非常相似:它们都允许 Rust 代码调用非 Rust 编写的代码。<sup id="fnref:xlang"><a href="#fn:xlang" class="footnote" rel="footnote" role="doc-noteref">1</a></sup> 我不会在文章中反复重复“内联汇编或 FFI”,但每次我提到内联汇编时,也包含了 FFI。</p>
<p>首先,让我解释一下为什么有些事情是内联汇编从根本上就不允许做的。</p>
<h2 id="why-cant-inline-assembly-do-whatever-it-wants">为什么内联汇编不能为所欲为?</h2>
<p>人们喜欢认为内联汇编能让他们摆脱抽象机所有复杂的要求。不幸的是,那只是个空想。下面是一个示例来证明这一点:</p>
<div class="language-rust highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">use</span> <span class="nn">std</span><span class="p">::</span><span class="nn">arch</span><span class="p">::</span><span clas…
Show original
<p>The Rust Abstract Machine is full of <a href="/blog/2020/12/14/provenance.html">wonderful oddities</a> that do not exist on the <a href="/blog/2019/07/14/uninit.html">actual hardware</a>.
Inevitably, every time this is discussed, someone asks: “But, what if I use inline assembly? What happens with provenance and uninitialized memory and Tree Borrows and all these other fun things you made up that don’t actually exist?”
This is a great question, but answering it properly requires some effort.
In this post, I will lay down my current thinking on how inline assembly fits into the Rust Abstract Machine by giving a <em>general principle</em> that explains how anything we decide about the semantics of pure Rust impacts what inline assembly may or may not do.</p>
<!-- MORE -->
<p>Note that everything I discuss here applies to FFI calls just as much as it applies to inline assembly.
Those mechanisms are fundamentally very similar: they allow Rust code to invoke code not written in Rust.<s…
Miri(还有,我们发表了一篇关于Miri的论文!)有什么“新”内容?
Translated
AI Summary
eng
[AI 摘要] 本文更新了Miri未定义行为检测工具的最新进展,包括新增的垫片支持、诊断改进、性能优化、并发支持增强,并宣布相关论文被POPL 2026会议收录。
View content
<p>又到了写一篇“Miri近况如何”博文的时候了。
事实上,这确实<em>拖得太久了</em>,上一次<a href="/blog/2022/07/02/miri.html">更新</a>已经是三年前的事了(时间到底是什么东西?!),但确实越来越难找到时间写博客了,所以……我们就这样吧。
迟到总比不到好。:)</p>
<p>对于不熟悉的人,<a href="https://github.com/rust-lang/miri/">Miri</a> 是一个用于Rust的<a href="https://doc.rust-lang.org/reference/behavior-considered-undefined.html">未定义行为</a>测试工具。
这意味着它可以发现你unsafe代码中的bug,这些bug未能遵守诸如“所有访问必须对齐”、“可变引用绝不能别名”或“绝对不能有数据竞争”之类的要求。
Miri的成名之处在于它是一个实用工具,能够发现<em>所有确定性Rust程序中事实上的未定义行为</em>。
据我所知,没有其他免费工具能做到这一点——对任何语言来说都是如此。<!-- MORE --><sup id="fnref:relwork"><a href="#fn:relwork" class="footnote" rel="footnote" role="doc-noteref">1</a></sup></p>
<p>我们只能谈论<em>事实上的未定义行为</em>,因为Rust尚未稳定其未定义行为的定义。
为此,我们仔细检查编译器的行为,尽最大努力确保Rust程序<em>当前</em>可能遇到的所有未定义行为都被Miri捕获。
这意味着通过Miri测试的程序应该能在<em>当前</em>的编译器上正确编译,但同一个程序在未来可能会遭受未定义行为。
此外,如果Rust程序是<em>非确定性</em>的,意味着它可以有多种执行方式,而Miri只会执行一次。
你可以使用 <code class="language-plaintext highlighter-rouge">-Zmiri-many-seeds</code> 让Miri随机探索多种可能的执行,但总可能还有Miri尚未发现的执行路径。
这是所有测试工具的根本局限;你通常需要借助模型检查或演绎验…
Show original
<p>It is time for another “what is happening in Miri” post.
In fact this is <em>way</em> overdue, with the <a href="/blog/2022/07/02/miri.html">previous update</a> being from more than 3 years ago (what even is time?!?), but it is also increasingly hard to find the time to blog, so… here we are.
Better late than never. :)</p>
<p>For the uninitiated, <a href="https://github.com/rust-lang/miri/">Miri</a> is an <a href="https://doc.rust-lang.org/reference/behavior-considered-undefined.html">Undefined Behavior</a> testing tool for Rust.
This means it can find bugs in your unsafe code where you failed to uphold requirements like “all accesses must be aligned” or “mutable references must never alias” or “there must not be any data races”.
Miri’s claim to fame is that it is a practical tool that can find <em>all de-facto Undefined Behavior in deterministic Rust programs</em>.
To my knowledge, no other freely available tool can claim this—for any language.<!-- MORE --><sup id="fnref:relwork">…
无线程安全,便无内存安全
Translated
AI Summary
eng
[AI 摘要] 本文论证了线程安全是真正内存安全的必要条件,并以Go语言为例,说明数据竞争如何导致内存破坏。
View content
<p>内存安全如今风头正劲。
但这个词究竟意味着什么?
事实证明,其定义可能比你想象的更难界定。
通常,人们用这个术语来指代那些确保程序中不存在释放后使用或越界内存访问的语言。
这常被视为与其他安全概念(如线程安全)的区别,后者指的是程序不存在某些并发错误。
然而,本文将论证这种区分意义不大,我们真正希望程序拥有的特性是<em>消除未定义行为</em>。</p>
<!-- MORE -->
<h2 id="breaking-memory-safety-with-a-data-race">通过数据竞争破坏内存安全</h2>
<p>我对安全概念被细分为内存安全、线程安全等细粒度类别存在一个主要疑问:一个线程不安全的语言无法以任何有意义的方式提供内存安全。
要理解我的意思,请看这个用Go编写的程序,根据<a href="https://en.wikipedia.org/wiki/Go_(programming_language)">维基百科</a>,Go是内存安全的:</p>
<div class="language-go highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">package</span> <span class="n">main</span>
<span class="c">// 仅作为一个任意接口,以便后续使用接口类型。</span>
<span class="k">type</span> <span class="n">Thing</span> <span class="k">interface</span> <span class="p">{</span>
<span class="n">get</span><span class="p">()</span> <span class="kt">int</span>
<span class="p">}</span>
<span class="c">// 两种实现接口的类型,具有非常不同类型的字段。</span>
<span class="k">type</span> <span class="n">Int</span> <span class="k">struct<…
Show original
<p>Memory safety is all the rage these days.
But what does the term even mean?
That turns out to be harder to nail down than you may think.
Typically, people use this term to refer to languages that make sure that there are no use-after-free or out-of-bounds memory accesses in the program.
This is then often seen as distinct from other notions of safety such as thread safety, which refers to programs that do not have certain kinds of concurrency bugs.
However, in this post I will argue that this distinction isn’t all that useful, and that the actual property we want our programs to have is <em>absence of Undefined Behavior</em>.</p>
<!-- MORE -->
<h2 id="breaking-memory-safety-with-a-data-race">Breaking memory safety with a data race</h2>
<p>My main issue with the division of safety into fine-grained classes such as memory safety and thread safety is that there’s no meaningful sense in which a thread-unsafe language provides memory safety.
To see what I mean by this, consider this p…
Tree Borrows论文终于发表了
Translated
AI Summary
eng
[AI 摘要] Tree Borrows论文已发表并获PLDI杰出论文奖,其形式化证明和广泛评估得到了认可。
View content
<p>经过数年的工作,我们的Tree Borrows论文最近终于在首尔举行的PLDI 2025大会上进行了展示。
与之前在这个博客和<a href="https://perso.crans.org/vanille/treebor/">Neven的网站</a>上提到的内容相比,Tree Borrows本身并没有太大变化。
我们利用所有额外的时间进行了<em>形式化证明</em>,以证明Tree Borrows确实允许我们期望从中获得的至少部分优化,并对crates.io上下载量最高的30,000个crate进行了广泛的Tree Borrows评估。
这一集实现、证明和评估于一体的综合成果给PLDI程序委员会留下了深刻印象,使我们获得了<em>杰出论文奖</em>。:-)
非常感谢Neven和Johannes的所有辛勤工作,并祝贺他们完成了一篇了不起的论文!</p>
<p>如果您想亲自查阅论文,所有内容均可<a href="https://plf.inf.ethz.ch/research/pldi25-tree-borrows.html">在开放获取下查看</a>。
Neven精彩的论文介绍演讲<a href="https://www.youtube.com/watch?v=CJi_Fcs4bak">可在此处找到</a>。</p>
Show original
<p>After several years of work, our Tree Borrows paper has finally been presented recently at PLDI 2025 in Seoul.
Tree Borrows has not changed much compared to what has previously been mentioned in this blog and on <a href="https://perso.crans.org/vanille/treebor/">Neven’s website</a>.
We used all that extra time for <em>formal proofs</em> that Tree Borrows indeed allows at least some of the optimizations that we hope to gain from it,
and to carry out an extensive evaluation of Tree Borrows on the 30 000 most-downloaded crates on crates.io.
This overall package of implementation, proof, and evaluation impressed the PLDI program committee enough that we got a <em>distinguished paper award</em>. :-)
Thanks a lot to Neven and Johannes for all the hard work and congratulations on an amazing paper!</p>
<p>If you want to check out the paper yourself, everything is <a href="https://plf.inf.ethz.ch/research/pldi25-tree-borrows.html">available under open access</a>.
Neven’s amazing talk presen…
MiniRust的当前状态
Translated
AI Summary
eng
[AI 摘要] 该文介绍了演讲者在RustWeek上关于MiniRust作为unsafe Rust规约工具的当前进展的分享。
View content
<p>几周前,许多Rust爱好者在乌得勒支参加了RustWeek,我们都度过了愉快的时光。
作为活动的一部分,我做了一个题为“MiniRust:一个用于规约Rust的核心语言”的演讲,介绍了MiniRust的现状。
这是我在一个(满座的)电影院里第一次发表演讲;不幸的是,我的特效预算无法赶上通常在那里放映的节目水平。
不过,如果您想了解更多关于我如何规约unsafe Rust复杂细节的愿景,<a href="https://www.youtube.com/watch?v=yoeuW_dSe0o">请观看我的演讲视频</a>。 :)</p>
<p>感谢在场所有人的精彩聆听,也感谢组织者带来了精彩的一周和高质量的录像!</p>
Show original
<p>A few weeks ago, many Rust folks met in Utrecht for RustWeek and we all had a great time.
As part of that, I also gave a talk titled “MiniRust: A core language for specifying Rust” about the current state of MiniRust.
This was my first time giving a talk in a (fully packed) movie theater; unfortunately, my special effects budget cannot keep up with the shows that would usually be presented there.
But nevertheless, if you would like to learn more about my vision for how we should specify the gnarly details of unsafe Rust, <a href="https://www.youtube.com/watch?v=yoeuW_dSe0o">please go watch my talk</a>. :)</p>
<p>Thanks to everyone who was there for being a great audience, and thanks to the organizers for an amazing week and high-quality recordings!</p>
Rustlantis:基于随机化差异测试的Rust编译器模糊测试
Translated
AI Summary
eng
[AI 摘要] 该论文介绍了通过随机生成MIR程序并跨后端/优化级别对比行为的方式,对Rust编译器进行模糊测试,从而发现了22个新缺陷。
View content
<p>我们团队产出的首篇论文最近在OOPSLA会议上发表。:)
这篇论文通过随机生成MIR程序,并确保这些程序在不同后端、不同优化级别以及Miri中行为一致,实现了对Rust编译器优化和代码生成阶段的模糊测试。
该工作的核心部分由Andy(王乾)在其<a href="https://ethz.ch/content/dam/ethz/special-interest/infk/inst-pls/plf-dam/documents/StudentProjects/MasterTheses/2023-Andy-Thesis.pdf">硕士论文</a>中完成。
这本已是一篇出色的论文,但Andy在开始全职工作后仍持续推进,最终成就了这篇非常优秀的论文。
他共计在Rust编译器中发现了22个新缺陷,其中12个位于已受到前人广泛模糊测试的LLVM后端。</p>
<p>要了解更多信息,请<a href="https://plf.inf.ethz.ch/research/oopsla24-rustlantis.html">查阅论文</a>或<a href="https://www.youtube.com/watch?v=kHYEHSHLffU&t=20447s">观看Andy的演讲</a>(时间戳链接可能不稳定,若未自动跳转可手动定位至5小时40分处)。</p>
Show original
<p>The first paper produced entirely by my group has recently been published at OOPSLA. :)
The paper is about fuzzing the optimizations and code generation of the Rust compiler by randomly generating MIR programs and ensuring they behave the same across different backends, different optimization levels, and in Miri.
The core part of this work was done by Andy (Qian Wang) for his <a href="https://ethz.ch/content/dam/ethz/special-interest/infk/inst-pls/plf-dam/documents/StudentProjects/MasterTheses/2023-Andy-Thesis.pdf">master thesis</a>.
This was already a strong thesis, but Andy kept working on this even after he started having a regular dayjob, and we ended up with a very nice paper.
In total, he found 22 new bugs in the Rust compiler, 12 of them in the LLVM backend that has already been extensively fuzzed by prior work.</p>
<p>To learn more, <a href="https://plf.inf.ethz.ch/research/oopsla24-rustlantis.html">check out the paper</a> or <a href="https://www.youtube.com/watch?v=kHYEHSH…
什么是位置表达式?
Translated
AI Summary
eng
[AI 摘要] 本文解释了 Rust 中位置表达式与值表达式的区别,以及隐式加载操作如何影响未定义行为。
View content
<p>Rust 语言中一个比较微妙的方面是,实际上存在两种表达式:<em>值表达式</em>和<em>位置表达式</em>。大多数时候,程序员不需要过多思考这种区别,因为 Rust 会在遇到一种表达式但期望另一种时,自动插入转换。然而,在编写 unsafe 代码时,正确理解这种表达式的二分法可能是必要的。请看以下<a href="https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=9a8802d20da16d6569510124c5827794">示例</a>:</p>
<div class="language-rust highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c1">// 作为“packed”结构体,此类型的对齐要求为 1。</span>
<span class="nd">#[repr(packed)]</span>
<span class="k">struct</span> <span class="n">MyStruct</span> <span class="p">{</span>
<span class="n">field</span><span class="p">:</span> <span class="nb">i32</span>
<span class="p">}</span>
<span class="k">let</span> <span class="n">x</span> <span class="o">=</span> <span class="n">MyStruct</span> <span class="p">{</span> <span class="n">field</span><span class="p">:</span> <span class="mi">42</span> <span class="p">};</span>
<span class="k">let</span> <span class="n">ptr</span> <span class="o">=</sp…
Show original
<p>One of the more subtle aspects of the Rust language is the fact that there are actually two kinds of expressions:
<em>value expressions</em> and <em>place expressions</em>.
Most of the time, programmers do not have to think much about that distinction, as Rust will helpfully insert automatic conversions when one kind of expression is encountered but the other was expected.
However, when it comes to unsafe code, a proper understanding of this dichotomy of expressions can be required.
Consider the following <a href="https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=9a8802d20da16d6569510124c5827794">example</a>:</p>
<div class="language-rust highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c1">// As a "packed" struct, this type has alignment 1.</span>
<span class="nd">#[repr(packed)]</span>
<span class="k">struct</span> <span class="n">MyStruct</span> <span class="p">{</span>
<span class="n">field</span><span clas…
Google开源同行奖
Translated
AI Summary
eng
[AI 摘要] 作者收到谷歌开源同行奖后误以为是诈骗,确认真实后将奖金捐给了隐私保护组织。
View content
<p>我们大家都习惯收到垃圾邮件,这些邮件据称来自谷歌,内容是“你赢了”,然后我只需发送所有个人数据到某个地方就能领取彩票奖金。最近当我收到一封关于谷歌“开源同行奖”计划的邮件时,我差点把它当作另一种垃圾邮件丢弃了。但事实证明,有时候这些邮件竟然是真的!与此同时,<a href="https://opensource.googleblog.com/2023/12/google-open-source-peer-bonus-program-announces-second-group-of-2023-winners.html">官方公告</a>已经发布,将我列为该奖金的获得者,以感谢我在Rust语言方面的工作。所以这一次,它确实不是垃圾邮件!</p>
<!-- MORE -->
<p>非常感谢谷歌的这项计划,提供了250美元的奖励;看到开源工作能得到这样的表彰,真是太棒了。我已经将这笔款项全额捐赠给了<a href="https://noyb.eu/en">noyb</a>,我相信他们会将这笔钱用于<a href="https://noyb.eu/en/noyb-win-first-major-fine-eu-1-million-using-google-analytics">正当事业</a>。</p>
<p><strong>更新(2024-01-07):</strong>
事实上,这已经是我第二次获得谷歌开源同行奖了。第一次是在<a href="https://opensource.googleblog.com/2023/05/google-open-source-peer-bonus-program-announces-first-group-of-winners-2023.html">2023年上半年</a>。由于支付流程问题,那笔奖金延迟了一段时间才到账,但我现在可以确认它已经到达我的银行账户。我得找个合适的非营利组织捐赠这笔钱……或者也可能再次捐给noyb,我们拭目以待。
<strong>/更新</strong></p>
Show original
<p>We are all used to spam emails, supposedly from Google, that say “You won” and I just need to send all my data to somewhere to receive my lottery payout.
When I recently received an email about Google’s “Open Source Peer Bonus” program, I almost discarded it as yet another version of that kind of spam.
But it turns out sometimes these emails are real!
Meanwhile the <a href="https://opensource.googleblog.com/2023/12/google-open-source-peer-bonus-program-announces-second-group-of-2023-winners.html">official announcement</a> has been released which lists me as a recipient of this bonus as a thank you for my work on Rust.
So this one time, it wasn’t spam after all!</p>
<!-- MORE -->
<p>Thanks a lot to Google for this program at the $250 reward; it is great to see open source work honored this way.
I have donated the amount in full to <a href="https://noyb.eu/en">noyb</a>, who I’m sure will be using it <a href="https://noyb.eu/en/noyb-win-first-major-fine-eu-1-million-using-google-anal…
谈论未定义行为、不安全 Rust 和 Miri
Translated
AI Summary
eng
[AI 摘要] 作者在苏黎世 Rust 聚会上讲解了未定义行为、不安全 Rust 和 Miri,并分享了录像。
View content
<p>我最近在苏黎世的本地 Rust 聚会上做了一次关于未定义行为、不安全 Rust 和 Miri 的演讲。
录像可以在<a href="https://www.youtube.com/watch?v=svR0p6fSUYY">这里</a>观看。
它针对的是熟悉 Rust 但对不安全代码的细节不熟悉的听众,所以我希望你们中很多人会喜欢它!
玩得开心。:)</p>
Show original
<p>I recently gave a talk at a local Rust meetup in Zürich about Undefined Behavior, unsafe Rust, and Miri.
The recording is available <a href="https://www.youtube.com/watch?v=svR0p6fSUYY">here</a>.
It targets an audience that is familiar with Rust but not with the nasty details of unsafe code, so I hope many of you will enjoy it!
Have fun. :)</p>
从栈到树:Rust 的一种新别名模型
Translated
AI Summary
eng
[AI 摘要] 树借用是 Rust 的一种新别名模型,旨在解决栈借用过早强制唯一性等主要问题,通过两阶段借用和延迟初始化等机制提供更多灵活性。
View content
<p>自去年秋天以来,<a href="https://perso.crans.org/vanille/">Neven</a> 一直在实习,为 Rust 开发一种新的别名模型:树借用(Tree Borrows)。等一下,你可能会说——Rust 不是已经有一个别名模型了吗?Ralf 不是总在谈论那个“栈借用(Stacked Borrows)”吗?确实有,但栈借用只是一个可能别名模型的提案——它<a href="https://github.com/rust-lang/unsafe-code-guidelines/issues/133">存在</a><a href="https://github.com/rust-lang/unsafe-code-guidelines/issues/134">着</a><a href="https://github.com/rust-lang/unsafe-code-guidelines/issues/256">相当</a><a href="https://github.com/rust-lang/unsafe-code-guidelines/issues/274">多</a><a href="https://github.com/rust-lang/unsafe-code-guidelines/issues/276">的</a><a href="https://github.com/rust-lang/unsafe-code-guidelines/issues/303">问题</a>。树借用旨在吸收从栈借用中学到的经验,构建一个问题更少的新模型,并做出一些不同的设计决策,以便我们在为 Rust 确定正式模型之前,了解这些模型可能涉及的权衡和微调。</p>
<p>Neven 在<a href="https://perso.crans.org/vanille/treebor/">他的博客</a>上撰写了一篇关于树借用的详细介绍,你应该先去阅读一下。他在最近的一次 RFMIG 会议上做了这个报告,所以你也可以<a href="https://www.youtube.com/watch?v=zQ76zLXesxA">观看他的演讲</a>。在本文中,我将重点介绍与栈借用的区别。我假设你已经了解栈借用,并想理解树借用带来了哪些变化以及原因。</…
Show original
<p>Since last fall, <a href="https://perso.crans.org/vanille/">Neven</a> has been doing an internship to develop a new aliasing model for Rust: Tree Borrows.
Hang on a second, I hear you say – doesn’t Rust already have an aliasing model?
Isn’t there this “Stacked Borrows” that Ralf keeps talking about?
Indeed there is, but Stacked Borrows is just one proposal for a possible aliasing model – and it <a href="https://github.com/rust-lang/unsafe-code-guidelines/issues/133">has</a> <a href="https://github.com/rust-lang/unsafe-code-guidelines/issues/134">its</a> <a href="https://github.com/rust-lang/unsafe-code-guidelines/issues/256">fair</a> <a href="https://github.com/rust-lang/unsafe-code-guidelines/issues/274">share</a> <a href="https://github.com/rust-lang/unsafe-code-guidelines/issues/276">of</a> <a href="https://github.com/rust-lang/unsafe-code-guidelines/issues/303">problems</a>.
The purpose of Tree Borrows is to take the lessons learned from Stacked Borrows to build a new model with…
cargo careful:以额外的谨慎调试检查运行你的Rust代码
Translated
AI Summary
eng
[AI 摘要] 文章介绍了 cargo careful,一个运行 Rust 代码时增强调试检查以检测未定义行为的工具。
View content
<p>你知道吗?标准库中充满了用户从未见过的有用检查。标准库中有许多调试断言,它们会检查诸如 <code class="language-plaintext highlighter-rouge">char::from_u32_unchecked</code> 是否被调用于有效的 <code class="language-plaintext highlighter-rouge">char</code>,<code class="language-plaintext highlighter-rouge">CStr::from_bytes_with_nul_unchecked</code> 是否没有内部空字节,或者指针函数如 <code class="language-plaintext highlighter-rouge">copy</code> 或 <code class="language-plaintext highlighter-rouge">copy_nonoverlapping</code> 是否被调用于适当对齐的非空(且不重叠)指针。然而,由 rustup 分发的常规标准库是在没有调试断言的情况下编译的,因此用户无法轻松受益于所有这些额外检查。</p>
<!-- MORE -->
<p><a href="https://github.com/RalfJung/cargo-careful"><code class="language-plaintext highlighter-rouge">cargo careful</code></a> 正是为了弥合这一差距而生:首次调用时,它会从源码构建带有调试断言的标准库,然后使用该标准库运行你的程序或测试套件。安装 <code class="language-plaintext highlighter-rouge">cargo careful</code> 就像 <code class="language-plaintext highlighter-rouge">cargo install cargo-careful</code> 一样简单,之后你可以执行 <code class="language-plaintext highlighter-rouge">cargo +nightly careful run<…
Show original
<p>Did you know that the standard library is full of useful checks that users never get to see?
There are plenty of debug assertions in the standard library that will do things like check that <code class="language-plaintext highlighter-rouge">char::from_u32_unchecked</code> is called on a valid <code class="language-plaintext highlighter-rouge">char</code>, that <code class="language-plaintext highlighter-rouge">CStr::from_bytes_with_nul_unchecked</code> does not have internal nul bytes, or that pointer functions such as <code class="language-plaintext highlighter-rouge">copy</code> or <code class="language-plaintext highlighter-rouge">copy_nonoverlapping</code> are called on suitably aligned non-null (and non-overlapping) pointers.
However, the regular standard library that is distributed by rustup is compiled without debug assertions, so there is no easy way for users to benefit from all this extra checking.</p>
<!-- MORE -->
<p><a href="https://github.com/RalfJung/cargo-careful">…
新的开始
Translated
AI Summary
eng
[AI 摘要] 文章宣布作者将于11月1日起在ETH苏黎世担任助理教授,并表达了激动、感激及对未来的期待。
View content
<p>我有一些非常激动人心的消息要分享:从11月1日起,我将在ETH苏黎世担任助理教授!
成为教授本身就是一个梦想成真,而能在ETH苏黎世这样的地方当教授更是我从未敢梦想过的事。
我仍然不敢相信这真的发生了(我要当<em>教授</em>了???),但<a href="https://twitter.com/CSatETH/status/1548944615285350400">消息已经公布</a>,所以我想这是真的。:D</p>
<!-- MORE -->
<p>我感到既兴奋又恐惧,而且两者的程度差不多。
兴奋于所有新的可能性,期待与学生合作并激励下一代研究者;
恐惧于所有的责任,以及几个月后就得站在教室里讲课的前景。
但不知为何,其他人似乎都相信我能做到,所以我想我只好顺其自然,希望不会让他们失望……</p>
<p>我也深感谦卑,并永远感激能获得这个机会。
能在ETH这样的环境中工作是无法想象的特权,我不知道自己怎么如此幸运。
我可能用尽了今生所有的福报,我会尽我所能不辜负这份特权。
我深深感激所有与我共事过的人,首先当然是我的博士导师<a href="https://people.mpi-sws.org/~dreyer/">Derek Dreyer</a>。
但我也特别想感谢Rust社区,因为我认为如果没有Rust就不会有这一切——感谢<em>每一位</em>为这门语言做出贡献的人,我基本上是依托它建立自己的事业<sup id="fnref:rust"><a href="#fn:rust" class="footnote" rel="footnote" role="doc-noteref">1</a></sup>,特别感谢那些包容我对Rust如何处理不安全代码的想法、并帮助我塑造语言这一部分的人。</p>
<p>那么接下来呢?
我即将完成在MIT的博士后研究,搬回欧洲,然后于10月搬到苏黎世。
接着我就得弄明白当教授是怎么回事了。;)
我的首要任务是建立一个研究团队:“编程语言基础实验室”<sup id="fnref:lab"><a href="#fn:lab" class="footnote" rel="footnote" role="doc-noteref">2</a></sup>。
因此,如果你有兴趣攻读博士或从事博士后研究,研究,嗯,编程语言基础…
Show original
<p>I have some very exciting news to share: starting November 1st, I will work at ETH Zürich as an assistant professor!
Becoming a professor in the first place is a dream come true, and becoming a professor at a place like ETH Zürich is not something I even dared to dream of.
I still cannot quite believe that this is actually happening (I will be <em>professor</em>?!??), but <a href="https://twitter.com/CSatETH/status/1548944615285350400">the news is out</a> so I guess this is real. :D</p>
<!-- MORE -->
<p>I feel excited and terrified in about equal parts.
Excited by all the new possibilities, by the prospect of working with students and inspiring the next generation of researchers;
terrified by all the responsibility and the prospect of having to stand in a classroom and give a lecture in only a few months’ time.
But somehow everyone else seems confident that I can do this, so I guess I’ll just play along and hope that I will not prove them wrong…</p>
<p>I am also humbled and etern…