Skip to content

librustc: Remove @str from the language #11967

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

Closed
wants to merge 37 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
92ad5a4
libsyntax: Introduce an `InternedString` type to reduce `@str` in the
pcwalton Jan 8, 2014
131d77c
libsyntax: De-`@str` literal strings in the AST
pcwalton Jan 10, 2014
98957b2
libsyntax: De-`@str` `to_source`
pcwalton Jan 11, 2014
1ecabfd
librustc: Fix merge fallout.
pcwalton Jan 13, 2014
637f772
libsyntax: Remove the unnecessary `src` field from the lexer
pcwalton Jan 16, 2014
34b6c52
librustc: Stop using `@str` for source.
pcwalton Jan 16, 2014
1ed30ce
libsyntax: De-`@str` pathnames
pcwalton Jan 16, 2014
d65cdb4
libsyntax: Make float literals not use `@str`
pcwalton Jan 16, 2014
77996ab
libsyntax: Remove all `@str` from the AST
pcwalton Jan 16, 2014
0b00023
libsyntax: De-`@str` `get_single_str_from_tts`
pcwalton Jan 16, 2014
87de14f
libsyntax: Remove `ident_to_str` from the parser, which was returning
pcwalton Jan 16, 2014
a24808c
librustc: Fix merge fallout.
pcwalton Jan 21, 2014
5c6404f
librustc: De-`@str` `NameAndSpan`
pcwalton Jan 30, 2014
df6bd91
libsyntax: De-`@str` `MacroDef`
pcwalton Jan 31, 2014
baf99da
libsyntax: Fix tests.
pcwalton Jan 31, 2014
97a1492
librustc: Remove a bunch of `@str` from the compiler around metadata
pcwalton Jan 31, 2014
b979760
librustc: De-`@str` resolve
pcwalton Jan 31, 2014
7f2d972
librustc: De-`@str` debuginfo
pcwalton Jan 31, 2014
949f32d
librustc: De-`@str` symbol hashing
pcwalton Jan 31, 2014
2f4dab6
librustc: De-`@str` liveness
pcwalton Jan 31, 2014
47fee10
librustc: De-`@str` type short names
pcwalton Jan 31, 2014
b72b715
librustc: De-`@str` the LLVM symbol list
pcwalton Jan 31, 2014
ca34fba
librustc: De-`@str` `ident()` and `str_of()`
pcwalton Jan 31, 2014
8a5b59a
librustc: Get rid of calls to `token::ident_to_str` in debug info
pcwalton Jan 31, 2014
5f7cf32
librustc: Get rid of `ident_to_str` calls in resolve
pcwalton Jan 31, 2014
60222b3
librustc: Remove uses of `token::ident_to_str()` from librustc
pcwalton Jan 31, 2014
bda001a
libsyntax: Remove many uses of `token::ident_to_str`
pcwalton Jan 31, 2014
f3d10bf
libsyntax: Remove uses of `token::ident_to_str()`
pcwalton Jan 31, 2014
1165794
librustc: Remove uses of `interner_get` in librustc
pcwalton Feb 1, 2014
ebd6665
libsyntax: Remove the `interner_get` function and all uses
pcwalton Feb 1, 2014
89d53e2
libsyntax: Remove an `@str` in pretty printing
pcwalton Feb 1, 2014
cd214ad
librustc: Remove one more `@str` from librustc
pcwalton Feb 1, 2014
3186514
test: Remove `@str` from the test suite
pcwalton Feb 1, 2014
098060e
libsyntax: Remove `@str` from the interner
pcwalton Feb 1, 2014
10064b4
doc: Remove references to `@str` from the documentation
pcwalton Feb 1, 2014
086849b
libextra: Remove `@str` from all the libraries
pcwalton Feb 1, 2014
8544cb2
librustc: Remove `@str` from the language
pcwalton Feb 1, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/rust.md
Original file line number Diff line number Diff line change
Expand Up @@ -3079,7 +3079,7 @@ A value of type `str` is a Unicode string,
represented as a vector of 8-bit unsigned bytes holding a sequence of UTF-8 codepoints.
Since `str` is of unknown size, it is not a _first class_ type,
but can only be instantiated through a pointer type,
such as `&str`, `@str` or `~str`.
such as `&str` or `~str`.

### Tuple types

Expand Down
12 changes: 0 additions & 12 deletions src/libextra/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,18 +310,6 @@ impl<D:Decoder> Decodable<D> for ~str {
}
}

impl<S:Encoder> Encodable<S> for @str {
fn encode(&self, s: &mut S) {
s.emit_str(*self)
}
}

impl<D:Decoder> Decodable<D> for @str {
fn decode(d: &mut D) -> @str {
d.read_str().to_managed()
}
}

impl<S:Encoder> Encodable<S> for f32 {
fn encode(&self, s: &mut S) {
s.emit_f32(*self)
Expand Down
20 changes: 10 additions & 10 deletions src/librustc/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -510,7 +510,8 @@ fn truncated_hash_result(symbol_hasher: &mut Sha256) -> ~str {
pub fn symbol_hash(tcx: ty::ctxt,
symbol_hasher: &mut Sha256,
t: ty::t,
link_meta: &LinkMeta) -> @str {
link_meta: &LinkMeta)
-> ~str {
// NB: do *not* use abbrevs here as we want the symbol names
// to be independent of one another in the crate.

Expand All @@ -523,23 +524,22 @@ pub fn symbol_hash(tcx: ty::ctxt,
let mut hash = truncated_hash_result(symbol_hasher);
// Prefix with 'h' so that it never blends into adjacent digits
hash.unshift_char('h');
// tjc: allocation is unfortunate; need to change std::hash
hash.to_managed()
hash
}

pub fn get_symbol_hash(ccx: &CrateContext, t: ty::t) -> @str {
pub fn get_symbol_hash(ccx: &CrateContext, t: ty::t) -> ~str {
{
let type_hashcodes = ccx.type_hashcodes.borrow();
match type_hashcodes.get().find(&t) {
Some(&h) => return h,
Some(h) => return h.to_str(),
None => {}
}
}

let mut type_hashcodes = ccx.type_hashcodes.borrow_mut();
let mut symbol_hasher = ccx.symbol_hasher.borrow_mut();
let hash = symbol_hash(ccx.tcx, symbol_hasher.get(), t, &ccx.link_meta);
type_hashcodes.get().insert(t, hash);
type_hashcodes.get().insert(t, hash.clone());
hash
}

Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/back/lto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down
86 changes: 49 additions & 37 deletions src/librustc/driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ use syntax::codemap;
use syntax::diagnostic;
use syntax::ext::base::CrateLoader;
use syntax::parse;
use syntax::parse::token::InternedString;
use syntax::parse::token;
use syntax::print::{pp, pprust};
use syntax;
Expand All @@ -60,52 +61,56 @@ pub enum PpMode {
* The name used for source code that doesn't originate in a file
* (e.g. source from stdin or a string)
*/
pub fn anon_src() -> @str { @"<anon>" }
pub fn anon_src() -> ~str {
"<anon>".to_str()
}

pub fn source_name(input: &Input) -> @str {
pub fn source_name(input: &Input) -> ~str {
match *input {
// FIXME (#9639): This needs to handle non-utf8 paths
FileInput(ref ifile) => ifile.as_str().unwrap().to_managed(),
FileInput(ref ifile) => ifile.as_str().unwrap().to_str(),
StrInput(_) => anon_src()
}
}

pub fn default_configuration(sess: Session) ->
ast::CrateConfig {
let tos = match sess.targ_cfg.os {
abi::OsWin32 => @"win32",
abi::OsMacos => @"macos",
abi::OsLinux => @"linux",
abi::OsAndroid => @"android",
abi::OsFreebsd => @"freebsd"
abi::OsWin32 => InternedString::new("win32"),
abi::OsMacos => InternedString::new("macos"),
abi::OsLinux => InternedString::new("linux"),
abi::OsAndroid => InternedString::new("android"),
abi::OsFreebsd => InternedString::new("freebsd"),
};

// ARM is bi-endian, however using NDK seems to default
// to little-endian unless a flag is provided.
let (end,arch,wordsz) = match sess.targ_cfg.arch {
abi::X86 => (@"little", @"x86", @"32"),
abi::X86_64 => (@"little", @"x86_64", @"64"),
abi::Arm => (@"little", @"arm", @"32"),
abi::Mips => (@"big", @"mips", @"32")
abi::X86 => ("little", "x86", "32"),
abi::X86_64 => ("little", "x86_64", "64"),
abi::Arm => ("little", "arm", "32"),
abi::Mips => ("big", "mips", "32")
};

let fam = match sess.targ_cfg.os {
abi::OsWin32 => @"windows",
_ => @"unix"
abi::OsWin32 => InternedString::new("windows"),
_ => InternedString::new("unix")
};

let mk = attr::mk_name_value_item_str;
return ~[ // Target bindings.
attr::mk_word_item(fam),
mk(@"target_os", tos),
mk(@"target_family", fam),
mk(@"target_arch", arch),
mk(@"target_endian", end),
mk(@"target_word_size", wordsz),
attr::mk_word_item(fam.clone()),
mk(InternedString::new("target_os"), tos),
mk(InternedString::new("target_family"), fam),
mk(InternedString::new("target_arch"), InternedString::new(arch)),
mk(InternedString::new("target_endian"), InternedString::new(end)),
mk(InternedString::new("target_word_size"),
InternedString::new(wordsz)),
];
}

pub fn append_configuration(cfg: &mut ast::CrateConfig, name: @str) {
pub fn append_configuration(cfg: &mut ast::CrateConfig,
name: InternedString) {
if !cfg.iter().any(|mi| mi.name() == name) {
cfg.push(attr::mk_word_item(name))
}
Expand All @@ -118,9 +123,15 @@ pub fn build_configuration(sess: Session) ->
let default_cfg = default_configuration(sess);
let mut user_cfg = sess.opts.cfg.clone();
// If the user wants a test runner, then add the test cfg
if sess.opts.test { append_configuration(&mut user_cfg, @"test") }
if sess.opts.test {
append_configuration(&mut user_cfg, InternedString::new("test"))
}
// If the user requested GC, then add the GC cfg
append_configuration(&mut user_cfg, if sess.opts.gc { @"gc" } else { @"nogc" });
append_configuration(&mut user_cfg, if sess.opts.gc {
InternedString::new("gc")
} else {
InternedString::new("nogc")
});
return vec::append(user_cfg, default_cfg);
}

Expand All @@ -129,16 +140,15 @@ fn parse_cfgspecs(cfgspecs: ~[~str], demitter: @diagnostic::Emitter)
-> ast::CrateConfig {
cfgspecs.move_iter().map(|s| {
let sess = parse::new_parse_sess(Some(demitter));
parse::parse_meta_from_source_str(@"cfgspec", s.to_managed(), ~[], sess)
parse::parse_meta_from_source_str("cfgspec".to_str(), s, ~[], sess)
}).collect::<ast::CrateConfig>()
}

pub enum Input {
/// Load source from file
FileInput(Path),
/// The string is the source
// FIXME (#2319): Don't really want to box the source string
StrInput(@str)
StrInput(~str)
}

pub fn phase_1_parse_input(sess: Session, cfg: ast::CrateConfig, input: &Input)
Expand All @@ -148,9 +158,11 @@ pub fn phase_1_parse_input(sess: Session, cfg: ast::CrateConfig, input: &Input)
FileInput(ref file) => {
parse::parse_crate_from_file(&(*file), cfg.clone(), sess.parse_sess)
}
StrInput(src) => {
parse::parse_crate_from_source_str(
anon_src(), src, cfg.clone(), sess.parse_sess)
StrInput(ref src) => {
parse::parse_crate_from_source_str(anon_src(),
(*src).clone(),
cfg.clone(),
sess.parse_sess)
}
}
})
Expand Down Expand Up @@ -474,13 +486,13 @@ fn write_out_deps(sess: Session, input: &Input, outputs: &OutputFilenames, crate

// Build a list of files used to compile the output and
// write Makefile-compatible dependency rules
let files: ~[@str] = {
let files: ~[~str] = {
let files = sess.codemap.files.borrow();
files.get()
.iter()
.filter_map(|fmap| {
if fmap.is_real_file() {
Some(fmap.name)
Some(fmap.name.clone())
} else {
None
}
Expand Down Expand Up @@ -615,7 +627,7 @@ pub fn pretty_print_input(sess: Session,
_ => @pprust::NoAnn as @pprust::PpAnn,
};

let src = sess.codemap.get_filemap(source_name(input)).src;
let src = &sess.codemap.get_filemap(source_name(input)).src;
let mut rdr = MemReader::new(src.as_bytes().to_owned());
let stdout = io::stdout();
pprust::print_crate(sess.codemap,
Expand Down Expand Up @@ -1100,17 +1112,17 @@ pub fn build_output_filenames(input: &Input,

let mut stem = match *input {
// FIXME (#9639): This needs to handle non-utf8 paths
FileInput(ref ifile) => (*ifile).filestem_str().unwrap().to_managed(),
StrInput(_) => @"rust_out"
FileInput(ref ifile) => {
(*ifile).filestem_str().unwrap().to_str()
}
StrInput(_) => ~"rust_out"
};

// If a crateid is present, we use it as the link name
let crateid = attr::find_crateid(attrs);
match crateid {
None => {}
Some(crateid) => {
stem = crateid.name.to_managed()
}
Some(crateid) => stem = crateid.name.to_str(),
}

if sess.building_library.get() {
Expand Down
37 changes: 25 additions & 12 deletions src/librustc/driver/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,9 +352,11 @@ impl Session_ {
self.debugging_opt(NO_LANDING_PADS)
}

// pointless function, now...
pub fn str_of(&self, id: ast::Ident) -> @str {
token::ident_to_str(&id)
// DEPRECATED. This function results in a lot of allocations when they
// are not necessary.
pub fn str_of(&self, id: ast::Ident) -> ~str {
let string = token::get_ident(id.name);
string.get().to_str()
}

// pointless function, now...
Expand Down Expand Up @@ -417,7 +419,12 @@ pub fn building_library(options: &Options, crate: &ast::Crate) -> bool {
}
}
match syntax::attr::first_attr_value_str_by_name(crate.attrs, "crate_type") {
Some(s) => "lib" == s || "rlib" == s || "dylib" == s || "staticlib" == s,
Some(s) => {
s.equiv(&("lib")) ||
s.equiv(&("rlib")) ||
s.equiv(&("dylib")) ||
s.equiv(&("staticlib"))
}
_ => false
}
}
Expand All @@ -435,16 +442,22 @@ pub fn collect_outputs(session: &Session,
}
let mut base = session.opts.outputs.clone();
let mut iter = attrs.iter().filter_map(|a| {
if "crate_type" == a.name() {
if a.name().equiv(&("crate_type")) {
match a.value_str() {
Some(n) if "rlib" == n => Some(OutputRlib),
Some(n) if "dylib" == n => Some(OutputDylib),
Some(n) if "lib" == n => Some(default_lib_output()),
Some(n) if "staticlib" == n => Some(OutputStaticlib),
Some(n) if "bin" == n => Some(OutputExecutable),
Some(ref n) if n.equiv(&("rlib")) => Some(OutputRlib),
Some(ref n) if n.equiv(&("dylib")) => Some(OutputDylib),
Some(ref n) if n.equiv(&("lib")) => {
Some(default_lib_output())
}
Some(ref n) if n.equiv(&("staticlib")) => {
Some(OutputStaticlib)
}
Some(ref n) if n.equiv(&("bin")) => Some(OutputExecutable),
Some(_) => {
session.add_lint(lint::UnknownCrateType, ast::CRATE_NODE_ID,
a.span, ~"invalid `crate_type` value");
session.add_lint(lint::UnknownCrateType,
ast::CRATE_NODE_ID,
a.span,
~"invalid `crate_type` value");
None
}
_ => {
Expand Down
Loading