Skip to content

Commit

Permalink
Updated rustc verision
Browse files Browse the repository at this point in the history
  • Loading branch information
FractalFir committed Nov 30, 2024
1 parent 8be0247 commit 13ed088
Show file tree
Hide file tree
Showing 22 changed files with 132 additions and 73 deletions.
9 changes: 4 additions & 5 deletions cilly/src/v2/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,13 +431,12 @@ impl Assembly {
let def_class = def.class();
let ref_idx = self.alloc_methodref(mref);
// Check that this def is unique
if !self.method_defs.contains_key(&MethodDefIdx(ref_idx)){
if !self.method_defs.contains_key(&MethodDefIdx(ref_idx)) {
self.class_defs
.get_mut(&def_class)
.expect("Method added without a class")
.add_def(MethodDefIdx(ref_idx));
.get_mut(&def_class)
.expect("Method added without a class")
.add_def(MethodDefIdx(ref_idx));
}


self.method_defs.insert(MethodDefIdx(ref_idx), def);

Expand Down
4 changes: 1 addition & 3 deletions cilly/src/v2/c_exporter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ fn local_name(locals: &[LocalDef], asm: &Assembly, loc: u32) -> String {
.count()
> 1
{

return format!("L{loc}");
}
match locals[loc as usize].0 {
Expand Down Expand Up @@ -981,14 +980,13 @@ impl CExporter {
let locals: Vec<_> = def.iter_locals(asm).copied().collect();
for (idx, (lname, local_type)) in locals.iter().enumerate() {
// If the name of this local is found multiple times, use the L form.

writeln!(
method_defs,
"{local_type} {lname};",
lname = local_name(&locals, asm, idx as u32),
local_type = nonvoid_c_type(asm[*local_type], asm),
)?;

}
let blocks = def.blocks(asm).unwrap().to_vec();
for block in blocks {
Expand Down
4 changes: 1 addition & 3 deletions cilly/src/v2/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ impl ClassDef {
assert_eq!(self.generics, 0);
ClassRef::new(self.name, None, self.is_valuetype, vec![].into())
}
pub fn add_def(&mut self,val:MethodDefIdx){
pub fn add_def(&mut self, val: MethodDefIdx) {
self.methods.push(val);
assert_unique(self.methods(), "add_def failed: method were not unique!");
}
Expand Down Expand Up @@ -583,8 +583,6 @@ impl ClassDef {
assert_eq!(self.access(), translated.access());
}



pub fn align(&self) -> Option<NonZeroU32> {
self.align
}
Expand Down
11 changes: 9 additions & 2 deletions cilly/src/v2/il_exporter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@ use crate::v2::MethodImpl;
use std::{io::Write, path::Path};

use super::{
asm::{IlasmFlavour, ILASM_FLAVOUR, ILASM_PATH}, cilnode::{ExtendKind, UnOp}, cilroot::BranchCond, method::LocalDef, tpe::simd::SIMDElem, Assembly, BinOp, CILIter, CILIterElem, CILNode, ClassRefIdx, Exporter, Int, MethodDefIdx, NodeIdx, RootIdx, SigIdx, Type
asm::{IlasmFlavour, ILASM_FLAVOUR, ILASM_PATH},
cilnode::{ExtendKind, UnOp},
cilroot::BranchCond,
method::LocalDef,
tpe::simd::SIMDElem,
Assembly, BinOp, CILIter, CILIterElem, CILNode, ClassRefIdx, Exporter, Int, MethodDefIdx,
NodeIdx, RootIdx, SigIdx, Type,
};

pub struct ILExporter {
Expand Down Expand Up @@ -82,7 +88,8 @@ impl ILExporter {
};
}
// Debug check
let mut ensure_unqiue:std::collections::HashSet<MethodDefIdx> = std::collections::HashSet::new();
let mut ensure_unqiue: std::collections::HashSet<MethodDefIdx> =
std::collections::HashSet::new();
// Export all methods

for method_id in class_def.methods() {
Expand Down
2 changes: 1 addition & 1 deletion src/aggregate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub fn handle_aggregate<'tcx>(
.collect();
match aggregate_kind {
AggregateKind::Adt(adt_def, variant_idx, subst, _utai, active_field) => {
let penv = ParamEnv::reveal_all();
let penv = rustc_middle::ty::TypingEnv::fully_monomorphized();
let subst = ctx.monomorphize(*subst);
//eprintln!("Preparing to resolve {adt_def:?} {subst:?}");
let adt_type = Instance::try_resolve(ctx.tcx(), penv, *adt_def, subst);
Expand Down
8 changes: 7 additions & 1 deletion src/assembly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,13 @@ pub fn add_fn<'tcx, 'asm, 'a: 'asm>(
name: &str,
ctx: &'a mut MethodCompileCtx<'tcx, 'asm>,
) -> Result<(), MethodCodegenError> {
let kind = ctx.instance().ty(ctx.tcx(), ParamEnv::reveal_all()).kind();
let kind = ctx
.instance()
.ty(
ctx.tcx(),
rustc_middle::ty::TypingEnv::fully_monomorphized(),
)
.kind();
if let TyKind::FnDef(_, _) = kind {
//ALL OK.
} else if let TyKind::Closure(_, _) = kind {
Expand Down
17 changes: 12 additions & 5 deletions src/binop/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,18 @@ pub(crate) fn binop<'tcx>(
.get_lang_items(())
.get(LangItem::OrderingEnum)
.unwrap();
let ordering =
Instance::try_resolve(ctx.tcx(), ParamEnv::reveal_all(), ordering, List::empty())
.unwrap()
.unwrap();
let ordering_ty = ordering.ty(ctx.tcx(), ParamEnv::reveal_all());
let ordering = Instance::try_resolve(
ctx.tcx(),
rustc_middle::ty::TypingEnv::fully_monomorphized(),
ordering,
List::empty(),
)
.unwrap()
.unwrap();
let ordering_ty = ordering.ty(
ctx.tcx(),
rustc_middle::ty::TypingEnv::fully_monomorphized(),
);
let ordering_type = ctx.type_from_cache(ordering_ty);
let lt = -conv_i8!(lt_unchecked(ty_a, ops_a.clone(), ops_b.clone(), ctx));
let gt = conv_i8!(gt_unchecked(ty_a, ops_a, ops_b, ctx));
Expand Down
11 changes: 7 additions & 4 deletions src/call_info.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use cilly::v2::FnSig;
use rustc_middle::ty::{Instance, List, ParamEnv, ParamEnvAnd, TyKind};
use rustc_middle::ty::{Instance, List, ParamEnv, PseudoCanonicalInput, TyKind};
use rustc_target::abi::call::Conv;
use rustc_target::spec::abi::Abi as TargetAbi;

Expand All @@ -15,8 +15,8 @@ impl CallInfo {
function: Instance<'tcx>,
ctx: &mut MethodCompileCtx<'tcx, '_>,
) -> Self {
let fn_abi = ctx.tcx().fn_abi_of_instance(ParamEnvAnd {
param_env: ParamEnv::reveal_all(),
let fn_abi = ctx.tcx().fn_abi_of_instance(PseudoCanonicalInput {
typing_env: rustc_middle::ty::TypingEnv::fully_monomorphized(),
value: (function, List::empty()),
});
let fn_abi = match fn_abi {
Expand All @@ -39,7 +39,10 @@ impl CallInfo {
args.push(get_type(arg.layout.ty, ctx));
}
// There are 2 ABI enums for some reasons(they differ in what memebers they have)
let fn_ty = function.ty(ctx.tcx(), ParamEnv::reveal_all());
let fn_ty = function.ty(
ctx.tcx(),
rustc_middle::ty::TypingEnv::fully_monomorphized(),
);
let internal_abi = match fn_ty.kind() {
TyKind::FnDef(_, _) => fn_ty.fn_sig(ctx.tcx()).abi(),
TyKind::Closure(_, args) => args.as_closure().sig().abi(),
Expand Down
4 changes: 2 additions & 2 deletions src/comptime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ pub fn interpret<'tcx>(
func_ty.kind()
{
let subst_ref = ctx.monomorphize(*subst_ref);
let env = ParamEnv::reveal_all();
let env = rustc_middle::ty::TypingEnv::fully_monomorphized();
let Some(call_instance) =
Instance::try_resolve(ctx.tcx(), env, *def_id, subst_ref)
.expect("Invalid function def")
Expand Down Expand Up @@ -183,7 +183,7 @@ pub fn interpret<'tcx>(
{
let subst_ref =
crate::utilis::monomorphize(&instance, *subst_ref, ctx.tcx());
let env = ParamEnv::reveal_all();
let env = rustc_middle::ty::TypingEnv::fully_monomorphized();
let Some(instance) =
Instance::try_resolve(ctx.tcx(), env, *def_id, subst_ref)
.expect("Invalid function def")
Expand Down
6 changes: 5 additions & 1 deletion src/constant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ pub fn handle_constant<'tcx>(
let constant = constant_op.const_;
let constant = ctx.monomorphize(constant);
let evaluated = constant
.eval(ctx.tcx(), ParamEnv::reveal_all(), constant_op.span)
.eval(
ctx.tcx(),
rustc_middle::ty::TypingEnv::fully_monomorphized(),
constant_op.span,
)
.expect("Could not evaluate constant!");
load_const_value(evaluated, constant.ty(), ctx)
}
Expand Down
18 changes: 9 additions & 9 deletions src/fn_ctx.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::r#type::get_type;
use cilly::v2::Assembly;
use cilly::Type;
use rustc_middle::ty::{Instance, ParamEnv, TyCtxt};

use crate::r#type::get_type;
use rustc_middle::ty::layout::HasTypingEnv;
use rustc_middle::ty::{Instance, PseudoCanonicalInput, TyCtxt};
pub struct MethodCompileCtx<'tcx, 'asm> {
tcx: TyCtxt<'tcx>,
method: Option<&'tcx rustc_middle::mir::Body<'tcx>>,
Expand Down Expand Up @@ -78,7 +78,7 @@ impl<'tcx, 'asm> MethodCompileCtx<'tcx, 'asm> {
self.instance()
.instantiate_mir_and_normalize_erasing_regions(
self.tcx(),
ParamEnv::reveal_all(),
rustc_middle::ty::TypingEnv::fully_monomorphized(),
rustc_middle::ty::EarlyBinder::bind(ty),
)
}
Expand All @@ -93,8 +93,8 @@ impl<'tcx, 'asm> MethodCompileCtx<'tcx, 'asm> {
) -> rustc_middle::ty::layout::TyAndLayout<'tcx> {
let ty = self.monomorphize(ty);
self.tcx
.layout_of(rustc_middle::ty::ParamEnvAnd {
param_env: ParamEnv::reveal_all(),
.layout_of(PseudoCanonicalInput {
typing_env: rustc_middle::ty::TypingEnv::fully_monomorphized(),
value: ty,
})
.expect("Could not get type layout!")
Expand All @@ -118,8 +118,8 @@ impl rustc_abi::HasDataLayout for MethodCompileCtx<'_, '_> {
self.tcx.data_layout()
}
}
impl<'tcx> rustc_middle::ty::layout::HasParamEnv<'tcx> for MethodCompileCtx<'tcx, '_> {
fn param_env(&self) -> ParamEnv<'tcx> {
ParamEnv::reveal_all()
impl<'tcx> HasTypingEnv<'tcx> for MethodCompileCtx<'tcx, '_> {
fn typing_env(&self) -> rustc_middle::ty::TypingEnv<'tcx> {
rustc_middle::ty::TypingEnv::fully_monomorphized()
}
}
17 changes: 11 additions & 6 deletions src/function_sig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::codegen_error::CodegenError;
use crate::fn_ctx::MethodCompileCtx;
use crate::r#type::get_type;
use cilly::{v2::FnSig, Type};
use rustc_middle::ty::{Instance, List, ParamEnv, ParamEnvAnd, Ty, TyCtxt, TyKind};
use rustc_middle::ty::{Instance, List, ParamEnv, PseudoCanonicalInput, Ty, TyCtxt, TyKind};
use rustc_target::abi::call::Conv;
use rustc_target::spec::abi::Abi as TargetAbi;

Expand All @@ -25,10 +25,12 @@ pub fn sig_from_instance_<'tcx>(
function: Instance<'tcx>,
ctx: &mut MethodCompileCtx<'tcx, '_>,
) -> Result<FnSig, CodegenError> {
let fn_abi = ctx.tcx().fn_abi_of_instance(ParamEnvAnd {
param_env: ParamEnv::reveal_all(),
value: (function, List::empty()),
});
let fn_abi = ctx
.tcx()
.fn_abi_of_instance(rustc_middle::ty::PseudoCanonicalInput {
typing_env: rustc_middle::ty::TypingEnv::fully_monomorphized(),
value: (function, List::empty()),
});
let fn_abi = match fn_abi {
Ok(abi) => abi,
Err(_error) => todo!(),
Expand All @@ -47,7 +49,10 @@ pub fn sig_from_instance_<'tcx>(
args.push(get_type(arg, ctx));
}
// There are 2 ABI enums for some reasons(they differ in what memebers they have)
let fn_ty = function.ty(ctx.tcx(), ParamEnv::reveal_all());
let fn_ty = function.ty(
ctx.tcx(),
rustc_middle::ty::TypingEnv::fully_monomorphized(),
);
let internal_abi = match fn_ty.kind() {
TyKind::FnDef(_, _) => fn_ty.fn_sig(ctx.tcx()),
TyKind::Closure(_, args) => args.as_closure().sig(),
Expand Down
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ use rustc_session::{
config::{OutputFilenames, OutputType},
Session,
};

use rustc_span::ErrorGuaranteed;

use std::{any::Any, path::Path};
Expand Down Expand Up @@ -216,7 +217,7 @@ impl CodegenBackend for MyBackend {
}

if let Some((entrypoint, _kind)) = tcx.entry_fn(()) {
let penv = rustc_middle::ty::ParamEnv::reveal_all();
let penv = rustc_middle::ty::TypingEnv::fully_monomorphized();
let entrypoint = rustc_middle::ty::Instance::try_resolve(
tcx,
penv,
Expand Down
6 changes: 5 additions & 1 deletion src/operand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ pub(crate) fn is_uninit<'tcx>(
let constant = const_val.const_;
let constant = ctx.monomorphize(constant);
let evaluated = constant
.eval(ctx.tcx(), ParamEnv::reveal_all(), const_val.span)
.eval(
ctx.tcx(),
rustc_middle::ty::TypingEnv::fully_monomorphized(),
const_val.span,
)
.expect("Could not evaluate constant!");
match evaluated {
ConstValue::Scalar(_) => false, // Scalars are never uninitialized.
Expand Down
8 changes: 6 additions & 2 deletions src/rvalue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,11 @@ pub fn handle_rvalue<'tcx>(
let layout = ctx.layout_of(*ty);
let offset = ctx
.tcx()
.offset_of_subfield(ParamEnv::reveal_all(), layout, fields.iter())
.offset_of_subfield(
rustc_middle::ty::TypingEnv::fully_monomorphized(),
layout,
fields.iter(),
)
.bytes();
(vec![], CILNode::V2(ctx.alloc_node(Const::USize(offset))))
}
Expand Down Expand Up @@ -266,7 +270,7 @@ pub fn handle_rvalue<'tcx>(
let (instance, _subst_ref) = if let TyKind::FnDef(def_id, subst_ref) = operand_ty.kind()
{
let subst = ctx.monomorphize(*subst_ref);
let env = ParamEnv::reveal_all();
let env = rustc_middle::ty::TypingEnv::fully_monomorphized();
let Some(instance) = Instance::try_resolve(ctx.tcx(), env, *def_id, subst)
.expect("Invalid function def")
else {
Expand Down
1 change: 1 addition & 0 deletions src/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ pub fn handle_statement<'tcx>(
StatementKind::FakeRead(_) => {
panic!("Fake reads should not be passed from the backend to the forntend!")
}
rustc_middle::mir::StatementKind::BackwardIncompatibleDropHint { .. } => todo!(),
StatementKind::PlaceMention(place) => vec![CILRoot::Pop {
tree: place_get(place, ctx),
}
Expand Down
2 changes: 1 addition & 1 deletion src/terminator/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ pub fn call<'tcx>(
let fn_type = ctx.monomorphize(fn_type);
let (instance, subst_ref) = if let TyKind::FnDef(def_id, subst_ref) = fn_type.kind() {
let subst = ctx.monomorphize(*subst_ref);
let env = ParamEnv::reveal_all();
let env = rustc_middle::ty::TypingEnv::fully_monomorphized();
let Some(instance) =
Instance::try_resolve(ctx.tcx(), env, *def_id, subst).expect("Invalid function def")
else {
Expand Down
18 changes: 15 additions & 3 deletions src/terminator/intrinsics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ pub fn handle_intrinsic<'tcx>(
match fn_name {
"arith_offset" => arith_offset(args, destination, call_instance, ctx),
"breakpoint" => breakpoint(args),
"cold_path" | "assert_inhabited" | "assert_zero_valid" | "const_deallocate"=>CILRoot::Nop,
"black_box" => black_box(args, destination, call_instance, ctx),
"caller_location" => caller_location(destination, ctx, span),
"compare_bytes" => place_set(
Expand Down Expand Up @@ -115,7 +116,10 @@ pub fn handle_intrinsic<'tcx>(
.as_type()
.expect("needs_drop works only on types!"),
);
let needs_drop = tpe.needs_drop(ctx.tcx(), ParamEnv::reveal_all());
let needs_drop = tpe.needs_drop(
ctx.tcx(),
rustc_middle::ty::TypingEnv::fully_monomorphized(),
);
let needs_drop = i32::from(needs_drop);
place_set(destination, CILNode::V2(ctx.alloc_node(needs_drop)), ctx)
}
Expand Down Expand Up @@ -535,7 +539,11 @@ pub fn handle_intrinsic<'tcx>(
"type_name" => {
let const_val = ctx
.tcx()
.const_eval_instance(ParamEnv::reveal_all(), call_instance, span)
.const_eval_instance(
rustc_middle::ty::TypingEnv::fully_monomorphized(),
call_instance,
span,
)
.unwrap();
place_set(
destination,
Expand Down Expand Up @@ -1042,7 +1050,11 @@ pub fn handle_intrinsic<'tcx>(
"variant_count" => {
let const_val = ctx
.tcx()
.const_eval_instance(ParamEnv::reveal_all(), call_instance, span)
.const_eval_instance(
rustc_middle::ty::TypingEnv::fully_monomorphized(),
call_instance,
span,
)
.unwrap();
place_set(
destination,
Expand Down
Loading

0 comments on commit 13ed088

Please sign in to comment.