Skip to content

Rollup of 5 pull requests #110054

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 24 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
0b5f9ac
replace deprecated LLVMSetCurrentDebugLocation with LLVMSetCurrentDeb…
klensy Apr 2, 2023
7d6181e
add bunch of fixmes: currently there exist some functions that accept…
klensy Apr 2, 2023
c53a9fa
replace LLVMRustMetadataAsValue with LLVMMetadataAsValue
klensy Apr 2, 2023
076116b
replace LLVMRustAppendModuleInlineAsm with LLVMAppendModuleInlineAsm,…
klensy Apr 2, 2023
cc77ae0
Use existing llvm methods, instead of rust wrappers for:
klensy Apr 3, 2023
f41e711
replace
klensy Apr 3, 2023
c0bc001
review
klensy Apr 5, 2023
689beda
Implement `OwnedSlice`
WaffleLapkin Apr 5, 2023
c0ceefd
Use `OwnedSlice` instead of `owning_ref`
WaffleLapkin Apr 5, 2023
d705654
Yeet `owning_ref`
WaffleLapkin Apr 5, 2023
9405f58
Fix typo
WaffleLapkin Apr 5, 2023
504c4c4
Add context to phantom comment
Noratrieb Apr 5, 2023
502cb6f
chore(tcp): change the hardcoded port number to `port` var
enkron Apr 6, 2023
b6970d0
Use `FnOnce` for `slice_owned` instead of `Fn`
WaffleLapkin Apr 6, 2023
e0e39ca
Add basic tests for `OwnedSlice`
WaffleLapkin Apr 6, 2023
2733c29
Support multithreaded mode in `OwnedSlice` tests
WaffleLapkin Apr 6, 2023
5cad51c
rustdoc: add test and bug fix for theme defaults
notriddle Apr 7, 2023
d5b1ef1
Use smart-resolve when checking for trait in RHS of UFCS
compiler-errors Apr 3, 2023
fbe0591
Mark `OwnedSlice::{deref, borrow}` as `#[inline]`
WaffleLapkin Apr 7, 2023
f4547f6
Rollup merge of #109788 - compiler-errors:trait-item-from-non-trait, …
Noratrieb Apr 7, 2023
8b8994c
Rollup merge of #109862 - klensy:llvm-dd, r=nikic
Noratrieb Apr 7, 2023
fe98885
Rollup merge of #109971 - WaffleLapkin:yeet_ownership, r=Nilstrieb
Noratrieb Apr 7, 2023
33c6e08
Rollup merge of #109995 - enkron:u/enkron/substitute-hardcoded-port-n…
Noratrieb Apr 7, 2023
b8c372f
Rollup merge of #110037 - notriddle:notriddle/theme-default, r=Guilla…
Noratrieb Apr 7, 2023
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 compiler/rustc_codegen_llvm/src/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ impl<'tcx> AsmMethods<'tcx> for CodegenCx<'_, 'tcx> {
}

unsafe {
llvm::LLVMRustAppendModuleInlineAsm(
llvm::LLVMAppendModuleInlineAsm(
self.llmod,
template_str.as_ptr().cast(),
template_str.len(),
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_codegen_llvm/src/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -904,9 +904,9 @@ unsafe fn embed_bitcode(
// We need custom section flags, so emit module-level inline assembly.
let section_flags = if cgcx.is_pe_coff { "n" } else { "e" };
let asm = create_section_with_flags_asm(".llvmbc", section_flags, bitcode);
llvm::LLVMRustAppendModuleInlineAsm(llmod, asm.as_ptr().cast(), asm.len());
llvm::LLVMAppendModuleInlineAsm(llmod, asm.as_ptr().cast(), asm.len());
let asm = create_section_with_flags_asm(".llvmcmd", section_flags, cmdline.as_bytes());
llvm::LLVMRustAppendModuleInlineAsm(llmod, asm.as_ptr().cast(), asm.len());
llvm::LLVMAppendModuleInlineAsm(llmod, asm.as_ptr().cast(), asm.len());
}
}

Expand Down
19 changes: 9 additions & 10 deletions compiler/rustc_codegen_llvm/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -841,7 +841,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
}

fn intcast(&mut self, val: &'ll Value, dest_ty: &'ll Type, is_signed: bool) -> &'ll Value {
unsafe { llvm::LLVMRustBuildIntCast(self.llbuilder, val, dest_ty, is_signed) }
unsafe { llvm::LLVMBuildIntCast2(self.llbuilder, val, dest_ty, is_signed, UNNAMED) }
}

fn pointercast(&mut self, val: &'ll Value, dest_ty: &'ll Type) -> &'ll Value {
Expand Down Expand Up @@ -1001,11 +1001,11 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
fn cleanup_pad(&mut self, parent: Option<&'ll Value>, args: &[&'ll Value]) -> Funclet<'ll> {
let name = cstr!("cleanuppad");
let ret = unsafe {
llvm::LLVMRustBuildCleanupPad(
llvm::LLVMBuildCleanupPad(
self.llbuilder,
parent,
args.len() as c_uint,
args.as_ptr(),
args.len() as c_uint,
name.as_ptr(),
)
};
Expand All @@ -1014,19 +1014,19 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {

fn cleanup_ret(&mut self, funclet: &Funclet<'ll>, unwind: Option<&'ll BasicBlock>) {
unsafe {
llvm::LLVMRustBuildCleanupRet(self.llbuilder, funclet.cleanuppad(), unwind)
llvm::LLVMBuildCleanupRet(self.llbuilder, funclet.cleanuppad(), unwind)
.expect("LLVM does not have support for cleanupret");
}
}

fn catch_pad(&mut self, parent: &'ll Value, args: &[&'ll Value]) -> Funclet<'ll> {
let name = cstr!("catchpad");
let ret = unsafe {
llvm::LLVMRustBuildCatchPad(
llvm::LLVMBuildCatchPad(
self.llbuilder,
parent,
args.len() as c_uint,
args.as_ptr(),
args.len() as c_uint,
name.as_ptr(),
)
};
Expand All @@ -1041,7 +1041,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
) -> &'ll Value {
let name = cstr!("catchswitch");
let ret = unsafe {
llvm::LLVMRustBuildCatchSwitch(
llvm::LLVMBuildCatchSwitch(
self.llbuilder,
parent,
unwind,
Expand All @@ -1052,7 +1052,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
let ret = ret.expect("LLVM does not have support for catchswitch");
for handler in handlers {
unsafe {
llvm::LLVMRustAddHandler(ret, handler);
llvm::LLVMAddHandler(ret, handler);
}
}
ret
Expand Down Expand Up @@ -1376,8 +1376,7 @@ impl<'a, 'll, 'tcx> 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) };
let ret = unsafe { llvm::LLVMBuildCatchRet(self.llbuilder, funclet.cleanuppad(), unwind) };
ret.expect("LLVM does not have support for catchret")
}

Expand Down
17 changes: 7 additions & 10 deletions compiler/rustc_codegen_llvm/src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use crate::type_::Type;
use crate::type_of::LayoutLlvmExt;
use crate::value::Value;
use cstr::cstr;
use libc::c_uint;
use rustc_codegen_ssa::traits::*;
use rustc_hir::def_id::DefId;
use rustc_middle::middle::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs};
Expand Down Expand Up @@ -486,10 +485,10 @@ impl<'ll> StaticMethods for CodegenCx<'ll, '_> {
// go into custom sections of the wasm executable.
if self.tcx.sess.target.is_like_wasm {
if let Some(section) = attrs.link_section {
let section = llvm::LLVMMDStringInContext(
let section = llvm::LLVMMDStringInContext2(
self.llcx,
section.as_str().as_ptr().cast(),
section.as_str().len() as c_uint,
section.as_str().len(),
);
assert!(alloc.provenance().ptrs().is_empty());

Expand All @@ -498,17 +497,15 @@ impl<'ll> StaticMethods for CodegenCx<'ll, '_> {
// as part of the interpreter execution).
let bytes =
alloc.inspect_with_uninit_and_ptr_outside_interpreter(0..alloc.len());
let alloc = llvm::LLVMMDStringInContext(
self.llcx,
bytes.as_ptr().cast(),
bytes.len() as c_uint,
);
let alloc =
llvm::LLVMMDStringInContext2(self.llcx, bytes.as_ptr().cast(), bytes.len());
let data = [section, alloc];
let meta = llvm::LLVMMDNodeInContext(self.llcx, data.as_ptr(), 2);
let meta = llvm::LLVMMDNodeInContext2(self.llcx, data.as_ptr(), data.len());
let val = llvm::LLVMMetadataAsValue(self.llcx, meta);
llvm::LLVMAddNamedMetadataOperand(
self.llmod,
"wasm.custom_sections\0".as_ptr().cast(),
meta,
val,
);
}
} else {
Expand Down
25 changes: 7 additions & 18 deletions compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -864,29 +864,24 @@ pub fn build_compile_unit_di_node<'ll, 'tcx>(
);

if tcx.sess.opts.unstable_opts.profile {
let cu_desc_metadata =
llvm::LLVMRustMetadataAsValue(debug_context.llcontext, unit_metadata);
let default_gcda_path = &output_filenames.with_extension("gcda");
let gcda_path =
tcx.sess.opts.unstable_opts.profile_emit.as_ref().unwrap_or(default_gcda_path);

let gcov_cu_info = [
path_to_mdstring(debug_context.llcontext, &output_filenames.with_extension("gcno")),
path_to_mdstring(debug_context.llcontext, gcda_path),
cu_desc_metadata,
unit_metadata,
];
let gcov_metadata = llvm::LLVMMDNodeInContext(
let gcov_metadata = llvm::LLVMMDNodeInContext2(
debug_context.llcontext,
gcov_cu_info.as_ptr(),
gcov_cu_info.len() as c_uint,
gcov_cu_info.len(),
);
let val = llvm::LLVMMetadataAsValue(debug_context.llcontext, gcov_metadata);

let llvm_gcov_ident = cstr!("llvm.gcov");
llvm::LLVMAddNamedMetadataOperand(
debug_context.llmod,
llvm_gcov_ident.as_ptr(),
gcov_metadata,
);
llvm::LLVMAddNamedMetadataOperand(debug_context.llmod, llvm_gcov_ident.as_ptr(), val);
}

// Insert `llvm.ident` metadata on the wasm targets since that will
Expand All @@ -907,15 +902,9 @@ pub fn build_compile_unit_di_node<'ll, 'tcx>(
return unit_metadata;
};

fn path_to_mdstring<'ll>(llcx: &'ll llvm::Context, path: &Path) -> &'ll Value {
fn path_to_mdstring<'ll>(llcx: &'ll llvm::Context, path: &Path) -> &'ll llvm::Metadata {
let path_str = path_to_c_string(path);
unsafe {
llvm::LLVMMDStringInContext(
llcx,
path_str.as_ptr(),
path_str.as_bytes().len() as c_uint,
)
}
unsafe { llvm::LLVMMDStringInContext2(llcx, path_str.as_ptr(), path_str.as_bytes().len()) }
}
}

Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_codegen_llvm/src/debuginfo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,7 @@ impl<'ll> DebugInfoBuilderMethods for Builder<'_, 'll, '_> {

fn set_dbg_loc(&mut self, dbg_loc: &'ll DILocation) {
unsafe {
let dbg_loc_as_llval = llvm::LLVMRustMetadataAsValue(self.cx().llcx, dbg_loc);
llvm::LLVMSetCurrentDebugLocation(self.llbuilder, dbg_loc_as_llval);
llvm::LLVMSetCurrentDebugLocation2(self.llbuilder, dbg_loc);
}
}

Expand Down
40 changes: 24 additions & 16 deletions compiler/rustc_codegen_llvm/src/llvm/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1018,7 +1018,7 @@ extern "C" {
pub fn LLVMSetDataLayout(M: &Module, Triple: *const c_char);

/// See Module::setModuleInlineAsm.
pub fn LLVMRustAppendModuleInlineAsm(M: &Module, Asm: *const c_char, AsmLen: size_t);
pub fn LLVMAppendModuleInlineAsm(M: &Module, Asm: *const c_char, Len: size_t);

/// See llvm::LLVMTypeKind::getTypeID.
pub fn LLVMRustGetTypeKind(Ty: &Type) -> TypeKind;
Expand Down Expand Up @@ -1065,7 +1065,7 @@ extern "C" {

// Operations on other types
pub fn LLVMVoidTypeInContext(C: &Context) -> &Type;
pub fn LLVMRustMetadataTypeInContext(C: &Context) -> &Type;
pub fn LLVMMetadataTypeInContext(C: &Context) -> &Type;

// Operations on all values
pub fn LLVMTypeOf(Val: &Value) -> &Type;
Expand All @@ -1084,7 +1084,12 @@ extern "C" {
pub fn LLVMGetPoison(Ty: &Type) -> &Value;

// Operations on metadata
// FIXME: deprecated, replace with LLVMMDStringInContext2
pub fn LLVMMDStringInContext(C: &Context, Str: *const c_char, SLen: c_uint) -> &Value;

pub fn LLVMMDStringInContext2(C: &Context, Str: *const c_char, SLen: size_t) -> &Metadata;

// FIXME: deprecated, replace with LLVMMDNodeInContext2
pub fn LLVMMDNodeInContext<'a>(
C: &'a Context,
Vals: *const &'a Value,
Expand Down Expand Up @@ -1123,6 +1128,8 @@ extern "C" {
Packed: Bool,
) -> &'a Value;

// FIXME: replace with LLVMConstArray2 when bumped minimal version to llvm-17
// https://github.com/llvm/llvm-project/commit/35276f16e5a2cae0dfb49c0fbf874d4d2f177acc
pub fn LLVMConstArray<'a>(
ElementTy: &'a Type,
ConstantVals: *const &'a Value,
Expand Down Expand Up @@ -1262,7 +1269,7 @@ extern "C" {
pub fn LLVMDisposeBuilder<'a>(Builder: &'a mut Builder<'a>);

// Metadata
pub fn LLVMSetCurrentDebugLocation<'a>(Builder: &Builder<'a>, L: &'a Value);
pub fn LLVMSetCurrentDebugLocation2<'a>(Builder: &Builder<'a>, Loc: &'a Metadata);

// Terminators
pub fn LLVMBuildRetVoid<'a>(B: &Builder<'a>) -> &'a Value;
Expand Down Expand Up @@ -1302,38 +1309,38 @@ extern "C" {
pub fn LLVMBuildResume<'a>(B: &Builder<'a>, Exn: &'a Value) -> &'a Value;
pub fn LLVMBuildUnreachable<'a>(B: &Builder<'a>) -> &'a Value;

pub fn LLVMRustBuildCleanupPad<'a>(
pub fn LLVMBuildCleanupPad<'a>(
B: &Builder<'a>,
ParentPad: Option<&'a Value>,
ArgCnt: c_uint,
Args: *const &'a Value,
NumArgs: c_uint,
Name: *const c_char,
) -> Option<&'a Value>;
pub fn LLVMRustBuildCleanupRet<'a>(
pub fn LLVMBuildCleanupRet<'a>(
B: &Builder<'a>,
CleanupPad: &'a Value,
UnwindBB: Option<&'a BasicBlock>,
BB: Option<&'a BasicBlock>,
) -> Option<&'a Value>;
pub fn LLVMRustBuildCatchPad<'a>(
pub fn LLVMBuildCatchPad<'a>(
B: &Builder<'a>,
ParentPad: &'a Value,
ArgCnt: c_uint,
Args: *const &'a Value,
NumArgs: c_uint,
Name: *const c_char,
) -> Option<&'a Value>;
pub fn LLVMRustBuildCatchRet<'a>(
pub fn LLVMBuildCatchRet<'a>(
B: &Builder<'a>,
Pad: &'a Value,
CatchPad: &'a Value,
BB: &'a BasicBlock,
) -> Option<&'a Value>;
pub fn LLVMRustBuildCatchSwitch<'a>(
pub fn LLVMBuildCatchSwitch<'a>(
Builder: &Builder<'a>,
ParentPad: Option<&'a Value>,
BB: Option<&'a BasicBlock>,
UnwindBB: Option<&'a BasicBlock>,
NumHandlers: c_uint,
Name: *const c_char,
) -> Option<&'a Value>;
pub fn LLVMRustAddHandler<'a>(CatchSwitch: &'a Value, Handler: &'a BasicBlock);
pub fn LLVMAddHandler<'a>(CatchSwitch: &'a Value, Dest: &'a BasicBlock);
pub fn LLVMSetPersonalityFn<'a>(Func: &'a Value, Pers: &'a Value);

// Add a case to the switch instruction
Expand Down Expand Up @@ -1627,11 +1634,12 @@ extern "C" {
DestTy: &'a Type,
Name: *const c_char,
) -> &'a Value;
pub fn LLVMRustBuildIntCast<'a>(
pub fn LLVMBuildIntCast2<'a>(
B: &Builder<'a>,
Val: &'a Value,
DestTy: &'a Type,
IsSigned: bool,
Name: *const c_char,
) -> &'a Value;

// Comparisons
Expand Down Expand Up @@ -1920,7 +1928,7 @@ extern "C" {
);
pub fn LLVMRustHasModuleFlag(M: &Module, name: *const c_char, len: size_t) -> bool;

pub fn LLVMRustMetadataAsValue<'a>(C: &'a Context, MD: &'a Metadata) -> &'a Value;
pub fn LLVMMetadataAsValue<'a>(C: &'a Context, MD: &'a Metadata) -> &'a Value;

pub fn LLVMRustDIBuilderCreate(M: &Module) -> &mut DIBuilder<'_>;

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_llvm/src/type_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl<'ll> CodegenCx<'ll, '_> {
}

pub(crate) fn type_metadata(&self) -> &'ll Type {
unsafe { llvm::LLVMRustMetadataTypeInContext(self.llcx) }
unsafe { llvm::LLVMMetadataTypeInContext(self.llcx) }
}

///x Creates an integer type with the given number of bits, e.g., i24
Expand Down
11 changes: 5 additions & 6 deletions compiler/rustc_codegen_ssa/src/back/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ use object::{
use snap::write::FrameEncoder;

use rustc_data_structures::memmap::Mmap;
use rustc_data_structures::owning_ref::OwningRef;
use rustc_data_structures::rustc_erase_owner;
use rustc_data_structures::owned_slice::try_slice_owned;
use rustc_data_structures::sync::MetadataRef;
use rustc_metadata::fs::METADATA_FILENAME;
use rustc_metadata::EncodedMetadata;
Expand Down Expand Up @@ -42,10 +41,10 @@ fn load_metadata_with(
) -> Result<MetadataRef, String> {
let file =
File::open(path).map_err(|e| format!("failed to open file '{}': {}", path.display(), e))?;
let data = unsafe { Mmap::map(file) }
.map_err(|e| format!("failed to mmap file '{}': {}", path.display(), e))?;
let metadata = OwningRef::new(data).try_map(f)?;
return Ok(rustc_erase_owner!(metadata.map_owner_box()));

unsafe { Mmap::map(file) }
.map_err(|e| format!("failed to mmap file '{}': {}", path.display(), e))
.and_then(|mmap| try_slice_owned(mmap, |mmap| f(mmap)))
}

impl MetadataLoader for DefaultMetadataLoader {
Expand Down
6 changes: 4 additions & 2 deletions compiler/rustc_data_structures/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! Various data structures used by the Rust compiler. The intention
//! is that code in here should be not be *specific* to rustc, so that
//! is that code in here should not be *specific* to rustc, so that
//! it can be easily unit tested and so forth.
//!
//! # Note
Expand Down Expand Up @@ -27,6 +27,8 @@
#![feature(thread_id_value)]
#![feature(vec_into_raw_parts)]
#![feature(get_mut_unchecked)]
#![feature(lint_reasons)]
#![feature(unwrap_infallible)]
#![allow(rustc::default_hash_types)]
#![allow(rustc::potential_query_instability)]
#![deny(rustc::untranslatable_diagnostic)]
Expand Down Expand Up @@ -59,7 +61,6 @@ pub mod intern;
pub mod jobserver;
pub mod macros;
pub mod obligation_forest;
pub mod owning_ref;
pub mod sip128;
pub mod small_c_str;
pub mod small_str;
Expand All @@ -82,6 +83,7 @@ pub mod vec_linked_list;
pub mod work_queue;
pub use atomic_ref::AtomicRef;
pub mod frozen;
pub mod owned_slice;
pub mod sso;
pub mod steal;
pub mod tagged_ptr;
Expand Down
Loading