Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Remove few LLVMRust...() methods instead use LLVM C-API. #67353

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
7ec9dc7
Remove
vivekvpandya Dec 16, 2019
61f995f
Improve `str` prefix/suffix comparison
ranma42 Dec 11, 2019
c59272c
Prefer encoding the char when checking for string prefix/suffix
ranma42 Dec 11, 2019
c657406
Minor cleanup in `Pattern::{is_prefix_of,is_suffix_of}` for `char`
ranma42 Dec 12, 2019
5e8cab4
Delete flaky test net::tcp::tests::fast_rebind
dtolnay Dec 15, 2019
8c8cddd
comment -> doc comment
Centril Dec 15, 2019
d7bb25c
document check_pat_slice
Centril Dec 15, 2019
e046381
improve hir::PatKind::Slice docs
Centril Dec 15, 2019
ad533a1
use Self alias in place of macros
tesuji Dec 15, 2019
fe3f435
make transparent enums more ordinary
Centril Dec 15, 2019
d10ec95
Fix JS error when loading page with search
GuillaumeGomez Dec 15, 2019
da3265c
improve lower_pat_slice docs + while -> for
Centril Dec 15, 2019
e4feeaa
.gitignore: Don't ignore a file that exists in the repository
joshtriplett Dec 16, 2019
f2eba30
Minor: update Unsize docs for dyn syntax
petertodd Dec 16, 2019
64b7b9b
Add benchmarks for `start_with` and `ends_with`
ranma42 Dec 16, 2019
0a25a57
Change the default thread count to min(4, vCPUs)
Mark-Simulacrum Dec 16, 2019
20eed30
Always build and ship parallel-enabled compilers
Mark-Simulacrum Dec 16, 2019
496cc30
Move AtomicU64 usage to AtomicUsize
Mark-Simulacrum Dec 17, 2019
8a6f726
Disable cargo tests for now
Mark-Simulacrum Dec 17, 2019
2b3259e
Revert "Auto merge of #67362 - Mark-Simulacrum:par-4-default, r=alexc…
Mark-Simulacrum Dec 17, 2019
8e61952
Remove LLVMRustGetLinkage
vivekvpandya Dec 17, 2019
6c58683
Remove LLVMRustAddHandler() instead use LLVMAddHandler()
vivekvpandya Dec 18, 2019
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,6 @@ config.mk
config.stamp
Session.vim
.cargo
!/src/test/run-make/thumb-none-qemu/example/.cargo
no_llvm_build
# Before adding new lines, see the comment at the top.
1 change: 1 addition & 0 deletions src/libcore/benches/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ mod hash;
mod iter;
mod num;
mod ops;
mod pattern;
mod slice;
43 changes: 43 additions & 0 deletions src/libcore/benches/pattern.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
use test::black_box;
use test::Bencher;

#[bench]
fn starts_with_char(b: &mut Bencher) {
let text = black_box("kdjsfhlakfhlsghlkvcnljknfqiunvcijqenwodind");
b.iter(|| {
for _ in 0..1024 {
black_box(text.starts_with('k'));
}
})
}

#[bench]
fn starts_with_str(b: &mut Bencher) {
let text = black_box("kdjsfhlakfhlsghlkvcnljknfqiunvcijqenwodind");
b.iter(|| {
for _ in 0..1024 {
black_box(text.starts_with("k"));
}
})
}


#[bench]
fn ends_with_char(b: &mut Bencher) {
let text = black_box("kdjsfhlakfhlsghlkvcnljknfqiunvcijqenwodind");
b.iter(|| {
for _ in 0..1024 {
black_box(text.ends_with('k'));
}
})
}

#[bench]
fn ends_with_str(b: &mut Bencher) {
let text = black_box("kdjsfhlakfhlsghlkvcnljknfqiunvcijqenwodind");
b.iter(|| {
for _ in 0..1024 {
black_box(text.ends_with("k"));
}
})
}
2 changes: 1 addition & 1 deletion src/libcore/marker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ pub trait Sized {
/// Types that can be "unsized" to a dynamically-sized type.
///
/// For example, the sized array type `[i8; 2]` implements `Unsize<[i8]>` and
/// `Unsize<fmt::Debug>`.
/// `Unsize<dyn fmt::Debug>`.
///
/// All implementations of `Unsize` are provided automatically by the compiler.
///
Expand Down
4 changes: 2 additions & 2 deletions src/libcore/num/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ assert_eq!(size_of::<Option<core::num::", stringify!($Ty), ">>(), size_of::<", s
)]
#[inline]
pub const unsafe fn new_unchecked(n: $Int) -> Self {
$Ty(n)
Self(n)
}

/// Creates a non-zero if the given value is not zero.
Expand All @@ -76,7 +76,7 @@ assert_eq!(size_of::<Option<core::num::", stringify!($Ty), ">>(), size_of::<", s
pub fn new(n: $Int) -> Option<Self> {
if n != 0 {
// SAFETY: we just checked that there's no `0`
Some(unsafe { $Ty(n) })
Some(unsafe { Self(n) })
} else {
None
}
Expand Down
19 changes: 4 additions & 15 deletions src/libcore/str/pattern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -445,21 +445,13 @@ impl<'a> Pattern<'a> for char {

#[inline]
fn is_prefix_of(self, haystack: &'a str) -> bool {
if let Some(ch) = haystack.chars().next() {
self == ch
} else {
false
}
self.encode_utf8(&mut [0u8; 4]).is_prefix_of(haystack)
}

#[inline]
fn is_suffix_of(self, haystack: &'a str) -> bool where Self::Searcher: ReverseSearcher<'a>
{
if let Some(ch) = haystack.chars().next_back() {
self == ch
} else {
false
}
self.encode_utf8(&mut [0u8; 4]).is_suffix_of(haystack)
}
}

Expand Down Expand Up @@ -710,16 +702,13 @@ impl<'a, 'b> Pattern<'a> for &'b str {
/// Checks whether the pattern matches at the front of the haystack
#[inline]
fn is_prefix_of(self, haystack: &'a str) -> bool {
haystack.is_char_boundary(self.len()) &&
self == &haystack[..self.len()]
haystack.as_bytes().starts_with(self.as_bytes())
}

/// Checks whether the pattern matches at the back of the haystack
#[inline]
fn is_suffix_of(self, haystack: &'a str) -> bool {
self.len() <= haystack.len() &&
haystack.is_char_boundary(haystack.len() - self.len()) &&
self == &haystack[haystack.len() - self.len()..]
haystack.as_bytes().ends_with(self.as_bytes())
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/libcore/sync/atomic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1263,7 +1263,7 @@ let atomic_forty_two = ", stringify!($atomic_type), "::new(42);
#[$stable]
#[cfg_attr(not(bootstrap), $const_stable)]
pub const fn new(v: $int_type) -> Self {
$atomic_type {v: UnsafeCell::new(v)}
Self {v: UnsafeCell::new(v)}
}
}

Expand Down
38 changes: 26 additions & 12 deletions src/librustc/hir/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2852,19 +2852,23 @@ impl<'a> LoweringContext<'a> {
let mut rest = None;

let mut iter = pats.iter().enumerate();
while let Some((idx, pat)) = iter.next() {
// Interpret the first `..` pattern as a subtuple pattern.
for (idx, pat) in iter.by_ref() {
// Interpret the first `..` pattern as a sub-tuple pattern.
// Note that unlike for slice patterns,
// where `xs @ ..` is a legal sub-slice pattern,
// it is not a legal sub-tuple pattern.
if pat.is_rest() {
rest = Some((idx, pat.span));
break;
}
// It was not a subslice pattern so lower it normally.
// It was not a sub-tuple pattern so lower it normally.
elems.push(self.lower_pat(pat));
}

while let Some((_, pat)) = iter.next() {
// There was a previous subtuple pattern; make sure we don't allow more.
for (_, pat) in iter {
// There was a previous sub-tuple pattern; make sure we don't allow more...
if pat.is_rest() {
// ...but there was one again, so error.
self.ban_extra_rest_pat(pat.span, rest.unwrap().1, ctx);
} else {
elems.push(self.lower_pat(pat));
Expand All @@ -2874,36 +2878,44 @@ impl<'a> LoweringContext<'a> {
(elems.into(), rest.map(|(ddpos, _)| ddpos))
}

/// Lower a slice pattern of form `[pat_0, ..., pat_n]` into
/// `hir::PatKind::Slice(before, slice, after)`.
///
/// When encountering `($binding_mode $ident @)? ..` (`slice`),
/// this is interpreted as a sub-slice pattern semantically.
/// Patterns that follow, which are not like `slice` -- or an error occurs, are in `after`.
fn lower_pat_slice(&mut self, pats: &[AstP<Pat>]) -> hir::PatKind {
let mut before = Vec::new();
let mut after = Vec::new();
let mut slice = None;
let mut prev_rest_span = None;

let mut iter = pats.iter();
while let Some(pat) = iter.next() {
// Interpret the first `((ref mut?)? x @)? ..` pattern as a subslice pattern.
// Lower all the patterns until the first occurence of a sub-slice pattern.
for pat in iter.by_ref() {
match pat.kind {
// Found a sub-slice pattern `..`. Record, lower it to `_`, and stop here.
PatKind::Rest => {
prev_rest_span = Some(pat.span);
slice = Some(self.pat_wild_with_node_id_of(pat));
break;
},
// Found a sub-slice pattern `$binding_mode $ident @ ..`.
// Record, lower it to `$binding_mode $ident @ _`, and stop here.
PatKind::Ident(ref bm, ident, Some(ref sub)) if sub.is_rest() => {
prev_rest_span = Some(sub.span);
let lower_sub = |this: &mut Self| Some(this.pat_wild_with_node_id_of(sub));
let node = self.lower_pat_ident(pat, bm, ident, lower_sub);
slice = Some(self.pat_with_node_id_of(pat, node));
break;
},
_ => {}
// It was not a subslice pattern so lower it normally.
_ => before.push(self.lower_pat(pat)),
}

// It was not a subslice pattern so lower it normally.
before.push(self.lower_pat(pat));
}

while let Some(pat) = iter.next() {
// Lower all the patterns after the first sub-slice pattern.
for pat in iter {
// There was a previous subslice pattern; make sure we don't allow more.
let rest_span = match pat.kind {
PatKind::Rest => Some(pat.span),
Expand All @@ -2915,8 +2927,10 @@ impl<'a> LoweringContext<'a> {
_ => None,
};
if let Some(rest_span) = rest_span {
// We have e.g., `[a, .., b, ..]`. That's no good, error!
self.ban_extra_rest_pat(rest_span, prev_rest_span.unwrap(), "slice");
} else {
// Lower the pattern normally.
after.push(self.lower_pat(pat));
}
}
Expand Down
11 changes: 9 additions & 2 deletions src/librustc/hir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1048,8 +1048,15 @@ pub enum PatKind {
/// A range pattern (e.g., `1..=2` or `1..2`).
Range(P<Expr>, P<Expr>, RangeEnd),

/// `[a, b, ..i, y, z]` is represented as:
/// `PatKind::Slice(box [a, b], Some(i), box [y, z])`.
/// A slice pattern, `[before_0, ..., before_n, (slice, after_0, ..., after_n)?]`.
///
/// Here, `slice` is lowered from the syntax `($binding_mode $ident @)? ..`.
/// If `slice` exists, then `after` can be non-empty.
///
/// The representation for e.g., `[a, b, .., c, d]` is:
/// ```
/// PatKind::Slice([Binding(a), Binding(b)], Some(Wild), [Binding(c), Binding(d)])
/// ```
Slice(HirVec<P<Pat>>, Option<P<Pat>>, HirVec<P<Pat>>),
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_llvm/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -830,7 +830,7 @@ fn create_msvc_imps(
let i8p_ty = Type::i8p_llcx(llcx);
let globals = base::iter_globals(llmod)
.filter(|&val| {
llvm::LLVMRustGetLinkage(val) == llvm::Linkage::ExternalLinkage &&
llvm::LLVMGetLinkage(val) == llvm::Linkage::ExternalLinkage &&
llvm::LLVMIsDeclaration(val) == 0
})
.filter_map(|val| {
Expand Down
28 changes: 14 additions & 14 deletions src/librustc_codegen_llvm/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -889,11 +889,11 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
args: &[&'ll Value]) -> Funclet<'ll> {
let name = const_cstr!("cleanuppad");
let ret = unsafe {
llvm::LLVMRustBuildCleanupPad(self.llbuilder,
parent,
args.len() as c_uint,
args.as_ptr(),
name.as_ptr())
llvm::LLVMBuildCleanupPad(self.llbuilder,
parent,
args.as_ptr(),
args.len() as c_uint,
name.as_ptr())
};
Funclet::new(ret.expect("LLVM does not have support for cleanuppad"))
}
Expand All @@ -903,7 +903,7 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
unwind: Option<&'ll BasicBlock>,
) -> &'ll Value {
let ret = unsafe {
llvm::LLVMRustBuildCleanupRet(self.llbuilder, funclet.cleanuppad(), unwind)
llvm::LLVMBuildCleanupRet(self.llbuilder, funclet.cleanuppad(), unwind)
};
ret.expect("LLVM does not have support for cleanupret")
}
Expand All @@ -913,9 +913,9 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
args: &[&'ll Value]) -> Funclet<'ll> {
let name = const_cstr!("catchpad");
let ret = unsafe {
llvm::LLVMRustBuildCatchPad(self.llbuilder, parent,
args.len() as c_uint, args.as_ptr(),
name.as_ptr())
llvm::LLVMBuildCatchPad(self.llbuilder, parent,
args.as_ptr(), args.len() as c_uint,
name.as_ptr())
};
Funclet::new(ret.expect("LLVM does not have support for catchpad"))
}
Expand All @@ -928,16 +928,16 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
) -> &'ll Value {
let name = const_cstr!("catchswitch");
let ret = unsafe {
llvm::LLVMRustBuildCatchSwitch(self.llbuilder, parent, unwind,
num_handlers as c_uint,
name.as_ptr())
llvm::LLVMBuildCatchSwitch(self.llbuilder, parent, unwind,
num_handlers as c_uint,
name.as_ptr())
};
ret.expect("LLVM does not have support for catchswitch")
}

fn add_handler(&mut self, catch_switch: &'ll Value, handler: &'ll BasicBlock) {
unsafe {
llvm::LLVMRustAddHandler(catch_switch, handler);
llvm::LLVMAddHandler(catch_switch, handler);
}
}

Expand Down Expand Up @@ -1182,7 +1182,7 @@ impl Builder<'a, 'll, 'tcx> {

pub fn catch_ret(&mut self, funclet: &Funclet<'ll>, unwind: &'ll BasicBlock) -> &'ll Value {
let ret = unsafe {
llvm::LLVMRustBuildCatchRet(self.llbuilder, funclet.cleanuppad(), unwind)
llvm::LLVMBuildCatchRet(self.llbuilder, funclet.cleanuppad(), unwind)
};
ret.expect("LLVM does not have support for catchret")
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_llvm/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ impl StaticMethods for CodegenCx<'ll, 'tcx> {
let name = llvm::get_value_name(g).to_vec();
llvm::set_value_name(g, b"");

let linkage = llvm::LLVMRustGetLinkage(g);
let linkage = llvm::LLVMGetLinkage(g);
let visibility = llvm::LLVMRustGetVisibility(g);

let new_g = llvm::LLVMRustGetOrInsertGlobal(
Expand Down
Loading