librustc: Remove a bunch of @str from the compiler around metadata
handling
This commit is contained in:
parent
b890237e79
commit
9869374256
11 changed files with 101 additions and 73 deletions
|
|
@ -473,10 +473,10 @@ pub fn build_link_meta(sess: Session,
|
|||
symbol_hasher: &mut Sha256)
|
||||
-> LinkMeta {
|
||||
// This calculates CMH as defined above
|
||||
fn crate_hash(symbol_hasher: &mut Sha256, crateid: &CrateId) -> @str {
|
||||
fn crate_hash(symbol_hasher: &mut Sha256, crateid: &CrateId) -> ~str {
|
||||
symbol_hasher.reset();
|
||||
symbol_hasher.input_str(crateid.to_str());
|
||||
truncated_hash_result(symbol_hasher).to_managed()
|
||||
truncated_hash_result(symbol_hasher)
|
||||
}
|
||||
|
||||
let crateid = match attr::find_crateid(attrs) {
|
||||
|
|
@ -963,7 +963,7 @@ fn link_staticlib(sess: Session, obj_filename: &Path, out_filename: &Path) {
|
|||
|
||||
let crates = sess.cstore.get_used_crates(cstore::RequireStatic);
|
||||
for &(cnum, ref path) in crates.iter() {
|
||||
let name = sess.cstore.get_crate_data(cnum).name;
|
||||
let name = sess.cstore.get_crate_data(cnum).name.clone();
|
||||
let p = match *path {
|
||||
Some(ref p) => p.clone(), None => {
|
||||
sess.err(format!("could not find rlib for: `{}`", name));
|
||||
|
|
@ -1221,7 +1221,7 @@ fn add_upstream_rust_crates(args: &mut ~[~str], sess: Session,
|
|||
// If we're not doing LTO, then our job is simply to just link
|
||||
// against the archive.
|
||||
if sess.lto() {
|
||||
let name = sess.cstore.get_crate_data(cnum).name;
|
||||
let name = sess.cstore.get_crate_data(cnum).name.clone();
|
||||
time(sess.time_passes(), format!("altering {}.rlib", name),
|
||||
(), |()| {
|
||||
let dst = tmpdir.join(cratepath.filename().unwrap());
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ pub fn run(sess: session::Session, llmod: ModuleRef,
|
|||
// module that we've got.
|
||||
let crates = sess.cstore.get_used_crates(cstore::RequireStatic);
|
||||
for (cnum, path) in crates.move_iter() {
|
||||
let name = sess.cstore.get_crate_data(cnum).name;
|
||||
let name = sess.cstore.get_crate_data(cnum).name.clone();
|
||||
let path = match path {
|
||||
Some(p) => p,
|
||||
None => {
|
||||
|
|
|
|||
|
|
@ -210,5 +210,5 @@ pub static tag_macro_def: uint = 0x112;
|
|||
#[deriving(Clone)]
|
||||
pub struct LinkMeta {
|
||||
crateid: CrateId,
|
||||
crate_hash: @str,
|
||||
crate_hash: ~str,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@ impl<'a> visit::Visitor<()> for ReadCrateVisitor<'a> {
|
|||
struct cache_entry {
|
||||
cnum: ast::CrateNum,
|
||||
span: Span,
|
||||
hash: @str,
|
||||
hash: ~str,
|
||||
crateid: CrateId,
|
||||
}
|
||||
|
||||
|
|
@ -146,8 +146,12 @@ fn visit_view_item(e: &mut Env, i: &ast::ViewItem) {
|
|||
|
||||
match extract_crate_info(i) {
|
||||
Some(info) => {
|
||||
let cnum = resolve_crate(e, info.ident, info.name, info.version,
|
||||
@"", i.span);
|
||||
let cnum = resolve_crate(e,
|
||||
info.ident.clone(),
|
||||
info.name.clone(),
|
||||
info.version.clone(),
|
||||
~"",
|
||||
i.span);
|
||||
e.sess.cstore.add_extern_mod_stmt_cnum(info.id, cnum);
|
||||
}
|
||||
None => ()
|
||||
|
|
@ -155,36 +159,36 @@ fn visit_view_item(e: &mut Env, i: &ast::ViewItem) {
|
|||
}
|
||||
|
||||
struct CrateInfo {
|
||||
ident: @str,
|
||||
name: @str,
|
||||
version: @str,
|
||||
ident: ~str,
|
||||
name: ~str,
|
||||
version: ~str,
|
||||
id: ast::NodeId,
|
||||
}
|
||||
|
||||
fn extract_crate_info(i: &ast::ViewItem) -> Option<CrateInfo> {
|
||||
match i.node {
|
||||
ast::ViewItemExternMod(ref ident, ref path_opt, id) => {
|
||||
let ident = token::ident_to_str(ident);
|
||||
let ident = token::get_ident(ident.name);
|
||||
debug!("resolving extern mod stmt. ident: {:?} path_opt: {:?}",
|
||||
ident, path_opt);
|
||||
ident.get(), path_opt);
|
||||
let (name, version) = match *path_opt {
|
||||
Some((ref path_str, _)) => {
|
||||
let crateid: Option<CrateId> = from_str(path_str.get());
|
||||
match crateid {
|
||||
None => (@"", @""),
|
||||
None => (~"", ~""),
|
||||
Some(crateid) => {
|
||||
let version = match crateid.version {
|
||||
None => @"",
|
||||
Some(ref ver) => ver.to_managed(),
|
||||
None => ~"",
|
||||
Some(ref ver) => ver.to_str(),
|
||||
};
|
||||
(crateid.name.to_managed(), version)
|
||||
(crateid.name.to_str(), version)
|
||||
}
|
||||
}
|
||||
}
|
||||
None => (ident, @""),
|
||||
None => (ident.get().to_str(), ~""),
|
||||
};
|
||||
Some(CrateInfo {
|
||||
ident: ident,
|
||||
ident: ident.get().to_str(),
|
||||
name: name,
|
||||
version: version,
|
||||
id: id,
|
||||
|
|
@ -278,14 +282,14 @@ fn visit_item(e: &Env, i: &ast::Item) {
|
|||
}
|
||||
}
|
||||
|
||||
fn existing_match(e: &Env, name: @str, version: @str, hash: &str) -> Option<ast::CrateNum> {
|
||||
fn existing_match(e: &Env, name: ~str, version: ~str, hash: &str) -> Option<ast::CrateNum> {
|
||||
let crate_cache = e.crate_cache.borrow();
|
||||
for c in crate_cache.get().iter() {
|
||||
let crateid_version = match c.crateid.version {
|
||||
None => @"0.0",
|
||||
Some(ref ver) => ver.to_managed(),
|
||||
None => ~"0.0",
|
||||
Some(ref ver) => ver.to_str(),
|
||||
};
|
||||
if (name.is_empty() || c.crateid.name.to_managed() == name) &&
|
||||
if (name.is_empty() || c.crateid.name == name) &&
|
||||
(version.is_empty() || crateid_version == version) &&
|
||||
(hash.is_empty() || c.hash.as_slice() == hash) {
|
||||
return Some(c.cnum);
|
||||
|
|
@ -295,19 +299,19 @@ fn existing_match(e: &Env, name: @str, version: @str, hash: &str) -> Option<ast:
|
|||
}
|
||||
|
||||
fn resolve_crate(e: &mut Env,
|
||||
ident: @str,
|
||||
name: @str,
|
||||
version: @str,
|
||||
hash: @str,
|
||||
ident: ~str,
|
||||
name: ~str,
|
||||
version: ~str,
|
||||
hash: ~str,
|
||||
span: Span)
|
||||
-> ast::CrateNum {
|
||||
match existing_match(e, name, version, hash) {
|
||||
match existing_match(e, name.clone(), version.clone(), hash.clone()) {
|
||||
None => {
|
||||
let load_ctxt = loader::Context {
|
||||
sess: e.sess,
|
||||
span: span,
|
||||
ident: ident,
|
||||
name: name,
|
||||
name: name.clone(),
|
||||
version: version,
|
||||
hash: hash,
|
||||
os: e.os,
|
||||
|
|
@ -368,10 +372,13 @@ fn resolve_crate_deps(e: &mut Env, cdata: &[u8]) -> cstore::cnum_map {
|
|||
let r = decoder::get_crate_deps(cdata);
|
||||
for dep in r.iter() {
|
||||
let extrn_cnum = dep.cnum;
|
||||
let cname_str = token::ident_to_str(&dep.name);
|
||||
let cname_str = token::get_ident(dep.name.name);
|
||||
debug!("resolving dep crate {} ver: {} hash: {}",
|
||||
cname_str, dep.vers, dep.hash);
|
||||
match existing_match(e, cname_str, dep.vers, dep.hash) {
|
||||
match existing_match(e,
|
||||
cname_str.get().to_str(),
|
||||
dep.vers.clone(),
|
||||
dep.hash.clone()) {
|
||||
Some(local_cnum) => {
|
||||
debug!("already have it");
|
||||
// We've already seen this crate
|
||||
|
|
@ -383,8 +390,12 @@ fn resolve_crate_deps(e: &mut Env, cdata: &[u8]) -> cstore::cnum_map {
|
|||
// FIXME (#2404): Need better error reporting than just a bogus
|
||||
// span.
|
||||
let fake_span = DUMMY_SP;
|
||||
let local_cnum = resolve_crate(e, cname_str, cname_str, dep.vers,
|
||||
dep.hash, fake_span);
|
||||
let local_cnum = resolve_crate(e,
|
||||
cname_str.get().to_str(),
|
||||
cname_str.get().to_str(),
|
||||
dep.vers.clone(),
|
||||
dep.hash.clone(),
|
||||
fake_span);
|
||||
cnum_map.insert(extrn_cnum, local_cnum);
|
||||
}
|
||||
}
|
||||
|
|
@ -415,8 +426,12 @@ impl Loader {
|
|||
impl CrateLoader for Loader {
|
||||
fn load_crate(&mut self, crate: &ast::ViewItem) -> MacroCrate {
|
||||
let info = extract_crate_info(crate).unwrap();
|
||||
let cnum = resolve_crate(&mut self.env, info.ident, info.name,
|
||||
info.version, @"", crate.span);
|
||||
let cnum = resolve_crate(&mut self.env,
|
||||
info.ident.clone(),
|
||||
info.name.clone(),
|
||||
info.version.clone(),
|
||||
~"",
|
||||
crate.span);
|
||||
let library = self.env.sess.cstore.get_used_crate_source(cnum).unwrap();
|
||||
MacroCrate {
|
||||
lib: library.dylib,
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ pub enum MetadataBlob {
|
|||
}
|
||||
|
||||
pub struct crate_metadata {
|
||||
name: @str,
|
||||
name: ~str,
|
||||
data: MetadataBlob,
|
||||
cnum_map: cnum_map,
|
||||
cnum: ast::CrateNum
|
||||
|
|
@ -89,12 +89,12 @@ impl CStore {
|
|||
*metas.get().get(&cnum)
|
||||
}
|
||||
|
||||
pub fn get_crate_hash(&self, cnum: ast::CrateNum) -> @str {
|
||||
pub fn get_crate_hash(&self, cnum: ast::CrateNum) -> ~str {
|
||||
let cdata = self.get_crate_data(cnum);
|
||||
decoder::get_crate_hash(cdata.data())
|
||||
}
|
||||
|
||||
pub fn get_crate_vers(&self, cnum: ast::CrateNum) -> @str {
|
||||
pub fn get_crate_vers(&self, cnum: ast::CrateNum) -> ~str {
|
||||
let cdata = self.get_crate_data(cnum);
|
||||
decoder::get_crate_vers(cdata.data())
|
||||
}
|
||||
|
|
@ -192,7 +192,7 @@ impl CStore {
|
|||
|
||||
// returns hashes of crates directly used by this crate. Hashes are sorted by
|
||||
// (crate name, crate version, crate hash) in lexicographic order (not semver)
|
||||
pub fn get_dep_hashes(&self) -> ~[@str] {
|
||||
pub fn get_dep_hashes(&self) -> ~[~str] {
|
||||
let mut result = ~[];
|
||||
|
||||
let extern_mod_crate_map = self.extern_mod_crate_map.borrow();
|
||||
|
|
@ -202,7 +202,7 @@ impl CStore {
|
|||
let vers = decoder::get_crate_vers(cdata.data());
|
||||
debug!("Add hash[{}]: {} {}", cdata.name, vers, hash);
|
||||
result.push(crate_hash {
|
||||
name: cdata.name,
|
||||
name: cdata.name.clone(),
|
||||
vers: vers,
|
||||
hash: hash
|
||||
});
|
||||
|
|
@ -215,15 +215,23 @@ impl CStore {
|
|||
debug!(" hash[{}]: {}", x.name, x.hash);
|
||||
}
|
||||
|
||||
result.map(|ch| ch.hash)
|
||||
let mut hashes = ~[];
|
||||
for ch in result.move_iter() {
|
||||
let crate_hash {
|
||||
hash,
|
||||
..
|
||||
} = ch;
|
||||
hashes.push(hash)
|
||||
}
|
||||
hashes
|
||||
}
|
||||
}
|
||||
|
||||
#[deriving(Clone, TotalEq, TotalOrd)]
|
||||
struct crate_hash {
|
||||
name: @str,
|
||||
vers: @str,
|
||||
hash: @str,
|
||||
name: ~str,
|
||||
vers: ~str,
|
||||
hash: ~str,
|
||||
}
|
||||
|
||||
impl crate_metadata {
|
||||
|
|
|
|||
|
|
@ -1113,8 +1113,8 @@ pub fn get_crate_attributes(data: &[u8]) -> ~[ast::Attribute] {
|
|||
pub struct CrateDep {
|
||||
cnum: ast::CrateNum,
|
||||
name: ast::Ident,
|
||||
vers: @str,
|
||||
hash: @str
|
||||
vers: ~str,
|
||||
hash: ~str
|
||||
}
|
||||
|
||||
pub fn get_crate_deps(data: &[u8]) -> ~[CrateDep] {
|
||||
|
|
@ -1122,9 +1122,9 @@ pub fn get_crate_deps(data: &[u8]) -> ~[CrateDep] {
|
|||
let cratedoc = reader::Doc(data);
|
||||
let depsdoc = reader::get_doc(cratedoc, tag_crate_deps);
|
||||
let mut crate_num = 1;
|
||||
fn docstr(doc: ebml::Doc, tag_: uint) -> @str {
|
||||
fn docstr(doc: ebml::Doc, tag_: uint) -> ~str {
|
||||
let d = reader::get_doc(doc, tag_);
|
||||
d.as_str_slice().to_managed()
|
||||
d.as_str_slice().to_str()
|
||||
}
|
||||
reader::tagged_docs(depsdoc, tag_crate_dep, |depdoc| {
|
||||
deps.push(CrateDep {cnum: crate_num,
|
||||
|
|
@ -1149,17 +1149,17 @@ fn list_crate_deps(data: &[u8], out: &mut io::Writer) {
|
|||
write!(out, "\n");
|
||||
}
|
||||
|
||||
pub fn get_crate_hash(data: &[u8]) -> @str {
|
||||
pub fn get_crate_hash(data: &[u8]) -> ~str {
|
||||
let cratedoc = reader::Doc(data);
|
||||
let hashdoc = reader::get_doc(cratedoc, tag_crate_hash);
|
||||
hashdoc.as_str_slice().to_managed()
|
||||
hashdoc.as_str_slice().to_str()
|
||||
}
|
||||
|
||||
pub fn get_crate_vers(data: &[u8]) -> @str {
|
||||
pub fn get_crate_vers(data: &[u8]) -> ~str {
|
||||
let attrs = decoder::get_crate_attributes(data);
|
||||
match attr::find_crateid(attrs) {
|
||||
None => @"0.0",
|
||||
Some(crateid) => crateid.version_or_default().to_managed(),
|
||||
None => ~"0.0",
|
||||
Some(crateid) => crateid.version_or_default().to_str(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1614,7 +1614,7 @@ fn encode_crate_deps(ecx: &EncodeContext,
|
|||
ebml_w.start_tag(tag_crate_deps);
|
||||
let r = get_ordered_deps(ecx, cstore);
|
||||
for dep in r.iter() {
|
||||
encode_crate_dep(ecx, ebml_w, *dep);
|
||||
encode_crate_dep(ecx, ebml_w, (*dep).clone());
|
||||
}
|
||||
ebml_w.end_tag();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,10 +46,10 @@ pub enum Os {
|
|||
pub struct Context {
|
||||
sess: Session,
|
||||
span: Span,
|
||||
ident: @str,
|
||||
name: @str,
|
||||
version: @str,
|
||||
hash: @str,
|
||||
ident: ~str,
|
||||
name: ~str,
|
||||
version: ~str,
|
||||
hash: ~str,
|
||||
os: Os,
|
||||
intr: @IdentInterner
|
||||
}
|
||||
|
|
@ -80,7 +80,7 @@ impl Context {
|
|||
|
||||
fn find_library_crate(&self) -> Option<Library> {
|
||||
let filesearch = self.sess.filesearch;
|
||||
let crate_name = self.name;
|
||||
let crate_name = self.name.clone();
|
||||
let (dyprefix, dysuffix) = self.dylibname();
|
||||
|
||||
// want: crate_name.dir_part() + prefix + crate_name.file_part + "-"
|
||||
|
|
@ -109,8 +109,10 @@ impl Context {
|
|||
} else if candidate {
|
||||
match get_metadata_section(self.os, path) {
|
||||
Some(cvec) =>
|
||||
if crate_matches(cvec.as_slice(), self.name,
|
||||
self.version, self.hash) {
|
||||
if crate_matches(cvec.as_slice(),
|
||||
self.name.clone(),
|
||||
self.version.clone(),
|
||||
self.hash.clone()) {
|
||||
debug!("found {} with matching crate_id",
|
||||
path.display());
|
||||
let (rlib, dylib) = if file.ends_with(".rlib") {
|
||||
|
|
@ -235,9 +237,9 @@ pub fn note_crateid_attr(diag: @SpanHandler, crateid: &CrateId) {
|
|||
}
|
||||
|
||||
fn crate_matches(crate_data: &[u8],
|
||||
name: @str,
|
||||
version: @str,
|
||||
hash: @str) -> bool {
|
||||
name: ~str,
|
||||
version: ~str,
|
||||
hash: ~str) -> bool {
|
||||
let attrs = decoder::get_crate_attributes(crate_data);
|
||||
match attr::find_crateid(attrs) {
|
||||
None => false,
|
||||
|
|
@ -246,8 +248,9 @@ fn crate_matches(crate_data: &[u8],
|
|||
let chash = decoder::get_crate_hash(crate_data);
|
||||
if chash != hash { return false; }
|
||||
}
|
||||
name == crateid.name.to_managed() &&
|
||||
(version.is_empty() || version == crateid.version_or_default().to_managed())
|
||||
name == crateid.name &&
|
||||
(version.is_empty() ||
|
||||
crateid.version_or_default() == version)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1797,9 +1797,9 @@ fn trans_log_level<'a>(bcx: &'a Block<'a>)
|
|||
let external_srcs = ccx.external_srcs.borrow();
|
||||
srccrate = match external_srcs.get().find(&bcx.fcx.id) {
|
||||
Some(&src) => {
|
||||
ccx.sess.cstore.get_crate_data(src.crate).name
|
||||
ccx.sess.cstore.get_crate_data(src.crate).name.clone()
|
||||
}
|
||||
None => ccx.link_meta.crateid.name.to_managed(),
|
||||
None => ccx.link_meta.crateid.name.to_str(),
|
||||
};
|
||||
};
|
||||
let mut modpath = ~[PathMod(ccx.sess.ident_of(srccrate))];
|
||||
|
|
|
|||
|
|
@ -337,8 +337,10 @@ pub fn trans_intrinsic(ccx: @CrateContext,
|
|||
Ret(bcx, td);
|
||||
}
|
||||
"type_id" => {
|
||||
let hash = ty::hash_crate_independent(ccx.tcx, substs.tys[0],
|
||||
ccx.link_meta.crate_hash);
|
||||
let hash = ty::hash_crate_independent(
|
||||
ccx.tcx,
|
||||
substs.tys[0],
|
||||
ccx.link_meta.crate_hash.clone());
|
||||
// NB: This needs to be kept in lockstep with the TypeId struct in
|
||||
// libstd/unstable/intrinsics.rs
|
||||
let val = C_named_struct(type_of::type_of(ccx, output_type), [C_u64(hash)]);
|
||||
|
|
|
|||
|
|
@ -4834,7 +4834,7 @@ pub fn trait_method_of_method(tcx: ctxt,
|
|||
|
||||
/// Creates a hash of the type `t` which will be the same no matter what crate
|
||||
/// context it's calculated within. This is used by the `type_id` intrinsic.
|
||||
pub fn hash_crate_independent(tcx: ctxt, t: t, local_hash: @str) -> u64 {
|
||||
pub fn hash_crate_independent(tcx: ctxt, t: t, local_hash: ~str) -> u64 {
|
||||
use std::hash::{SipState, Streaming};
|
||||
|
||||
let mut hash = SipState::new(0, 0);
|
||||
|
|
@ -4865,7 +4865,7 @@ pub fn hash_crate_independent(tcx: ctxt, t: t, local_hash: @str) -> u64 {
|
|||
};
|
||||
let did = |hash: &mut SipState, did: DefId| {
|
||||
let h = if ast_util::is_local(did) {
|
||||
local_hash
|
||||
local_hash.clone()
|
||||
} else {
|
||||
tcx.sess.cstore.get_crate_hash(did.crate)
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue