On 15/08/2010 11:39 PM, ori bar wrote:

I always wondered about this, what is wrong with specifying in a
language that if a function only consists of 'ret<const-expr>' then
it is compiled as a constant? I know C++ started doing something like
this with constexprs and I think it might be the good approach for
this as well instead of adding another feature to the language (then
again, the ability to differentiate between constants and function
calls by looking at the code where the symbol is referred has an
appeal of it's own).

Hm. I'm not sure what you mean in terms of C++ doing this.

You have to consider cases wherein the caller doesn't statically know that the callee is constant. Indirect calls, intra-linkage-unit calls, that sort of thing. In these cases, there needs to be code sitting around to be-called, because the caller will have a call instruction that needs to jump to some code.

Some languages uniformly treat all values as callable (or "enterable") thunks. Haskell for example. This treatment is, I think, somewhat costly, and certainly unusual enough to present difficulties integrating with debuggers, FFIs, or other tools with a more "static" view of data.

While it's possible, I think I don't want to go down this sort of road. I'd prefer to get to a place where being-read-only was a semantic category. It's a guarantee programmers certainly know how to reason about and, I think, like: knowing something has been compiled into read-only memory means hardware memory protection against mutation, plus you know startup costs will be "mmap + relocs", quite fast.

(Aside: It would also force us to untangle any residual mess in the effect system regarding lies-about-mutability. Obviously you can't cast hardware-protected read-only memory to mutable and expect it to work!)

(Aside #2: I do *not* want to get into a situation where we have .ctors or any kind of global static initializers that have to run on startup. That's a terrible botch. Relocs are one thing, but they should be the limit!)

-Graydon

_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to