change syntax of newtype_index to look like a struct decl

This commit is contained in:
Niko Matsakis 2018-07-25 13:41:32 +03:00
parent 5a3292f163
commit 1242639b88
13 changed files with 108 additions and 37 deletions

View File

@ -39,7 +39,9 @@ pub struct DepGraph {
fingerprints: Lrc<Lock<IndexVec<DepNodeIndex, Fingerprint>>>
}
newtype_index!(DepNodeIndex);
newtype_index! {
pub struct DepNodeIndex { .. }
}
impl DepNodeIndex {
const INVALID: DepNodeIndex = DepNodeIndex(::std::u32::MAX);

View File

@ -14,7 +14,9 @@ use dep_graph::DepNode;
use ich::Fingerprint;
use rustc_data_structures::indexed_vec::{IndexVec, Idx};
newtype_index!(SerializedDepNodeIndex);
newtype_index! {
pub struct SerializedDepNodeIndex { .. }
}
/// Data for use when recompiling the **current crate**.
#[derive(Debug, RustcEncodable, RustcDecodable)]

View File

@ -15,8 +15,8 @@ use serialize;
use std::fmt;
use std::u32;
newtype_index!(CrateNum
{
newtype_index! {
pub struct CrateNum {
ENCODABLE = custom
DEBUG_FORMAT = "crate{}",
@ -35,7 +35,8 @@ newtype_index!(CrateNum
/// A special CrateNum that we use for the tcx.rcache when decoding from
/// the incr. comp. cache.
const RESERVED_FOR_INCR_COMP_CACHE = u32::MAX - 2,
});
}
}
impl CrateNum {
pub fn new(x: usize) -> CrateNum {

View File

@ -159,11 +159,12 @@ pub struct BlockRemainder {
pub first_statement_index: FirstStatementIndex,
}
newtype_index!(FirstStatementIndex
{
newtype_index! {
pub struct FirstStatementIndex {
pub idx
MAX = SCOPE_DATA_REMAINDER_MAX
});
}
}
impl From<ScopeData> for Scope {
#[inline]

View File

@ -523,11 +523,12 @@ impl BorrowKind {
///////////////////////////////////////////////////////////////////////////
// Variables and temps
newtype_index!(Local
{
newtype_index! {
pub struct Local {
DEBUG_FORMAT = "_{}",
const RETURN_PLACE = 0,
});
}
}
/// Classifies locals into categories. See `Mir::local_kind`.
#[derive(PartialEq, Eq, Debug)]
@ -852,7 +853,11 @@ pub struct UpvarDecl {
///////////////////////////////////////////////////////////////////////////
// BasicBlock
newtype_index!(BasicBlock { DEBUG_FORMAT = "bb{}" });
newtype_index! {
pub struct BasicBlock {
DEBUG_FORMAT = "bb{}"
}
}
impl BasicBlock {
pub fn start_location(self) -> Location {
@ -1822,7 +1827,11 @@ pub type PlaceProjection<'tcx> = Projection<'tcx, Place<'tcx>, Local, Ty<'tcx>>;
/// and the index is a local.
pub type PlaceElem<'tcx> = ProjectionElem<'tcx, Local, Ty<'tcx>>;
newtype_index!(Field { DEBUG_FORMAT = "field[{}]" });
newtype_index! {
pub struct Field {
DEBUG_FORMAT = "field[{}]"
}
}
impl<'tcx> Place<'tcx> {
pub fn field(self, f: Field, ty: Ty<'tcx>) -> Place<'tcx> {
@ -1895,11 +1904,12 @@ impl<'tcx> Debug for Place<'tcx> {
///////////////////////////////////////////////////////////////////////////
// Scopes
newtype_index!(SourceScope
{
newtype_index! {
pub struct SourceScope {
DEBUG_FORMAT = "scope[{}]",
const OUTERMOST_SOURCE_SCOPE = 0,
});
}
}
#[derive(Clone, Debug, RustcEncodable, RustcDecodable)]
pub struct SourceScopeData {
@ -2271,7 +2281,11 @@ pub struct Constant<'tcx> {
pub literal: &'tcx ty::Const<'tcx>,
}
newtype_index!(Promoted { DEBUG_FORMAT = "promoted[{}]" });
newtype_index! {
pub struct Promoted {
DEBUG_FORMAT = "promoted[{}]"
}
}
impl<'tcx> Debug for Constant<'tcx> {
fn fmt(&self, fmt: &mut Formatter) -> fmt::Result {

View File

@ -1034,11 +1034,12 @@ impl<'a, 'gcx, 'tcx> ParamTy {
/// is the outer fn.
///
/// [dbi]: http://en.wikipedia.org/wiki/De_Bruijn_index
newtype_index!(DebruijnIndex
{
newtype_index! {
pub struct DebruijnIndex {
DEBUG_FORMAT = "DebruijnIndex({})",
const INNERMOST = 0,
});
}
}
pub type Region<'tcx> = &'tcx RegionKind;
@ -1176,11 +1177,12 @@ pub struct FloatVid {
pub index: u32,
}
newtype_index!(RegionVid
{
newtype_index! {
pub struct RegionVid {
pub idx
DEBUG_FORMAT = custom,
});
}
}
impl Atom for RegionVid {
fn index(self) -> usize {
@ -1217,7 +1219,9 @@ pub enum InferTy {
CanonicalTy(CanonicalVar),
}
newtype_index!(CanonicalVar);
newtype_index! {
pub struct CanonicalVar { .. }
}
/// A `ProjectionPredicate` for an `ExistentialTraitRef`.
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, RustcEncodable, RustcDecodable)]

View File

@ -53,20 +53,22 @@ macro_rules! newtype_index {
// ---- public rules ----
// Use default constants
($name:ident) => (
($v:vis struct $name:ident { .. }) => (
newtype_index!(
// Leave out derives marker so we can use its absence to ensure it comes first
@type [$name]
@max [::std::u32::MAX]
@vis [$v]
@debug_format ["{}"]);
);
// Define any constants
($name:ident { $($tokens:tt)+ }) => (
($v:vis struct $name:ident { $($tokens:tt)+ }) => (
newtype_index!(
// Leave out derives marker so we can use its absence to ensure it comes first
@type [$name]
@max [::std::u32::MAX]
@vis [$v]
@debug_format ["{}"]
$($tokens)+);
);
@ -78,9 +80,10 @@ macro_rules! newtype_index {
@pub [$($pub:tt)*]
@type [$type:ident]
@max [$max:expr]
@vis [$v:vis]
@debug_format [$debug_format:tt]) => (
#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, $($derives),*)]
pub struct $type($($pub)* u32);
$v struct $type($($pub)* u32);
impl Idx for $type {
#[inline]
@ -170,6 +173,7 @@ macro_rules! newtype_index {
// Handle the case where someone wants to make the internal field public
(@type [$type:ident]
@max [$max:expr]
@vis [$v:vis]
@debug_format [$debug_format:tt]
pub idx
$($tokens:tt)*) => (
@ -177,6 +181,7 @@ macro_rules! newtype_index {
@pub [pub]
@type [$type]
@max [$max]
@vis [$v]
@debug_format [$debug_format]
$($tokens)*);
);
@ -184,12 +189,14 @@ macro_rules! newtype_index {
// The default case is that the internal field is private
(@type [$type:ident]
@max [$max:expr]
@vis [$v:vis]
@debug_format [$debug_format:tt]
$($tokens:tt)*) => (
newtype_index!(
@pub []
@type [$type]
@max [$max]
@vis [$v]
@debug_format [$debug_format]
$($tokens)*);
);
@ -198,6 +205,7 @@ macro_rules! newtype_index {
(@pub [$($pub:tt)*]
@type [$type:ident]
@max [$max:expr]
@vis [$v:vis]
@debug_format [$debug_format:tt]
derive [$($derives:ident),*]
$($tokens:tt)*) => (
@ -205,6 +213,7 @@ macro_rules! newtype_index {
@pub [$($pub)*]
@type [$type]
@max [$max]
@vis [$v]
@debug_format [$debug_format]
derive [$($derives,)*]
$($tokens)*);
@ -215,6 +224,7 @@ macro_rules! newtype_index {
(@pub [$($pub:tt)*]
@type [$type:ident]
@max [$max:expr]
@vis [$v:vis]
@debug_format [$debug_format:tt]
derive [$($derives:ident,)+]
ENCODABLE = custom
@ -224,6 +234,7 @@ macro_rules! newtype_index {
@pub [$($pub)*]
@type [$type]
@max [$max]
@vis [$v]
@debug_format [$debug_format]
$($tokens)*);
);
@ -233,6 +244,7 @@ macro_rules! newtype_index {
(@pub [$($pub:tt)*]
@type [$type:ident]
@max [$max:expr]
@vis [$v:vis]
@debug_format [$debug_format:tt]
derive [$($derives:ident,)+]
$($tokens:tt)*) => (
@ -241,6 +253,7 @@ macro_rules! newtype_index {
@pub [$($pub)*]
@type [$type]
@max [$max]
@vis [$v]
@debug_format [$debug_format]
$($tokens)*);
);
@ -250,6 +263,7 @@ macro_rules! newtype_index {
(@pub [$($pub:tt)*]
@type [$type:ident]
@max [$max:expr]
@vis [$v:vis]
@debug_format [$debug_format:tt]
ENCODABLE = custom
$($tokens:tt)*) => (
@ -258,6 +272,7 @@ macro_rules! newtype_index {
@pub [$($pub)*]
@type [$type]
@max [$max]
@vis [$v]
@debug_format [$debug_format]
$($tokens)*);
);
@ -266,6 +281,7 @@ macro_rules! newtype_index {
(@pub [$($pub:tt)*]
@type [$type:ident]
@max [$max:expr]
@vis [$v:vis]
@debug_format [$debug_format:tt]
$($tokens:tt)*) => (
newtype_index!(
@ -273,6 +289,7 @@ macro_rules! newtype_index {
@pub [$($pub)*]
@type [$type]
@max [$max]
@vis [$v]
@debug_format [$debug_format]
$($tokens)*);
);
@ -282,6 +299,7 @@ macro_rules! newtype_index {
@pub [$($pub:tt)*]
@type [$type:ident]
@max [$max:expr]
@vis [$v:vis]
@debug_format [$debug_format:tt]
$name:ident = $constant:expr) => (
newtype_index!(
@ -289,6 +307,7 @@ macro_rules! newtype_index {
@pub [$($pub)*]
@type [$type]
@max [$max]
@vis [$v]
@debug_format [$debug_format]
$name = $constant,);
);
@ -298,6 +317,7 @@ macro_rules! newtype_index {
@pub [$($pub:tt)*]
@type [$type:ident]
@max [$_max:expr]
@vis [$v:vis]
@debug_format [$debug_format:tt]
$(#[doc = $doc:expr])*
const $name:ident = $constant:expr) => (
@ -306,6 +326,7 @@ macro_rules! newtype_index {
@pub [$($pub)*]
@type [$type]
@max [$max]
@vis [$v]
@debug_format [$debug_format]
$(#[doc = $doc])* const $name = $constant,);
);
@ -315,6 +336,7 @@ macro_rules! newtype_index {
@pub [$($pub:tt)*]
@type [$type:ident]
@max [$_max:expr]
@vis [$v:vis]
@debug_format [$debug_format:tt]
MAX = $max:expr,
$($tokens:tt)*) => (
@ -323,6 +345,7 @@ macro_rules! newtype_index {
@pub [$($pub)*]
@type [$type]
@max [$max]
@vis [$v]
@debug_format [$debug_format]
$($tokens)*);
);
@ -332,6 +355,7 @@ macro_rules! newtype_index {
@pub [$($pub:tt)*]
@type [$type:ident]
@max [$max:expr]
@vis [$v:vis]
@debug_format [$_debug_format:tt]
DEBUG_FORMAT = $debug_format:tt,
$($tokens:tt)*) => (
@ -340,6 +364,7 @@ macro_rules! newtype_index {
@pub [$($pub)*]
@type [$type]
@max [$max]
@vis [$v]
@debug_format [$debug_format]
$($tokens)*);
);
@ -349,6 +374,7 @@ macro_rules! newtype_index {
@pub [$($pub:tt)*]
@type [$type:ident]
@max [$max:expr]
@vis [$v:vis]
@debug_format [$debug_format:tt]
$(#[doc = $doc:expr])*
const $name:ident = $constant:expr,
@ -360,6 +386,7 @@ macro_rules! newtype_index {
@pub [$($pub)*]
@type [$type]
@max [$max]
@vis [$v]
@debug_format [$debug_format]
$($tokens)*);
);

View File

@ -27,7 +27,11 @@ crate struct LocationTable {
statements_before_block: IndexVec<BasicBlock, usize>,
}
newtype_index!(LocationIndex { DEBUG_FORMAT = "LocationIndex({})" });
newtype_index! {
pub struct LocationIndex {
DEBUG_FORMAT = "LocationIndex({})"
}
}
#[derive(Copy, Clone, Debug)]
crate enum RichLocation {

View File

@ -98,6 +98,14 @@ impl fmt::Debug for OutlivesConstraint {
}
}
newtype_index!(ConstraintIndex { DEBUG_FORMAT = "ConstraintIndex({})" });
newtype_index! {
pub struct ConstraintIndex {
DEBUG_FORMAT = "ConstraintIndex({})"
}
}
newtype_index!(ConstraintSccIndex { DEBUG_FORMAT = "ConstraintSccIndex({})" });
newtype_index! {
pub struct ConstraintSccIndex {
DEBUG_FORMAT = "ConstraintSccIndex({})"
}
}

View File

@ -123,13 +123,17 @@ impl RegionValueElements {
/// A single integer representing a `Location` in the MIR control-flow
/// graph. Constructed efficiently from `RegionValueElements`.
newtype_index!(PointIndex { DEBUG_FORMAT = "PointIndex({})" });
newtype_index! {
pub struct PointIndex { DEBUG_FORMAT = "PointIndex({})" }
}
/// A single integer representing a (non-zero) `UniverseIndex`.
/// Computed just by subtracting one from `UniverseIndex`; this is
/// because the `0` value for `UniverseIndex` represents the root
/// universe, and we don't need/want a bit for that one.
newtype_index!(PlaceholderIndex { DEBUG_FORMAT = "PlaceholderIndex({})" });
newtype_index! {
pub struct PlaceholderIndex { DEBUG_FORMAT = "PlaceholderIndex({})" }
}
/// An individual element in a region value -- the value of a
/// particular region variable consists of a set of these elements.

View File

@ -97,6 +97,6 @@ impl NllLivenessMap {
/// compute liveness information. For many locals, we are able to
/// skip liveness information: for example, those variables whose
/// types contain no regions.
newtype_index!(
LiveVar
);
newtype_index! {
pub struct LiveVar { .. }
}

View File

@ -48,7 +48,9 @@ struct Appearance {
next: Option<AppearanceIndex>,
}
newtype_index!(AppearanceIndex);
newtype_index! {
pub struct AppearanceIndex { .. }
}
impl vll::LinkElem for Appearance {
type LinkIndex = AppearanceIndex;

View File

@ -402,7 +402,9 @@ struct CFG<'tcx> {
basic_blocks: IndexVec<BasicBlock, BasicBlockData<'tcx>>,
}
newtype_index!(ScopeId);
newtype_index! {
pub struct ScopeId { .. }
}
///////////////////////////////////////////////////////////////////////////
/// The `BlockAnd` "monad" packages up the new basic block along with a