Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change "use" to "extern mod" #2082

Closed
andrew-d opened this issue Mar 30, 2012 · 17 comments
Closed

Change "use" to "extern mod" #2082

andrew-d opened this issue Mar 30, 2012 · 17 comments
Assignees
Labels
A-linkage Area: linking into static, shared libraries and binaries C-cleanup Category: PRs that clean code up or issues documenting cleanup.
Milestone

Comments

@andrew-d
Copy link
Contributor

Hello,

I was recently reading about the 0.2 release of Rust, and it looks really interesting! One thing that bugged me that I wanted to bring up - I'm not a fan of the "crust" keyword. The word "crust" has an intrinsic meaning in English, and my brain insists on reading it incorrectly at first read. I'd like to suggest changing it to "externc", which mimics C's extern "C", and also doesn't have any other intrinsic meaning.

Thanks!

@graydon
Copy link
Contributor

graydon commented Mar 30, 2012

We're likely to take the word extern to stand in for native in the current module-declaration scheme. But I agree that these two matters ought to be unified. Here's my suggestion:

  • Differentiate declarations and definitions. For both consts and fns. See Allow referencing non-function symbols in native modules #1071
  • An extern module is one that is full of declarations only.
  • A declaration is only legal when qualified with extern explicitly, or implicitly within an extern module.
  • A definition might be extern as well. If so, it's equivalent to today's crust fn types. That is: by placing extern on a definition you're saying you want to make that definition visible-and-usable to external language/linkage rules.
  • We define a default interpretation of the ABI-and-language-rules-you-mean when you say extern, and permit overriding that by attributes rather than fixed strings. The default is C and cdecl or something.

@graydon
Copy link
Contributor

graydon commented Mar 30, 2012

I've upgraded this to RFC an edited the title. Hope that's ok with the original reporter.

@andrew-d
Copy link
Contributor Author

@graydon: Fine with me :-)

@brson
Copy link
Contributor

brson commented Mar 31, 2012

All those suggestions sound reasonable to me. In particular I would prefer to be able to declare externs outside of native mods (or get rid of native mods completely)

@brson
Copy link
Contributor

brson commented Mar 31, 2012

I do think I would prefer to just get rid of native mods. Perhaps the ABI and whatever options can be associated with the current scope, so a native mod would just be a mod tagged with the requested ABI and filled with externs.

@nikomatsakis
Copy link
Contributor

I like it, although it seems like an extern prototype and an extern declaration are basically overloaded uses of the same keyword. But I guess that's ok. And extern is certainly better than crust.

@graydon
Copy link
Contributor

graydon commented Mar 31, 2012

Re: getting rid of naive mods, I thought about this but thought maybe having the symbols scoped to a module is useful since it gives you an item to hang the library name off of. Maybe that doesn't matter as much as I think, though.

(also saves you writing extern over and over)

@pcwalton
Copy link
Contributor

pcwalton commented Apr 1, 2012

Could we just have extern blocks like C++ and allow people to hang the library name off any module, not just native ones? That'd eliminate the complexity of native mod while still keeping the programmer-convenience aspect.

@jsternberg
Copy link
Contributor

@nikomatsakis I like @graydon's suggestion. It seemed like an overloaded use of the word "extern", but if you view the word "extern" as just "uses the C ABI", then I think it makes more sense. To call into rust from C, you need to declare the function as using the C ABI using extern. To call into C from rust, you need to do the same thing.

@graydon
Copy link
Contributor

graydon commented May 2, 2012

@pcwalton I suppose we could do that, yes. In general we haven't any support for item-qualifier blocks yet (eg. extern blocks, pub / priv blocks, unsafe blocks for globals as in #553) but I'm not opposed to that approach. It'll take a bit of legwork, is all.

Library names on arbitrary modules will probably come to pass as part of #2176, though I am not sure. Lots of interdependencies in this cluster of bugs, sadly.

@graydon
Copy link
Contributor

graydon commented Jun 23, 2012

Thinking about this more, here's the organization I propose (also in light of @pcwalton's renaming-modules thing required for the rewrite of resolve in #1935, and @brson's suggestion that we squish .rs and .rc files together in #2176):

  • use std becomes extern mod std;
  • use std (k=v, a=b); becomes extern mod std = (k=v, a=b);
  • native mod foo { ... } becomes extern mod foo { ... }
  • crust fn foo(...) { ... } becomes extern fn foo(...) { ... }
  • mod std = path::to::other is used to alias mods in a crate.
  • mod std = "path/in/filesystem" is used to compile-in other mods, as in crate files.
  • mod std; is equal to mod std = "std"; as in crate files.
  • import foo becomes use foo
  • export foo becomes pub foo ... on the item
  • ABIs, link-args on the current crate, etc. all remain in attrs

That is: we lose the keywords use, native and crust, import and export. We express most stuff through extern.

The first step in making this is just to make extern work for crust and native presently.

@graydon
Copy link
Contributor

graydon commented Jun 26, 2012

First step on this landed in 697f1e3. extern is now recognized where native and crust were. Need a snapshot to purge the remainder. All uses of "native" nomenclature in the compiler have changed to "foreign" to distinguish from other sorts of extern.

(I hope this doesn't wind up too ambiguous when hacking on the compiler. I think losing the extra keywords is the right thing. Hope!)

@nikomatsakis
Copy link
Contributor

+1 for extern mod in place of use. That's clever.

@z0w0
Copy link
Contributor

z0w0 commented Jul 7, 2012

I'm also loving the idea of extern mod, because it makes it easier to get rid of cargo and unify it with the single rust tool idea. That way, it could potentially lead to a URL rather than a file path. e.g. extern mod sdl = "git://github.com/brson/rust-sdl.git/sdl.rs"; or extern mod sdl = "http://libsdl.org/rustpkg.tar.gz/sdl.rs";.

@pcwalton
Copy link
Contributor

pcwalton commented Aug 7, 2012

Updated title (was "RFC: Change 'crust' to 'extern'") to reflect the work that remains on this bug.

@ghost ghost assigned pcwalton Aug 31, 2012
@pcwalton
Copy link
Contributor

pcwalton commented Sep 6, 2012

This works now. Snapshot needed to remove old syntax.

@brson
Copy link
Contributor

brson commented Sep 29, 2012

I think we can call this done, though there's still some cleanup work left and we may yet change extern mod to something else. Will open another issue for purging export

@brson brson closed this as completed Sep 29, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-linkage Area: linking into static, shared libraries and binaries C-cleanup Category: PRs that clean code up or issues documenting cleanup.
Projects
None yet
Development

No branches or pull requests

7 participants