Skip to content

Avoid more Symbol-to-string operations #64303

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 3 additions & 3 deletions src/librustc/middle/weak_lang_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ fn verify<'tcx>(tcx: TyCtxt<'tcx>,
}

impl<'a, 'tcx> Context<'a, 'tcx> {
fn register(&mut self, name: &str, span: Span) {
$(if name == stringify!($name) {
fn register(&mut self, name: Symbol, span: Span) {
$(if name == sym::$name {
if self.items.$name().is_none() {
self.items.missing.push(lang_items::$item);
}
Expand All @@ -136,7 +136,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for Context<'a, 'tcx> {

fn visit_foreign_item(&mut self, i: &hir::ForeignItem) {
if let Some((lang_item, _)) = lang_items::extract(&i.attrs) {
self.register(&lang_item.as_str(), i.span);
self.register(lang_item, i.span);
}
intravisit::walk_foreign_item(self, i)
}
Expand Down
3 changes: 2 additions & 1 deletion src/librustc_codegen_llvm/back/archive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use crate::llvm::{self, ArchiveKind};
use rustc_codegen_ssa::{METADATA_FILENAME, RLIB_BYTECODE_EXTENSION};
use rustc_codegen_ssa::back::archive::{ArchiveBuilder, find_library};
use rustc::session::Session;
use syntax::symbol::Symbol;

struct ArchiveConfig<'a> {
pub sess: &'a Session,
Expand Down Expand Up @@ -109,7 +110,7 @@ impl<'a> ArchiveBuilder<'a> for LlvmArchiveBuilder<'a> {

/// Adds all of the contents of a native library to this archive. This will
/// search in the relevant locations for a library named `name`.
fn add_native_library(&mut self, name: &str) {
fn add_native_library(&mut self, name: Symbol) {
let location = find_library(name, &self.config.lib_search_paths,
self.config.sess);
self.add_archive(&location, |_| false).unwrap_or_else(|e| {
Expand Down
5 changes: 3 additions & 2 deletions src/librustc_codegen_ssa/back/archive.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use rustc::session::Session;
use syntax::symbol::Symbol;

use std::io;
use std::path::{Path, PathBuf};

pub fn find_library(name: &str, search_paths: &[PathBuf], sess: &Session)
pub fn find_library(name: Symbol, search_paths: &[PathBuf], sess: &Session)
-> PathBuf {
// On Windows, static libraries sometimes show up as libfoo.a and other
// times show up as foo.lib
Expand Down Expand Up @@ -40,7 +41,7 @@ pub trait ArchiveBuilder<'a> {
lto: bool,
skip_objects: bool,
) -> io::Result<()>;
fn add_native_library(&mut self, name: &str);
fn add_native_library(&mut self, name: Symbol);
fn update_symbols(&mut self);

fn build(self);
Expand Down
6 changes: 6 additions & 0 deletions src/librustc_codegen_ssa/back/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use std::mem;
use std::process::{self, Output};

use rustc_target::spec::LldFlavor;
use syntax::symbol::Symbol;

#[derive(Clone)]
pub struct Command {
Expand Down Expand Up @@ -49,6 +50,11 @@ impl Command {
self
}

pub fn sym_arg(&mut self, arg: Symbol) -> &mut Command {
self.arg(&arg.as_str());
self
}

pub fn args<I>(&mut self, args: I) -> &mut Command
where
I: IntoIterator<Item: AsRef<OsStr>>,
Expand Down
24 changes: 12 additions & 12 deletions src/librustc_codegen_ssa/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use rustc::hir::def_id::CrateNum;
use rustc_data_structures::fx::FxHashSet;
use rustc_fs_util::fix_windows_verbatim_for_gcc;
use rustc_target::spec::{PanicStrategy, RelroLevel, LinkerFlavor};
use syntax::symbol::Symbol;

use crate::{METADATA_FILENAME, RLIB_BYTECODE_EXTENSION, CrateInfo, CodegenResults};
use super::archive::ArchiveBuilder;
Expand Down Expand Up @@ -316,7 +317,7 @@ fn link_rlib<'a, B: ArchiveBuilder<'a>>(sess: &'a Session,
NativeLibraryKind::NativeUnknown => continue,
}
if let Some(name) = lib.name {
ab.add_native_library(&name.as_str());
ab.add_native_library(name);
}
}

Expand Down Expand Up @@ -1273,15 +1274,14 @@ pub fn add_local_native_libraries(cmd: &mut dyn Linker,
let search_path = archive_search_paths(sess);
for lib in relevant_libs {
let name = match lib.name {
Some(ref l) => l,
Some(l) => l,
None => continue,
};
match lib.kind {
NativeLibraryKind::NativeUnknown => cmd.link_dylib(&name.as_str()),
NativeLibraryKind::NativeFramework => cmd.link_framework(&name.as_str()),
NativeLibraryKind::NativeStaticNobundle => cmd.link_staticlib(&name.as_str()),
NativeLibraryKind::NativeStatic => cmd.link_whole_staticlib(&name.as_str(),
&search_path)
NativeLibraryKind::NativeUnknown => cmd.link_dylib(name),
NativeLibraryKind::NativeFramework => cmd.link_framework(name),
NativeLibraryKind::NativeStaticNobundle => cmd.link_staticlib(name),
NativeLibraryKind::NativeStatic => cmd.link_whole_staticlib(name, &search_path)
}
}
}
Expand Down Expand Up @@ -1594,7 +1594,7 @@ fn add_upstream_rust_crates<'a, B: ArchiveBuilder<'a>>(cmd: &mut dyn Linker,
cmd.include_path(&fix_windows_verbatim_for_gcc(dir));
}
let filestem = cratepath.file_stem().unwrap().to_str().unwrap();
cmd.link_rust_dylib(&unlib(&sess.target, filestem),
cmd.link_rust_dylib(Symbol::intern(&unlib(&sess.target, filestem)),
parent.unwrap_or(Path::new("")));
}
}
Expand Down Expand Up @@ -1637,22 +1637,22 @@ pub fn add_upstream_native_libraries(cmd: &mut dyn Linker,
for &(cnum, _) in crates {
for lib in codegen_results.crate_info.native_libraries[&cnum].iter() {
let name = match lib.name {
Some(ref l) => l,
Some(l) => l,
None => continue,
};
if !relevant_lib(sess, &lib) {
continue
}
match lib.kind {
NativeLibraryKind::NativeUnknown => cmd.link_dylib(&name.as_str()),
NativeLibraryKind::NativeFramework => cmd.link_framework(&name.as_str()),
NativeLibraryKind::NativeUnknown => cmd.link_dylib(name),
NativeLibraryKind::NativeFramework => cmd.link_framework(name),
NativeLibraryKind::NativeStaticNobundle => {
// Link "static-nobundle" native libs only if the crate they originate from
// is being linked statically to the current crate. If it's linked dynamically
// or is an rlib already included via some other dylib crate, the symbols from
// native libs will have already been included in that dylib.
if data[cnum.as_usize() - 1] == Linkage::Static {
cmd.link_staticlib(&name.as_str())
cmd.link_staticlib(name)
}
},
// ignore statically included native libraries here as we've
Expand Down
79 changes: 42 additions & 37 deletions src/librustc_codegen_ssa/back/linker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use rustc::session::config::{self, CrateType, OptLevel, DebugInfo,
use rustc::ty::TyCtxt;
use rustc_target::spec::{LinkerFlavor, LldFlavor};
use rustc_serialize::{json, Encoder};
use syntax::symbol::Symbol;

/// For all the linkers we support, and information they might
/// need out of the shared crate context before we get rid of it.
Expand Down Expand Up @@ -99,13 +100,13 @@ impl LinkerInfo {
/// used to dispatch on whether a GNU-like linker (generally `ld.exe`) or an
/// MSVC linker (e.g., `link.exe`) is being used.
pub trait Linker {
fn link_dylib(&mut self, lib: &str);
fn link_rust_dylib(&mut self, lib: &str, path: &Path);
fn link_framework(&mut self, framework: &str);
fn link_staticlib(&mut self, lib: &str);
fn link_dylib(&mut self, lib: Symbol);
fn link_rust_dylib(&mut self, lib: Symbol, path: &Path);
fn link_framework(&mut self, framework: Symbol);
fn link_staticlib(&mut self, lib: Symbol);
fn link_rlib(&mut self, lib: &Path);
fn link_whole_rlib(&mut self, lib: &Path);
fn link_whole_staticlib(&mut self, lib: &str, search_path: &[PathBuf]);
fn link_whole_staticlib(&mut self, lib: Symbol, search_path: &[PathBuf]);
fn include_path(&mut self, path: &Path);
fn framework_path(&mut self, path: &Path);
fn output_filename(&mut self, path: &Path);
Expand Down Expand Up @@ -215,9 +216,13 @@ impl<'a> GccLinker<'a> {
}

impl<'a> Linker for GccLinker<'a> {
fn link_dylib(&mut self, lib: &str) { self.hint_dynamic(); self.cmd.arg(format!("-l{}", lib)); }
fn link_staticlib(&mut self, lib: &str) {
self.hint_static(); self.cmd.arg(format!("-l{}", lib));
fn link_dylib(&mut self, lib: Symbol) {
self.hint_dynamic();
self.cmd.arg(format!("-l{}", lib));
}
fn link_staticlib(&mut self, lib: Symbol) {
self.hint_static();
self.cmd.arg(format!("-l{}", lib));
}
fn link_rlib(&mut self, lib: &Path) { self.hint_static(); self.cmd.arg(lib); }
fn include_path(&mut self, path: &Path) { self.cmd.arg("-L").arg(path); }
Expand All @@ -232,14 +237,14 @@ impl<'a> Linker for GccLinker<'a> {
fn build_static_executable(&mut self) { self.cmd.arg("-static"); }
fn args(&mut self, args: &[String]) { self.cmd.args(args); }

fn link_rust_dylib(&mut self, lib: &str, _path: &Path) {
fn link_rust_dylib(&mut self, lib: Symbol, _path: &Path) {
self.hint_dynamic();
self.cmd.arg(format!("-l{}", lib));
}

fn link_framework(&mut self, framework: &str) {
fn link_framework(&mut self, framework: Symbol) {
self.hint_dynamic();
self.cmd.arg("-framework").arg(framework);
self.cmd.arg("-framework").sym_arg(framework);
}

// Here we explicitly ask that the entire archive is included into the
Expand All @@ -248,7 +253,7 @@ impl<'a> Linker for GccLinker<'a> {
// don't otherwise explicitly reference them. This can occur for
// libraries which are just providing bindings, libraries with generic
// functions, etc.
fn link_whole_staticlib(&mut self, lib: &str, search_path: &[PathBuf]) {
fn link_whole_staticlib(&mut self, lib: Symbol, search_path: &[PathBuf]) {
self.hint_static();
let target = &self.sess.target.target;
if !target.options.is_like_osx {
Expand Down Expand Up @@ -539,11 +544,11 @@ impl<'a> Linker for MsvcLinker<'a> {
}
}

fn link_dylib(&mut self, lib: &str) {
fn link_dylib(&mut self, lib: Symbol) {
self.cmd.arg(&format!("{}.lib", lib));
}

fn link_rust_dylib(&mut self, lib: &str, path: &Path) {
fn link_rust_dylib(&mut self, lib: Symbol, path: &Path) {
// When producing a dll, the MSVC linker may not actually emit a
// `foo.lib` file if the dll doesn't actually export any symbols, so we
// check to see if the file is there and just omit linking to it if it's
Expand All @@ -554,7 +559,7 @@ impl<'a> Linker for MsvcLinker<'a> {
}
}

fn link_staticlib(&mut self, lib: &str) {
fn link_staticlib(&mut self, lib: Symbol) {
self.cmd.arg(&format!("{}.lib", lib));
}

Expand Down Expand Up @@ -605,11 +610,11 @@ impl<'a> Linker for MsvcLinker<'a> {
fn framework_path(&mut self, _path: &Path) {
bug!("frameworks are not supported on windows")
}
fn link_framework(&mut self, _framework: &str) {
fn link_framework(&mut self, _framework: Symbol) {
bug!("frameworks are not supported on windows")
}

fn link_whole_staticlib(&mut self, lib: &str, _search_path: &[PathBuf]) {
fn link_whole_staticlib(&mut self, lib: Symbol, _search_path: &[PathBuf]) {
// not supported?
self.link_staticlib(lib);
}
Expand Down Expand Up @@ -740,8 +745,8 @@ impl<'a> Linker for EmLinker<'a> {
self.cmd.arg("-L").arg(path);
}

fn link_staticlib(&mut self, lib: &str) {
self.cmd.arg("-l").arg(lib);
fn link_staticlib(&mut self, lib: Symbol) {
self.cmd.arg("-l").sym_arg(lib);
}

fn output_filename(&mut self, path: &Path) {
Expand All @@ -752,12 +757,12 @@ impl<'a> Linker for EmLinker<'a> {
self.cmd.arg(path);
}

fn link_dylib(&mut self, lib: &str) {
fn link_dylib(&mut self, lib: Symbol) {
// Emscripten always links statically
self.link_staticlib(lib);
}

fn link_whole_staticlib(&mut self, lib: &str, _search_path: &[PathBuf]) {
fn link_whole_staticlib(&mut self, lib: Symbol, _search_path: &[PathBuf]) {
// not supported?
self.link_staticlib(lib);
}
Expand All @@ -767,7 +772,7 @@ impl<'a> Linker for EmLinker<'a> {
self.link_rlib(lib);
}

fn link_rust_dylib(&mut self, lib: &str, _path: &Path) {
fn link_rust_dylib(&mut self, lib: Symbol, _path: &Path) {
self.link_dylib(lib);
}

Expand Down Expand Up @@ -803,7 +808,7 @@ impl<'a> Linker for EmLinker<'a> {
bug!("frameworks are not supported on Emscripten")
}

fn link_framework(&mut self, _framework: &str) {
fn link_framework(&mut self, _framework: Symbol) {
bug!("frameworks are not supported on Emscripten")
}

Expand Down Expand Up @@ -948,12 +953,12 @@ impl<'a> WasmLd<'a> {
}

impl<'a> Linker for WasmLd<'a> {
fn link_dylib(&mut self, lib: &str) {
self.cmd.arg("-l").arg(lib);
fn link_dylib(&mut self, lib: Symbol) {
self.cmd.arg("-l").sym_arg(lib);
}

fn link_staticlib(&mut self, lib: &str) {
self.cmd.arg("-l").arg(lib);
fn link_staticlib(&mut self, lib: Symbol) {
self.cmd.arg("-l").sym_arg(lib);
}

fn link_rlib(&mut self, lib: &Path) {
Expand Down Expand Up @@ -995,16 +1000,16 @@ impl<'a> Linker for WasmLd<'a> {
self.cmd.args(args);
}

fn link_rust_dylib(&mut self, lib: &str, _path: &Path) {
self.cmd.arg("-l").arg(lib);
fn link_rust_dylib(&mut self, lib: Symbol, _path: &Path) {
self.cmd.arg("-l").sym_arg(lib);
}

fn link_framework(&mut self, _framework: &str) {
fn link_framework(&mut self, _framework: Symbol) {
panic!("frameworks not supported")
}

fn link_whole_staticlib(&mut self, lib: &str, _search_path: &[PathBuf]) {
self.cmd.arg("-l").arg(lib);
fn link_whole_staticlib(&mut self, lib: Symbol, _search_path: &[PathBuf]) {
self.cmd.arg("-l").sym_arg(lib);
}

fn link_whole_rlib(&mut self, lib: &Path) {
Expand Down Expand Up @@ -1162,27 +1167,27 @@ impl<'a> Linker for PtxLinker<'a> {
::std::mem::replace(&mut self.cmd, Command::new(""))
}

fn link_dylib(&mut self, _lib: &str) {
fn link_dylib(&mut self, _lib: Symbol) {
panic!("external dylibs not supported")
}

fn link_rust_dylib(&mut self, _lib: &str, _path: &Path) {
fn link_rust_dylib(&mut self, _lib: Symbol, _path: &Path) {
panic!("external dylibs not supported")
}

fn link_staticlib(&mut self, _lib: &str) {
fn link_staticlib(&mut self, _lib: Symbol) {
panic!("staticlibs not supported")
}

fn link_whole_staticlib(&mut self, _lib: &str, _search_path: &[PathBuf]) {
fn link_whole_staticlib(&mut self, _lib: Symbol, _search_path: &[PathBuf]) {
panic!("staticlibs not supported")
}

fn framework_path(&mut self, _path: &Path) {
panic!("frameworks not supported")
}

fn link_framework(&mut self, _framework: &str) {
fn link_framework(&mut self, _framework: Symbol) {
panic!("frameworks not supported")
}

Expand Down
Loading