Skip to content

Commit

Permalink
Make THIR data structures public
Browse files Browse the repository at this point in the history
  • Loading branch information
LeSeulArtichaut committed Mar 11, 2021
1 parent 61365c0 commit 2a34428
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 62 deletions.
3 changes: 1 addition & 2 deletions compiler/rustc_mir_build/src/build/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::build;
use crate::build::scope::DropKind;
use crate::thir::cx::build_thir;
use crate::thir::{Arena, BindingMode, Expr, LintLevel, Pat, PatKind};
use crate::thir::{build_thir, Arena, BindingMode, Expr, LintLevel, Pat, PatKind};
use rustc_attr::{self as attr, UnwindAttr};
use rustc_errors::ErrorReported;
use rustc_hir as hir;
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir_build/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ extern crate rustc_middle;

mod build;
mod lints;
mod thir;
pub mod thir;

use rustc_middle::ty::query::Providers;

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir_build/src/thir/cx/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use rustc_middle::middle::region;
use rustc_middle::mir::interpret::{LitToConstError, LitToConstInput};
use rustc_middle::ty::{self, Ty, TyCtxt};

crate fn build_thir<'thir, 'tcx>(
pub fn build_thir<'thir, 'tcx>(
tcx: TyCtxt<'tcx>,
owner_def: ty::WithOptConstParam<LocalDefId>,
arena: &'thir Arena<'thir, 'tcx>,
Expand Down
79 changes: 40 additions & 39 deletions compiler/rustc_mir_build/src/thir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,50 +18,51 @@ use rustc_target::abi::VariantIdx;
use rustc_target::asm::InlineAsmRegOrRegClass;

crate mod constant;

crate mod cx;
pub use cx::build_thir;

crate mod pattern;
crate use self::pattern::PatTyProj;
crate use self::pattern::{BindingMode, FieldPat, Pat, PatKind, PatRange};
pub use self::pattern::{Ascription, BindingMode, FieldPat, Pat, PatKind, PatRange, PatTyProj};

mod arena;
crate use arena::Arena;
pub use arena::Arena;

mod util;

#[derive(Copy, Clone, Debug)]
crate enum LintLevel {
pub enum LintLevel {
Inherited,
Explicit(hir::HirId),
}

#[derive(Debug)]
crate struct Block<'thir, 'tcx> {
crate targeted_by_break: bool,
crate region_scope: region::Scope,
crate opt_destruction_scope: Option<region::Scope>,
crate span: Span,
crate stmts: &'thir [Stmt<'thir, 'tcx>],
crate expr: Option<&'thir Expr<'thir, 'tcx>>,
crate safety_mode: BlockSafety,
pub struct Block<'thir, 'tcx> {
pub targeted_by_break: bool,
pub region_scope: region::Scope,
pub opt_destruction_scope: Option<region::Scope>,
pub span: Span,
pub stmts: &'thir [Stmt<'thir, 'tcx>],
pub expr: Option<&'thir Expr<'thir, 'tcx>>,
pub safety_mode: BlockSafety,
}

#[derive(Copy, Clone, Debug)]
crate enum BlockSafety {
pub enum BlockSafety {
Safe,
ExplicitUnsafe(hir::HirId),
PushUnsafe,
PopUnsafe,
}

#[derive(Debug)]
crate struct Stmt<'thir, 'tcx> {
crate kind: StmtKind<'thir, 'tcx>,
crate opt_destruction_scope: Option<region::Scope>,
pub struct Stmt<'thir, 'tcx> {
pub kind: StmtKind<'thir, 'tcx>,
pub opt_destruction_scope: Option<region::Scope>,
}

#[derive(Debug)]
crate enum StmtKind<'thir, 'tcx> {
pub enum StmtKind<'thir, 'tcx> {
Expr {
/// scope for this statement; may be used as lifetime of temporaries
scope: region::Scope,
Expand Down Expand Up @@ -111,23 +112,23 @@ rustc_data_structures::static_assert_size!(Expr<'_, '_>, 144);
/// example, method calls and overloaded operators are absent: they are
/// expected to be converted into `Expr::Call` instances.
#[derive(Debug)]
crate struct Expr<'thir, 'tcx> {
pub struct Expr<'thir, 'tcx> {
/// type of this expression
crate ty: Ty<'tcx>,
pub ty: Ty<'tcx>,

/// lifetime of this expression if it should be spilled into a
/// temporary; should be None only if in a constant context
crate temp_lifetime: Option<region::Scope>,
pub temp_lifetime: Option<region::Scope>,

/// span of the expression in the source
crate span: Span,
pub span: Span,

/// kind of expression
crate kind: ExprKind<'thir, 'tcx>,
pub kind: ExprKind<'thir, 'tcx>,
}

#[derive(Debug)]
crate enum ExprKind<'thir, 'tcx> {
pub enum ExprKind<'thir, 'tcx> {
Scope {
region_scope: region::Scope,
lint_level: LintLevel,
Expand Down Expand Up @@ -316,41 +317,41 @@ crate enum ExprKind<'thir, 'tcx> {
}

#[derive(Debug)]
crate struct FieldExpr<'thir, 'tcx> {
crate name: Field,
crate expr: &'thir Expr<'thir, 'tcx>,
pub struct FieldExpr<'thir, 'tcx> {
pub name: Field,
pub expr: &'thir Expr<'thir, 'tcx>,
}

#[derive(Debug)]
crate struct FruInfo<'thir, 'tcx> {
crate base: &'thir Expr<'thir, 'tcx>,
crate field_types: &'thir [Ty<'tcx>],
pub struct FruInfo<'thir, 'tcx> {
pub base: &'thir Expr<'thir, 'tcx>,
pub field_types: &'thir [Ty<'tcx>],
}

#[derive(Debug)]
crate struct Arm<'thir, 'tcx> {
crate pattern: Pat<'tcx>,
crate guard: Option<Guard<'thir, 'tcx>>,
crate body: &'thir Expr<'thir, 'tcx>,
crate lint_level: LintLevel,
crate scope: region::Scope,
crate span: Span,
pub struct Arm<'thir, 'tcx> {
pub pattern: Pat<'tcx>,
pub guard: Option<Guard<'thir, 'tcx>>,
pub body: &'thir Expr<'thir, 'tcx>,
pub lint_level: LintLevel,
pub scope: region::Scope,
pub span: Span,
}

#[derive(Debug)]
crate enum Guard<'thir, 'tcx> {
pub enum Guard<'thir, 'tcx> {
If(&'thir Expr<'thir, 'tcx>),
IfLet(Pat<'tcx>, &'thir Expr<'thir, 'tcx>),
}

#[derive(Copy, Clone, Debug)]
crate enum LogicalOp {
pub enum LogicalOp {
And,
Or,
}

#[derive(Debug)]
crate enum InlineAsmOperand<'thir, 'tcx> {
pub enum InlineAsmOperand<'thir, 'tcx> {
In {
reg: InlineAsmRegOrRegClass,
expr: &'thir Expr<'thir, 'tcx>,
Expand Down
38 changes: 19 additions & 19 deletions compiler/rustc_mir_build/src/thir/pattern/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,22 @@ crate enum PatternError {
}

#[derive(Copy, Clone, Debug, PartialEq)]
crate enum BindingMode {
pub enum BindingMode {
ByValue,
ByRef(BorrowKind),
}

#[derive(Clone, Debug, PartialEq)]
crate struct FieldPat<'tcx> {
crate field: Field,
crate pattern: Pat<'tcx>,
pub struct FieldPat<'tcx> {
pub field: Field,
pub pattern: Pat<'tcx>,
}

#[derive(Clone, Debug, PartialEq)]
crate struct Pat<'tcx> {
crate ty: Ty<'tcx>,
crate span: Span,
crate kind: Box<PatKind<'tcx>>,
pub struct Pat<'tcx> {
pub ty: Ty<'tcx>,
pub span: Span,
pub kind: Box<PatKind<'tcx>>,
}

impl<'tcx> Pat<'tcx> {
Expand All @@ -65,8 +65,8 @@ impl<'tcx> Pat<'tcx> {
}

#[derive(Copy, Clone, Debug, PartialEq)]
crate struct PatTyProj<'tcx> {
crate user_ty: CanonicalUserType<'tcx>,
pub struct PatTyProj<'tcx> {
pub user_ty: CanonicalUserType<'tcx>,
}

impl<'tcx> PatTyProj<'tcx> {
Expand All @@ -92,8 +92,8 @@ impl<'tcx> PatTyProj<'tcx> {
}

#[derive(Copy, Clone, Debug, PartialEq)]
crate struct Ascription<'tcx> {
crate user_ty: PatTyProj<'tcx>,
pub struct Ascription<'tcx> {
pub user_ty: PatTyProj<'tcx>,
/// Variance to use when relating the type `user_ty` to the **type of the value being
/// matched**. Typically, this is `Variance::Covariant`, since the value being matched must
/// have a type that is some subtype of the ascribed type.
Expand All @@ -112,12 +112,12 @@ crate struct Ascription<'tcx> {
/// requires that `&'static str <: T_x`, where `T_x` is the type of `x`. Really, we should
/// probably be checking for a `PartialEq` impl instead, but this preserves the behavior
/// of the old type-check for now. See #57280 for details.
crate variance: ty::Variance,
crate user_ty_span: Span,
pub variance: ty::Variance,
pub user_ty_span: Span,
}

#[derive(Clone, Debug, PartialEq)]
crate enum PatKind<'tcx> {
pub enum PatKind<'tcx> {
Wild,

AscribeUserType {
Expand Down Expand Up @@ -195,10 +195,10 @@ crate enum PatKind<'tcx> {
}

#[derive(Copy, Clone, Debug, PartialEq)]
crate struct PatRange<'tcx> {
crate lo: &'tcx ty::Const<'tcx>,
crate hi: &'tcx ty::Const<'tcx>,
crate end: RangeEnd,
pub struct PatRange<'tcx> {
pub lo: &'tcx ty::Const<'tcx>,
pub hi: &'tcx ty::Const<'tcx>,
pub end: RangeEnd,
}

impl<'tcx> fmt::Display for Pat<'tcx> {
Expand Down

0 comments on commit 2a34428

Please sign in to comment.