Skip to content

Commit 3b91ccc

Browse files
committed
---
yaml --- r: 147223 b: refs/heads/try2 c: aafed3e h: refs/heads/master i: 147221: b9a8919 147219: d2a4380 147215: 5783dda v: v3
1 parent 2005a83 commit 3b91ccc

File tree

17 files changed

+219
-220
lines changed

17 files changed

+219
-220
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 5de42701a87cb0e517921cce7bc3a512e513301c
8+
refs/heads/try2: aafed3ece58be56e5e88c51d32d065254f10309a
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/doc/rust.md

Lines changed: 16 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -609,10 +609,8 @@ Attributes on the anonymous crate module define important metadata that influenc
609609
the behavior of the compiler.
610610

611611
~~~~
612-
// Linkage attributes
613-
#[ link(name = "projx",
614-
vers = "2.5",
615-
uuid = "9cccc5d5-aceb-4af5-8285-811211826b82") ];
612+
// Package ID
613+
#[ pkgid = "projx#2.5" ];
616614
617615
// Additional metadata attributes
618616
#[ desc = "Project X" ];
@@ -775,36 +773,24 @@ An _`extern mod` declaration_ specifies a dependency on an external crate.
775773
The external crate is then bound into the declaring scope
776774
as the `ident` provided in the `extern_mod_decl`.
777775

778-
The external crate is resolved to a specific `soname` at compile time,
779-
and a runtime linkage requirement to that `soname` is passed to the linker for
780-
loading at runtime.
781-
The `soname` is resolved at compile time by scanning the compiler's library path
782-
and matching the `link_attrs` provided in the `use_decl` against any `#link` attributes that
783-
were declared on the external crate when it was compiled.
784-
If no `link_attrs` are provided,
785-
a default `name` attribute is assumed,
786-
equal to the `ident` given in the `use_decl`.
787-
788-
Optionally, an identifier in an `extern mod` declaration may be followed by an equals sign,
789-
then a string literal denoting a relative path on the filesystem.
790-
This path should exist in one of the directories in the Rust path,
791-
which by default contains the `.rust` subdirectory of the current directory and each of its parents,
792-
as well as any directories in the colon-separated (or semicolon-separated on Windows)
793-
list of paths that is the `RUST_PATH` environment variable.
794-
The meaning of `extern mod a = "b/c/d";`, supposing that `/a` is in the RUST_PATH,
795-
is that the name `a` should be taken as a reference to the crate whose absolute location is
796-
`/a/b/c/d`.
776+
The external crate is resolved to a specific `soname` at compile time, and a
777+
runtime linkage requirement to that `soname` is passed to the linker for
778+
loading at runtime. The `soname` is resolved at compile time by scanning the
779+
compiler's library path and matching the optional `pkgid` provided as a string literal
780+
against the `pkgid` attributes that were declared on the external crate when
781+
it was compiled. If no `pkgid` is provided, a default `name` attribute is
782+
assumed, equal to the `ident` given in the `extern_mod_decl`.
797783

798784
Four examples of `extern mod` declarations:
799785

800786
~~~~ {.xfail-test}
801-
extern mod pcre (uuid = "54aba0f8-a7b1-4beb-92f1-4cf625264841");
787+
extern mod pcre;
802788
803-
extern mod extra; // equivalent to: extern mod extra ( name = "extra" );
789+
extern mod extra; // equivalent to: extern mod extra = "extra";
804790
805-
extern mod rustextra (name = "extra"); // linking to 'extra' under another name
791+
extern mod rustextra = "extra"; // linking to 'extra' under another name
806792
807-
extern mod complicated_mod = "some-file/in/the-rust/path";
793+
extern mod foo = "some/where/foo#1.0"; // a full package ID for rustpkg
808794
~~~~
809795

810796
##### Use declarations
@@ -1742,7 +1728,8 @@ names are effectively reserved. Some significant attributes include:
17421728
* The `doc` attribute, for documenting code in-place.
17431729
* The `cfg` attribute, for conditional-compilation by build-configuration.
17441730
* The `lang` attribute, for custom definitions of traits and functions that are known to the Rust compiler (see [Language items](#language-items)).
1745-
* The `link` attribute, for describing linkage metadata for a crate.
1731+
* The `link` attribute, for describing linkage metadata for a extern blocks.
1732+
* The `pkgid` attribute, for describing the package ID of a crate.
17461733
* The `test` attribute, for marking functions as unit tests.
17471734
* The `allow`, `warn`, `forbid`, and `deny` attributes, for
17481735
controlling lint checks (see [Lint check attributes](#lint-check-attributes)).
@@ -3795,7 +3782,7 @@ specified then log level 4 is assumed. Debug messages can be omitted
37953782
by passing `--cfg ndebug` to `rustc`.
37963783

37973784
As an example, to see all the logs generated by the compiler, you would set
3798-
`RUST_LOG` to `rustc`, which is the crate name (as specified in its `link`
3785+
`RUST_LOG` to `rustc`, which is the crate name (as specified in its `pkgid`
37993786
[attribute](#attributes)). To narrow down the logs to just crate resolution,
38003787
you would set it to `rustc::metadata::creader`. To see just error logging
38013788
use `rustc=0`.

branches/try2/doc/rustdoc.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ comments":
1313
~~~
1414
// the "link" crate attribute is currently required for rustdoc, but normally
1515
// isn't needed.
16-
#[link(name="universe")];
16+
#[pkgid = "universe"];
1717
#[crate_type="lib"];
1818
1919
//! Tools for dealing with universes (this is a doc comment, and is shown on

branches/try2/doc/rustpkg.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ as well as `foo/src/bar/extras/baz/lib.rs`,
8989
then both `bar` and `bar/extras/baz` are valid package identifiers
9090
in the workspace `foo`.
9191

92+
Because rustpkg uses generic source file names as the main inputs, you will
93+
need to specify the package identifier in them using the `pkgid` attribute
94+
on the crate.
95+
9296
## Source files
9397

9498
rustpkg searches for four different fixed filenames in order to determine the crates to build:
@@ -108,9 +112,6 @@ When building a package that is not under version control,
108112
or that has no tags, `rustpkg` assumes the intended version is 0.1.
109113

110114
> **Note:** A future version of rustpkg will support semantic versions.
111-
> Also, a future version will add the option to specify a version with a metadata
112-
> attribute like `#[link(vers = "3.1415")]` inside the crate module,
113-
> though this attribute will never be mandatory.
114115
115116
# Dependencies
116117

branches/try2/doc/tutorial.md

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3070,22 +3070,21 @@ Therefore, if you plan to compile your crate as a library, you should annotate i
30703070
// lib.rs
30713071
30723072
# #[crate_type = "lib"];
3073-
// Crate linkage metadata
3074-
#[link(name = "farm", vers = "2.5")];
3073+
// Package ID
3074+
#[pkgid = "farm#2.5"];
30753075
30763076
// ...
30773077
# fn farm() {}
30783078
~~~~
30793079

3080-
You can also in turn require in a `extern mod` statement that certain link metadata items match some criteria.
3081-
For that, Rust currently parses a comma-separated list of name/value pairs that appear after
3082-
it, and ensures that they match the attributes provided in the `link` attribute of a crate file.
3083-
This enables you to, e.g., pick a crate based on its version number, or link a library under a
3084-
different name. For example, these two `mod` statements would both accept and select the crate define above:
3080+
You can also specify package ID information in a `extern mod` statement. For
3081+
example, these `extern mod` statements would both accept and select the
3082+
crate define above:
30853083

30863084
~~~~ {.xfail-test}
3087-
extern mod farm(vers = "2.5");
3088-
extern mod my_farm(name = "farm", vers = "2.5");
3085+
extern mod farm;
3086+
extern mod farm = "farm#2.5";
3087+
extern mod my_farm = "farm";
30893088
~~~~
30903089

30913090
Other crate settings and metadata include things like enabling/disabling certain errors or warnings,
@@ -3096,21 +3095,18 @@ or setting the crate type (library or executable) explicitly:
30963095
// ...
30973096
30983097
// This crate is a library ("bin" is the default)
3098+
#[pkgid = "farm#2.5"];
30993099
#[crate_type = "lib"];
31003100
31013101
// Turn on a warning
31023102
#[warn(non_camel_case_types)]
31033103
# fn farm() {}
31043104
~~~~
31053105

3106-
If you're compiling your crate with `rustpkg`,
3107-
link annotations will not be necessary, because they get
3108-
inferred by `rustpkg` based on the Package id and naming conventions.
3109-
3110-
3111-
> ***Note:*** The rules regarding link metadata, both as attributes and on `extern mod`,
3112-
as well as their interaction with `rustpkg`
3113-
are currently not clearly defined and will likely change in the future.
3106+
> ***Note:*** The rules regarding package IDs, both as attributes and as used
3107+
in `extern mod`, as well as their interaction with `rustpkg` are
3108+
currently not clearly defined and will likely change in the
3109+
future.
31143110

31153111
## A minimal example
31163112

@@ -3120,7 +3116,7 @@ We define two crates, and use one of them as a library in the other.
31203116

31213117
~~~~
31223118
// world.rs
3123-
#[link(name = "world", vers = "0.42")];
3119+
#[pkgid = "world#0.42"];
31243120
# extern mod extra;
31253121
pub fn explore() -> &'static str { "world" }
31263122
# fn main() {}
@@ -3144,7 +3140,7 @@ Now compile and run like this (adjust to your platform if necessary):
31443140
Notice that the library produced contains the version in the file name
31453141
as well as an inscrutable string of alphanumerics. As explained in the previous paragraph,
31463142
these are both part of Rust's library versioning scheme. The alphanumerics are
3147-
a hash representing the crates link metadata.
3143+
a hash representing the crates package ID.
31483144

31493145
## The standard library and the prelude
31503146

branches/try2/mk/platform.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ CFG_LIB_GLOB_arm-linux-androideabi=lib$(1)-*.so
287287
CFG_LIB_DSYM_GLOB_arm-linux-androideabi=lib$(1)-*.dylib.dSYM
288288
CFG_GCCISH_CFLAGS_arm-linux-androideabi := -Wall -g -fPIC -D__arm__ -DANDROID -D__ANDROID__
289289
CFG_GCCISH_CXXFLAGS_arm-linux-androideabi := -fno-rtti
290-
CFG_GCCISH_LINK_FLAGS_arm-linux-androideabi := -shared -fPIC -ldl -g -lm -lsupc++ -lgnustl_shared
290+
CFG_GCCISH_LINK_FLAGS_arm-linux-androideabi := -shared -fPIC -ldl -g -lm -lsupc++
291291
CFG_GCCISH_DEF_FLAG_arm-linux-androideabi := -Wl,--export-dynamic,--dynamic-list=
292292
CFG_GCCISH_PRE_LIB_FLAGS_arm-linux-androideabi := -Wl,-whole-archive
293293
CFG_GCCISH_POST_LIB_FLAGS_arm-linux-androideabi := -Wl,-no-whole-archive

branches/try2/mk/tests.mk

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,6 @@ $(info check: android device test dir $(CFG_ADB_TEST_DIR) ready \
156156
$(shell adb shell mkdir $(CFG_ADB_TEST_DIR)) \
157157
$(shell adb shell mkdir $(CFG_ADB_TEST_DIR)/tmp) \
158158
$(shell adb push $(S)src/etc/adb_run_wrapper.sh $(CFG_ADB_TEST_DIR) 1>/dev/null) \
159-
$(shell adb push $(CFG_ANDROID_CROSS_PATH)/arm-linux-androideabi/lib/armv7-a/libgnustl_shared.so \
160-
$(CFG_ADB_TEST_DIR) 1>/dev/null) \
161159
$(shell adb push $(TLIB2_T_arm-linux-androideabi_H_$(CFG_BUILD))/$(CFG_RUNTIME_arm-linux-androideabi) \
162160
$(CFG_ADB_TEST_DIR)) \
163161
$(shell adb push $(TLIB2_T_arm-linux-androideabi_H_$(CFG_BUILD))/$(STDLIB_GLOB_arm-linux-androideabi) \

branches/try2/src/etc/combine-tests.py

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,15 @@ def scrub(b):
4141

4242
c = open("tmp/run_pass_stage2.rc", "w")
4343
i = 0
44-
c.write("// AUTO-GENERATED FILE: DO NOT EDIT\n")
45-
c.write("#[pkgid=\"run_pass_stage2#0.1\"];\n")
46-
c.write("#[link(name=\"run_pass_stage2\", vers=\"0.1\")];\n")
47-
c.write("#[feature(globs, macro_rules, struct_variant, managed_boxes)];\n")
48-
c.write("#[allow(attribute_usage)];\n")
44+
c.write(
45+
"""
46+
// AUTO-GENERATED FILE: DO NOT EDIT
47+
#[pkgid=\"run_pass_stage2#0.1\"];
48+
#[link(name=\"run_pass_stage2\", vers=\"0.1\")];
49+
#[feature(globs, macro_rules, struct_variant, managed_boxes)];
50+
#[allow(warnings)];
51+
"""
52+
)
4953
for t in stage2_tests:
5054
p = os.path.join(run_pass, t)
5155
p = p.replace("\\", "\\\\")
@@ -56,15 +60,19 @@ def scrub(b):
5660

5761

5862
d = open("tmp/run_pass_stage2_driver.rs", "w")
59-
d.write("// AUTO-GENERATED FILE: DO NOT EDIT\n")
60-
d.write("#[feature(globs, managed_boxes)];\n")
61-
d.write("extern mod extra;\n")
62-
d.write("extern mod run_pass_stage2;\n")
63-
d.write("use run_pass_stage2::*;\n")
64-
d.write("use std::io;\n")
65-
d.write("use std::io::Writer;\n")
66-
d.write("fn main() {\n")
67-
d.write(" let mut out = io::stdout();\n")
63+
d.write(
64+
"""
65+
// AUTO-GENERATED FILE: DO NOT EDIT
66+
#[feature(globs, managed_boxes)];
67+
extern mod extra;
68+
extern mod run_pass_stage2;
69+
use run_pass_stage2::*;
70+
use std::io;
71+
use std::io::Writer;
72+
fn main() {
73+
let mut out = io::stdout();
74+
"""
75+
)
6876
i = 0
6977
for t in stage2_tests:
7078
p = os.path.join("test", "run-pass", t)

branches/try2/src/librustc/middle/dead.rs

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ fn should_explore(tcx: ty::ctxt, def_id: ast::DefId) -> bool {
3737
match tcx.items.find(&def_id.node) {
3838
Some(&ast_map::node_item(..))
3939
| Some(&ast_map::node_method(..))
40+
| Some(&ast_map::node_foreign_item(..))
4041
| Some(&ast_map::node_trait_method(..)) => true,
4142
_ => false
4243
}
@@ -61,11 +62,10 @@ impl MarkSymbolVisitor {
6162
}
6263
}
6364

64-
fn lookup_and_handle_definition(&mut self, id: &ast::NodeId,
65-
span: codemap::Span) {
65+
fn lookup_and_handle_definition(&mut self, id: &ast::NodeId) {
6666
let def = match self.tcx.def_map.find(id) {
6767
Some(&def) => def,
68-
None => self.tcx.sess.span_bug(span, "def ID not in def map?!"),
68+
None => return
6969
};
7070
let def_id = match def {
7171
ast::DefVariant(enum_id, _, _) => Some(enum_id),
@@ -107,8 +107,7 @@ impl MarkSymbolVisitor {
107107
match item.node {
108108
ast::item_fn(..)
109109
| ast::item_ty(..)
110-
| ast::item_static(..)
111-
| ast::item_foreign_mod(_) => {
110+
| ast::item_static(..) => {
112111
visit::walk_item(self, item, ());
113112
}
114113
_ => ()
@@ -120,6 +119,9 @@ impl MarkSymbolVisitor {
120119
ast_map::node_method(method, _, _) => {
121120
visit::walk_block(self, method.body, ());
122121
}
122+
ast_map::node_foreign_item(foreign_item, _, _, _) => {
123+
visit::walk_foreign_item(self, foreign_item, ());
124+
}
123125
_ => ()
124126
}
125127
}
@@ -129,9 +131,6 @@ impl Visitor<()> for MarkSymbolVisitor {
129131

130132
fn visit_expr(&mut self, expr: @ast::Expr, _: ()) {
131133
match expr.node {
132-
ast::ExprPath(_) | ast::ExprStruct(..) => {
133-
self.lookup_and_handle_definition(&expr.id, expr.span);
134-
}
135134
ast::ExprMethodCall(..) => {
136135
match self.method_map.find(&expr.id) {
137136
Some(&typeck::method_map_entry {
@@ -160,12 +159,16 @@ impl Visitor<()> for MarkSymbolVisitor {
160159
fn visit_ty(&mut self, typ: &ast::Ty, _: ()) {
161160
match typ.node {
162161
ast::ty_path(_, _, ref id) => {
163-
self.lookup_and_handle_definition(id, typ.span);
162+
self.lookup_and_handle_definition(id);
164163
}
165164
_ => visit::walk_ty(self, typ, ()),
166165
}
167166
}
168167

168+
fn visit_path(&mut self, _: &ast::Path, id: ast::NodeId, _: ()) {
169+
self.lookup_and_handle_definition(&id);
170+
}
171+
169172
fn visit_item(&mut self, _item: @ast::item, _: ()) {
170173
// Do not recurse into items. These items will be added to the
171174
// worklist and recursed into manually if necessary.
@@ -299,19 +302,31 @@ impl DeadVisitor {
299302
}
300303
false
301304
}
305+
306+
fn warn_dead_code(&mut self, id: ast::NodeId,
307+
span: codemap::Span, ident: &ast::Ident) {
308+
self.tcx.sess.add_lint(dead_code, id, span,
309+
format!("code is never used: `{}`",
310+
token::ident_to_str(ident)));
311+
}
302312
}
303313

304314
impl Visitor<()> for DeadVisitor {
305315
fn visit_item(&mut self, item: @ast::item, _: ()) {
306316
let ctor_id = get_struct_ctor_id(item);
307317
if !self.symbol_is_live(item.id, ctor_id) && should_warn(item) {
308-
self.tcx.sess.add_lint(dead_code, item.id, item.span,
309-
format!("code is never used: `{}`",
310-
token::ident_to_str(&item.ident)));
318+
self.warn_dead_code(item.id, item.span, &item.ident);
311319
}
312320
visit::walk_item(self, item, ());
313321
}
314322

323+
fn visit_foreign_item(&mut self, fi: @ast::foreign_item, _: ()) {
324+
if !self.symbol_is_live(fi.id, None) {
325+
self.warn_dead_code(fi.id, fi.span, &fi.ident);
326+
}
327+
visit::walk_foreign_item(self, fi, ());
328+
}
329+
315330
fn visit_fn(&mut self, fk: &visit::fn_kind,
316331
_: &ast::fn_decl, block: ast::P<ast::Block>,
317332
span: codemap::Span, id: ast::NodeId, _: ()) {
@@ -320,10 +335,7 @@ impl Visitor<()> for DeadVisitor {
320335
visit::fk_method(..) => {
321336
let ident = visit::name_of_fn(fk);
322337
if !self.symbol_is_live(id, None) {
323-
self.tcx.sess
324-
.add_lint(dead_code, id, span,
325-
format!("code is never used: `{}`",
326-
token::ident_to_str(&ident)));
338+
self.warn_dead_code(id, span, &ident);
327339
}
328340
}
329341
_ => ()

0 commit comments

Comments
 (0)