On 25/08/2012 12:36 PM, Patrick Walton wrote:
Hi everyone,

Currently, the keyword "extern" is highly overloaded. "extern" has the
following meanings:

1. "extern fn" in a type means "a function that closes over nothing" (at
least at one point; if this has already changed then disregard.)

I'd get rid of this, yes. Confusing. Niko suggests this can go away, yes?

2. "extern fn" in a declaration means "a function callable as a callback
from C to Rust". In this case the type is actually *u8, not "extern fn".
The latter means something completely different -- namely, (1) above --
a fact that causes numerous problems, including the inability to write
generic callbacks.

3. "extern mod foo { ... }" means "a module of C functions in a native
library called foo".

4. "extern mod foo;" means "link to the Rust crate named foo".

I agree with your proposed (a) and (b) changes. Or at least (b). I don't understand (a) enough to comment, Niko suggests maybe the problem can evaporate, which is fine by me. 'extern' should probably be a full function type qualifier though (or indeed, 'extern ["linkage"]' as in C), if it's not already.

Concerning the #3 and #4 points above, and generally their interaction with #2: these all mean something similar to what they mean in C++. Some combination of:

  - "this thing participates in linkage in a not-purely-local way"
  - "possibly let me declare this thing without defining it"

I'd like to go a bit further down the road we've sketched out for these 3 first (in particular: allowing non-defining 'extern' item declarations such as function signatures and const declarations at random locations, etc.)

I think parsimony with keywords is warranted here as 2/3 of the uses are infrequent in "most" rust programs, just libraries that interface to C code; that's a majority _today_ but I assume/hope it won't be forever. Moreover, the other 1/3 is still infrequent on a source-file-by-source-file basis, only written once-per-linkage (i.e. all in one file, in a large multi-file project).

If case #4 continues to be a thorn (eg. in small one-file programs) I'd be ... disappointed, but ok switching it back to "link". But that's not entirely clear to me yet.

(It may also be worth considering the extent to which 'extern "rust" foo' is equivalent to formalizing the lazily-imported-item concept that we were discussing yesterday at the language level, and whether that carries any additional benefits relative to hiding it as an implementation technique...)

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

Reply via email to