Skip to content

Commit

Permalink
Updated to latest nightly
Browse files Browse the repository at this point in the history
  • Loading branch information
FractalFir committed Jan 17, 2024
1 parent 7aaeafe commit f08c6c0
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 71 deletions.
83 changes: 42 additions & 41 deletions src/terminator/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ use rustc_middle::{
mir::{Body, Operand, Place, SwitchTargets, Terminator, TerminatorKind},
ty::{GenericArg, Instance, ParamEnv, Ty, TyCtxt, TyKind},
};
fn decode_interop_call<'ctx>(
use rustc_span::source_map::Spanned;
fn decode_interop_call<'tyctx>(
function_name: &str,
prefix: &str,
subst_ref: &[GenericArg<'ctx>],
tyctx: TyCtxt<'ctx>,
subst_ref: &[GenericArg<'tyctx>],
tyctx: TyCtxt<'tyctx>,
) -> CallSite {
let argument_count = argc_from_fn_name(function_name, MANAGED_CALL_FN_NAME);
let asm = AssemblyRef::decode_assembly_ref(subst_ref[0], tyctx);
Expand All @@ -39,15 +40,15 @@ fn argc_from_fn_name(function_name: &str, prefix: &str) -> u32 {
argument_count.parse::<u32>().unwrap()
}
/// Calls a non-virtual managed function(used for interop)
fn call_managed<'ctx>(
tyctx: TyCtxt<'ctx>,
subst_ref: &[GenericArg<'ctx>],
fn call_managed<'tyctx>(
tyctx: TyCtxt<'tyctx>,
subst_ref: &[GenericArg<'tyctx>],
function_name: &str,
args: &[Operand<'ctx>],
destination: &Place<'ctx>,
method: &'ctx Body<'ctx>,
method_instance: Instance<'ctx>,
fn_instance: Instance<'ctx>,
args: &[Spanned<Operand<'tyctx>>],
destination: &Place<'tyctx>,
method: &'tyctx Body<'tyctx>,
method_instance: Instance<'tyctx>,
fn_instance: Instance<'tyctx>,
type_cache: &mut crate::r#type::TyCache,
) -> Vec<CILOp> {
let argument_count = argc_from_fn_name(function_name, MANAGED_CALL_FN_NAME);
Expand Down Expand Up @@ -90,7 +91,7 @@ fn call_managed<'ctx>(
let mut call = Vec::new();
for arg in args {
call.extend(crate::operand::handle_operand(
arg,
&arg.node,
tyctx,
method,
method_instance,
Expand Down Expand Up @@ -118,15 +119,15 @@ fn call_managed<'ctx>(
}
}
/// Calls a virtual managed function(used for interop)
fn callvirt_managed<'ctx>(
tyctx: TyCtxt<'ctx>,
subst_ref: &[GenericArg<'ctx>],
fn callvirt_managed<'tyctx>(
tyctx: TyCtxt<'tyctx>,
subst_ref: &[GenericArg<'tyctx>],
function_name: &str,
args: &[Operand<'ctx>],
destination: &Place<'ctx>,
method: &'ctx Body<'ctx>,
method_instance: Instance<'ctx>,
fn_instance: Instance<'ctx>,
args: &[Spanned<Operand<'tyctx>>],
destination: &Place<'tyctx>,
method: &'tyctx Body<'tyctx>,
method_instance: Instance<'tyctx>,
fn_instance: Instance<'tyctx>,
type_cache: &mut crate::r#type::TyCache,
) -> Vec<CILOp> {
let argument_count = argc_from_fn_name(function_name, MANAGED_CALL_VIRT_FN_NAME);
Expand Down Expand Up @@ -173,7 +174,7 @@ fn callvirt_managed<'ctx>(
let mut call = Vec::new();
for arg in args {
call.extend(crate::operand::handle_operand(
arg,
&arg.node,
tyctx,
method,
method_instance,
Expand Down Expand Up @@ -201,14 +202,14 @@ fn callvirt_managed<'ctx>(
}
}
/// Creates a new managed object, and places a reference to it in destination
fn call_ctor<'ctx>(
tyctx: TyCtxt<'ctx>,
subst_ref: &[GenericArg<'ctx>],
fn call_ctor<'tyctx>(
tyctx: TyCtxt<'tyctx>,
subst_ref: &[GenericArg<'tyctx>],
function_name: &str,
args: &[Operand<'ctx>],
destination: &Place<'ctx>,
method: &'ctx Body<'ctx>,
method_instance: Instance<'ctx>,
args: &[Spanned<Operand<'tyctx>>],
destination: &Place<'tyctx>,
method: &'tyctx Body<'tyctx>,
method_instance: Instance<'tyctx>,
type_cache: &mut crate::r#type::TyCache,
) -> Vec<CILOp> {
let argument_count = argc_from_fn_name(function_name, CTOR_FN_NAME);
Expand Down Expand Up @@ -258,7 +259,7 @@ fn call_ctor<'ctx>(
let mut call = Vec::new();
for arg in args {
call.extend(crate::operand::handle_operand(
arg,
&arg.node,
tyctx,
method,
method_instance,
Expand All @@ -282,7 +283,7 @@ fn call_ctor<'ctx>(
}
}
pub fn call_closure<'tyctx>(
args: &[Operand<'tyctx>],
args: &[Spanned<Operand<'tyctx>>],
destination: &Place<'tyctx>,
tyctx: TyCtxt<'tyctx>,
sig: FnSig,
Expand All @@ -298,21 +299,21 @@ pub fn call_closure<'tyctx>(
let other_args = &args[..args.len() - 1];
for arg in other_args {
call.extend(crate::operand::handle_operand(
arg,
&arg.node,
tyctx,
body,
method_instance,
type_cache,
));
}
let last_arg_type =
crate::utilis::monomorphize(&method_instance, last_arg.ty(body, tyctx), tyctx);
crate::utilis::monomorphize(&method_instance, last_arg.node.ty(body, tyctx), tyctx);
match last_arg_type.kind() {
TyKind::Tuple(elements) => {
if elements.is_empty() {
} else {
call.extend(crate::operand::handle_operand(
last_arg,
&last_arg.node,
tyctx,
body,
method_instance,
Expand Down Expand Up @@ -357,13 +358,13 @@ pub fn call_closure<'tyctx>(
}
}
/// Calls `fn_type` with `args`, placing the return value in destination.
pub fn call<'ctx>(
fn_type: Ty<'ctx>,
body: &'ctx Body<'ctx>,
tyctx: TyCtxt<'ctx>,
args: &[Operand<'ctx>],
destination: &Place<'ctx>,
method_instance: Instance<'ctx>,
pub fn call<'tyctx>(
fn_type: Ty<'tyctx>,
body: &'tyctx Body<'tyctx>,
tyctx: TyCtxt<'tyctx>,
args: &[Spanned<Operand<'tyctx>>],
destination: &Place<'tyctx>,
method_instance: Instance<'tyctx>,
type_cache: &mut crate::r#type::TyCache,
) -> Vec<CILOp> {
let fn_type = crate::utilis::monomorphize(&method_instance, fn_type, tyctx);
Expand Down Expand Up @@ -475,7 +476,7 @@ pub fn call<'ctx>(
let mut call = Vec::new();
for arg in args {
call.extend(crate::operand::handle_operand(
arg,
&arg.node,
tyctx,
body,
method_instance,
Expand Down
59 changes: 30 additions & 29 deletions src/terminator/intrinsics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ use crate::{
place::place_set,
r#type::{tycache, DotnetTypeRef, Type},
};
use rustc_span::source_map::Spanned;
use rustc_middle::{
mir::{Body, Operand, Place, SwitchTargets, Terminator, TerminatorKind},
ty::{GenericArg, Instance, ParamEnv, Ty, TyCtxt, TyKind, UintTy},
};
use tycache::TyCache;
pub fn handle_intrinsic<'tyctx>(
fn_name: &str,
args: &[Operand<'tyctx>],
args: &[Spanned<Operand<'tyctx>>],
destination: &Place<'tyctx>,
tyctx: TyCtxt<'tyctx>,
body: &'tyctx Body<'tyctx>,
Expand All @@ -24,7 +25,7 @@ pub fn handle_intrinsic<'tyctx>(
let mut call = Vec::new();
for arg in args {
call.extend(crate::operand::handle_operand(
arg,
&arg.node,
tyctx,
body,
method_instance,
Expand All @@ -50,7 +51,7 @@ pub fn handle_intrinsic<'tyctx>(
place_set(
destination,
tyctx,
handle_operand(&args[0], tyctx, body, method_instance, type_cache),
handle_operand(&args[0].node, tyctx, body, method_instance, type_cache),
body,
method_instance,
type_cache,
Expand Down Expand Up @@ -93,7 +94,7 @@ pub fn handle_intrinsic<'tyctx>(
place_set(
destination,
tyctx,
handle_operand(&args[0], tyctx, body, method_instance, type_cache),
handle_operand(&args[0].node, tyctx, body, method_instance, type_cache),
body,
method_instance,
type_cache,
Expand All @@ -111,7 +112,7 @@ pub fn handle_intrinsic<'tyctx>(
let bit_operations = Some(bit_operations);
let mut res = Vec::new();
res.extend(handle_operand(
&args[0],
&args[0].node,
tyctx,
body,
method_instance,
Expand Down Expand Up @@ -141,7 +142,7 @@ pub fn handle_intrinsic<'tyctx>(
let bit_operations = Some(bit_operations);
let mut res = Vec::new();
res.extend(handle_operand(
&args[0],
&args[0].node,
tyctx,
body,
method_instance,
Expand Down Expand Up @@ -172,7 +173,7 @@ pub fn handle_intrinsic<'tyctx>(
let bit_operations = Some(bit_operations);
let mut res = Vec::new();
res.extend(handle_operand(
&args[0],
&args[0].node,
tyctx,
body,
method_instance,
Expand Down Expand Up @@ -202,14 +203,14 @@ pub fn handle_intrinsic<'tyctx>(
let bit_operations = Some(bit_operations);
let mut res = Vec::new();
res.extend(handle_operand(
&args[0],
&args[0].node,
tyctx,
body,
method_instance,
type_cache,
));
res.extend(handle_operand(
&args[1],
&args[1].node,
tyctx,
body,
method_instance,
Expand All @@ -233,9 +234,9 @@ pub fn handle_intrinsic<'tyctx>(
3,
"The intrinsic `write_bytes` MUST take in exactly 3 argument!"
);
let dst = handle_operand(&args[0], tyctx, body, method_instance, type_cache);
let val = handle_operand(&args[1], tyctx, body, method_instance, type_cache);
let count = handle_operand(&args[2], tyctx, body, method_instance, type_cache);
let dst = handle_operand(&args[0].node, tyctx, body, method_instance, type_cache);
let val = handle_operand(&args[1].node, tyctx, body, method_instance, type_cache);
let count = handle_operand(&args[2].node, tyctx, body, method_instance, type_cache);
let mut ops = dst;
ops.extend(val);
ops.extend(count);
Expand All @@ -248,9 +249,9 @@ pub fn handle_intrinsic<'tyctx>(
3,
"The intrinsic `copy` MUST take in exactly 3 argument!"
);
let dst = handle_operand(&args[0], tyctx, body, method_instance, type_cache);
let val = handle_operand(&args[1], tyctx, body, method_instance, type_cache);
let count = handle_operand(&args[2], tyctx, body, method_instance, type_cache);
let dst = handle_operand(&args[0].node, tyctx, body, method_instance, type_cache);
let val = handle_operand(&args[1].node, tyctx, body, method_instance, type_cache);
let count = handle_operand(&args[2].node, tyctx, body, method_instance, type_cache);
let mut ops = dst;
ops.extend(val);
ops.extend(count);
Expand All @@ -263,8 +264,8 @@ pub fn handle_intrinsic<'tyctx>(
2,
"The intrinsic `exact_div` MUST take in exactly 2 argument!"
);
let lhs = handle_operand(&args[0], tyctx, body, method_instance, type_cache);
let rhs = handle_operand(&args[1], tyctx, body, method_instance, type_cache);
let lhs = handle_operand(&args[0].node, tyctx, body, method_instance, type_cache);
let rhs = handle_operand(&args[1].node, tyctx, body, method_instance, type_cache);
let mut ops = lhs;
ops.extend(rhs);
ops.push(CILOp::Div);
Expand Down Expand Up @@ -309,11 +310,11 @@ pub fn handle_intrinsic<'tyctx>(
1,
"The intrinsic `volatile_load` MUST take in exactly 1 argument!"
);
let mut ops = handle_operand(&args[0], tyctx, body, method_instance, type_cache);
let mut ops = handle_operand(&args[0].node, tyctx, body, method_instance, type_cache);
ops.push(CILOp::Volatile);
ops.extend(
crate::place::deref_op(
args[0].ty(body, tyctx).into(),
args[0].node.ty(body, tyctx).into(),
tyctx,
&method_instance,
type_cache,
Expand All @@ -329,11 +330,11 @@ pub fn handle_intrinsic<'tyctx>(
1,
"The intrinsic `atomic_load_unordered` MUST take in exactly 1 argument!"
);
let mut ops = handle_operand(&args[0], tyctx, body, method_instance, type_cache);
let mut ops = handle_operand(&args[0].node, tyctx, body, method_instance, type_cache);
ops.push(CILOp::Volatile);
ops.extend(
crate::place::deref_op(
args[0].ty(body, tyctx).into(),
args[0].node.ty(body, tyctx).into(),
tyctx,
&method_instance,
type_cache,
Expand All @@ -349,11 +350,11 @@ pub fn handle_intrinsic<'tyctx>(
1,
"The intrinsic `atomic_load_acquire` MUST take in exactly 1 argument!"
);
let mut ops = handle_operand(&args[0], tyctx, body, method_instance, type_cache);
let mut ops = handle_operand(&args[0].node, tyctx, body, method_instance, type_cache);
ops.push(CILOp::Volatile);
ops.extend(
crate::place::deref_op(
args[0].ty(body, tyctx).into(),
args[0].node.ty(body, tyctx).into(),
tyctx,
&method_instance,
type_cache,
Expand All @@ -370,7 +371,7 @@ pub fn handle_intrinsic<'tyctx>(
1,
"The intrinsic `sqrtf32` MUST take in exactly 1 argument!"
);
let mut ops = handle_operand(&args[0], tyctx, body, method_instance, type_cache);
let mut ops = handle_operand(&args[0].node, tyctx, body, method_instance, type_cache);
ops.push(CILOp::ConvF64(false));
ops.push(CILOp::Call(CallSite::boxed(
Some(DotnetTypeRef::new("System.Runtime".into(), "System.Math")),
Expand All @@ -387,7 +388,7 @@ pub fn handle_intrinsic<'tyctx>(
1,
"The intrinsic `size_of_val` MUST take in exactly 1 argument!"
);
let tpe = args[0].ty(body, tyctx);
let tpe = args[0].node.ty(body, tyctx);
let tpe = crate::utilis::monomorphize(&method_instance, tpe, tyctx);
let tpe = type_cache.type_from_cache(tpe, tyctx, Some(method_instance));
place_set(
Expand All @@ -405,7 +406,7 @@ pub fn handle_intrinsic<'tyctx>(
1,
"The intrinsic `sqrtf64` MUST take in exactly 1 argument!"
);
let mut ops = handle_operand(&args[0], tyctx, body, method_instance, type_cache);
let mut ops = handle_operand(&args[0].node, tyctx, body, method_instance, type_cache);
ops.push(CILOp::Call(CallSite::boxed(
Some(DotnetTypeRef::new("System.Runtime".into(), "System.Math")),
"Sqrt".into(),
Expand All @@ -419,7 +420,7 @@ pub fn handle_intrinsic<'tyctx>(
}
}
fn bswap<'tyctx>(
args: &[Operand<'tyctx>],
args: &[Spanned<Operand<'tyctx>>],
destination: &Place<'tyctx>,
tyctx: TyCtxt<'tyctx>,
body: &'tyctx Body<'tyctx>,
Expand All @@ -431,9 +432,9 @@ fn bswap<'tyctx>(
1,
"The intrinsic `bswap` MUST take in exactly 1 argument!"
);
let ty = args[0].ty(body, tyctx);
let ty = args[0].node.ty(body, tyctx);
let ty = crate::utilis::monomorphize(&method_instance, ty, tyctx);
let operand = handle_operand(&args[0], tyctx, body, method_instance, type_cache);
let operand = handle_operand(&args[0].node, tyctx, body, method_instance, type_cache);
place_set(
destination,
tyctx,
Expand Down
Loading

0 comments on commit f08c6c0

Please sign in to comment.