diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:20:39 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:20:39 +0000 |
commit | 1376c5a617be5c25655d0d7cb63e3beaa5a6e026 (patch) | |
tree | 3bb8d61aee02bc7a15eab3f36e3b921afc2075d0 /compiler/rustc_mir_build/src/build/custom | |
parent | Releasing progress-linux version 1.69.0+dfsg1-1~progress7.99u1. (diff) | |
download | rustc-1376c5a617be5c25655d0d7cb63e3beaa5a6e026.tar.xz rustc-1376c5a617be5c25655d0d7cb63e3beaa5a6e026.zip |
Merging upstream version 1.70.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'compiler/rustc_mir_build/src/build/custom')
-rw-r--r-- | compiler/rustc_mir_build/src/build/custom/mod.rs | 6 | ||||
-rw-r--r-- | compiler/rustc_mir_build/src/build/custom/parse.rs | 4 | ||||
-rw-r--r-- | compiler/rustc_mir_build/src/build/custom/parse/instruction.rs | 56 |
3 files changed, 48 insertions, 18 deletions
diff --git a/compiler/rustc_mir_build/src/build/custom/mod.rs b/compiler/rustc_mir_build/src/build/custom/mod.rs index 33fdc1901..d385153ba 100644 --- a/compiler/rustc_mir_build/src/build/custom/mod.rs +++ b/compiler/rustc_mir_build/src/build/custom/mod.rs @@ -21,7 +21,7 @@ use rustc_ast::Attribute; use rustc_data_structures::fx::FxHashMap; use rustc_hir::def_id::DefId; use rustc_hir::HirId; -use rustc_index::vec::IndexVec; +use rustc_index::vec::{IndexSlice, IndexVec}; use rustc_middle::{ mir::*, thir::*, @@ -37,7 +37,7 @@ pub(super) fn build_custom_mir<'tcx>( hir_id: HirId, thir: &Thir<'tcx>, expr: ExprId, - params: &IndexVec<ParamId, Param<'tcx>>, + params: &IndexSlice<ParamId, Param<'tcx>>, return_ty: Ty<'tcx>, return_ty_span: Span, span: Span, @@ -49,7 +49,7 @@ pub(super) fn build_custom_mir<'tcx>( phase: MirPhase::Built, source_scopes: IndexVec::new(), generator: None, - local_decls: LocalDecls::new(), + local_decls: IndexVec::new(), user_type_annotations: IndexVec::new(), arg_count: params.len(), spread_arg: None, diff --git a/compiler/rustc_mir_build/src/build/custom/parse.rs b/compiler/rustc_mir_build/src/build/custom/parse.rs index d72770e70..12b2f5d80 100644 --- a/compiler/rustc_mir_build/src/build/custom/parse.rs +++ b/compiler/rustc_mir_build/src/build/custom/parse.rs @@ -1,4 +1,4 @@ -use rustc_index::vec::IndexVec; +use rustc_index::vec::IndexSlice; use rustc_middle::{mir::*, thir::*, ty::Ty}; use rustc_span::Span; @@ -81,7 +81,7 @@ impl<'tcx, 'body> ParseCtxt<'tcx, 'body> { } } - pub fn parse_args(&mut self, params: &IndexVec<ParamId, Param<'tcx>>) -> PResult<()> { + pub fn parse_args(&mut self, params: &IndexSlice<ParamId, Param<'tcx>>) -> PResult<()> { for param in params.iter() { let (var, span) = { let pat = param.pat.as_ref().unwrap(); diff --git a/compiler/rustc_mir_build/src/build/custom/parse/instruction.rs b/compiler/rustc_mir_build/src/build/custom/parse/instruction.rs index dbba529ae..931fe1b24 100644 --- a/compiler/rustc_mir_build/src/build/custom/parse/instruction.rs +++ b/compiler/rustc_mir_build/src/build/custom/parse/instruction.rs @@ -1,8 +1,9 @@ use rustc_middle::mir::interpret::{ConstValue, Scalar}; use rustc_middle::mir::tcx::PlaceTy; +use rustc_middle::ty::cast::mir_cast_kind; use rustc_middle::{mir::*, thir::*, ty}; use rustc_span::Span; -use rustc_target::abi::VariantIdx; +use rustc_target::abi::{FieldIdx, VariantIdx}; use crate::build::custom::ParseError; use crate::build::expr::as_constant::as_constant_inner; @@ -55,15 +56,7 @@ impl<'tcx, 'body> ParseCtxt<'tcx, 'body> { Ok(TerminatorKind::Drop { place: self.parse_place(args[0])?, target: self.parse_block(args[1])?, - unwind: None, - }) - }, - @call("mir_drop_and_replace", args) => { - Ok(TerminatorKind::DropAndReplace { - place: self.parse_place(args[0])?, - value: self.parse_operand(args[1])?, - target: self.parse_block(args[2])?, - unwind: None, + unwind: UnwindAction::Continue, }) }, @call("mir_call", args) => { @@ -133,7 +126,7 @@ impl<'tcx, 'body> ParseCtxt<'tcx, 'body> { args, destination, target: Some(target), - cleanup: None, + unwind: UnwindAction::Continue, from_hir_call: *from_hir_call, fn_span: *fn_span, }) @@ -142,8 +135,12 @@ impl<'tcx, 'body> ParseCtxt<'tcx, 'body> { } fn parse_rvalue(&self, expr_id: ExprId) -> PResult<Rvalue<'tcx>> { - parse_by_kind!(self, expr_id, _, "rvalue", + parse_by_kind!(self, expr_id, expr, "rvalue", @call("mir_discriminant", args) => self.parse_place(args[0]).map(Rvalue::Discriminant), + @call("mir_cast_transmute", args) => { + let source = self.parse_operand(args[0])?; + Ok(Rvalue::Cast(CastKind::Transmute, source, expr.ty)) + }, @call("mir_checked", args) => { parse_by_kind!(self, args[0], _, "binary op", ExprKind::Binary { op, lhs, rhs } => Ok(Rvalue::CheckedBinaryOp( @@ -151,6 +148,11 @@ impl<'tcx, 'body> ParseCtxt<'tcx, 'body> { )), ) }, + @call("mir_offset", args) => { + let ptr = self.parse_operand(args[0])?; + let offset = self.parse_operand(args[1])?; + Ok(Rvalue::BinaryOp(BinOp::Offset, Box::new((ptr, offset)))) + }, @call("mir_len", args) => Ok(Rvalue::Len(self.parse_place(args[0])?)), ExprKind::Borrow { borrow_kind, arg } => Ok( Rvalue::Ref(self.tcx.lifetimes.re_erased, *borrow_kind, self.parse_place(*arg)?) @@ -167,6 +169,34 @@ impl<'tcx, 'body> ParseCtxt<'tcx, 'body> { ExprKind::Repeat { value, count } => Ok( Rvalue::Repeat(self.parse_operand(*value)?, *count) ), + ExprKind::Cast { source } => { + let source = self.parse_operand(*source)?; + let source_ty = source.ty(self.body.local_decls(), self.tcx); + let cast_kind = mir_cast_kind(source_ty, expr.ty); + Ok(Rvalue::Cast(cast_kind, source, expr.ty)) + }, + ExprKind::Tuple { fields } => Ok( + Rvalue::Aggregate( + Box::new(AggregateKind::Tuple), + fields.iter().map(|e| self.parse_operand(*e)).collect::<Result<_, _>>()? + ) + ), + ExprKind::Array { fields } => { + let elem_ty = expr.ty.builtin_index().expect("ty must be an array"); + Ok(Rvalue::Aggregate( + Box::new(AggregateKind::Array(elem_ty)), + fields.iter().map(|e| self.parse_operand(*e)).collect::<Result<_, _>>()? + )) + }, + ExprKind::Adt(box AdtExpr{ adt_def, variant_index, substs, fields, .. }) => { + let is_union = adt_def.is_union(); + let active_field_index = is_union.then(|| fields[0].name); + + Ok(Rvalue::Aggregate( + Box::new(AggregateKind::Adt(adt_def.did(), *variant_index, substs, None, active_field_index)), + fields.iter().map(|f| self.parse_operand(f.expr)).collect::<Result<_, _>>()? + )) + }, _ => self.parse_operand(expr_id).map(Rvalue::Use), ) } @@ -198,7 +228,7 @@ impl<'tcx, 'body> ParseCtxt<'tcx, 'body> { let (parent, proj) = parse_by_kind!(self, expr_id, expr, "place", @call("mir_field", args) => { let (parent, ty) = self.parse_place_inner(args[0])?; - let field = Field::from_u32(self.parse_integer_literal(args[1])? as u32); + let field = FieldIdx::from_u32(self.parse_integer_literal(args[1])? as u32); let field_ty = ty.field_ty(self.tcx, field); let proj = PlaceElem::Field(field, field_ty); let place = parent.project_deeper(&[proj], self.tcx); |