Skip to content
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

Sync rust 25-03-2024 #11

Closed
wants to merge 26 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
3242b04
use Instance::expect_resolve() instead of unwraping Instance::resolve()
RalfJung Mar 10, 2024
7d1f3ad
Rename `IntoDiagnostic` as `Diagnostic`.
nnethercote Mar 6, 2024
126fe9f
Forbid implementing `Freeze` even if the trait is stabilized
oli-obk Feb 23, 2024
efbad5f
Check whether a static is mutable instead of passing it down
oli-obk Oct 6, 2023
4650031
Make some functions private that are only ever used in the same module
oli-obk Feb 26, 2024
1d637d4
Ensure nested allocations in statics do not get deduplicated
oli-obk Feb 26, 2024
5074720
Some comment nits
oli-obk Mar 11, 2024
82dc439
avoid naming LLVM basic blocks when fewer_names is true
erikdesjardins Mar 15, 2024
4e460df
revert changes and just delete the fixme
erikdesjardins Mar 16, 2024
e60b6bc
Stabilize associated type bounds
compiler-errors Mar 5, 2024
8eeb10e
Make RawPtr take Ty and Mutbl separately
compiler-errors Mar 21, 2024
5030174
Mark codegen_gcc fields used only on feature master as such
krtab Jan 4, 2024
9ab3faa
CFI: Use Instance at callsites
maurer Mar 15, 2024
c02296d
Unbox and unwrap the contents of `StatementKind::Coverage`
Zalathar Mar 23, 2024
4f1990e
Update rustc version to 2024-03-26
GuillaumeGomez Mar 26, 2024
621c466
Fix libcore patch
GuillaumeGomez Mar 26, 2024
aaad00e
Fix non-master build
GuillaumeGomez Mar 26, 2024
521ebf0
format code
GuillaumeGomez Mar 26, 2024
0d1682c
Fix cast failures
GuillaumeGomez Mar 26, 2024
502a39f
Update libgccjit version
GuillaumeGomez Mar 27, 2024
294ca9d
Remove usage of `-Zno-parallel-llvm`
GuillaumeGomez Mar 27, 2024
9b6e54e
Fix clippy lint
GuillaumeGomez Mar 27, 2024
ca385c6
Ignore cfi tests
GuillaumeGomez Mar 28, 2024
d834c8c
Update rustc version to nightly-2024-03-28
GuillaumeGomez Mar 28, 2024
cbd94ff
Fix stdarch crate add patch
GuillaumeGomez Apr 2, 2024
ff1c5db
Improve code to generate static items
GuillaumeGomez Apr 2, 2024
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 build_system/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,7 @@ fn should_remove_test(file_path: &Path) -> Result<bool, String> {
"-Cllvm-args",
"//~",
"thread",
"-Zsanitizer=cfi",
]
.iter()
.any(|check| line.contains(check))
Expand Down
2 changes: 1 addition & 1 deletion example/mini_core.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![feature(
no_core, lang_items, intrinsics, unboxed_closures, type_ascription, extern_types,
decl_macro, rustc_attrs, transparent_unions, auto_traits,
decl_macro, rustc_attrs, transparent_unions, auto_traits, freeze_impls,
thread_local
)]
#![no_core]
Expand Down
2 changes: 1 addition & 1 deletion libgccjit.version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
b6f163f52
2cf6ca7373dbaf81a5bbc5d286a98c72fff8c8ee
2 changes: 1 addition & 1 deletion patches/0001-Add-stdarch-Cargo.toml-for-testing.patch
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ index 0000000..4c63700
+members = [
+ "crates/core_arch",
+ "crates/std_detect",
+ "crates/stdarch-gen",
+ "crates/stdarch-gen-arm",
+ #"examples/"
+]
+exclude = [
Expand Down
2 changes: 1 addition & 1 deletion patches/0022-core-Disable-not-compiling-tests.patch
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ index 42a26ae..5ac1042 100644
+#![cfg(test)]
#![feature(alloc_layout_extra)]
#![feature(array_chunks)]
#![feature(array_windows)]
#![feature(array_ptr_get)]
2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "nightly-2024-03-10"
channel = "nightly-2024-03-28"
components = ["rust-src", "rustc-dev", "llvm-tools-preview"]
2 changes: 1 addition & 1 deletion src/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ impl<'a, 'gcc, 'tcx> AsmBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
let builtin_unreachable = self.context.get_builtin_function("__builtin_unreachable");
let builtin_unreachable: RValue<'gcc> =
unsafe { std::mem::transmute(builtin_unreachable) };
self.call(self.type_void(), None, None, builtin_unreachable, &[], None);
self.call(self.type_void(), None, None, builtin_unreachable, &[], None, None);
}

// Write results to outputs.
Expand Down
49 changes: 41 additions & 8 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use rustc_middle::ty::layout::{
FnAbiError, FnAbiOfHelpers, FnAbiRequest, HasParamEnv, HasTyCtxt, LayoutError, LayoutOfHelpers,
TyAndLayout,
};
use rustc_middle::ty::{ParamEnv, Ty, TyCtxt};
use rustc_middle::ty::{Instance, ParamEnv, Ty, TyCtxt};
use rustc_span::def_id::DefId;
use rustc_span::Span;
use rustc_target::abi::{
Expand Down Expand Up @@ -68,7 +68,17 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
src: RValue<'gcc>,
order: AtomicOrdering,
) -> RValue<'gcc> {
#[cfg(feature = "master")]
let size = src.get_type().get_size();
#[cfg(not(feature = "master"))]
let size = {
let type_ = src.get_type();
if type_.get_pointee().is_some() {
std::mem::size_of::<*const ()>() as u32
} else {
type_.get_size()
}
};

let func = self.current_func();

Expand Down Expand Up @@ -138,7 +148,18 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
failure_order: AtomicOrdering,
weak: bool,
) -> RValue<'gcc> {
#[cfg(feature = "master")]
let size = src.get_type().get_size();
#[cfg(not(feature = "master"))]
let size = {
let type_ = src.get_type();
if type_.get_pointee().is_some() {
std::mem::size_of::<*const ()>() as u32
} else {
type_.get_size()
}
};

let compare_exchange =
self.context.get_builtin_function(&format!("__atomic_compare_exchange_{}", size));
let order = self.context.new_rvalue_from_int(self.i32_type, order.to_gcc());
Expand All @@ -153,7 +174,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {

// NOTE: not sure why, but we have the wrong type here.
let int_type = compare_exchange.get_param(2).to_rvalue().get_type();
let src = self.context.new_cast(self.location, src, int_type);
let src = self.context.new_bitcast(self.location, src, int_type);
self.context.new_call(
self.location,
compare_exchange,
Expand Down Expand Up @@ -190,8 +211,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
let casted_args: Vec<_> = param_types
.into_iter()
.zip(args.iter())
.enumerate()
.map(|(_i, (expected_ty, &actual_val))| {
.map(|(expected_ty, &actual_val)| {
let actual_ty = actual_val.get_type();
if expected_ty != actual_ty {
self.bitcast(actual_val, expected_ty)
Expand Down Expand Up @@ -592,12 +612,13 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
then: Block<'gcc>,
catch: Block<'gcc>,
_funclet: Option<&Funclet>,
instance: Option<Instance<'tcx>>,
) -> RValue<'gcc> {
let try_block = self.current_func().new_block("try");

let current_block = self.block;
self.block = try_block;
let call = self.call(typ, fn_attrs, None, func, args, None); // TODO(antoyo): use funclet here?
let call = self.call(typ, fn_attrs, None, func, args, None, instance); // TODO(antoyo): use funclet here?
self.block = current_block;

let return_value =
Expand Down Expand Up @@ -629,8 +650,9 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
then: Block<'gcc>,
catch: Block<'gcc>,
_funclet: Option<&Funclet>,
instance: Option<Instance<'tcx>>,
) -> RValue<'gcc> {
let call_site = self.call(typ, fn_attrs, None, func, args, None);
let call_site = self.call(typ, fn_attrs, None, func, args, None, instance);
let condition = self.context.new_rvalue_from_int(self.bool_type, 1);
self.llbb().end_with_conditional(self.location, condition, then, catch);
if let Some(_fn_abi) = fn_abi {
Expand Down Expand Up @@ -1129,7 +1151,7 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
// the following cast is required to avoid this error:
// gcc_jit_context_new_call: mismatching types for argument 2 of function "__atomic_store_4": assignment to param arg1 (type: int) from loadedValue3577 (type: unsigned int __attribute__((aligned(4))))
let int_type = atomic_store.get_param(1).to_rvalue().get_type();
let value = self.context.new_cast(self.location, value, int_type);
let value = self.context.new_bitcast(self.location, value, int_type);
self.llbb().add_eval(
self.location,
self.context.new_call(self.location, atomic_store, &[ptr, value, ordering]),
Expand Down Expand Up @@ -1598,7 +1620,17 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
src: RValue<'gcc>,
order: AtomicOrdering,
) -> RValue<'gcc> {
#[cfg(feature = "master")]
let size = src.get_type().get_size();
#[cfg(not(feature = "master"))]
let size = {
let type_ = src.get_type();
if type_.get_pointee().is_some() {
std::mem::size_of::<*const ()>() as u32
} else {
type_.get_size()
}
};
let name = match op {
AtomicRmwBinOp::AtomicXchg => format!("__atomic_exchange_{}", size),
AtomicRmwBinOp::AtomicAdd => format!("__atomic_fetch_add_{}", size),
Expand Down Expand Up @@ -1629,7 +1661,7 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
let dst = self.context.new_cast(self.location, dst, volatile_void_ptr_type);
// FIXME(antoyo): not sure why, but we have the wrong type here.
let new_src_type = atomic_function.get_param(1).to_rvalue().get_type();
let src = self.context.new_cast(self.location, src, new_src_type);
let src = self.context.new_bitcast(self.location, src, new_src_type);
let res = self.context.new_call(self.location, atomic_function, &[dst, src, order]);
self.context.new_cast(self.location, res, src.get_type())
}
Expand Down Expand Up @@ -1667,6 +1699,7 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
func: RValue<'gcc>,
args: &[RValue<'gcc>],
funclet: Option<&Funclet>,
_instance: Option<Instance<'tcx>>,
) -> RValue<'gcc> {
// FIXME(antoyo): remove when having a proper API.
let gcc_func = unsafe { std::mem::transmute(func) };
Expand Down
57 changes: 36 additions & 21 deletions src/consts.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
#[cfg(feature = "master")]
use gccjit::{FnAttribute, VarAttribute, Visibility};
use gccjit::{Function, GlobalKind, LValue, RValue, ToRValue};
use rustc_codegen_ssa::traits::{BaseTypeMethods, ConstMethods, DerivedTypeMethods, StaticMethods};
use rustc_codegen_ssa::traits::{BaseTypeMethods, ConstMethods, StaticMethods};
use rustc_hir::def::DefKind;
use rustc_middle::middle::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs};
use rustc_middle::mir::interpret::{
self, read_target_uint, ConstAllocation, ErrorHandled, Scalar as InterpScalar,
};
use rustc_middle::mir::mono::MonoItem;
use rustc_middle::span_bug;
use rustc_middle::ty::layout::LayoutOf;
use rustc_middle::ty::{self, Instance, Ty};
use rustc_middle::ty::{self, Instance};
use rustc_middle::{bug, span_bug};
use rustc_span::def_id::DefId;
use rustc_target::abi::{self, Align, HasDataLayout, Primitive, Size, WrappingRange};

Expand Down Expand Up @@ -63,36 +64,34 @@ impl<'gcc, 'tcx> StaticMethods for CodegenCx<'gcc, 'tcx> {
global_value
}

fn codegen_static(&self, def_id: DefId, is_mutable: bool) {
fn codegen_static(&self, def_id: DefId) {
let attrs = self.tcx.codegen_fn_attrs(def_id);

let value = match codegen_static_initializer(self, def_id) {
Ok((value, _)) => value,
let Ok((value, alloc)) = codegen_static_initializer(self, def_id) else {
// Error has already been reported
Err(_) => return,
return;
};

let global = self.get_static(def_id);
let alloc = alloc.inner();

// boolean SSA values are i1, but they have to be stored in i8 slots,
// otherwise some LLVM optimization passes don't work as expected
let val_llty = self.val_ty(value);
if val_llty == self.type_i1() {
unimplemented!();
};
let global = self.get_static_inner(def_id, val_llty);

let instance = Instance::mono(self.tcx, def_id);
let ty = instance.ty(self.tcx, ty::ParamEnv::reveal_all());
let gcc_type = self.layout_of(ty).gcc_type(self);
let gcc_type = self.val_ty(global.to_rvalue());

set_global_alignment(self, global, self.align_of(ty));
set_global_alignment(self, global, alloc.align);

let value = self.bitcast_if_needed(value, gcc_type);
global.global_set_initializer_rvalue(value);

// As an optimization, all shared statics which do not have interior
// mutability are placed into read-only memory.
if !is_mutable && self.type_is_freeze(ty) {
if !alloc.mutability.is_not() {
#[cfg(feature = "master")]
global.global_set_readonly();
}
Expand Down Expand Up @@ -205,7 +204,21 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {

pub fn get_static(&self, def_id: DefId) -> LValue<'gcc> {
let instance = Instance::mono(self.tcx, def_id);
let fn_attrs = self.tcx.codegen_fn_attrs(def_id);

let DefKind::Static { nested, .. } = self.tcx.def_kind(def_id) else { bug!() };
// Nested statics do not have a type, so pick a dummy type and let `codegen_static` figure out
// the llvm type from the actual evaluated initializer.
let llty = if nested {
self.type_i8()
} else {
let ty = instance.ty(self.tcx, ty::ParamEnv::reveal_all());
self.layout_of(ty).gcc_type(self)
};
self.get_static_inner(def_id, llty)
}

pub fn get_static_inner(&self, def_id: DefId, llty: gccjit::Type<'gcc>) -> LValue<'gcc> {
let instance = Instance::mono(self.tcx, def_id);
if let Some(&global) = self.instances.borrow().get(&instance) {
return global;
}
Expand All @@ -219,18 +232,17 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
def_id
);

let ty = instance.ty(self.tcx, ty::ParamEnv::reveal_all());
let sym = self.tcx.symbol_name(instance).name;
let fn_attrs = self.tcx.codegen_fn_attrs(def_id);

let is_tls = fn_attrs.flags.contains(CodegenFnAttrFlags::THREAD_LOCAL);
let global = if def_id.is_local() && !self.tcx.is_foreign_item(def_id) {
let llty = self.layout_of(ty).gcc_type(self);
if let Some(global) = self.get_declared_value(sym) {
if self.val_ty(global) != self.type_ptr_to(llty) {
span_bug!(self.tcx.def_span(def_id), "Conflicting types for static");
}
}

let is_tls = fn_attrs.flags.contains(CodegenFnAttrFlags::THREAD_LOCAL);
let global =
self.declare_global(sym, llty, GlobalKind::Exported, is_tls, fn_attrs.link_section);

Expand All @@ -241,7 +253,11 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {

global
} else {
check_and_apply_linkage(self, fn_attrs, ty, sym)
let global = check_and_apply_linkage(self, fn_attrs, llty, sym);
if is_tls {
global.set_tls_model(self.tls_model);
}
global
};

if !def_id.is_local() {
Expand Down Expand Up @@ -344,7 +360,7 @@ pub fn const_alloc_to_gcc<'gcc, 'tcx>(
cx.const_struct(&llvals, true)
}

pub fn codegen_static_initializer<'gcc, 'tcx>(
fn codegen_static_initializer<'gcc, 'tcx>(
cx: &CodegenCx<'gcc, 'tcx>,
def_id: DefId,
) -> Result<(RValue<'gcc>, ConstAllocation<'tcx>), ErrorHandled> {
Expand All @@ -355,11 +371,10 @@ pub fn codegen_static_initializer<'gcc, 'tcx>(
fn check_and_apply_linkage<'gcc, 'tcx>(
cx: &CodegenCx<'gcc, 'tcx>,
attrs: &CodegenFnAttrs,
ty: Ty<'tcx>,
gcc_type: gccjit::Type<'gcc>,
sym: &str,
) -> LValue<'gcc> {
let is_tls = attrs.flags.contains(CodegenFnAttrFlags::THREAD_LOCAL);
let gcc_type = cx.layout_of(ty).gcc_type(cx);
if let Some(linkage) = attrs.import_linkage {
// Declare a symbol `foo` with the desired linkage.
let global1 =
Expand Down
10 changes: 6 additions & 4 deletions src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ pub struct CodegenCx<'gcc, 'tcx> {
local_gen_sym_counter: Cell<usize>,

eh_personality: Cell<Option<RValue<'gcc>>>,
#[cfg(feature = "master")]
pub rust_try_fn: Cell<Option<(Type<'gcc>, Function<'gcc>)>>,

pub pointee_infos: RefCell<FxHashMap<(Ty<'tcx>, Size), Option<PointeeInfo>>>,
Expand All @@ -121,6 +122,7 @@ pub struct CodegenCx<'gcc, 'tcx> {
/// FIXME(antoyo): fix the rustc API to avoid having this hack.
pub structs_as_pointer: RefCell<FxHashSet<RValue<'gcc>>>,

#[cfg(feature = "master")]
pub cleanup_blocks: RefCell<FxHashSet<Block<'gcc>>>,
}

Expand Down Expand Up @@ -325,9 +327,11 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
struct_types: Default::default(),
local_gen_sym_counter: Cell::new(0),
eh_personality: Cell::new(None),
#[cfg(feature = "master")]
rust_try_fn: Cell::new(None),
pointee_infos: Default::default(),
structs_as_pointer: Default::default(),
#[cfg(feature = "master")]
cleanup_blocks: Default::default(),
};
// TODO(antoyo): instead of doing this, add SsizeT to libgccjit.
Expand Down Expand Up @@ -473,14 +477,12 @@ impl<'gcc, 'tcx> MiscMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
let tcx = self.tcx;
let func = match tcx.lang_items().eh_personality() {
Some(def_id) if !wants_msvc_seh(self.sess()) => {
let instance = ty::Instance::resolve(
let instance = ty::Instance::expect_resolve(
tcx,
ty::ParamEnv::reveal_all(),
def_id,
ty::List::empty(),
)
.unwrap()
.unwrap();
);

let symbol_name = tcx.symbol_name(instance).name;
let fn_abi = self.fn_abi_of_instance(instance, ty::List::empty());
Expand Down
4 changes: 2 additions & 2 deletions src/coverageinfo.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use rustc_codegen_ssa::traits::CoverageInfoBuilderMethods;
use rustc_middle::mir::Coverage;
use rustc_middle::mir::coverage::CoverageKind;
use rustc_middle::ty::Instance;

use crate::builder::Builder;

impl<'a, 'gcc, 'tcx> CoverageInfoBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
fn add_coverage(&mut self, _instance: Instance<'tcx>, _coverage: &Coverage) {
fn add_coverage(&mut self, _instance: Instance<'tcx>, _kind: &CoverageKind) {
// TODO(antoyo)
}
}
Loading
Loading