2014-02-10 15:36:31 +01:00
|
|
|
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
|
2012-12-04 01:48:01 +01:00
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2014-03-22 02:05:05 +01:00
|
|
|
#![allow(non_camel_case_types)]
|
2013-01-07 23:16:52 +01:00
|
|
|
|
2011-07-08 03:39:44 +02:00
|
|
|
// The crate store - a central repo for information collected about external
|
|
|
|
// crates and libraries
|
|
|
|
|
2014-11-06 09:05:53 +01:00
|
|
|
pub use self::MetadataBlob::*;
|
|
|
|
pub use self::LinkagePreference::*;
|
librustc: Make `Copy` opt-in.
This change makes the compiler no longer infer whether types (structures
and enumerations) implement the `Copy` trait (and thus are implicitly
copyable). Rather, you must implement `Copy` yourself via `impl Copy for
MyType {}`.
A new warning has been added, `missing_copy_implementations`, to warn
you if a non-generic public type has been added that could have
implemented `Copy` but didn't.
For convenience, you may *temporarily* opt out of this behavior by using
`#![feature(opt_out_copy)]`. Note though that this feature gate will never be
accepted and will be removed by the time that 1.0 is released, so you should
transition your code away from using it.
This breaks code like:
#[deriving(Show)]
struct Point2D {
x: int,
y: int,
}
fn main() {
let mypoint = Point2D {
x: 1,
y: 1,
};
let otherpoint = mypoint;
println!("{}{}", mypoint, otherpoint);
}
Change this code to:
#[deriving(Show)]
struct Point2D {
x: int,
y: int,
}
impl Copy for Point2D {}
fn main() {
let mypoint = Point2D {
x: 1,
y: 1,
};
let otherpoint = mypoint;
println!("{}{}", mypoint, otherpoint);
}
This is the backwards-incompatible part of #13231.
Part of RFC #3.
[breaking-change]
2014-12-06 02:01:33 +01:00
|
|
|
pub use self::NativeLibraryKind::*;
|
2014-11-06 09:05:53 +01:00
|
|
|
|
2014-02-25 04:45:20 +01:00
|
|
|
use back::svh::Svh;
|
2012-12-23 23:41:37 +01:00
|
|
|
use metadata::decoder;
|
2013-12-17 05:58:21 +01:00
|
|
|
use metadata::loader;
|
2015-01-06 17:46:07 +01:00
|
|
|
use session::search_paths::PathKind;
|
2014-11-09 23:59:56 +01:00
|
|
|
use util::nodemap::{FnvHashMap, NodeMap};
|
2012-12-23 23:41:37 +01:00
|
|
|
|
2013-12-21 04:43:27 +01:00
|
|
|
use std::cell::RefCell;
|
2014-03-27 18:28:38 +01:00
|
|
|
use std::rc::Rc;
|
2015-02-27 06:00:43 +01:00
|
|
|
use std::path::PathBuf;
|
2014-11-25 22:28:35 +01:00
|
|
|
use flate::Bytes;
|
2013-03-26 21:38:07 +01:00
|
|
|
use syntax::ast;
|
2015-02-11 18:29:49 +01:00
|
|
|
use syntax::codemap;
|
2014-01-09 14:05:33 +01:00
|
|
|
use syntax::parse::token::IdentInterner;
|
2011-07-08 03:00:16 +02:00
|
|
|
|
2011-07-08 21:08:43 +02:00
|
|
|
// A map from external crate numbers (as decoded from some crate file) to
|
|
|
|
// local crate numbers (as generated during this session). Each external
|
|
|
|
// crate may refer to types in other external crates, and each has their
|
|
|
|
// own crate numbers.
|
2014-11-09 23:59:56 +01:00
|
|
|
pub type cnum_map = FnvHashMap<ast::CrateNum, ast::CrateNum>;
|
2011-07-08 21:08:43 +02:00
|
|
|
|
2013-12-18 23:10:28 +01:00
|
|
|
pub enum MetadataBlob {
|
2014-11-25 22:28:35 +01:00
|
|
|
MetadataVec(Bytes),
|
2013-12-17 05:58:21 +01:00
|
|
|
MetadataArchive(loader::ArchiveMetadata),
|
2013-12-18 23:10:28 +01:00
|
|
|
}
|
|
|
|
|
2015-02-11 18:29:49 +01:00
|
|
|
/// Holds information about a codemap::FileMap imported from another crate.
|
|
|
|
/// See creader::import_codemap() for more information.
|
|
|
|
pub struct ImportedFileMap {
|
|
|
|
/// This FileMap's byte-offset within the codemap of its original crate
|
|
|
|
pub original_start_pos: codemap::BytePos,
|
|
|
|
/// The end of this FileMap within the codemap of its original crate
|
|
|
|
pub original_end_pos: codemap::BytePos,
|
|
|
|
/// The imported FileMap's representation within the local codemap
|
|
|
|
pub translated_filemap: Rc<codemap::FileMap>
|
|
|
|
}
|
|
|
|
|
2013-02-19 08:40:42 +01:00
|
|
|
pub struct crate_metadata {
|
2014-05-23 01:57:53 +02:00
|
|
|
pub name: String,
|
2014-03-28 18:05:27 +01:00
|
|
|
pub data: MetadataBlob,
|
|
|
|
pub cnum_map: cnum_map,
|
|
|
|
pub cnum: ast::CrateNum,
|
2015-02-11 18:29:49 +01:00
|
|
|
pub codemap_import_info: Vec<ImportedFileMap>,
|
|
|
|
pub span: codemap::Span,
|
2013-02-19 08:40:42 +01:00
|
|
|
}
|
2011-07-08 03:00:16 +02:00
|
|
|
|
2015-01-28 14:34:18 +01:00
|
|
|
#[derive(Copy, Debug, PartialEq, Clone)]
|
Add generation of static libraries to rustc
This commit implements the support necessary for generating both intermediate
and result static rust libraries. This is an implementation of my thoughts in
https://mail.mozilla.org/pipermail/rust-dev/2013-November/006686.html.
When compiling a library, we still retain the "lib" option, although now there
are "rlib", "staticlib", and "dylib" as options for crate_type (and these are
stackable). The idea of "lib" is to generate the "compiler default" instead of
having too choose (although all are interchangeable). For now I have left the
"complier default" to be a dynamic library for size reasons.
Of the rust libraries, lib{std,extra,rustuv} will bootstrap with an
rlib/dylib pair, but lib{rustc,syntax,rustdoc,rustpkg} will only be built as a
dynamic object. I chose this for size reasons, but also because you're probably
not going to be embedding the rustc compiler anywhere any time soon.
Other than the options outlined above, there are a few defaults/preferences that
are now opinionated in the compiler:
* If both a .dylib and .rlib are found for a rust library, the compiler will
prefer the .rlib variant. This is overridable via the -Z prefer-dynamic option
* If generating a "lib", the compiler will generate a dynamic library. This is
overridable by explicitly saying what flavor you'd like (rlib, staticlib,
dylib).
* If no options are passed to the command line, and no crate_type is found in
the destination crate, then an executable is generated
With this change, you can successfully build a rust program with 0 dynamic
dependencies on rust libraries. There is still a dynamic dependency on
librustrt, but I plan on removing that in a subsequent commit.
This change includes no tests just yet. Our current testing
infrastructure/harnesses aren't very amenable to doing flavorful things with
linking, so I'm planning on adding a new mode of testing which I believe belongs
as a separate commit.
Closes #552
2013-11-15 23:03:29 +01:00
|
|
|
pub enum LinkagePreference {
|
|
|
|
RequireDynamic,
|
|
|
|
RequireStatic,
|
|
|
|
}
|
|
|
|
|
2015-01-04 04:54:18 +01:00
|
|
|
#[derive(Copy, Clone, PartialEq, FromPrimitive)]
|
librustc: Make `Copy` opt-in.
This change makes the compiler no longer infer whether types (structures
and enumerations) implement the `Copy` trait (and thus are implicitly
copyable). Rather, you must implement `Copy` yourself via `impl Copy for
MyType {}`.
A new warning has been added, `missing_copy_implementations`, to warn
you if a non-generic public type has been added that could have
implemented `Copy` but didn't.
For convenience, you may *temporarily* opt out of this behavior by using
`#![feature(opt_out_copy)]`. Note though that this feature gate will never be
accepted and will be removed by the time that 1.0 is released, so you should
transition your code away from using it.
This breaks code like:
#[deriving(Show)]
struct Point2D {
x: int,
y: int,
}
fn main() {
let mypoint = Point2D {
x: 1,
y: 1,
};
let otherpoint = mypoint;
println!("{}{}", mypoint, otherpoint);
}
Change this code to:
#[deriving(Show)]
struct Point2D {
x: int,
y: int,
}
impl Copy for Point2D {}
fn main() {
let mypoint = Point2D {
x: 1,
y: 1,
};
let otherpoint = mypoint;
println!("{}{}", mypoint, otherpoint);
}
This is the backwards-incompatible part of #13231.
Part of RFC #3.
[breaking-change]
2014-12-06 02:01:33 +01:00
|
|
|
pub enum NativeLibraryKind {
|
2013-11-30 20:39:55 +01:00
|
|
|
NativeStatic, // native static library (.a archive)
|
|
|
|
NativeFramework, // OSX-specific
|
|
|
|
NativeUnknown, // default way to specify a dynamic library
|
Add generation of static libraries to rustc
This commit implements the support necessary for generating both intermediate
and result static rust libraries. This is an implementation of my thoughts in
https://mail.mozilla.org/pipermail/rust-dev/2013-November/006686.html.
When compiling a library, we still retain the "lib" option, although now there
are "rlib", "staticlib", and "dylib" as options for crate_type (and these are
stackable). The idea of "lib" is to generate the "compiler default" instead of
having too choose (although all are interchangeable). For now I have left the
"complier default" to be a dynamic library for size reasons.
Of the rust libraries, lib{std,extra,rustuv} will bootstrap with an
rlib/dylib pair, but lib{rustc,syntax,rustdoc,rustpkg} will only be built as a
dynamic object. I chose this for size reasons, but also because you're probably
not going to be embedding the rustc compiler anywhere any time soon.
Other than the options outlined above, there are a few defaults/preferences that
are now opinionated in the compiler:
* If both a .dylib and .rlib are found for a rust library, the compiler will
prefer the .rlib variant. This is overridable via the -Z prefer-dynamic option
* If generating a "lib", the compiler will generate a dynamic library. This is
overridable by explicitly saying what flavor you'd like (rlib, staticlib,
dylib).
* If no options are passed to the command line, and no crate_type is found in
the destination crate, then an executable is generated
With this change, you can successfully build a rust program with 0 dynamic
dependencies on rust libraries. There is still a dynamic dependency on
librustrt, but I plan on removing that in a subsequent commit.
This change includes no tests just yet. Our current testing
infrastructure/harnesses aren't very amenable to doing flavorful things with
linking, so I'm planning on adding a new mode of testing which I believe belongs
as a separate commit.
Closes #552
2013-11-15 23:03:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Where a crate came from on the local filesystem. One of these two options
|
|
|
|
// must be non-None.
|
2015-01-04 04:54:18 +01:00
|
|
|
#[derive(PartialEq, Clone)]
|
Add generation of static libraries to rustc
This commit implements the support necessary for generating both intermediate
and result static rust libraries. This is an implementation of my thoughts in
https://mail.mozilla.org/pipermail/rust-dev/2013-November/006686.html.
When compiling a library, we still retain the "lib" option, although now there
are "rlib", "staticlib", and "dylib" as options for crate_type (and these are
stackable). The idea of "lib" is to generate the "compiler default" instead of
having too choose (although all are interchangeable). For now I have left the
"complier default" to be a dynamic library for size reasons.
Of the rust libraries, lib{std,extra,rustuv} will bootstrap with an
rlib/dylib pair, but lib{rustc,syntax,rustdoc,rustpkg} will only be built as a
dynamic object. I chose this for size reasons, but also because you're probably
not going to be embedding the rustc compiler anywhere any time soon.
Other than the options outlined above, there are a few defaults/preferences that
are now opinionated in the compiler:
* If both a .dylib and .rlib are found for a rust library, the compiler will
prefer the .rlib variant. This is overridable via the -Z prefer-dynamic option
* If generating a "lib", the compiler will generate a dynamic library. This is
overridable by explicitly saying what flavor you'd like (rlib, staticlib,
dylib).
* If no options are passed to the command line, and no crate_type is found in
the destination crate, then an executable is generated
With this change, you can successfully build a rust program with 0 dynamic
dependencies on rust libraries. There is still a dynamic dependency on
librustrt, but I plan on removing that in a subsequent commit.
This change includes no tests just yet. Our current testing
infrastructure/harnesses aren't very amenable to doing flavorful things with
linking, so I'm planning on adding a new mode of testing which I believe belongs
as a separate commit.
Closes #552
2013-11-15 23:03:29 +01:00
|
|
|
pub struct CrateSource {
|
2015-02-27 06:00:43 +01:00
|
|
|
pub dylib: Option<(PathBuf, PathKind)>,
|
|
|
|
pub rlib: Option<(PathBuf, PathKind)>,
|
2014-03-28 18:05:27 +01:00
|
|
|
pub cnum: ast::CrateNum,
|
Add generation of static libraries to rustc
This commit implements the support necessary for generating both intermediate
and result static rust libraries. This is an implementation of my thoughts in
https://mail.mozilla.org/pipermail/rust-dev/2013-November/006686.html.
When compiling a library, we still retain the "lib" option, although now there
are "rlib", "staticlib", and "dylib" as options for crate_type (and these are
stackable). The idea of "lib" is to generate the "compiler default" instead of
having too choose (although all are interchangeable). For now I have left the
"complier default" to be a dynamic library for size reasons.
Of the rust libraries, lib{std,extra,rustuv} will bootstrap with an
rlib/dylib pair, but lib{rustc,syntax,rustdoc,rustpkg} will only be built as a
dynamic object. I chose this for size reasons, but also because you're probably
not going to be embedding the rustc compiler anywhere any time soon.
Other than the options outlined above, there are a few defaults/preferences that
are now opinionated in the compiler:
* If both a .dylib and .rlib are found for a rust library, the compiler will
prefer the .rlib variant. This is overridable via the -Z prefer-dynamic option
* If generating a "lib", the compiler will generate a dynamic library. This is
overridable by explicitly saying what flavor you'd like (rlib, staticlib,
dylib).
* If no options are passed to the command line, and no crate_type is found in
the destination crate, then an executable is generated
With this change, you can successfully build a rust program with 0 dynamic
dependencies on rust libraries. There is still a dynamic dependency on
librustrt, but I plan on removing that in a subsequent commit.
This change includes no tests just yet. Our current testing
infrastructure/harnesses aren't very amenable to doing flavorful things with
linking, so I'm planning on adding a new mode of testing which I believe belongs
as a separate commit.
Closes #552
2013-11-15 23:03:29 +01:00
|
|
|
}
|
|
|
|
|
2013-02-04 23:02:01 +01:00
|
|
|
pub struct CStore {
|
2014-11-09 23:59:56 +01:00
|
|
|
metas: RefCell<FnvHashMap<ast::CrateNum, Rc<crate_metadata>>>,
|
|
|
|
/// Map from NodeId's of local extern crate statements to crate numbers
|
|
|
|
extern_mod_crate_map: RefCell<NodeMap<ast::CrateNum>>,
|
2014-03-28 18:05:27 +01:00
|
|
|
used_crate_sources: RefCell<Vec<CrateSource>>,
|
librustc: Make `Copy` opt-in.
This change makes the compiler no longer infer whether types (structures
and enumerations) implement the `Copy` trait (and thus are implicitly
copyable). Rather, you must implement `Copy` yourself via `impl Copy for
MyType {}`.
A new warning has been added, `missing_copy_implementations`, to warn
you if a non-generic public type has been added that could have
implemented `Copy` but didn't.
For convenience, you may *temporarily* opt out of this behavior by using
`#![feature(opt_out_copy)]`. Note though that this feature gate will never be
accepted and will be removed by the time that 1.0 is released, so you should
transition your code away from using it.
This breaks code like:
#[deriving(Show)]
struct Point2D {
x: int,
y: int,
}
fn main() {
let mypoint = Point2D {
x: 1,
y: 1,
};
let otherpoint = mypoint;
println!("{}{}", mypoint, otherpoint);
}
Change this code to:
#[deriving(Show)]
struct Point2D {
x: int,
y: int,
}
impl Copy for Point2D {}
fn main() {
let mypoint = Point2D {
x: 1,
y: 1,
};
let otherpoint = mypoint;
println!("{}{}", mypoint, otherpoint);
}
This is the backwards-incompatible part of #13231.
Part of RFC #3.
[breaking-change]
2014-12-06 02:01:33 +01:00
|
|
|
used_libraries: RefCell<Vec<(String, NativeLibraryKind)>>,
|
2014-05-23 01:57:53 +02:00
|
|
|
used_link_args: RefCell<Vec<String>>,
|
2014-03-28 18:05:27 +01:00
|
|
|
pub intr: Rc<IdentInterner>,
|
2013-02-04 23:02:01 +01:00
|
|
|
}
|
2011-07-10 07:56:12 +02:00
|
|
|
|
2013-12-25 21:08:04 +01:00
|
|
|
impl CStore {
|
2014-03-27 18:28:38 +01:00
|
|
|
pub fn new(intr: Rc<IdentInterner>) -> CStore {
|
2013-12-25 21:08:04 +01:00
|
|
|
CStore {
|
2015-01-16 23:27:43 +01:00
|
|
|
metas: RefCell::new(FnvHashMap()),
|
|
|
|
extern_mod_crate_map: RefCell::new(FnvHashMap()),
|
2014-03-04 19:02:49 +01:00
|
|
|
used_crate_sources: RefCell::new(Vec::new()),
|
|
|
|
used_libraries: RefCell::new(Vec::new()),
|
|
|
|
used_link_args: RefCell::new(Vec::new()),
|
2013-12-25 21:08:04 +01:00
|
|
|
intr: intr
|
|
|
|
}
|
|
|
|
}
|
2011-07-08 03:00:16 +02:00
|
|
|
|
2014-04-07 21:14:33 +02:00
|
|
|
pub fn next_crate_num(&self) -> ast::CrateNum {
|
|
|
|
self.metas.borrow().len() as ast::CrateNum + 1
|
|
|
|
}
|
|
|
|
|
2014-04-17 14:06:25 +02:00
|
|
|
pub fn get_crate_data(&self, cnum: ast::CrateNum) -> Rc<crate_metadata> {
|
2015-03-22 02:15:47 +01:00
|
|
|
self.metas.borrow().get(&cnum).unwrap().clone()
|
2013-12-25 21:08:04 +01:00
|
|
|
}
|
2011-07-08 03:00:16 +02:00
|
|
|
|
2014-02-25 04:45:20 +01:00
|
|
|
pub fn get_crate_hash(&self, cnum: ast::CrateNum) -> Svh {
|
2013-12-25 21:08:04 +01:00
|
|
|
let cdata = self.get_crate_data(cnum);
|
|
|
|
decoder::get_crate_hash(cdata.data())
|
|
|
|
}
|
2012-04-06 12:45:49 +02:00
|
|
|
|
2014-04-17 14:06:25 +02:00
|
|
|
pub fn set_crate_data(&self, cnum: ast::CrateNum, data: Rc<crate_metadata>) {
|
2014-03-21 03:49:20 +01:00
|
|
|
self.metas.borrow_mut().insert(cnum, data);
|
2013-12-25 21:08:04 +01:00
|
|
|
}
|
2011-07-08 03:00:16 +02:00
|
|
|
|
2014-12-09 02:26:43 +01:00
|
|
|
pub fn iter_crate_data<I>(&self, mut i: I) where
|
|
|
|
I: FnMut(ast::CrateNum, &crate_metadata),
|
|
|
|
{
|
2015-01-31 18:20:46 +01:00
|
|
|
for (&k, v) in &*self.metas.borrow() {
|
2014-04-17 14:06:25 +02:00
|
|
|
i(k, &**v);
|
2013-12-25 21:08:04 +01:00
|
|
|
}
|
2013-02-04 23:02:01 +01:00
|
|
|
}
|
2011-07-08 03:00:16 +02:00
|
|
|
|
2014-04-25 18:06:49 +02:00
|
|
|
/// Like `iter_crate_data`, but passes source paths (if available) as well.
|
2014-12-09 02:26:43 +01:00
|
|
|
pub fn iter_crate_data_origins<I>(&self, mut i: I) where
|
|
|
|
I: FnMut(ast::CrateNum, &crate_metadata, Option<CrateSource>),
|
|
|
|
{
|
2015-01-31 18:20:46 +01:00
|
|
|
for (&k, v) in &*self.metas.borrow() {
|
2014-04-25 18:06:49 +02:00
|
|
|
let origin = self.get_used_crate_source(k);
|
|
|
|
origin.as_ref().map(|cs| { assert!(k == cs.cnum); });
|
|
|
|
i(k, &**v, origin);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-21 05:00:58 +01:00
|
|
|
pub fn add_used_crate_source(&self, src: CrateSource) {
|
2013-12-21 04:50:13 +01:00
|
|
|
let mut used_crate_sources = self.used_crate_sources.borrow_mut();
|
2014-03-21 03:49:20 +01:00
|
|
|
if !used_crate_sources.contains(&src) {
|
|
|
|
used_crate_sources.push(src);
|
2013-12-25 21:08:04 +01:00
|
|
|
}
|
2011-07-08 03:25:56 +02:00
|
|
|
}
|
|
|
|
|
2013-12-25 19:10:33 +01:00
|
|
|
pub fn get_used_crate_source(&self, cnum: ast::CrateNum)
|
|
|
|
-> Option<CrateSource> {
|
2014-03-21 03:49:20 +01:00
|
|
|
self.used_crate_sources.borrow_mut()
|
2015-02-13 08:33:44 +01:00
|
|
|
.iter().find(|source| source.cnum == cnum).cloned()
|
2013-12-25 19:10:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn reset(&self) {
|
2014-03-21 03:55:52 +01:00
|
|
|
self.metas.borrow_mut().clear();
|
|
|
|
self.extern_mod_crate_map.borrow_mut().clear();
|
|
|
|
self.used_crate_sources.borrow_mut().clear();
|
|
|
|
self.used_libraries.borrow_mut().clear();
|
|
|
|
self.used_link_args.borrow_mut().clear();
|
2013-12-25 19:10:33 +01:00
|
|
|
}
|
|
|
|
|
2014-03-14 02:47:43 +01:00
|
|
|
// This method is used when generating the command line to pass through to
|
|
|
|
// system linker. The linker expects undefined symbols on the left of the
|
|
|
|
// command line to be defined in libraries on the right, not the other way
|
|
|
|
// around. For more info, see some comments in the add_used_library function
|
|
|
|
// below.
|
|
|
|
//
|
|
|
|
// In order to get this left-to-right dependency ordering, we perform a
|
|
|
|
// topological sort of all crates putting the leaves at the right-most
|
|
|
|
// positions.
|
2013-12-25 21:08:04 +01:00
|
|
|
pub fn get_used_crates(&self, prefer: LinkagePreference)
|
2015-02-27 06:00:43 +01:00
|
|
|
-> Vec<(ast::CrateNum, Option<PathBuf>)> {
|
2014-03-14 02:47:43 +01:00
|
|
|
let mut ordering = Vec::new();
|
|
|
|
fn visit(cstore: &CStore, cnum: ast::CrateNum,
|
|
|
|
ordering: &mut Vec<ast::CrateNum>) {
|
2014-11-27 19:53:34 +01:00
|
|
|
if ordering.contains(&cnum) { return }
|
2014-03-14 02:47:43 +01:00
|
|
|
let meta = cstore.get_crate_data(cnum);
|
2015-01-31 18:20:46 +01:00
|
|
|
for (_, &dep) in &meta.cnum_map {
|
2014-03-14 02:47:43 +01:00
|
|
|
visit(cstore, dep, ordering);
|
|
|
|
}
|
|
|
|
ordering.push(cnum);
|
|
|
|
};
|
2015-01-31 18:20:46 +01:00
|
|
|
for (&num, _) in &*self.metas.borrow() {
|
2014-03-14 02:47:43 +01:00
|
|
|
visit(self, num, &mut ordering);
|
|
|
|
}
|
2014-11-27 22:47:48 +01:00
|
|
|
ordering.reverse();
|
2014-03-21 03:49:20 +01:00
|
|
|
let mut libs = self.used_crate_sources.borrow()
|
2013-12-21 04:50:13 +01:00
|
|
|
.iter()
|
2013-12-25 21:08:04 +01:00
|
|
|
.map(|src| (src.cnum, match prefer {
|
2015-01-06 17:46:07 +01:00
|
|
|
RequireDynamic => src.dylib.clone().map(|p| p.0),
|
|
|
|
RequireStatic => src.rlib.clone().map(|p| p.0),
|
2013-12-25 21:08:04 +01:00
|
|
|
}))
|
2015-01-06 17:46:07 +01:00
|
|
|
.collect::<Vec<_>>();
|
2014-03-14 02:47:43 +01:00
|
|
|
libs.sort_by(|&(a, _), &(b, _)| {
|
|
|
|
ordering.position_elem(&a).cmp(&ordering.position_elem(&b))
|
|
|
|
});
|
|
|
|
libs
|
2013-12-25 21:08:04 +01:00
|
|
|
}
|
|
|
|
|
librustc: Make `Copy` opt-in.
This change makes the compiler no longer infer whether types (structures
and enumerations) implement the `Copy` trait (and thus are implicitly
copyable). Rather, you must implement `Copy` yourself via `impl Copy for
MyType {}`.
A new warning has been added, `missing_copy_implementations`, to warn
you if a non-generic public type has been added that could have
implemented `Copy` but didn't.
For convenience, you may *temporarily* opt out of this behavior by using
`#![feature(opt_out_copy)]`. Note though that this feature gate will never be
accepted and will be removed by the time that 1.0 is released, so you should
transition your code away from using it.
This breaks code like:
#[deriving(Show)]
struct Point2D {
x: int,
y: int,
}
fn main() {
let mypoint = Point2D {
x: 1,
y: 1,
};
let otherpoint = mypoint;
println!("{}{}", mypoint, otherpoint);
}
Change this code to:
#[deriving(Show)]
struct Point2D {
x: int,
y: int,
}
impl Copy for Point2D {}
fn main() {
let mypoint = Point2D {
x: 1,
y: 1,
};
let otherpoint = mypoint;
println!("{}{}", mypoint, otherpoint);
}
This is the backwards-incompatible part of #13231.
Part of RFC #3.
[breaking-change]
2014-12-06 02:01:33 +01:00
|
|
|
pub fn add_used_library(&self, lib: String, kind: NativeLibraryKind) {
|
2013-12-25 21:08:04 +01:00
|
|
|
assert!(!lib.is_empty());
|
2014-03-21 03:49:20 +01:00
|
|
|
self.used_libraries.borrow_mut().push((lib, kind));
|
2013-12-25 21:08:04 +01:00
|
|
|
}
|
2011-07-08 03:25:56 +02:00
|
|
|
|
2013-12-21 04:54:01 +01:00
|
|
|
pub fn get_used_libraries<'a>(&'a self)
|
librustc: Make `Copy` opt-in.
This change makes the compiler no longer infer whether types (structures
and enumerations) implement the `Copy` trait (and thus are implicitly
copyable). Rather, you must implement `Copy` yourself via `impl Copy for
MyType {}`.
A new warning has been added, `missing_copy_implementations`, to warn
you if a non-generic public type has been added that could have
implemented `Copy` but didn't.
For convenience, you may *temporarily* opt out of this behavior by using
`#![feature(opt_out_copy)]`. Note though that this feature gate will never be
accepted and will be removed by the time that 1.0 is released, so you should
transition your code away from using it.
This breaks code like:
#[deriving(Show)]
struct Point2D {
x: int,
y: int,
}
fn main() {
let mypoint = Point2D {
x: 1,
y: 1,
};
let otherpoint = mypoint;
println!("{}{}", mypoint, otherpoint);
}
Change this code to:
#[deriving(Show)]
struct Point2D {
x: int,
y: int,
}
impl Copy for Point2D {}
fn main() {
let mypoint = Point2D {
x: 1,
y: 1,
};
let otherpoint = mypoint;
println!("{}{}", mypoint, otherpoint);
}
This is the backwards-incompatible part of #13231.
Part of RFC #3.
[breaking-change]
2014-12-06 02:01:33 +01:00
|
|
|
-> &'a RefCell<Vec<(String,
|
|
|
|
NativeLibraryKind)>> {
|
2013-12-21 04:54:01 +01:00
|
|
|
&self.used_libraries
|
2013-12-25 21:08:04 +01:00
|
|
|
}
|
2011-07-08 03:33:59 +02:00
|
|
|
|
2013-12-21 05:00:58 +01:00
|
|
|
pub fn add_used_link_args(&self, args: &str) {
|
2014-07-07 18:54:38 +02:00
|
|
|
for s in args.split(' ').filter(|s| !s.is_empty()) {
|
2014-05-25 12:17:19 +02:00
|
|
|
self.used_link_args.borrow_mut().push(s.to_string());
|
2013-12-25 21:08:04 +01:00
|
|
|
}
|
|
|
|
}
|
2011-07-08 03:33:59 +02:00
|
|
|
|
2014-05-23 01:57:53 +02:00
|
|
|
pub fn get_used_link_args<'a>(&'a self) -> &'a RefCell<Vec<String> > {
|
2013-12-21 04:56:29 +01:00
|
|
|
&self.used_link_args
|
2013-12-25 21:08:04 +01:00
|
|
|
}
|
2011-07-08 03:33:59 +02:00
|
|
|
|
2013-12-21 05:00:58 +01:00
|
|
|
pub fn add_extern_mod_stmt_cnum(&self,
|
2013-12-25 21:08:04 +01:00
|
|
|
emod_id: ast::NodeId,
|
|
|
|
cnum: ast::CrateNum) {
|
2014-03-21 03:49:20 +01:00
|
|
|
self.extern_mod_crate_map.borrow_mut().insert(emod_id, cnum);
|
2013-03-24 07:51:18 +01:00
|
|
|
}
|
2011-07-08 03:38:42 +02:00
|
|
|
|
2013-12-25 21:08:04 +01:00
|
|
|
pub fn find_extern_mod_stmt_cnum(&self, emod_id: ast::NodeId)
|
|
|
|
-> Option<ast::CrateNum> {
|
2015-02-13 08:33:44 +01:00
|
|
|
self.extern_mod_crate_map.borrow().get(&emod_id).cloned()
|
2013-12-25 21:08:04 +01:00
|
|
|
}
|
2013-07-02 21:47:32 +02:00
|
|
|
}
|
|
|
|
|
2013-12-18 23:10:28 +01:00
|
|
|
impl crate_metadata {
|
|
|
|
pub fn data<'a>(&'a self) -> &'a [u8] { self.data.as_slice() }
|
2014-06-06 22:21:18 +02:00
|
|
|
pub fn name(&self) -> String { decoder::get_crate_name(self.data()) }
|
2014-04-07 21:14:33 +02:00
|
|
|
pub fn hash(&self) -> Svh { decoder::get_crate_hash(self.data()) }
|
2013-12-18 23:10:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
impl MetadataBlob {
|
|
|
|
pub fn as_slice<'a>(&'a self) -> &'a [u8] {
|
2014-12-05 06:32:34 +01:00
|
|
|
let slice = match *self {
|
2015-03-18 17:14:54 +01:00
|
|
|
MetadataVec(ref vec) => &vec[..],
|
2013-12-17 05:58:21 +01:00
|
|
|
MetadataArchive(ref ar) => ar.as_slice(),
|
2014-12-05 06:32:34 +01:00
|
|
|
};
|
|
|
|
if slice.len() < 4 {
|
2014-12-13 03:00:17 +01:00
|
|
|
&[] // corrupt metadata
|
2014-12-05 06:32:34 +01:00
|
|
|
} else {
|
2014-12-13 03:00:17 +01:00
|
|
|
let len = (((slice[0] as u32) << 24) |
|
|
|
|
((slice[1] as u32) << 16) |
|
|
|
|
((slice[2] as u32) << 8) |
|
|
|
|
((slice[3] as u32) << 0)) as uint;
|
|
|
|
if len + 4 <= slice.len() {
|
2015-01-18 01:15:52 +01:00
|
|
|
&slice[4.. len + 4]
|
2014-12-13 03:00:17 +01:00
|
|
|
} else {
|
|
|
|
&[] // corrupt or old metadata
|
|
|
|
}
|
2013-12-18 23:10:28 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|