mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 06:44:35 +00:00
Split rustc_type_ir to avoid rustc_ast from depending on it
This commit is contained in:
parent
53ed660d47
commit
8a6d3535f7
15
Cargo.lock
15
Cargo.lock
@ -3432,18 +3432,29 @@ version = "0.0.0"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 2.4.2",
|
"bitflags 2.4.2",
|
||||||
"memchr",
|
"memchr",
|
||||||
|
"rustc_ast_ir",
|
||||||
"rustc_data_structures",
|
"rustc_data_structures",
|
||||||
"rustc_index",
|
"rustc_index",
|
||||||
"rustc_lexer",
|
"rustc_lexer",
|
||||||
"rustc_macros",
|
"rustc_macros",
|
||||||
"rustc_serialize",
|
"rustc_serialize",
|
||||||
"rustc_span",
|
"rustc_span",
|
||||||
"rustc_type_ir",
|
|
||||||
"smallvec",
|
"smallvec",
|
||||||
"thin-vec",
|
"thin-vec",
|
||||||
"tracing",
|
"tracing",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rustc_ast_ir"
|
||||||
|
version = "0.0.0"
|
||||||
|
dependencies = [
|
||||||
|
"rustc_data_structures",
|
||||||
|
"rustc_macros",
|
||||||
|
"rustc_serialize",
|
||||||
|
"rustc_span",
|
||||||
|
"smallvec",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rustc_ast_lowering"
|
name = "rustc_ast_lowering"
|
||||||
version = "0.0.0"
|
version = "0.0.0"
|
||||||
@ -4196,6 +4207,7 @@ dependencies = [
|
|||||||
"rustc_apfloat",
|
"rustc_apfloat",
|
||||||
"rustc_arena",
|
"rustc_arena",
|
||||||
"rustc_ast",
|
"rustc_ast",
|
||||||
|
"rustc_ast_ir",
|
||||||
"rustc_attr",
|
"rustc_attr",
|
||||||
"rustc_data_structures",
|
"rustc_data_structures",
|
||||||
"rustc_error_messages",
|
"rustc_error_messages",
|
||||||
@ -4676,6 +4688,7 @@ version = "0.0.0"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 2.4.2",
|
"bitflags 2.4.2",
|
||||||
"derivative",
|
"derivative",
|
||||||
|
"rustc_ast_ir",
|
||||||
"rustc_data_structures",
|
"rustc_data_structures",
|
||||||
"rustc_index",
|
"rustc_index",
|
||||||
"rustc_macros",
|
"rustc_macros",
|
||||||
|
@ -8,14 +8,13 @@ edition = "2021"
|
|||||||
# tidy-alphabetical-start
|
# tidy-alphabetical-start
|
||||||
bitflags = "2.4.1"
|
bitflags = "2.4.1"
|
||||||
memchr = "=2.5.0"
|
memchr = "=2.5.0"
|
||||||
|
rustc_ast_ir = { path = "../rustc_ast_ir" }
|
||||||
rustc_data_structures = { path = "../rustc_data_structures" }
|
rustc_data_structures = { path = "../rustc_data_structures" }
|
||||||
rustc_index = { path = "../rustc_index" }
|
rustc_index = { path = "../rustc_index" }
|
||||||
rustc_lexer = { path = "../rustc_lexer" }
|
rustc_lexer = { path = "../rustc_lexer" }
|
||||||
rustc_macros = { path = "../rustc_macros" }
|
rustc_macros = { path = "../rustc_macros" }
|
||||||
rustc_serialize = { path = "../rustc_serialize" }
|
rustc_serialize = { path = "../rustc_serialize" }
|
||||||
rustc_span = { path = "../rustc_span" }
|
rustc_span = { path = "../rustc_span" }
|
||||||
# For Mutability and Movability, which could be uplifted into a common crate.
|
|
||||||
rustc_type_ir = { path = "../rustc_type_ir" }
|
|
||||||
smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }
|
smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }
|
||||||
thin-vec = "0.2.12"
|
thin-vec = "0.2.12"
|
||||||
tracing = "0.1"
|
tracing = "0.1"
|
||||||
|
@ -27,6 +27,7 @@ pub use UnsafeSource::*;
|
|||||||
use crate::ptr::P;
|
use crate::ptr::P;
|
||||||
use crate::token::{self, CommentKind, Delimiter};
|
use crate::token::{self, CommentKind, Delimiter};
|
||||||
use crate::tokenstream::{DelimSpan, LazyAttrTokenStream, TokenStream};
|
use crate::tokenstream::{DelimSpan, LazyAttrTokenStream, TokenStream};
|
||||||
|
pub use rustc_ast_ir::{Movability, Mutability};
|
||||||
use rustc_data_structures::packed::Pu128;
|
use rustc_data_structures::packed::Pu128;
|
||||||
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
|
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
|
||||||
use rustc_data_structures::stack::ensure_sufficient_stack;
|
use rustc_data_structures::stack::ensure_sufficient_stack;
|
||||||
@ -35,7 +36,6 @@ use rustc_macros::HashStable_Generic;
|
|||||||
use rustc_span::source_map::{respan, Spanned};
|
use rustc_span::source_map::{respan, Spanned};
|
||||||
use rustc_span::symbol::{kw, sym, Ident, Symbol};
|
use rustc_span::symbol::{kw, sym, Ident, Symbol};
|
||||||
use rustc_span::{ErrorGuaranteed, Span, DUMMY_SP};
|
use rustc_span::{ErrorGuaranteed, Span, DUMMY_SP};
|
||||||
pub use rustc_type_ir::{Movability, Mutability};
|
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use thin_vec::{thin_vec, ThinVec};
|
use thin_vec::{thin_vec, ThinVec};
|
||||||
|
22
compiler/rustc_ast_ir/Cargo.toml
Normal file
22
compiler/rustc_ast_ir/Cargo.toml
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
[package]
|
||||||
|
name = "rustc_ast_ir"
|
||||||
|
version = "0.0.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
# tidy-alphabetical-start
|
||||||
|
rustc_data_structures = { path = "../rustc_data_structures", optional = true }
|
||||||
|
rustc_macros = { path = "../rustc_macros", optional = true }
|
||||||
|
rustc_serialize = { path = "../rustc_serialize", optional = true }
|
||||||
|
rustc_span = { path = "../rustc_span", optional = true }
|
||||||
|
smallvec = { version = "1.8.1" }
|
||||||
|
# tidy-alphabetical-end
|
||||||
|
|
||||||
|
[features]
|
||||||
|
default = ["nightly"]
|
||||||
|
nightly = [
|
||||||
|
"rustc_serialize",
|
||||||
|
"rustc_data_structures",
|
||||||
|
"rustc_macros",
|
||||||
|
"rustc_span",
|
||||||
|
]
|
68
compiler/rustc_ast_ir/src/lib.rs
Normal file
68
compiler/rustc_ast_ir/src/lib.rs
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
#![cfg_attr(feature = "nightly", feature(rustc_attrs))]
|
||||||
|
#![cfg_attr(feature = "nightly", allow(internal_features))]
|
||||||
|
|
||||||
|
#[cfg(feature = "nightly")]
|
||||||
|
#[macro_use]
|
||||||
|
extern crate rustc_macros;
|
||||||
|
|
||||||
|
/// The movability of a coroutine / closure literal:
|
||||||
|
/// whether a coroutine contains self-references, causing it to be `!Unpin`.
|
||||||
|
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Copy)]
|
||||||
|
#[cfg_attr(feature = "nightly", derive(Encodable, Decodable, HashStable_NoContext))]
|
||||||
|
pub enum Movability {
|
||||||
|
/// May contain self-references, `!Unpin`.
|
||||||
|
Static,
|
||||||
|
/// Must not contain self-references, `Unpin`.
|
||||||
|
Movable,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Copy)]
|
||||||
|
#[cfg_attr(feature = "nightly", derive(Encodable, Decodable, HashStable_NoContext))]
|
||||||
|
pub enum Mutability {
|
||||||
|
// N.B. Order is deliberate, so that Not < Mut
|
||||||
|
Not,
|
||||||
|
Mut,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Mutability {
|
||||||
|
pub fn invert(self) -> Self {
|
||||||
|
match self {
|
||||||
|
Mutability::Mut => Mutability::Not,
|
||||||
|
Mutability::Not => Mutability::Mut,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns `""` (empty string) or `"mut "` depending on the mutability.
|
||||||
|
pub fn prefix_str(self) -> &'static str {
|
||||||
|
match self {
|
||||||
|
Mutability::Mut => "mut ",
|
||||||
|
Mutability::Not => "",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns `"&"` or `"&mut "` depending on the mutability.
|
||||||
|
pub fn ref_prefix_str(self) -> &'static str {
|
||||||
|
match self {
|
||||||
|
Mutability::Not => "&",
|
||||||
|
Mutability::Mut => "&mut ",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns `""` (empty string) or `"mutably "` depending on the mutability.
|
||||||
|
pub fn mutably_str(self) -> &'static str {
|
||||||
|
match self {
|
||||||
|
Mutability::Not => "",
|
||||||
|
Mutability::Mut => "mutably ",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Return `true` if self is mutable
|
||||||
|
pub fn is_mut(self) -> bool {
|
||||||
|
matches!(self, Self::Mut)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Return `true` if self is **not** mutable
|
||||||
|
pub fn is_not(self) -> bool {
|
||||||
|
matches!(self, Self::Not)
|
||||||
|
}
|
||||||
|
}
|
@ -11,11 +11,10 @@ use rustc_middle::mir::interpret::{
|
|||||||
PointerKind, ResourceExhaustionInfo, UndefinedBehaviorInfo, UnsupportedOpInfo,
|
PointerKind, ResourceExhaustionInfo, UndefinedBehaviorInfo, UnsupportedOpInfo,
|
||||||
ValidationErrorInfo,
|
ValidationErrorInfo,
|
||||||
};
|
};
|
||||||
use rustc_middle::ty::{self, Ty};
|
use rustc_middle::ty::{self, Mutability, Ty};
|
||||||
use rustc_span::Span;
|
use rustc_span::Span;
|
||||||
use rustc_target::abi::call::AdjustForForeignAbiError;
|
use rustc_target::abi::call::AdjustForForeignAbiError;
|
||||||
use rustc_target::abi::{Size, WrappingRange};
|
use rustc_target::abi::{Size, WrappingRange};
|
||||||
use rustc_type_ir::Mutability;
|
|
||||||
|
|
||||||
use crate::interpret::InternKind;
|
use crate::interpret::InternKind;
|
||||||
|
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
use rustc_hir::LangItem;
|
use rustc_hir::LangItem;
|
||||||
use rustc_middle::mir;
|
use rustc_middle::mir;
|
||||||
use rustc_middle::query::TyCtxtAt;
|
use rustc_middle::query::TyCtxtAt;
|
||||||
use rustc_middle::ty;
|
|
||||||
use rustc_middle::ty::layout::LayoutOf;
|
use rustc_middle::ty::layout::LayoutOf;
|
||||||
|
use rustc_middle::ty::{self, Mutability};
|
||||||
use rustc_span::symbol::Symbol;
|
use rustc_span::symbol::Symbol;
|
||||||
use rustc_type_ir::Mutability;
|
|
||||||
|
|
||||||
use crate::const_eval::{mk_eval_cx_to_read_const_val, CanAccessMutGlobal, CompileTimeEvalContext};
|
use crate::const_eval::{mk_eval_cx_to_read_const_val, CanAccessMutGlobal, CompileTimeEvalContext};
|
||||||
use crate::interpret::*;
|
use crate::interpret::*;
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir_pretty::qpath_to_string;
|
use rustc_hir_pretty::qpath_to_string;
|
||||||
use rustc_lint_defs::builtin::STATIC_MUT_REFS;
|
use rustc_lint_defs::builtin::STATIC_MUT_REFS;
|
||||||
use rustc_middle::ty::TyCtxt;
|
use rustc_middle::ty::{Mutability, TyCtxt};
|
||||||
use rustc_span::Span;
|
use rustc_span::Span;
|
||||||
use rustc_type_ir::Mutability;
|
|
||||||
|
|
||||||
use crate::errors;
|
use crate::errors;
|
||||||
|
|
||||||
|
@ -17,6 +17,7 @@ rustc-rayon-core = { version = "0.5.0", optional = true }
|
|||||||
rustc_apfloat = "0.2.0"
|
rustc_apfloat = "0.2.0"
|
||||||
rustc_arena = { path = "../rustc_arena" }
|
rustc_arena = { path = "../rustc_arena" }
|
||||||
rustc_ast = { path = "../rustc_ast" }
|
rustc_ast = { path = "../rustc_ast" }
|
||||||
|
rustc_ast_ir = { path = "../rustc_ast_ir" }
|
||||||
rustc_attr = { path = "../rustc_attr" }
|
rustc_attr = { path = "../rustc_attr" }
|
||||||
rustc_data_structures = { path = "../rustc_data_structures" }
|
rustc_data_structures = { path = "../rustc_data_structures" }
|
||||||
rustc_error_messages = { path = "../rustc_error_messages" } # Used for intra-doc links
|
rustc_error_messages = { path = "../rustc_error_messages" } # Used for intra-doc links
|
||||||
|
@ -4,6 +4,7 @@ use crate::error;
|
|||||||
use crate::mir::{ConstAlloc, ConstValue};
|
use crate::mir::{ConstAlloc, ConstValue};
|
||||||
use crate::ty::{layout, tls, Ty, TyCtxt, ValTree};
|
use crate::ty::{layout, tls, Ty, TyCtxt, ValTree};
|
||||||
|
|
||||||
|
use rustc_ast_ir::Mutability;
|
||||||
use rustc_data_structures::sync::Lock;
|
use rustc_data_structures::sync::Lock;
|
||||||
use rustc_errors::{
|
use rustc_errors::{
|
||||||
DiagnosticArgName, DiagnosticArgValue, DiagnosticMessage, ErrorGuaranteed, IntoDiagnosticArg,
|
DiagnosticArgName, DiagnosticArgValue, DiagnosticMessage, ErrorGuaranteed, IntoDiagnosticArg,
|
||||||
@ -12,7 +13,6 @@ use rustc_macros::HashStable;
|
|||||||
use rustc_session::CtfeBacktrace;
|
use rustc_session::CtfeBacktrace;
|
||||||
use rustc_span::{def_id::DefId, Span, DUMMY_SP};
|
use rustc_span::{def_id::DefId, Span, DUMMY_SP};
|
||||||
use rustc_target::abi::{call, Align, Size, VariantIdx, WrappingRange};
|
use rustc_target::abi::{call, Align, Size, VariantIdx, WrappingRange};
|
||||||
use rustc_type_ir::Mutability;
|
|
||||||
|
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use std::{any::Any, backtrace::Backtrace, fmt};
|
use std::{any::Any, backtrace::Backtrace, fmt};
|
||||||
|
@ -32,6 +32,7 @@ pub use generic_args::*;
|
|||||||
pub use generics::*;
|
pub use generics::*;
|
||||||
use rustc_ast as ast;
|
use rustc_ast as ast;
|
||||||
use rustc_ast::node_id::NodeMap;
|
use rustc_ast::node_id::NodeMap;
|
||||||
|
pub use rustc_ast_ir::{Movability, Mutability};
|
||||||
use rustc_attr as attr;
|
use rustc_attr as attr;
|
||||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap, FxIndexSet};
|
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap, FxIndexSet};
|
||||||
use rustc_data_structures::intern::Interned;
|
use rustc_data_structures::intern::Interned;
|
||||||
|
@ -7,6 +7,7 @@ edition = "2021"
|
|||||||
# tidy-alphabetical-start
|
# tidy-alphabetical-start
|
||||||
bitflags = "2.4.1"
|
bitflags = "2.4.1"
|
||||||
derivative = "2.2.0"
|
derivative = "2.2.0"
|
||||||
|
rustc_ast_ir = { path = "../rustc_ast_ir" }
|
||||||
rustc_data_structures = { path = "../rustc_data_structures", optional = true }
|
rustc_data_structures = { path = "../rustc_data_structures", optional = true }
|
||||||
rustc_index = { path = "../rustc_index", default-features = false }
|
rustc_index = { path = "../rustc_index", default-features = false }
|
||||||
rustc_macros = { path = "../rustc_macros", optional = true }
|
rustc_macros = { path = "../rustc_macros", optional = true }
|
||||||
@ -25,4 +26,5 @@ nightly = [
|
|||||||
"rustc_span",
|
"rustc_span",
|
||||||
"rustc_data_structures",
|
"rustc_data_structures",
|
||||||
"rustc_macros",
|
"rustc_macros",
|
||||||
|
"rustc_ast_ir/nightly"
|
||||||
]
|
]
|
||||||
|
@ -51,6 +51,6 @@ TrivialTypeTraversalImpls! {
|
|||||||
crate::DebruijnIndex,
|
crate::DebruijnIndex,
|
||||||
crate::AliasRelationDirection,
|
crate::AliasRelationDirection,
|
||||||
crate::UniverseIndex,
|
crate::UniverseIndex,
|
||||||
crate::Mutability,
|
rustc_ast_ir::Mutability,
|
||||||
crate::Movability,
|
rustc_ast_ir::Movability,
|
||||||
}
|
}
|
||||||
|
@ -11,67 +11,7 @@ use crate::{DebruijnIndex, DebugWithInfcx, InferCtxtLike, WithInfcx};
|
|||||||
|
|
||||||
use self::TyKind::*;
|
use self::TyKind::*;
|
||||||
|
|
||||||
/// The movability of a coroutine / closure literal:
|
use rustc_ast_ir::Mutability;
|
||||||
/// whether a coroutine contains self-references, causing it to be `!Unpin`.
|
|
||||||
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Copy)]
|
|
||||||
#[cfg_attr(feature = "nightly", derive(Encodable, Decodable, HashStable_NoContext))]
|
|
||||||
pub enum Movability {
|
|
||||||
/// May contain self-references, `!Unpin`.
|
|
||||||
Static,
|
|
||||||
/// Must not contain self-references, `Unpin`.
|
|
||||||
Movable,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Copy)]
|
|
||||||
#[cfg_attr(feature = "nightly", derive(Encodable, Decodable, HashStable_NoContext))]
|
|
||||||
pub enum Mutability {
|
|
||||||
// N.B. Order is deliberate, so that Not < Mut
|
|
||||||
Not,
|
|
||||||
Mut,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Mutability {
|
|
||||||
pub fn invert(self) -> Self {
|
|
||||||
match self {
|
|
||||||
Mutability::Mut => Mutability::Not,
|
|
||||||
Mutability::Not => Mutability::Mut,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns `""` (empty string) or `"mut "` depending on the mutability.
|
|
||||||
pub fn prefix_str(self) -> &'static str {
|
|
||||||
match self {
|
|
||||||
Mutability::Mut => "mut ",
|
|
||||||
Mutability::Not => "",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns `"&"` or `"&mut "` depending on the mutability.
|
|
||||||
pub fn ref_prefix_str(self) -> &'static str {
|
|
||||||
match self {
|
|
||||||
Mutability::Not => "&",
|
|
||||||
Mutability::Mut => "&mut ",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns `""` (empty string) or `"mutably "` depending on the mutability.
|
|
||||||
pub fn mutably_str(self) -> &'static str {
|
|
||||||
match self {
|
|
||||||
Mutability::Not => "",
|
|
||||||
Mutability::Mut => "mutably ",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Return `true` if self is mutable
|
|
||||||
pub fn is_mut(self) -> bool {
|
|
||||||
matches!(self, Self::Mut)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Return `true` if self is **not** mutable
|
|
||||||
pub fn is_not(self) -> bool {
|
|
||||||
matches!(self, Self::Not)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Specifies how a trait object is represented.
|
/// Specifies how a trait object is represented.
|
||||||
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
|
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
|
||||||
|
Loading…
Reference in New Issue
Block a user