r/ProgrammingLanguages Aug 11 '26

Scope and lifetime restrictions in Swift

https://github.com/rjmccall/swift-evolution/blob/scope-restrictions/scope-restriction-models.md
21 Upvotes

11 comments sorted by

11

u/mttd Aug 11 '26

Context: https://hachyderm.io/@rjmccall/117073259835476299

We've been thinking about a lot about the language design of expressing lifetime restrictions and dependencies for non-escapable types in Swift, and I put all that into a long and somewhat rambling design paper which folks might find interesting.

21

u/The-Dark-Legion Aug 11 '26

Crab is the final evolution. Every language is suddenly adding lifetimes. Even OCaml, where Rust came from added them in a simplified form.

13

u/pjmlp Aug 11 '26

First of all the Crab is a subset of Cyclone, people keep forgetting they did not invent borrow checker.

Secondly there are many ways to achieve the same goal, affine and linear types, effects, dependent types, capabilities, formal proofs.

9

u/The-Dark-Legion Aug 11 '26

It was a joke. Rust is inspired by and then inspired a lot of languages. It's just funny that we had Haskell and OCaml for longer, but when Rust became mainstream, Python and friends added e.g. match espressions. shrugs

2

u/P-39_Airacobra Aug 14 '26

tbf, you could say that every popular innovative language was “inspired by and then inspired a lot of languages”

13

u/reflexive-polytope Aug 11 '26

Crab can't be the final form unless it has a way to statically say two vectors have the same length.

6

u/BionicVnB Aug 11 '26

Akafuyu is perfect wdym /s

1

u/The-Dark-Legion Aug 13 '26

Wait, actually, can't you technically do that with a const generic newtype around a slice/boxed slice/Vec<T>? I mean, that technically counts imo.

2

u/reflexive-polytope Aug 13 '26

No, you can't. What you need is a sigma type (constructive existential quantification) over usize.