Hacker News new | past | comments | ask | show | jobs | submit login

Rust's borrow checker isn't a type system. It's a static analyzer that tries to determine if it can figure out when to free your allocation.



Why do you think that’s not a type system?

Literally all type systems could be described as “a static analyzer” that tries to assign and validate properties over the code it’s analyzing.

All compilers also rely on the results of that static analysis to direct codegen.

Rust’s type system implements substructural typing, and the borrow checker is an integral element of that type system.


Based on your definition, then any static analyzer is a type system, because type information and the usage of those types is basically all that’s available for static analysis.

Types define what operations can be performed. The borrow checker looks at allocations and determines when they can be freed. It really has nothing to do with types. An ideal implementation of the borrow checker could be totally type unaware and work with dynamically typed languages.


> It really has nothing to do with types.

I was under the impression that it's substantially an implementation of an affine type system (https://en.m.wikipedia.org/wiki/Substructural_type_system).

Probably you could build such a thing without thinking about types per-se, but I don't think the designers of Rust did that, and I am not sure that makes it "not a type system" anyway.

> any static analyzer is a type system

"Any static analysis checking correctness is either a linter or a type checker" isn't a claim I would make, but I am not sure offhand how I would argue against it.


I'm not deeply familiar with Rust borrow checker, but my understanding is that Swift will in the near-future support move only types. Are those not somewhat similar to what Rust has?

See here for more re Swift: https://github.com/apple/swift/blob/main/docs/OwnershipManif...


> Rust's borrow checker isn't a type system

No, it's the thing that enforces a type system.

The borrow/move semantics it enforces are a (part of a) type system.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: