Skip to content Skip to footer
0 items - $0.00 0

How does Ada’s memory safety compare against Rust? by pabs3

How does Ada’s memory safety compare against Rust? by pabs3

11 Comments

  • Post Author
    ajxs
    Posted February 10, 2025 at 5:34 am

    Author here: Thank you so much for posting! Happy to answer any questions anyone might have about the article.

  • Post Author
    bawolff
    Posted February 10, 2025 at 5:35 am

    I don't program in rust or ada, however it seems like such a comparison is missing important details. After all, if memory safety was all that mattered we'd all be using python. The thing that gets people excited about rust is not just memory safety but the tradeoffs taken to make that happen.

  • Post Author
    mustache_kimono
    Posted February 10, 2025 at 5:40 am

    Very interesting and timely especially since I see the following so often:

    > Why wouldn’t the Linux kernel team choose Ada instead of Rust?

    To which I say: Ada doesn't have a large user base beyond DOD projects. Virtually no greenfield projects except for DOD. Whereas there has been a Cambrian explosion of Unix kernels/tools/servers written in Rust.

    More generally, these questions of the form "Why are you ignoring X?" where X is Ada or Zig or C++ are really "Why didn't you write/don't you rewrite this in Rust?" by a different name.

    And my/that answer goes both ways. Notably, Roc recently has stated it is moving away from Rust. Ghostty uses Zig because Mitchell Hashimoto doesn't like Rust. But the answer is always someone has to show up and do the work, usually because they like doing the work in some language.

    So — it's okay to like the project strictly because of the language chosen. That being said — I'm super interested in the more technical differences.

  • Post Author
    pjmlp
    Posted February 10, 2025 at 6:18 am

    Directly using Unchecked_Deallocation is frowned upon, either use ControlledTypes (which the article mentions), or Bound/Unbounded Collections (which the article misses).

    Using it directly is similar to the usual discussion of using unsafe in Rust for double linked lists.

    As of Ada 202x, SPARK covers most of the language, no longer a subset, and also does affine types, aka borrow checking.

  • Post Author
    trott
    Posted February 10, 2025 at 7:51 am

    > but Ada's real strengths lie elsewhere. Its strong typing,

    Ada is not actually type-safe: https://www.enyo.de/fw/notes/ada-type-safety.html

  • Post Author
    roydivision
    Posted February 10, 2025 at 7:51 am

    I thought this would be comparing Rust to Ada Lovelace's code…

    And I've coded in Ada…

  • Post Author
    renox
    Posted February 10, 2025 at 8:25 am

    > [about Ada] You never miss worrying about whether a parameter is passed by value or reference

    Uh? I thought that Ada suffered from the "aliasing issue"(1): given that the compiler choose whether to copy or alias, there is a risk that the semantic of your program change when the compiler/optimisation change, am I wrong?

    1: if you have a function with two parameters, one "in" and the other "inout" and you pass the same variable to the two parameters.

  • Post Author
    Yoric
    Posted February 10, 2025 at 8:28 am

    Thank you very much!

    I have been attempting to compare Ada and Rust for a while, but never got around to doing it quite so much in depth.

    So, my take on this is that:

    – out of the box, Rust is distinctly better at memory safety than Ada without SPARK

    – Ada + SPARK is extremely powerful (but iirc, SPARK doesn't allow compositional reasoning, which makes it harder to use in a crate-based library)

    – for this specific use case, Rust's error model makes much more sense than Ada's (with or without SPARK)

    – Ada's tooling to avoid memory allocation remain more powerful in some dimensions than Rust's.

    Also, I think that we all (should) agree that the move towards memory safety in system-level programming is a very good thing, whether it comes through Rust, Ada, or any other language.

  • Post Author
    kennysoona
    Posted February 10, 2025 at 9:03 am

    The SPARK subset of ADA really seems the best here, but doesn't seem anywhere near as fun to write as Rust, or have anywhere near the amount of libraries available. The community is much smaller also, and I think community counts for a lot here. The takeaway is Rust, really is, really really great. It's fantastic there is so much documentation and such a strong community, and that so many people are invested in writing safe code because it's finally easy to do so.

  • Post Author
    transpute
    Posted February 10, 2025 at 9:22 am

    Ada+Rust (2022), https://blog.adacore.com/adacore-and-ferrous-systems-joining…

    > Ferrous Systems and AdaCore are.. joining forces to develop Ferrocene – a safety-qualified Rust toolchain, which is aimed at supporting the needs of various regulated markets, such as automotive, avionics, space, and railway.. qualifying the Ferrocene Rust compiler according to various safety standards.. [including] development and qualification of the necessary dynamic and static analysis tools.. our long-term commitment to Rust and Ada extends to developers who will be using both languages at the same time. We are looking at interoperability between them – including, in particular, the idea of developing bi-directional binding generators.

    Nvidia uses Ada/SPARK for formally-verified security firmware on RISC-V cores on GPUs [1] and SPDM attestation of devices like GPUs and Infiniband NICs [2].

    [1] https://blog.adacore.com/when-formal-verification-with-spark… & https://static.sched.com/hosted_files/riscvsummit2024/fe/Key…

    [2] https://www.adacore.com/papers/nvidia-using-recordflux-and-s… & https://docs.nvidia.com/networking/display/nvidiadeviceattes…

  • Post Author
    vlovich123
    Posted February 10, 2025 at 9:39 am

    > Nothing prevents you from writing Ada code that dereferences an access type after it's been freed; However any access dereference triggers a runtime check to ensure it's non-null. Unlike in C, freeing an access type in Ada automatically sets its value to null, and any subsequent attempt to dereference it will raise a Constraint_Error exception, which can be caught and handled.

    > Ada has its own nomenclature for multithreading: Tasks, and provides its own built-in mechanism for preventing data races between them. Ada's Protected Objects encapsulate data inside an implicit mutex, allowing only one thread access at a time via a public interface.

    I believe ADA doesn’t have a guarantee that you are accessing data thread safely. And that lack of guarantee is where use-after-free and double-free can hide. Heck, you don’t even need any threading.

    1. Create an alias

    2. Free the original value

    3. Access the alias

    If I read it correctly, the variable holding the original value is reset to null after a free but the alias can still access freed memory.

    TLDR: Rust has almost no competitors when it comes to the very robust safety guarantees it makes and none when you combine with the performance niche it services.

Leave a comment

In the Shadows of Innovation”

© 2025 HackTech.info. All Rights Reserved.

Sign Up to Our Newsletter

Be the first to know the latest updates

Whoops, you're not connected to Mailchimp. You need to enter a valid Mailchimp API key.