Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 14 pull requests #90119

Merged
merged 44 commits into from
Oct 21, 2021
Merged
Changes from 1 commit
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
734bfde
Disallow octal zeros in IPv4 addresses
syvb Jul 8, 2021
69de693
Clarify docs on what IPv4 octal addresses are
syvb Jul 9, 2021
b9b97bb
Reject too-long IPs quicker
syvb Jul 9, 2021
a331e5f
Simplify leading zero checks
syvb Jul 11, 2021
ace518d
Add example with a bunch of leading zeos
syvb Jul 11, 2021
d65ab29
Remove unnecessary condition in Barrier::wait()
twetzel59 Jul 24, 2021
403d269
Specify maximum IP address length
syvb Aug 10, 2021
85d6029
`AbstractConst::root`: Always run `subst` when `Node` is `Leaf`
eopb Sep 4, 2021
22c2738
Minor cleanup: make imports more consistent
eopb Sep 4, 2021
6e40618
Remove left over comment
eopb Sep 4, 2021
fc5633f
Make fields on `AbstractConst` private
eopb Sep 4, 2021
b7d9998
Add line that was unintentionally removed
eopb Sep 4, 2021
4a37b9c
Avoid overflow in `VecDeque::with_capacity_in()`.
hkratz Oct 18, 2021
93f80bf
Remove comment saying that we don't build debug rustc in CI, since we do
tgnottingham Oct 18, 2021
aefbd40
Add test for debug logging during incremental compilation
tgnottingham Oct 18, 2021
f2a234e
config: add the option to enable LLVM tests
durin42 Oct 18, 2021
e8b5af1
Upgrade browser-ui-test version to 0.4.5 (it allows to have multi-lin…
GuillaumeGomez Oct 19, 2021
05eb6f3
Cleanup dead code in hir::map::blocks.
cjgillot Oct 19, 2021
99b8c01
Address lcnr review
eopb Oct 19, 2021
6e98688
Replace FnLikeNode by FnKind.
cjgillot Oct 19, 2021
aad48f7
replace format!("") with String::new()
klensy Oct 9, 2021
f3fb821
use array explicitly instead of vec for const content (even if optimi…
klensy Oct 9, 2021
2fc7806
Make `From` impls of NonZero integer const.
lilasta Oct 20, 2021
be30e60
remove duplicate subst
eopb Oct 20, 2021
457f578
Add test for line-number setting
GuillaumeGomez Oct 19, 2021
0aa68a8
Prevent invalid values from existing in Vec::swap_remove
SkiFire13 Oct 20, 2021
50dc319
Add test for duplicated sidebar entries for reexported macro
GuillaumeGomez Oct 20, 2021
69ca324
Add test to ensure that the missing_doc_code_examples is not triggere…
GuillaumeGomez Oct 20, 2021
86b3dd9
stabilize CString::from_vec_with_nul[_unchecked]
CleanCut Sep 26, 2021
39af41e
fix 'since' version number
CleanCut Oct 20, 2021
09de34c
Rollup merge of #86984 - Smittyvb:ipv4-octal-zero, r=m-ou-se
JohnTitor Oct 21, 2021
fb9232b
Rollup merge of #87440 - twetzel59:fix-barrier-no-op, r=yaahc
JohnTitor Oct 21, 2021
6f0acbc
Rollup merge of #88644 - eopb:abstractconst_leaf_subst, r=lcnr
JohnTitor Oct 21, 2021
20687bb
Rollup merge of #89292 - CleanCut:stabilize-cstring_from_vec_with_nul…
JohnTitor Oct 21, 2021
d29e98f
Rollup merge of #90010 - rusticstuff:vecdeque_with_capacity_in_overfl…
JohnTitor Oct 21, 2021
a980587
Rollup merge of #90029 - tgnottingham:incr-debug-logging-test, r=Mark…
JohnTitor Oct 21, 2021
632f06d
Rollup merge of #90031 - durin42:allow-llvm-tests, r=Mark-Simulacrum
JohnTitor Oct 21, 2021
47a1f67
Rollup merge of #90048 - GuillaumeGomez:line-number-setting, r=jsha
JohnTitor Oct 21, 2021
afdd0c3
Rollup merge of #90071 - cjgillot:no-blocks, r=oli-obk
JohnTitor Oct 21, 2021
371fd4f
Rollup merge of #90074 - klensy:upvar-all, r=wesleywiser
JohnTitor Oct 21, 2021
e4cfaa1
Rollup merge of #90077 - woppopo:const_nonzero_from, r=oli-obk
JohnTitor Oct 21, 2021
759a8ae
Rollup merge of #90097 - GuillaumeGomez:duplicated-sidebar-entry-reex…
JohnTitor Oct 21, 2021
68a5680
Rollup merge of #90098 - GuillaumeGomez:add-test-foreign-impl-missing…
JohnTitor Oct 21, 2021
3680ecd
Rollup merge of #90099 - SkiFire13:fix-vec-swap-remove, r=dtolnay
JohnTitor Oct 21, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Cleanup dead code in hir::map::blocks.
  • Loading branch information
cjgillot committed Oct 19, 2021
commit 05eb6f36f1e17aa00ef286c2dacc9d890fdc899c
186 changes: 14 additions & 172 deletions compiler/rustc_middle/src/hir/map/blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,9 @@
//! nested within a uniquely determined `FnLike`), and users can ask
//! for the `Code` associated with a particular NodeId.

use crate::hir::map::Map;
use rustc_hir as hir;
use rustc_hir::intravisit::FnKind;
use rustc_hir::{Expr, FnDecl, Node};
use rustc_span::symbol::Ident;
use rustc_span::Span;
use rustc_hir::Node;

/// An FnLikeNode is a Node that is like a fn, in that it has a decl
/// and a body (as well as a NodeId, a span, etc).
Expand All @@ -33,139 +30,21 @@ pub struct FnLikeNode<'a> {
node: Node<'a>,
}

/// MaybeFnLike wraps a method that indicates if an object
/// corresponds to some FnLikeNode.
trait MaybeFnLike {
fn is_fn_like(&self) -> bool;
}

impl MaybeFnLike for hir::Item<'_> {
fn is_fn_like(&self) -> bool {
matches!(self.kind, hir::ItemKind::Fn(..))
}
}

impl MaybeFnLike for hir::ImplItem<'_> {
fn is_fn_like(&self) -> bool {
matches!(self.kind, hir::ImplItemKind::Fn(..))
}
}

impl MaybeFnLike for hir::TraitItem<'_> {
fn is_fn_like(&self) -> bool {
matches!(self.kind, hir::TraitItemKind::Fn(_, hir::TraitFn::Provided(_)))
}
}

impl MaybeFnLike for hir::Expr<'_> {
fn is_fn_like(&self) -> bool {
matches!(self.kind, hir::ExprKind::Closure(..))
}
}

/// Carries either an FnLikeNode or an Expr, as these are the two
/// constructs that correspond to "code" (as in, something from which
/// we can construct a control-flow graph).
#[derive(Copy, Clone)]
pub enum Code<'a> {
FnLike(FnLikeNode<'a>),
Expr(&'a Expr<'a>),
}

impl<'a> Code<'a> {
pub fn id(&self) -> hir::HirId {
match *self {
Code::FnLike(node) => node.id(),
Code::Expr(block) => block.hir_id,
}
}

/// Attempts to construct a Code from presumed FnLike or Expr node input.
pub fn from_node(map: &Map<'a>, id: hir::HirId) -> Option<Code<'a>> {
match map.get(id) {
Node::Block(_) => {
// Use the parent, hopefully an expression node.
Code::from_node(map, map.get_parent_node(id))
}
Node::Expr(expr) => Some(Code::Expr(expr)),
node => FnLikeNode::from_node(node).map(Code::FnLike),
}
}
}

/// These are all the components one can extract from a fn item for
/// use when implementing FnLikeNode operations.
struct ItemFnParts<'a> {
ident: Ident,
decl: &'a hir::FnDecl<'a>,
header: hir::FnHeader,
vis: &'a hir::Visibility<'a>,
generics: &'a hir::Generics<'a>,
body: hir::BodyId,
id: hir::HirId,
span: Span,
}

/// These are all the components one can extract from a closure expr
/// for use when implementing FnLikeNode operations.
struct ClosureParts<'a> {
decl: &'a FnDecl<'a>,
body: hir::BodyId,
id: hir::HirId,
span: Span,
}

impl<'a> ClosureParts<'a> {
fn new(d: &'a FnDecl<'a>, b: hir::BodyId, id: hir::HirId, s: Span) -> Self {
ClosureParts { decl: d, body: b, id, span: s }
}
}

impl<'a> FnLikeNode<'a> {
/// Attempts to construct a FnLikeNode from presumed FnLike node input.
pub fn from_node(node: Node<'_>) -> Option<FnLikeNode<'_>> {
let fn_like = match node {
Node::Item(item) => item.is_fn_like(),
Node::TraitItem(tm) => tm.is_fn_like(),
Node::ImplItem(it) => it.is_fn_like(),
Node::Expr(e) => e.is_fn_like(),
Node::Item(item) => matches!(item.kind, hir::ItemKind::Fn(..)),
Node::TraitItem(tm) => {
matches!(tm.kind, hir::TraitItemKind::Fn(_, hir::TraitFn::Provided(_)))
}
Node::ImplItem(it) => matches!(it.kind, hir::ImplItemKind::Fn(..)),
Node::Expr(e) => matches!(e.kind, hir::ExprKind::Closure(..)),
_ => false,
};
fn_like.then_some(FnLikeNode { node })
}

pub fn body(self) -> hir::BodyId {
self.handle(
|i: ItemFnParts<'a>| i.body,
|_, _, _: &'a hir::FnSig<'a>, _, body: hir::BodyId, _| body,
|c: ClosureParts<'a>| c.body,
)
}

pub fn decl(self) -> &'a FnDecl<'a> {
self.handle(
|i: ItemFnParts<'a>| &*i.decl,
|_, _, sig: &'a hir::FnSig<'a>, _, _, _| &sig.decl,
|c: ClosureParts<'a>| c.decl,
)
}

pub fn span(self) -> Span {
self.handle(
|i: ItemFnParts<'_>| i.span,
|_, _, _: &'a hir::FnSig<'a>, _, _, span| span,
|c: ClosureParts<'_>| c.span,
)
}

pub fn id(self) -> hir::HirId {
self.handle(
|i: ItemFnParts<'_>| i.id,
|id, _, _: &'a hir::FnSig<'a>, _, _, _| id,
|c: ClosureParts<'_>| c.id,
)
}

pub fn constness(self) -> hir::Constness {
self.kind().header().map_or(hir::Constness::NotConst, |header| header.constness)
}
Expand All @@ -174,63 +53,26 @@ impl<'a> FnLikeNode<'a> {
self.kind().header().map_or(hir::IsAsync::NotAsync, |header| header.asyncness)
}

pub fn unsafety(self) -> hir::Unsafety {
self.kind().header().map_or(hir::Unsafety::Normal, |header| header.unsafety)
}

pub fn kind(self) -> FnKind<'a> {
let item = |p: ItemFnParts<'a>| -> FnKind<'a> {
FnKind::ItemFn(p.ident, p.generics, p.header, p.vis)
};
let closure = |_: ClosureParts<'a>| FnKind::Closure;
let method =
|_, ident: Ident, sig: &'a hir::FnSig<'a>, vis, _, _| FnKind::Method(ident, sig, vis);
self.handle(item, method, closure)
}

fn handle<A, I, M, C>(self, item_fn: I, method: M, closure: C) -> A
where
I: FnOnce(ItemFnParts<'a>) -> A,
M: FnOnce(
hir::HirId,
Ident,
&'a hir::FnSig<'a>,
Option<&'a hir::Visibility<'a>>,
hir::BodyId,
Span,
) -> A,
C: FnOnce(ClosureParts<'a>) -> A,
{
match self.node {
Node::Item(i) => match i.kind {
hir::ItemKind::Fn(ref sig, ref generics, block) => item_fn(ItemFnParts {
id: i.hir_id(),
ident: i.ident,
decl: &sig.decl,
body: block,
vis: &i.vis,
span: i.span,
header: sig.header,
generics,
}),
hir::ItemKind::Fn(ref sig, ref generics, _) => {
FnKind::ItemFn(i.ident, generics, sig.header, &i.vis)
}
_ => bug!("item FnLikeNode that is not fn-like"),
},
Node::TraitItem(ti) => match ti.kind {
hir::TraitItemKind::Fn(ref sig, hir::TraitFn::Provided(body)) => {
method(ti.hir_id(), ti.ident, sig, None, body, ti.span)
hir::TraitItemKind::Fn(ref sig, hir::TraitFn::Provided(_)) => {
FnKind::Method(ti.ident, sig, None)
}
_ => bug!("trait method FnLikeNode that is not fn-like"),
},
Node::ImplItem(ii) => match ii.kind {
hir::ImplItemKind::Fn(ref sig, body) => {
method(ii.hir_id(), ii.ident, sig, Some(&ii.vis), body, ii.span)
}
hir::ImplItemKind::Fn(ref sig, _) => FnKind::Method(ii.ident, sig, Some(&ii.vis)),
_ => bug!("impl method FnLikeNode that is not fn-like"),
},
Node::Expr(e) => match e.kind {
hir::ExprKind::Closure(_, ref decl, block, _fn_decl_span, _gen) => {
closure(ClosureParts::new(&decl, block, e.hir_id, e.span))
}
hir::ExprKind::Closure(..) => FnKind::Closure,
_ => bug!("expr FnLikeNode that is not fn-like"),
},
_ => bug!("other FnLikeNode that is not fn-like"),
Expand Down