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

Reevaluate extern mod as syntax for importing crates. #9880

Closed
brson opened this issue Oct 15, 2013 · 21 comments · Fixed by #12272
Closed

Reevaluate extern mod as syntax for importing crates. #9880

brson opened this issue Oct 15, 2013 · 21 comments · Fixed by #12272
Labels
A-grammar Area: The grammar of Rust E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.
Milestone

Comments

@brson
Copy link
Contributor

brson commented Oct 15, 2013

It's not that well loved. It doesn't have anything to do with other uses of extern, and lexically it must be written in a different position than other extern things.

@brson
Copy link
Contributor Author

brson commented Oct 15, 2013

Nominating.

@catamorphism
Copy link
Contributor

+1. I always feel embarrassed when I have to explain this to someone.

@Kimundi
Copy link
Member

Kimundi commented Oct 16, 2013

The mod part is also confusing, as it doesn't declare a new module, but rather create an import of an external binaries crate root.

For example, this creates two interchangeable paths to the same module tree:

extern mod extra;
mod foo {
    extern mod extra;
}

While this creates two distinct modules:

mod extra;
mod foo {
    mod extra;
}

@catamorphism
Copy link
Contributor

1.0, backcompat

@brson
Copy link
Contributor Author

brson commented Oct 31, 2013

"crate" seems to be the consensus.

@brson
Copy link
Contributor Author

brson commented Jan 27, 2014

@huonw can mentor

@huonw
Copy link
Member

huonw commented Jan 27, 2014

If someone does want some mentorship, feel free to contact me by commenting here, on IRC (nick: dbaupp) or via email (in my profile).

@flaper87
Copy link
Contributor

I'll work on this one

@thestinger
Copy link
Contributor

I like extern mod, as it works the same way as a mod statement but includes an external module rather than an internal one via source code. I think the term crate is very much insider Rust jargon and won't be as helpful for a newcomer. I don't think this is why people have trouble with Rust's module system.

@eddyb
Copy link
Member

eddyb commented Jan 29, 2014

Do we really want to add another keyword with just one use case?
And so I'm not completely negative, I see two other ways we can say extern crate without crate being a keyword:

// A procedural macro can expand to an ExternCrate AST node.
extern_crate! extra;
// Similar here, though attributes may not map as well to the AST.
#[extern_crate(extra)];
// These should still work (do we allow visibility on extern mod?):
#[cfg(foo="bar")]
pub extern_crate! foobar;

@sfackler
Copy link
Member

Would crate really need to be an extra keyword? Is there any reason that the compiler can't special case a crate ident coming after an extern keyword?

@flaper87
Copy link
Contributor

@sfackler not 100% but I think that in the case of extern mod it is already treated as an ident.

@Kimundi
Copy link
Member

Kimundi commented Jan 30, 2014

For the record, extern mod does not currently work the same as mod:

  • Like mod, it adds new definitions to be usable from inside the crate.
  • But like use, multiple extern mod statements that refer to the same crate refer to the same definitions, and the items in them can be used interchangeably.

Example:

extern mod extra; 
mod foo { 
    extern mod extra; 
    pub fn bar() { 
        let x: ::extra::arc::Arc<uint> = ::foo::extra::arc::Arc::new(5u); 
        println!("{:?}", x); 
    }
} 
fn main() {
    foo::bar(); 
}

@lilyball
Copy link
Contributor

@sfackler I would like to see context-sensitive keywords as you suggest, but I don't believe Rust currently has any. If we were to start using context-sensitive keywords, I'd also like to see in (from for _ in ..) made context-sensitive.

@flaper87
Copy link
Contributor

@brson What is the final decision here?

@glaebhoerl
Copy link
Contributor

@Kimundi what about changing extern mod to be like mod then, and have each extern mod declaration be considered distinct (even if, under the hood, they may not be)?

(But they also maybe may be, if you're using package IDs or attributes or whatever to bring in e.g. different versions of the same library. Of course you could check "are these extern mods actually referring to the same thing" (and perhaps we already do?), but if they're always distinct then you don't have to care.)

@brson
Copy link
Contributor Author

brson commented Jan 31, 2014

@flaper87 let's make crate a full keyword. It can be contextualized later if we agree on it.

@flaper87
Copy link
Contributor

@brson roger that!

@thestinger
Copy link
Contributor

I still don't think adding a crate keyword is a good idea. The extern mod statement should work the same way as mod, but include an external module rather than a file. I don't think the crate terminology is going to be accessible to those who aren't familiar with the language. It's a Rust-specific term unlike module or library.

It would be simple enough to change the mod statement to refer to the same module when a file is included in more than one place in the tree.

@liigo
Copy link
Contributor

liigo commented Feb 4, 2014

+1 for extern crate xxx, xxx here is crate not mod.
2014年2月4日 上午7:04于 "Daniel Micay" notifications@github.com写道:

I still don't think adding a crate keyword is a good idea. The extern modstatement should work the same way as
mod, but include an external module rather than a file. I don't think the
crate terminology is going to be accessible to those who aren't familiar
with the language. It's a Rust-specific term unlike module or library.

It would be simple enough to change the mod statement to refer to the
same module when a file is included in more than one place in the tree.


Reply to this email directly or view it on GitHubhttps://github.com//issues/9880#issuecomment-34011635
.

flaper87 added a commit to flaper87/rust that referenced this issue Feb 13, 2014
This patch adds a new keyword `crate` which is intended to replace mod
in the context of `extern mod` as part of the issue rust-lang#9880. The patch
doesn't replace all `extern mod` cases since it is necessary to first
push a new snapshot 0.

The implementation could've been less invasive than this. However I
preferred to take this chance to split the `parse_item_foreign_mod`
method and pull the `extern crate` part out of there, hence the new
method `parse_item_foreign_crate`.
bors added a commit that referenced this issue Feb 14, 2014
The first setp for #9880 is to add a new `crate` keyword. This PR does exactly that. I took a chance to refactor `parse_item_foreign_mod` and I broke it down into 2 separate methods to isolate each feature.

The next step will be to push a new stage0 snapshot and then get rid of all `extern mod` around the code.
@flaper87
Copy link
Contributor

The patch that introduced the crate keyword landed already. The step left is creating a new snapshot for stage0 and replace all usages of extern mod with extern crate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-grammar Area: The grammar of Rust E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.
Projects
None yet
Development

Successfully merging a pull request may close this issue.