Skip to content

move most of front to libsyntax #16240

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 8 additions & 5 deletions src/librustc/driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ pub fn phase_1_parse_input(sess: &Session, cfg: ast::CrateConfig, input: &Input)
}

if sess.show_span() {
front::show_span::run(sess, &krate);
syntax::show_span::run(sess.diagnostic(), &krate);
}

krate
Expand Down Expand Up @@ -214,7 +214,7 @@ pub fn phase_2_configure_and_expand(sess: &Session,
// baz! should not use this definition unless foo is enabled.

krate = time(time_passes, "configuration 1", krate, |krate|
front::config::strip_unconfigured_items(krate));
syntax::config::strip_unconfigured_items(krate));

let mut addl_plugins = Some(addl_plugins);
let Plugins { macros, registrars }
Expand Down Expand Up @@ -283,16 +283,19 @@ pub fn phase_2_configure_and_expand(sess: &Session,

// strip again, in case expansion added anything with a #[cfg].
krate = time(time_passes, "configuration 2", krate, |krate|
front::config::strip_unconfigured_items(krate));
syntax::config::strip_unconfigured_items(krate));

krate = time(time_passes, "maybe building test harness", krate, |krate|
front::test::modify_for_testing(sess, krate));
syntax::test::modify_for_testing(&sess.parse_sess,
&sess.opts.cfg,
krate,
sess.diagnostic()));

krate = time(time_passes, "prelude injection", krate, |krate|
front::std_inject::maybe_inject_prelude(sess, krate));

let (krate, map) = time(time_passes, "assigning node ids and indexing ast", krate, |krate|
front::assign_node_ids_and_map::assign_node_ids_and_map(sess, krate));
syntax::assign_node_ids_and_map::assign_node_ids_and_map(&sess.parse_sess, krate));

if sess.opts.debugging_opts & config::AST_JSON != 0 {
let mut stdout = io::BufferedWriter::new(io::stdout());
Expand Down
13 changes: 2 additions & 11 deletions src/librustc/driver/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ pub struct Session {
pub working_dir: Path,
pub lint_store: RefCell<lint::LintStore>,
pub lints: RefCell<NodeMap<Vec<(lint::LintId, codemap::Span, String)>>>,
pub node_id: Cell<ast::NodeId>,
pub crate_types: RefCell<Vec<config::CrateType>>,
pub crate_metadata: RefCell<Vec<String>>,
pub features: front::feature_gate::Features,
Expand Down Expand Up @@ -129,17 +128,10 @@ impl Session {
lints.insert(id, vec!((lint_id, sp, msg)));
}
pub fn next_node_id(&self) -> ast::NodeId {
self.reserve_node_ids(1)
self.parse_sess.next_node_id()
}
pub fn reserve_node_ids(&self, count: ast::NodeId) -> ast::NodeId {
let v = self.node_id.get();

match v.checked_add(&count) {
Some(next) => { self.node_id.set(next); }
None => self.bug("Input too large, ran out of node ids!")
}

v
self.parse_sess.reserve_node_ids(count)
}
pub fn diagnostic<'a>(&'a self) -> &'a diagnostic::SpanHandler {
&self.parse_sess.span_diagnostic
Expand Down Expand Up @@ -251,7 +243,6 @@ pub fn build_session_(sopts: config::Options,
working_dir: os::getcwd(),
lint_store: RefCell::new(lint::LintStore::new()),
lints: RefCell::new(NodeMap::new()),
node_id: Cell::new(1),
crate_types: RefCell::new(Vec::new()),
crate_metadata: RefCell::new(Vec::new()),
features: front::feature_gate::Features::new(),
Expand Down
4 changes: 0 additions & 4 deletions src/librustc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,8 @@ pub mod middle {
}

pub mod front {
pub mod config;
pub mod test;
pub mod std_inject;
pub mod assign_node_ids_and_map;
pub mod feature_gate;
pub mod show_span;
}

pub mod metadata;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use driver::session::Session;

use syntax::ast;
use syntax::ast_map;
use ast;
use ast_map;
use parse::ParseSess;

struct NodeIdAssigner<'a> {
sess: &'a Session
sess: &'a ParseSess
}

impl<'a> ast_map::FoldOps for NodeIdAssigner<'a> {
Expand All @@ -24,6 +23,7 @@ impl<'a> ast_map::FoldOps for NodeIdAssigner<'a> {
}
}

pub fn assign_node_ids_and_map(sess: &Session, krate: ast::Crate) -> (ast::Crate, ast_map::Map) {
pub fn assign_node_ids_and_map(sess: &ParseSess,
krate: ast::Crate) -> (ast::Crate, ast_map::Map) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would move the functionality of this entire file to ast_map, maybe Map::from_crate?.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good idea

ast_map::map_crate(krate, NodeIdAssigner { sess: sess })
}
6 changes: 3 additions & 3 deletions src/librustc/front/config.rs → src/libsyntax/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use syntax::fold::Folder;
use syntax::{ast, fold, attr};
use syntax::codemap;
use fold::Folder;
use {ast, fold, attr};
use codemap;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this can be integrated into parsing and expansion, which would allow us to #[cfg]-gate code that wouldn't parse with a given version of rustc.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

again, yes, but out of scope


use std::gc::{Gc, GC};

Expand Down
4 changes: 4 additions & 0 deletions src/libsyntax/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,20 @@ pub mod syntax {
}

pub mod abi;
pub mod assign_node_ids_and_map;
pub mod ast;
pub mod ast_map;
pub mod ast_util;
pub mod attr;
pub mod codemap;
pub mod config;
pub mod crateid;
pub mod diagnostic;
pub mod fold;
pub mod owned_slice;
pub mod parse;
pub mod show_span;
pub mod test;
pub mod visit;

pub mod print {
Expand Down
21 changes: 20 additions & 1 deletion src/libsyntax/parse/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use diagnostic::{SpanHandler, mk_span_handler, default_handler, Auto};
use parse::attr::ParserAttr;
use parse::parser::Parser;

use std::cell::RefCell;
use std::cell::{Cell,RefCell};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't it idiomatic to have a space after ,?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes it is

use std::gc::Gc;
use std::io::File;
use std::rc::Rc;
Expand All @@ -36,19 +36,38 @@ pub struct ParseSess {
pub span_diagnostic: SpanHandler, // better be the same as the one in the reader!
/// Used to determine and report recursive mod inclusions
included_mod_stack: RefCell<Vec<Path>>,
pub node_id: Cell<ast::NodeId>,
}

pub fn new_parse_sess() -> ParseSess {
ParseSess {
span_diagnostic: mk_span_handler(default_handler(Auto, None), CodeMap::new()),
included_mod_stack: RefCell::new(Vec::new()),
node_id: Cell::new(1),
}
}

pub fn new_parse_sess_special_handler(sh: SpanHandler) -> ParseSess {
ParseSess {
span_diagnostic: sh,
included_mod_stack: RefCell::new(Vec::new()),
node_id: Cell::new(1),
}
}

impl ParseSess {
pub fn next_node_id(&self) -> ast::NodeId {
self.reserve_node_ids(1)
}
pub fn reserve_node_ids(&self, count: ast::NodeId) -> ast::NodeId {
let v = self.node_id.get();

match v.checked_add(&count) {
Some(next) => { self.node_id.set(next); }
None => fail!("Input too large, ran out of node ids!")
}

v
}
}

Expand Down
17 changes: 8 additions & 9 deletions src/librustc/front/show_span.rs → src/libsyntax/show_span.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,23 @@
//! This module shows spans for all expressions in the crate
//! to help with compiler debugging.

use syntax::ast;
use syntax::visit;
use syntax::visit::Visitor;

use driver::session::Session;
use ast;
use diagnostic;
use visit;
use visit::Visitor;

struct ShowSpanVisitor<'a> {
sess: &'a Session
span_diagnostic: &'a diagnostic::SpanHandler,
}

impl<'a> Visitor<()> for ShowSpanVisitor<'a> {
fn visit_expr(&mut self, e: &ast::Expr, _: ()) {
self.sess.span_note(e.span, "expression");
self.span_diagnostic.span_note(e.span, "expression");
visit::walk_expr(self, e, ());
}
}

pub fn run(sess: &Session, krate: &ast::Crate) {
let mut v = ShowSpanVisitor { sess: sess };
pub fn run(span_diagnostic: &diagnostic::SpanHandler, krate: &ast::Crate) {
let mut v = ShowSpanVisitor { span_diagnostic: span_diagnostic };
visit::walk_crate(&mut v, krate, ());
}
Loading