2014-06-09 13:12:30 -07:00
|
|
|
//! The Rust parser and macro expander.
|
|
|
|
//!
|
|
|
|
//! # Note
|
|
|
|
//!
|
|
|
|
//! This API is completely unstable and subject to change.
|
2013-03-29 12:51:10 -07:00
|
|
|
|
2019-12-22 17:42:04 -05:00
|
|
|
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/", test(attr(deny(warnings))))]
|
2019-10-08 01:14:42 +01:00
|
|
|
#![feature(bool_to_option)]
|
2019-06-12 09:36:12 +03:00
|
|
|
#![feature(box_syntax)]
|
2019-06-12 11:42:58 +03:00
|
|
|
#![feature(const_fn)]
|
|
|
|
#![feature(const_transmute)]
|
2018-06-23 01:05:07 +03:00
|
|
|
#![feature(crate_visibility_modifier)]
|
2019-01-02 02:21:05 +03:00
|
|
|
#![feature(label_break_value)]
|
2019-02-10 16:13:30 +09:00
|
|
|
#![feature(nll)]
|
2018-08-19 17:51:02 -07:00
|
|
|
#![feature(try_trait)]
|
2019-10-08 10:59:05 +02:00
|
|
|
#![feature(slice_patterns)]
|
2018-06-23 01:05:07 +03:00
|
|
|
#![feature(unicode_internals)]
|
2019-12-22 17:42:04 -05:00
|
|
|
#![recursion_limit = "256"]
|
2014-01-09 15:05:33 +02:00
|
|
|
|
2019-12-22 17:42:04 -05:00
|
|
|
use ast::AttrId;
|
2019-02-08 00:56:05 +09:00
|
|
|
pub use errors;
|
2018-03-07 02:44:10 +01:00
|
|
|
use rustc_data_structures::sync::Lock;
|
2019-09-26 05:30:10 +00:00
|
|
|
use rustc_index::bit_set::GrowableBitSet;
|
2019-12-31 20:15:40 +03:00
|
|
|
use rustc_span::edition::Edition;
|
2018-03-07 02:44:10 +01: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 17:42:04 -05:00
|
|
|
};
|
2017-03-03 09:23:59 +00:00
|
|
|
}
|
|
|
|
|
2018-04-26 00:49:52 +02: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 15:07:25 +10:00
|
|
|
used_attrs: Lock<GrowableBitSet<AttrId>>,
|
|
|
|
known_attrs: Lock<GrowableBitSet<AttrId>>,
|
2019-12-31 20:15:40 +03:00
|
|
|
rustc_span_globals: rustc_span::Globals,
|
2018-03-07 02:44:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Globals {
|
2019-04-06 00:15:49 +02:00
|
|
|
fn new(edition: Edition) -> Globals {
|
2018-03-07 02:44:10 +01:00
|
|
|
Globals {
|
2019-10-20 23:03:33 +08:00
|
|
|
// We have no idea how many attributes there will be, so just
|
2018-07-30 08:39:03 -06: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 15:07:25 +10:00
|
|
|
used_attrs: Lock::new(GrowableBitSet::new_empty()),
|
|
|
|
known_attrs: Lock::new(GrowableBitSet::new_empty()),
|
2019-12-31 20:15:40 +03:00
|
|
|
rustc_span_globals: rustc_span::Globals::new(edition),
|
2018-03-07 02:44:10 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-06 00:15:49 +02:00
|
|
|
pub fn with_globals<F, R>(edition: Edition, f: F) -> R
|
2019-12-22 17:42:04 -05:00
|
|
|
where
|
|
|
|
F: FnOnce() -> R,
|
2018-03-07 02:44:10 +01:00
|
|
|
{
|
2019-04-06 00:15:49 +02:00
|
|
|
let globals = Globals::new(edition);
|
2019-12-31 20:15:40 +03:00
|
|
|
GLOBALS.set(&globals, || rustc_span::GLOBALS.set(&globals.rustc_span_globals, f))
|
2018-03-07 02:44:10 +01:00
|
|
|
}
|
|
|
|
|
2019-04-06 00:15:49 +02:00
|
|
|
pub fn with_default_globals<F, R>(f: F) -> R
|
2019-12-22 17:42:04 -05:00
|
|
|
where
|
|
|
|
F: FnOnce() -> R,
|
2019-04-06 00:15:49 +02:00
|
|
|
{
|
|
|
|
with_globals(edition::DEFAULT_EDITION, f)
|
|
|
|
}
|
|
|
|
|
2019-02-07 02:33:01 +09:00
|
|
|
scoped_tls::scoped_thread_local!(pub static GLOBALS: Globals);
|
2018-03-07 02:44:10 +01:00
|
|
|
|
2016-06-28 19:40:40 +02:00
|
|
|
#[macro_use]
|
|
|
|
pub mod diagnostics {
|
|
|
|
#[macro_use]
|
|
|
|
pub mod macros;
|
|
|
|
}
|
|
|
|
|
2013-04-03 09:41:40 -07:00
|
|
|
pub mod util {
|
2019-10-15 22:48:13 +02:00
|
|
|
pub mod classify;
|
2019-10-11 14:39:52 +02:00
|
|
|
pub mod comments;
|
2015-11-26 00:21:38 +01:00
|
|
|
pub mod lev_distance;
|
2019-10-15 22:48:13 +02:00
|
|
|
pub mod literal;
|
2019-12-22 17:42:04 -05:00
|
|
|
pub mod map_in_place;
|
2015-11-11 18:26:14 +13:00
|
|
|
pub mod node_count;
|
|
|
|
pub mod parser;
|
2013-04-03 09:41:40 -07:00
|
|
|
}
|
|
|
|
|
2013-01-29 14:41:40 -08:00
|
|
|
pub mod ast;
|
2014-07-01 18:39:41 +02:00
|
|
|
pub mod attr;
|
2015-08-23 14:12:39 -04:00
|
|
|
pub mod entry;
|
2020-01-01 19:25:28 +01:00
|
|
|
pub mod expand;
|
2019-11-30 00:23:38 +01:00
|
|
|
pub mod feature_gate {
|
|
|
|
mod check;
|
2019-12-22 17:42:04 -05:00
|
|
|
pub use check::{check_attribute, check_crate, feature_err, feature_err_issue, get_features};
|
2019-11-30 00:23:38 +01:00
|
|
|
}
|
2019-02-06 09:10:05 +11:00
|
|
|
pub mod mut_visit;
|
2014-05-18 00:46:40 +03:00
|
|
|
pub mod ptr;
|
2014-07-25 14:44:24 +12:00
|
|
|
pub mod show_span;
|
2019-12-22 17:42:04 -05:00
|
|
|
pub use rustc_session::parse as sess;
|
2019-12-31 20:15:40 +03:00
|
|
|
pub use rustc_span::edition;
|
2019-10-11 12:46:32 +02:00
|
|
|
pub mod token;
|
2016-06-20 08:49:33 -07:00
|
|
|
pub mod tokenstream;
|
2014-07-01 18:39:41 +02:00
|
|
|
pub mod visit;
|
2013-01-29 14:41:40 -08:00
|
|
|
|
|
|
|
pub mod print {
|
2019-12-22 17:42:04 -05:00
|
|
|
mod helpers;
|
2013-01-29 14:41:40 -08:00
|
|
|
pub mod pp;
|
|
|
|
pub mod pprust;
|
2012-03-29 13:48:05 -07:00
|
|
|
}
|
|
|
|
|
2018-07-11 20:54:12 -05:00
|
|
|
pub mod early_buffered_lints;
|
2019-11-10 17:19:08 +01: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 20:15:40 +03:00
|
|
|
pub trait HashStableContext: rustc_span::HashStableContext {}
|