4 ms·
> "it's best that people document/annotate their types, > so we require it." That may be how people interpret it (I'd be surprised to find that line in any
by kibwen 10y ago
> "it's best that people document/annotate their types,
> so we require it."
That may be how people interpret it (I'd be surprised to find that line in any official source), but the reason for this choice was ultimately technical, not philosophical. Having function signatures be the ultimate source of truth means that the typechecker can ignore function bodies entirely, which has large implications for the design of the type system and the layout of the compiler pipeline, and more importantly this feature enables fine-grained incremental recompilation at the function level (i.e., if the body of a function changes but its signature does not, then the compiler knows that consumers of that function do not need to be recompiled and can skip an enormous amount of work (assuming that inlining is minimal, which is indeed the case in debug mode, where incremental recompilation is intended to shine)). We're not taking advantage of incremental recompilation yet, but it (along with speeding up the compiler in general, as corroborated by the survey) is the primary goal of the compiler team this year (the prerequisite overhaul of the compiler middle-end is just about to land: https://github.com/rust-lang/rust/milestones/Launch%20MIR%20into%20Orbit https://github.com/rust-lang/rust/milestones/Launch%20MIR%20... ).
- MichaelGG 10y agoNot official, but a Rust team member: "it's generally regarded as best practice to write out the types of your functions, hence Rust's choice here. ... Rust follows 'explicit over implicit'"[1] If it's a technical limitation then that's far more understandable. I've just not heard this explanation until now -- not that I really was seeking it I suppose. Thank you. 1: https://news.ycombinator.com/item?id=8321443 https://news.ycombinator.com/item?id=8321443