From 5b8bfe047123bad63ead0370c165cd9307a07caa Mon Sep 17 00:00:00 2001 From: Stein Somers Date: Wed, 3 Apr 2019 13:01:01 +0200 Subject: [PATCH 1/5] improve worst-case performance of HashSet.is_subset --- src/libstd/collections/hash/set.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/libstd/collections/hash/set.rs b/src/libstd/collections/hash/set.rs index 89d5b2ff30f..b9fcc2365fa 100644 --- a/src/libstd/collections/hash/set.rs +++ b/src/libstd/collections/hash/set.rs @@ -627,7 +627,11 @@ impl HashSet /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn is_subset(&self, other: &HashSet) -> bool { - self.iter().all(|v| other.contains(v)) + if self.len() <= other.len() { + self.iter().all(|v| other.contains(v)) + } else { + false + } } /// Returns `true` if the set is a superset of another, From a37c33b9261f534b56434c83258ff24d24bf9351 Mon Sep 17 00:00:00 2001 From: Konrad Borowski Date: Thu, 4 Apr 2019 10:51:18 +0200 Subject: [PATCH 2/5] Mark unix::ffi::OsStrExt methods as inline --- src/libstd/ffi/os_str.rs | 1 + src/libstd/sys_common/os_str_bytes.rs | 2 ++ 2 files changed, 3 insertions(+) diff --git a/src/libstd/ffi/os_str.rs b/src/libstd/ffi/os_str.rs index 01e7a57cd00..13aee783750 100644 --- a/src/libstd/ffi/os_str.rs +++ b/src/libstd/ffi/os_str.rs @@ -960,6 +960,7 @@ impl IntoInner for OsString { } impl AsInner for OsStr { + #[inline] fn as_inner(&self) -> &Slice { &self.inner } diff --git a/src/libstd/sys_common/os_str_bytes.rs b/src/libstd/sys_common/os_str_bytes.rs index 7cc93477a73..a4961974d89 100644 --- a/src/libstd/sys_common/os_str_bytes.rs +++ b/src/libstd/sys_common/os_str_bytes.rs @@ -236,9 +236,11 @@ pub trait OsStrExt { #[stable(feature = "rust1", since = "1.0.0")] impl OsStrExt for OsStr { + #[inline] fn from_bytes(slice: &[u8]) -> &OsStr { unsafe { mem::transmute(slice) } } + #[inline] fn as_bytes(&self) -> &[u8] { &self.as_inner().inner } From fdb8752850f9e8a6c5a846a6de3c5f1952fa1b38 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 4 Apr 2019 10:55:30 +0300 Subject: [PATCH 3/5] cleanup shebang handling in the lexer --- src/libsyntax/parse/lexer/mod.rs | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/src/libsyntax/parse/lexer/mod.rs b/src/libsyntax/parse/lexer/mod.rs index cd4944deadb..02451e01b1d 100644 --- a/src/libsyntax/parse/lexer/mod.rs +++ b/src/libsyntax/parse/lexer/mod.rs @@ -1,10 +1,9 @@ use crate::ast::{self, Ident}; -use crate::source_map::{SourceMap, FilePathMapping}; use crate::parse::{token, ParseSess}; use crate::symbol::Symbol; use errors::{Applicability, FatalError, Diagnostic, DiagnosticBuilder}; -use syntax_pos::{BytePos, CharPos, Pos, Span, NO_EXPANSION}; +use syntax_pos::{BytePos, Pos, Span, NO_EXPANSION}; use core::unicode::property::Pattern_White_Space; use std::borrow::Cow; @@ -667,14 +666,9 @@ impl<'a> StringReader<'a> { return None; } - // I guess this is the only way to figure out if - // we're at the beginning of the file... - let smap = SourceMap::new(FilePathMapping::empty()); - smap.files.borrow_mut().source_files.push(self.source_file.clone()); - let loc = smap.lookup_char_pos_adj(self.pos); - debug!("Skipping a shebang"); - if loc.line == 1 && loc.col == CharPos(0) { - // FIXME: Add shebang "token", return it + let is_beginning_of_file = self.pos == self.source_file.start_pos; + if is_beginning_of_file { + debug!("Skipping a shebang"); let start = self.pos; while !self.ch_is('\n') && !self.is_eof() { self.bump(); @@ -1911,7 +1905,7 @@ mod tests { use crate::ast::{Ident, CrateConfig}; use crate::symbol::Symbol; - use crate::source_map::SourceMap; + use crate::source_map::{SourceMap, FilePathMapping}; use crate::feature_gate::UnstableFeatures; use crate::parse::token; use crate::diagnostics::plugin::ErrorMap; From a96492112c413f0846245eb2c579bed1da251549 Mon Sep 17 00:00:00 2001 From: hgallagher1993 Date: Thu, 4 Apr 2019 13:23:11 -0400 Subject: [PATCH 4/5] Use declare_lint_pass! and impl_lint_pass! in more places --- src/librustc/lint/internal.rs | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-) diff --git a/src/librustc/lint/internal.rs b/src/librustc/lint/internal.rs index d5f8876d162..030a9c1f935 100644 --- a/src/librustc/lint/internal.rs +++ b/src/librustc/lint/internal.rs @@ -28,15 +28,7 @@ impl DefaultHashTypes { } } -impl LintPass for DefaultHashTypes { - fn get_lints(&self) -> LintArray { - lint_array!(DEFAULT_HASH_TYPES) - } - - fn name(&self) -> &'static str { - "DefaultHashTypes" - } -} +impl_lint_pass!(DefaultHashTypes => [DEFAULT_HASH_TYPES]); impl EarlyLintPass for DefaultHashTypes { fn check_ident(&mut self, cx: &EarlyContext<'_>, ident: Ident) { @@ -68,17 +60,7 @@ declare_lint! { "Usage of `ty::TyKind` outside of the `ty::sty` module" } -pub struct TyKindUsage; - -impl LintPass for TyKindUsage { - fn get_lints(&self) -> LintArray { - lint_array!(USAGE_OF_TY_TYKIND) - } - - fn name(&self) -> &'static str { - "TyKindUsage" - } -} +declare_lint_pass!(TyKindUsage => [USAGE_OF_TY_TYKIND]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TyKindUsage { fn check_path(&mut self, cx: &LateContext<'_, '_>, path: &'tcx Path, _: HirId) { From 471db2b84bbeafb128bae8a8a9cf7fed13d2df4f Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 4 Apr 2019 13:23:42 -0700 Subject: [PATCH 5/5] wasm32: Default to a "static" relocation model LLVM 9 is adding support for a "pic" relocation model for wasm code, which is quite different than the current model. In order to preserve the mode of compilation that we have today default to "static" to ensure that we don't accidentally start creating experimental relocatable binaries. --- src/librustc_target/spec/wasm32_base.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/librustc_target/spec/wasm32_base.rs b/src/librustc_target/spec/wasm32_base.rs index c7e75b4fa09..edaf902c130 100644 --- a/src/librustc_target/spec/wasm32_base.rs +++ b/src/librustc_target/spec/wasm32_base.rs @@ -118,6 +118,15 @@ pub fn options() -> TargetOptions { pre_link_args, + // This has no effect in LLVM 8 or prior, but in LLVM 9 and later when + // PIC code is implemented this has quite a drastric effect if it stays + // at the default, `pic`. In an effort to keep wasm binaries as minimal + // as possible we're defaulting to `static` for now, but the hope is + // that eventually we can ship a `pic`-compatible standard library which + // works with `static` as well (or works with some method of generating + // non-relative calls and such later on). + relocation_model: "static".to_string(), + .. Default::default() } }