From 3e3e70d529d8c7d7c4d7bc4fefc9f109393b9245 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:19:43 +0200 Subject: Merging upstream version 1.69.0+dfsg1. Signed-off-by: Daniel Baumann --- compiler/rustc_middle/src/thir.rs | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) (limited to 'compiler/rustc_middle/src/thir.rs') diff --git a/compiler/rustc_middle/src/thir.rs b/compiler/rustc_middle/src/thir.rs index 5f320708c..3b11fab8c 100644 --- a/compiler/rustc_middle/src/thir.rs +++ b/compiler/rustc_middle/src/thir.rs @@ -20,7 +20,7 @@ use rustc_middle::mir::interpret::AllocId; use rustc_middle::mir::{self, BinOp, BorrowKind, FakeReadCause, Field, Mutability, UnOp}; use rustc_middle::ty::adjustment::PointerCast; use rustc_middle::ty::subst::SubstsRef; -use rustc_middle::ty::{self, AdtDef, Ty, UpvarSubsts}; +use rustc_middle::ty::{self, AdtDef, FnSig, Ty, UpvarSubsts}; use rustc_middle::ty::{CanonicalUserType, CanonicalUserTypeAnnotation}; use rustc_span::def_id::LocalDefId; use rustc_span::{sym, Span, Symbol, DUMMY_SP}; @@ -32,7 +32,12 @@ use std::ops::Index; pub mod visit; macro_rules! thir_with_elements { - ($($name:ident: $id:ty => $value:ty => $format:literal,)*) => { + ( + $($field_name:ident: $field_ty:ty,)* + + @elements: + $($name:ident: $id:ty => $value:ty => $format:literal,)* + ) => { $( newtype_index! { #[derive(HashStable)] @@ -46,14 +51,20 @@ macro_rules! thir_with_elements { /// This can be indexed directly by any THIR index (e.g. [`ExprId`]). #[derive(Debug, HashStable, Clone)] pub struct Thir<'tcx> { + $( + pub $field_name: $field_ty, + )* $( pub $name: IndexVec<$id, $value>, )* } impl<'tcx> Thir<'tcx> { - pub fn new() -> Thir<'tcx> { + pub fn new($($field_name: $field_ty,)*) -> Thir<'tcx> { Thir { + $( + $field_name, + )* $( $name: IndexVec::new(), )* @@ -75,6 +86,9 @@ macro_rules! thir_with_elements { pub const UPVAR_ENV_PARAM: ParamId = ParamId::from_u32(0); thir_with_elements! { + body_type: BodyTy<'tcx>, + +@elements: arms: ArmId => Arm<'tcx> => "a{}", blocks: BlockId => Block => "b{}", exprs: ExprId => Expr<'tcx> => "e{}", @@ -82,6 +96,12 @@ thir_with_elements! { params: ParamId => Param<'tcx> => "p{}", } +#[derive(Debug, HashStable, Clone)] +pub enum BodyTy<'tcx> { + Const(Ty<'tcx>), + Fn(FnSig<'tcx>), +} + /// Description of a type-checked function parameter. #[derive(Clone, Debug, HashStable)] pub struct Param<'tcx> { @@ -217,6 +237,9 @@ pub struct LocalVarId(pub hir::HirId); /// A THIR expression. #[derive(Clone, Debug, HashStable)] pub struct Expr<'tcx> { + /// kind of expression + pub kind: ExprKind<'tcx>, + /// The type of this expression pub ty: Ty<'tcx>, @@ -226,9 +249,6 @@ pub struct Expr<'tcx> { /// span of the expression in the source pub span: Span, - - /// kind of expression - pub kind: ExprKind<'tcx>, } #[derive(Clone, Debug, HashStable)] -- cgit v1.2.3