#prog #rust #article
Four limitations of Rust's borrow checker
In this post, I’ll cover four surprising limitations of the borrow checker that I ran into in the course of my work.
Also note that when I say something can’t be done, I mean that it can’t be done in a way that leverages Rust’s type system, i.e. with static type checking. <...>. It’s never the case that you literally can’t solve a problem at all, since there are always those escape hatches (and I’ll even show examples of an escape hatch I used below), but it is impossible to solve the problem in a way that makes Rust Rust.
Four limitations of Rust's borrow checker
In this post, I’ll cover four surprising limitations of the borrow checker that I ran into in the course of my work.
Also note that when I say something can’t be done, I mean that it can’t be done in a way that leverages Rust’s type system, i.e. with static type checking. <...>. It’s never the case that you literally can’t solve a problem at all, since there are always those escape hatches (and I’ll even show examples of an escape hatch I used below), but it is impossible to solve the problem in a way that makes Rust Rust.
Considerations on Codecrafting
Four limitations of Rust’s borrow checker
I’ve been using Rust for hobby projects since 2016 and have been working professionally in Rust since 2021, so I tend to consider myself pretty knowledgeable about Rust. I’m already familiar with all the common limitations of Rust’s type system and how to…
🤔3
Куплю на Новый год много шоколадных яиц
Съем их все
И буду говорить, что полон сюрпризов
Съем их все
И буду говорить, что полон сюрпризов
😁17🤡13❤9🤯1🌚1
Блог*
Юрист (муж. р., ед. число) — поклонник жанра юри
Тотализатор (муж. р., ед. ч.) — человек, устанавливающий тоталитаризм
🤡15💯6🌚3😁2🤮1
#prog #rust #article
Compiling C to Safe Rust, Formalized (PDF)
<...> We instead explore a different path, and explore what it would take to translate C to safe Rust; that is, to produce code that is trivially memory safe, because it abides by Rust's type system without caveats. Our work sports several original contributions: a type-directed translation from (a subset of) C to safe Rust; a novel static analysis based on "split trees" that allows expressing C's pointer arithmetic using Rust's slices and splitting operations; an analysis that infers exactly which borrows need to be mutable; and a compilation strategy for C's struct types that is compatible with Rust's distinction between non-owned and owned allocations.
We apply our methodology to existing formally verified C codebases: the HACL* cryptographic library, and binary parsers and serializers from EverParse, and show that the subset of C we support is sufficient to translate both applications to safe Rust. Our evaluation shows that for the few places that do violate Rust's aliasing discipline, automated, surgical rewrites suffice; and that the few strategic copies we insert have a negligible performance impact.
По понятным причинам подход авторов покрывает лишь некоторое подмножество C, но вроде достаточно обширное для написания реалистичных программ.
Парочка претензий:
1. Написанный авторами инструмент пока что отсутствует в публичном доступе, поскольку "will be made public after the review process" (который, судя по всему, ещё не пройден).
2. Два примера кодовых баз, на которых автора проверяли свой инструмент, не были написаны изначально на C, а были написаны, как DSL в F* (для верификации одновременно с трансляцией в C) — на более реалистичных программах подход может показать себя менее эффективно.
Compiling C to Safe Rust, Formalized (PDF)
<...> We instead explore a different path, and explore what it would take to translate C to safe Rust; that is, to produce code that is trivially memory safe, because it abides by Rust's type system without caveats. Our work sports several original contributions: a type-directed translation from (a subset of) C to safe Rust; a novel static analysis based on "split trees" that allows expressing C's pointer arithmetic using Rust's slices and splitting operations; an analysis that infers exactly which borrows need to be mutable; and a compilation strategy for C's struct types that is compatible with Rust's distinction between non-owned and owned allocations.
We apply our methodology to existing formally verified C codebases: the HACL* cryptographic library, and binary parsers and serializers from EverParse, and show that the subset of C we support is sufficient to translate both applications to safe Rust. Our evaluation shows that for the few places that do violate Rust's aliasing discipline, automated, surgical rewrites suffice; and that the few strategic copies we insert have a negligible performance impact.
По понятным причинам подход авторов покрывает лишь некоторое подмножество C, но вроде достаточно обширное для написания реалистичных программ.
Парочка претензий:
1. Написанный авторами инструмент пока что отсутствует в публичном доступе, поскольку "will be made public after the review process" (который, судя по всему, ещё не пройден).
2. Два примера кодовых баз, на которых автора проверяли свой инструмент, не были написаны изначально на C, а были написаны, как DSL в F* (для верификации одновременно с трансляцией в C) — на более реалистичных программах подход может показать себя менее эффективно.
arXiv.org
Compiling C to Safe Rust, Formalized
The popularity of the Rust language continues to explode; yet, many critical codebases remain authored in C, and cannot be realistically rewritten by hand. Automatically translating C to Rust is...
👍10🔥1🤡1🌚1
#prog #rust #article
Fish 4.0: The Fish Of Theseus
Довольно подробно описывают различные моменты, возникшие во время переписывания. Советую к прочтению — возможно, портирование далеко не так сложно для вашего проекта, как кажется.
The port wasn’t without challenges, and it did not all go entirely as planned. But overall, it went pretty dang well. We’re now left with a codebase that we like a lot more, that has already gained some features that would have been much more annoying to add with C++, with more on the way, and we did it while creating a separate 3.7 release that also included some cool stuff.
(thanks @teamerlin)
Fish 4.0: The Fish Of Theseus
Довольно подробно описывают различные моменты, возникшие во время переписывания. Советую к прочтению — возможно, портирование далеко не так сложно для вашего проекта, как кажется.
The port wasn’t without challenges, and it did not all go entirely as planned. But overall, it went pretty dang well. We’re now left with a codebase that we like a lot more, that has already gained some features that would have been much more annoying to add with C++, with more on the way, and we did it while creating a separate 3.7 release that also included some cool stuff.
(thanks @teamerlin)
Fishshell
Fish 4.0: The Fish Of Theseus
A smart and user-friendly command line shell
🥰11
Forwarded from Awful Rust snippets for fun and profit
parsing sequences (like dates or version strings) by matching on part index
playground
original example
thanks to @kanashimia for suggesting this one!
playground
original example
thanks to @kanashimia for suggesting this one!
❤10👎3👍1
Forwarded from brain_leakage_etc
TIL, что GitHub ещё и STL умеет рендерить нынче (у меня 3D-принтера нет, так что я как-то это новшество упустил). Узнал о такой функциональности, решив взглянуть, как выглядит результат генерации этих весёлых ёлочных игрушек: https://github.com/joe-warren/christmas-ornaments/blob/main/haskell-ornament.stl
GitHub
christmas-ornaments/haskell-ornament.stl at main · joe-warren/christmas-ornaments
Contribute to joe-warren/christmas-ornaments development by creating an account on GitHub.
❤11
Мальчик: хвастается перед друзьями новой машиной
Мужчина: хвастается перед друзьями новыми джинсами
Мужчина: хвастается перед друзьями новыми джинсами
🌚12👍5