-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #27851 - nikomatsakis:cleanup-ty-decoder, r=eddyb
Just a little code cleanup I was doing as part of another refactoring (which may turn out not to be needed). The main thrust of this is to cleanup the interface to `tydecode.rs` to be less ridiculously repetitive. I also purged the generic "def-id conversion" parameter in favor of a trait object, just to reduce code duplication a bit and make the signatures a bit less messy. I measured the bootstrapping time to build stage2 with these changes, it was identical. (But it'd be easy enough to restore the unboxed closure if we wanted it.)
- Loading branch information
Showing
14 changed files
with
786 additions
and
1,011 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// Copyright 2012-2015 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
use syntax::ast; | ||
use syntax::ast_util::{IdRange, IdRangeComputingVisitor, | ||
IdVisitor, IdVisitingOperation}; | ||
use syntax::ptr::P; | ||
use syntax::visit::Visitor; | ||
use self::InlinedItem::*; | ||
|
||
/// The data we save and restore about an inlined item or method. This is not | ||
/// part of the AST that we parse from a file, but it becomes part of the tree | ||
/// that we trans. | ||
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] | ||
pub enum InlinedItem { | ||
Item(P<ast::Item>), | ||
TraitItem(ast::DefId /* impl id */, P<ast::TraitItem>), | ||
ImplItem(ast::DefId /* impl id */, P<ast::ImplItem>), | ||
Foreign(P<ast::ForeignItem>), | ||
} | ||
|
||
/// A borrowed version of `ast::InlinedItem`. | ||
pub enum InlinedItemRef<'a> { | ||
Item(&'a ast::Item), | ||
TraitItem(ast::DefId, &'a ast::TraitItem), | ||
ImplItem(ast::DefId, &'a ast::ImplItem), | ||
Foreign(&'a ast::ForeignItem) | ||
} | ||
|
||
impl InlinedItem { | ||
pub fn visit<'ast,V>(&'ast self, visitor: &mut V) | ||
where V: Visitor<'ast> | ||
{ | ||
match *self { | ||
Item(ref i) => visitor.visit_item(&**i), | ||
Foreign(ref i) => visitor.visit_foreign_item(&**i), | ||
TraitItem(_, ref ti) => visitor.visit_trait_item(ti), | ||
ImplItem(_, ref ii) => visitor.visit_impl_item(ii), | ||
} | ||
} | ||
|
||
pub fn visit_ids<O: IdVisitingOperation>(&self, operation: &mut O) { | ||
let mut id_visitor = IdVisitor { | ||
operation: operation, | ||
pass_through_items: true, | ||
visited_outermost: false, | ||
}; | ||
self.visit(&mut id_visitor); | ||
} | ||
|
||
pub fn compute_id_range(&self) -> IdRange { | ||
let mut visitor = IdRangeComputingVisitor::new(); | ||
self.visit_ids(&mut visitor); | ||
visitor.result() | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,3 +19,4 @@ pub mod csearch; | |
pub mod loader; | ||
pub mod filesearch; | ||
pub mod macro_import; | ||
pub mod inline; |
Oops, something went wrong.