2014-06-09 20:12:30 +00:00
|
|
|
//! The Rust parser and macro expander.
|
|
|
|
//!
|
|
|
|
//! # Note
|
|
|
|
//!
|
|
|
|
//! This API is completely unstable and subject to change.
|
2013-03-29 19:51:10 +00:00
|
|
|
|
2019-12-22 22:42:04 +00:00
|
|
|
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/", test(attr(deny(warnings))))]
|
2019-10-08 00:14:42 +00:00
|
|
|
#![feature(bool_to_option)]
|
2019-06-12 06:36:12 +00:00
|
|
|
#![feature(box_syntax)]
|
2019-06-12 08:42:58 +00:00
|
|
|
#![feature(const_fn)]
|
|
|
|
#![feature(const_transmute)]
|
2018-06-22 22:05:07 +00:00
|
|
|
#![feature(crate_visibility_modifier)]
|
2019-01-01 23:21:05 +00:00
|
|
|
#![feature(label_break_value)]
|
2019-02-10 07:13:30 +00:00
|
|
|
#![feature(nll)]
|
2018-08-20 00:51:02 +00:00
|
|
|
#![feature(try_trait)]
|
2019-10-08 08:59:05 +00:00
|
|
|
#![feature(slice_patterns)]
|
2018-06-22 22:05:07 +00:00
|
|
|
#![feature(unicode_internals)]
|
2019-12-22 22:42:04 +00:00
|
|
|
#![recursion_limit = "256"]
|
2014-01-09 13:05:33 +00:00
|
|
|
|
2019-12-22 22:42:04 +00:00
|
|
|
use ast::AttrId;
|
2019-02-07 15:56:05 +00:00
|
|
|
pub use errors;
|
2018-03-07 01:44:10 +00:00
|
|
|
use rustc_data_structures::sync::Lock;
|
2019-09-26 05:30:10 +00:00
|
|
|
use rustc_index::bit_set::GrowableBitSet;
|
2019-12-31 17:15:40 +00:00
|
|
|
use rustc_span::edition::Edition;
|
2018-03-07 01:44:10 +00:00
|
|
|
|
2017-03-03 09:23:59 +00:00
|
|
|
#[macro_export]
|
|
|
|
macro_rules! unwrap_or {
|
|
|
|
($opt:expr, $default:expr) => {
|
|
|
|
match $opt {
|
|
|
|
Some(x) => x,
|
|
|
|
None => $default,
|
|
|
|
}
|
2019-12-22 22:42:04 +00:00
|
|
|
};
|
2017-03-03 09:23:59 +00:00
|
|
|
}
|
|
|
|
|
2018-04-25 22:49:52 +00:00
|
|
|
pub struct Globals {
|
Merge indexed_set.rs into bitvec.rs, and rename it bit_set.rs.
Currently we have two files implementing bitsets (and 2D bit matrices).
This commit combines them into one, taking the best features from each.
This involves renaming a lot of things. The high level changes are as
follows.
- bitvec.rs --> bit_set.rs
- indexed_set.rs --> (removed)
- BitArray + IdxSet --> BitSet (merged, see below)
- BitVector --> GrowableBitSet
- {,Sparse,Hybrid}IdxSet --> {,Sparse,Hybrid}BitSet
- BitMatrix --> BitMatrix
- SparseBitMatrix --> SparseBitMatrix
The changes within the bitset types themselves are as follows.
```
OLD OLD NEW
BitArray<C> IdxSet<T> BitSet<T>
-------- ------ ------
grow - grow
new - (remove)
new_empty new_empty new_empty
new_filled new_filled new_filled
- to_hybrid to_hybrid
clear clear clear
set_up_to set_up_to set_up_to
clear_above - clear_above
count - count
contains(T) contains(&T) contains(T)
contains_all - superset
is_empty - is_empty
insert(T) add(&T) insert(T)
insert_all - insert_all()
remove(T) remove(&T) remove(T)
words words words
words_mut words_mut words_mut
- overwrite overwrite
merge union union
- subtract subtract
- intersect intersect
iter iter iter
```
In general, when choosing names I went with:
- names that are more obvious (e.g. `BitSet` over `IdxSet`).
- names that are more like the Rust libraries (e.g. `T` over `C`,
`insert` over `add`);
- names that are more set-like (e.g. `union` over `merge`, `superset`
over `contains_all`, `domain_size` over `num_bits`).
Also, using `T` for index arguments seems more sensible than `&T` --
even though the latter is standard in Rust collection types -- because
indices are always copyable. It also results in fewer `&` and `*`
sigils in practice.
2018-09-14 05:07:25 +00:00
|
|
|
used_attrs: Lock<GrowableBitSet<AttrId>>,
|
|
|
|
known_attrs: Lock<GrowableBitSet<AttrId>>,
|
2019-12-31 17:15:40 +00:00
|
|
|
rustc_span_globals: rustc_span::Globals,
|
2018-03-07 01:44:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Globals {
|
2019-04-05 22:15:49 +00:00
|
|
|
fn new(edition: Edition) -> Globals {
|
2018-03-07 01:44:10 +00:00
|
|
|
Globals {
|
2019-10-20 15:03:33 +00:00
|
|
|
// We have no idea how many attributes there will be, so just
|
2018-07-30 14:39:03 +00:00
|
|
|
// initiate the vectors with 0 bits. We'll grow them as necessary.
|
Merge indexed_set.rs into bitvec.rs, and rename it bit_set.rs.
Currently we have two files implementing bitsets (and 2D bit matrices).
This commit combines them into one, taking the best features from each.
This involves renaming a lot of things. The high level changes are as
follows.
- bitvec.rs --> bit_set.rs
- indexed_set.rs --> (removed)
- BitArray + IdxSet --> BitSet (merged, see below)
- BitVector --> GrowableBitSet
- {,Sparse,Hybrid}IdxSet --> {,Sparse,Hybrid}BitSet
- BitMatrix --> BitMatrix
- SparseBitMatrix --> SparseBitMatrix
The changes within the bitset types themselves are as follows.
```
OLD OLD NEW
BitArray<C> IdxSet<T> BitSet<T>
-------- ------ ------
grow - grow
new - (remove)
new_empty new_empty new_empty
new_filled new_filled new_filled
- to_hybrid to_hybrid
clear clear clear
set_up_to set_up_to set_up_to
clear_above - clear_above
count - count
contains(T) contains(&T) contains(T)
contains_all - superset
is_empty - is_empty
insert(T) add(&T) insert(T)
insert_all - insert_all()
remove(T) remove(&T) remove(T)
words words words
words_mut words_mut words_mut
- overwrite overwrite
merge union union
- subtract subtract
- intersect intersect
iter iter iter
```
In general, when choosing names I went with:
- names that are more obvious (e.g. `BitSet` over `IdxSet`).
- names that are more like the Rust libraries (e.g. `T` over `C`,
`insert` over `add`);
- names that are more set-like (e.g. `union` over `merge`, `superset`
over `contains_all`, `domain_size` over `num_bits`).
Also, using `T` for index arguments seems more sensible than `&T` --
even though the latter is standard in Rust collection types -- because
indices are always copyable. It also results in fewer `&` and `*`
sigils in practice.
2018-09-14 05:07:25 +00:00
|
|
|
used_attrs: Lock::new(GrowableBitSet::new_empty()),
|
|
|
|
known_attrs: Lock::new(GrowableBitSet::new_empty()),
|
2019-12-31 17:15:40 +00:00
|
|
|
rustc_span_globals: rustc_span::Globals::new(edition),
|
2018-03-07 01:44:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-05 22:15:49 +00:00
|
|
|
pub fn with_globals<F, R>(edition: Edition, f: F) -> R
|
2019-12-22 22:42:04 +00:00
|
|
|
where
|
|
|
|
F: FnOnce() -> R,
|
2018-03-07 01:44:10 +00:00
|
|
|
{
|
2019-04-05 22:15:49 +00:00
|
|
|
let globals = Globals::new(edition);
|
2019-12-31 17:15:40 +00:00
|
|
|
GLOBALS.set(&globals, || rustc_span::GLOBALS.set(&globals.rustc_span_globals, f))
|
2018-03-07 01:44:10 +00:00
|
|
|
}
|
|
|
|
|
2019-04-05 22:15:49 +00:00
|
|
|
pub fn with_default_globals<F, R>(f: F) -> R
|
2019-12-22 22:42:04 +00:00
|
|
|
where
|
|
|
|
F: FnOnce() -> R,
|
2019-04-05 22:15:49 +00:00
|
|
|
{
|
|
|
|
with_globals(edition::DEFAULT_EDITION, f)
|
|
|
|
}
|
|
|
|
|
2019-02-06 17:33:01 +00:00
|
|
|
scoped_tls::scoped_thread_local!(pub static GLOBALS: Globals);
|
2018-03-07 01:44:10 +00:00
|
|
|
|
2016-06-28 17:40:40 +00:00
|
|
|
#[macro_use]
|
|
|
|
pub mod diagnostics {
|
|
|
|
#[macro_use]
|
|
|
|
pub mod macros;
|
|
|
|
}
|
|
|
|
|
2013-04-03 16:41:40 +00:00
|
|
|
pub mod util {
|
2019-10-15 20:48:13 +00:00
|
|
|
pub mod classify;
|
2019-10-11 12:39:52 +00:00
|
|
|
pub mod comments;
|
2015-11-25 23:21:38 +00:00
|
|
|
pub mod lev_distance;
|
2019-10-15 20:48:13 +00:00
|
|
|
pub mod literal;
|
2019-12-22 22:42:04 +00:00
|
|
|
pub mod map_in_place;
|
2015-11-11 05:26:14 +00:00
|
|
|
pub mod node_count;
|
|
|
|
pub mod parser;
|
2013-04-03 16:41:40 +00:00
|
|
|
}
|
|
|
|
|
2013-01-29 22:41:40 +00:00
|
|
|
pub mod ast;
|
2014-07-01 16:39:41 +00:00
|
|
|
pub mod attr;
|
2015-08-23 18:12:39 +00:00
|
|
|
pub mod entry;
|
2020-01-01 18:25:28 +00:00
|
|
|
pub mod expand;
|
2019-11-29 23:23:38 +00:00
|
|
|
pub mod feature_gate {
|
|
|
|
mod check;
|
2019-12-22 22:42:04 +00:00
|
|
|
pub use check::{check_attribute, check_crate, feature_err, feature_err_issue, get_features};
|
2019-11-29 23:23:38 +00:00
|
|
|
}
|
2019-02-05 22:10:05 +00:00
|
|
|
pub mod mut_visit;
|
2014-05-17 21:46:40 +00:00
|
|
|
pub mod ptr;
|
2014-07-25 02:44:24 +00:00
|
|
|
pub mod show_span;
|
2019-12-22 22:42:04 +00:00
|
|
|
pub use rustc_session::parse as sess;
|
2019-12-31 17:15:40 +00:00
|
|
|
pub use rustc_span::edition;
|
2019-10-11 10:46:32 +00:00
|
|
|
pub mod token;
|
2016-06-20 15:49:33 +00:00
|
|
|
pub mod tokenstream;
|
2014-07-01 16:39:41 +00:00
|
|
|
pub mod visit;
|
2013-01-29 22:41:40 +00:00
|
|
|
|
|
|
|
pub mod print {
|
2019-12-22 22:42:04 +00:00
|
|
|
mod helpers;
|
2013-01-29 22:41:40 +00:00
|
|
|
pub mod pp;
|
|
|
|
pub mod pprust;
|
2012-03-29 20:48:05 +00:00
|
|
|
}
|
|
|
|
|
2018-07-12 01:54:12 +00:00
|
|
|
pub mod early_buffered_lints;
|
2019-11-10 16:19:08 +00:00
|
|
|
|
|
|
|
/// Requirements for a `StableHashingContext` to be used in this crate.
|
|
|
|
/// This is a hack to allow using the `HashStable_Generic` derive macro
|
|
|
|
/// instead of implementing everything in librustc.
|
2019-12-31 17:15:40 +00:00
|
|
|
pub trait HashStableContext: rustc_span::HashStableContext {}
|