Skip to content

Commit

Permalink
Ensure HAS_FREE_LOCAL_NAMES is set for ReFree
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewjasper committed Mar 12, 2020
1 parent c20d7ee commit f4eb6ed
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 26 deletions.
27 changes: 15 additions & 12 deletions src/librustc/ty/mod.rs
Expand Up @@ -554,24 +554,26 @@ bitflags! {
/// Does this have [ConstKind::Placeholder]?
const HAS_CT_PLACEHOLDER = 1 << 8;

/// `true` if there are "names" of regions and so forth
/// that are local to a particular fn/inferctxt
const HAS_FREE_LOCAL_REGIONS = 1 << 9;

/// `true` if there are "names" of types and regions and so forth
/// that are local to a particular fn
const HAS_FREE_LOCAL_NAMES = TypeFlags::HAS_TY_PARAM.bits
| TypeFlags::HAS_RE_PARAM.bits
| TypeFlags::HAS_CT_PARAM.bits
| TypeFlags::HAS_TY_INFER.bits
| TypeFlags::HAS_RE_INFER.bits
| TypeFlags::HAS_CT_INFER.bits
| TypeFlags::HAS_TY_PLACEHOLDER.bits
| TypeFlags::HAS_RE_PLACEHOLDER.bits
| TypeFlags::HAS_CT_PLACEHOLDER.bits;
| TypeFlags::HAS_CT_PLACEHOLDER.bits
| TypeFlags::HAS_FREE_LOCAL_REGIONS.bits;

/// Does this have [Projection] or [UnnormalizedProjection]?
const HAS_TY_PROJECTION = 1 << 9;
const HAS_TY_PROJECTION = 1 << 10;
/// Does this have [Opaque]?
const HAS_TY_OPAQUE = 1 << 10;
const HAS_TY_OPAQUE = 1 << 11;
/// Does this have [ConstKind::Unevaluated]?
const HAS_CT_PROJECTION = 1 << 11;
const HAS_CT_PROJECTION = 1 << 12;

/// Could this type be normalized further?
const HAS_PROJECTION = TypeFlags::HAS_TY_PROJECTION.bits
Expand All @@ -580,21 +582,21 @@ bitflags! {

/// Present if the type belongs in a local type context.
/// Set for placeholders and inference variables that are not "Fresh".
const KEEP_IN_LOCAL_TCX = 1 << 12;
const KEEP_IN_LOCAL_TCX = 1 << 13;

/// Is an error type reachable?
const HAS_TY_ERR = 1 << 13;
const HAS_TY_ERR = 1 << 14;

/// Does this have any region that "appears free" in the type?
/// Basically anything but [ReLateBound] and [ReErased].
const HAS_FREE_REGIONS = 1 << 14;
const HAS_FREE_REGIONS = 1 << 15;

/// Does this have any [ReLateBound] regions? Used to check
/// if a global bound is safe to evaluate.
const HAS_RE_LATE_BOUND = 1 << 15;
const HAS_RE_LATE_BOUND = 1 << 16;

/// Does this have any [ReErased] regions?
const HAS_RE_ERASED = 1 << 16;
const HAS_RE_ERASED = 1 << 17;

/// Flags representing the nominal content of a type,
/// computed by FlagsComputation. If you add a new nominal
Expand All @@ -608,6 +610,7 @@ bitflags! {
| TypeFlags::HAS_TY_PLACEHOLDER.bits
| TypeFlags::HAS_RE_PLACEHOLDER.bits
| TypeFlags::HAS_CT_PLACEHOLDER.bits
| TypeFlags::HAS_FREE_LOCAL_REGIONS.bits
| TypeFlags::HAS_TY_PROJECTION.bits
| TypeFlags::HAS_TY_OPAQUE.bits
| TypeFlags::HAS_CT_PROJECTION.bits
Expand Down
28 changes: 14 additions & 14 deletions src/librustc/ty/sty.rs
Expand Up @@ -1743,42 +1743,42 @@ impl RegionKind {
}
}

pub fn keep_in_local_tcx(&self) -> bool {
if let ty::ReVar(..) = self { true } else { false }
}

pub fn type_flags(&self) -> TypeFlags {
let mut flags = TypeFlags::empty();

if self.keep_in_local_tcx() {
flags = flags | TypeFlags::KEEP_IN_LOCAL_TCX;
}

match *self {
ty::ReVar(..) => {
flags = flags | TypeFlags::HAS_FREE_REGIONS;
flags = flags | TypeFlags::HAS_FREE_LOCAL_REGIONS;
flags = flags | TypeFlags::HAS_RE_INFER;
flags = flags | TypeFlags::KEEP_IN_LOCAL_TCX;
}
ty::RePlaceholder(..) => {
flags = flags | TypeFlags::HAS_FREE_REGIONS;
flags = flags | TypeFlags::HAS_FREE_LOCAL_REGIONS;
flags = flags | TypeFlags::HAS_RE_PLACEHOLDER;
}
ty::ReLateBound(..) => {
flags = flags | TypeFlags::HAS_RE_LATE_BOUND;
}
ty::ReEarlyBound(..) => {
flags = flags | TypeFlags::HAS_FREE_REGIONS;
flags = flags | TypeFlags::HAS_FREE_LOCAL_REGIONS;
flags = flags | TypeFlags::HAS_RE_PARAM;
}
ty::ReEmpty(_) | ty::ReStatic | ty::ReFree { .. } | ty::ReScope { .. } => {
ty::ReFree { .. } | ty::ReScope { .. } => {
flags = flags | TypeFlags::HAS_FREE_REGIONS;
flags = flags | TypeFlags::HAS_FREE_LOCAL_REGIONS;
}
ty::ReErased => {
flags = flags | TypeFlags::HAS_RE_ERASED;
ty::ReEmpty(_) | ty::ReStatic => {
flags = flags | TypeFlags::HAS_FREE_REGIONS;
}
ty::ReClosureBound(..) => {
flags = flags | TypeFlags::HAS_FREE_REGIONS;
}
ty::ReLateBound(..) => {
flags = flags | TypeFlags::HAS_RE_LATE_BOUND;
}
ty::ReErased => {
flags = flags | TypeFlags::HAS_RE_ERASED;
}
}

debug!("type_flags({:?}) = {:?}", self, flags);
Expand Down

0 comments on commit f4eb6ed

Please sign in to comment.