]> git.lizzy.rs Git - rust.git/commitdiff
Rename `mtwt` to `hygiene`
authorJeffrey Seyfried <jeffrey.seyfried@gmail.com>
Sat, 16 Jul 2016 19:11:28 +0000 (19:11 +0000)
committerJeffrey Seyfried <jeffrey.seyfried@gmail.com>
Sun, 17 Jul 2016 17:12:35 +0000 (17:12 +0000)
src/librustc/session/config.rs
src/librustc_driver/driver.rs
src/librustc_resolve/assign_ids.rs
src/librustc_resolve/lib.rs
src/libsyntax/ast.rs
src/libsyntax/ext/expand.rs
src/libsyntax/ext/hygiene.rs [new file with mode: 0644]
src/libsyntax/ext/mtwt.rs [deleted file]
src/libsyntax/lib.rs

index bc271e9ecc8ea46a67bf56410c759153d9eef52d..65b97abfccbd75f5cb456115f24431e70340939a 100644 (file)
@@ -735,8 +735,8 @@ fn parse_panic_strategy(slot: &mut PanicStrategy, v: Option<&str>) -> bool {
           "for every macro invocation, print its name and arguments"),
     enable_nonzeroing_move_hints: bool = (false, parse_bool,
           "force nonzeroing move optimization on"),
-    keep_mtwt_tables: bool = (false, parse_bool,
-          "don't clear the resolution tables after analysis"),
+    keep_hygiene_data: bool = (false, parse_bool,
+          "don't clear the hygiene data after analysis"),
     keep_ast: bool = (false, parse_bool,
           "keep the AST after lowering it to HIR"),
     show_span: Option<String> = (None, parse_opt_string,
index 6b141ca15c050ae467eea07b5fc17f1e84aab351..ab3b20e08c8099130c1b5c3a874a519f9b29fddb 100644 (file)
@@ -236,8 +236,8 @@ macro_rules! controller_entry_point {
     Ok(())
 }
 
-fn keep_mtwt_tables(sess: &Session) -> bool {
-    sess.opts.debugging_opts.keep_mtwt_tables
+fn keep_hygiene_data(sess: &Session) -> bool {
+    sess.opts.debugging_opts.keep_hygiene_data
 }
 
 fn keep_ast(sess: &Session) -> bool {
@@ -479,7 +479,7 @@ pub fn phase_1_parse_input<'a>(sess: &'a Session,
                                input: &Input)
                                -> PResult<'a, ast::Crate> {
     // These may be left in an incoherent state after a previous compile.
-    syntax::ext::mtwt::reset_hygiene_data();
+    syntax::ext::hygiene::reset_hygiene_data();
     // `clear_ident_interner` can be used to free memory, but it does not restore the initial state.
     token::reset_ident_interner();
     let continue_after_error = sess.opts.continue_parse_after_error;
@@ -760,9 +760,9 @@ pub fn phase_2_configure_and_expand<'a, F>(sess: &Session,
         hir_map::Forest::new(lower_crate(sess, &krate, &mut resolver), &sess.dep_graph)
     });
 
-    // Discard MTWT tables that aren't required past lowering to HIR.
-    if !keep_mtwt_tables(sess) {
-        syntax::ext::mtwt::reset_hygiene_data();
+    // Discard hygiene data, which isn't required past lowering to HIR.
+    if !keep_hygiene_data(sess) {
+        syntax::ext::hygiene::reset_hygiene_data();
     }
 
     Ok(ExpansionResult {
index 77facbfb61798ebbcf9e0a74e695e4cc40e7261e..70e566de8a7be5ab9a53900cd82678e7268329fe 100644 (file)
@@ -11,7 +11,7 @@
 use Resolver;
 use rustc::session::Session;
 use syntax::ast;
-use syntax::ext::mtwt::Mark;
+use syntax::ext::hygiene::Mark;
 use syntax::fold::{self, Folder};
 use syntax::ptr::P;
 use syntax::util::move_map::MoveMap;
index 36cd2ef6002ac39cbbbd73f7a99511a2d0b8393a..aa8c706ea1e27b9cb73978f7248864c3627ee7e8 100644 (file)
@@ -53,7 +53,7 @@
 use rustc::hir::{Freevar, FreevarMap, TraitCandidate, TraitMap, GlobMap};
 use rustc::util::nodemap::{NodeMap, NodeSet, FnvHashMap, FnvHashSet};
 
-use syntax::ext::mtwt::Mark;
+use syntax::ext::hygiene::Mark;
 use syntax::ast::{self, FloatTy};
 use syntax::ast::{CRATE_NODE_ID, Name, NodeId, CrateNum, IntTy, UintTy};
 use syntax::parse::token::{self, keywords};
index 1f716923a16e24993f662815e0141008d289b3ca..a8bb255fba4a4d4b099c936239dee1abdc7fee7c 100644 (file)
@@ -19,7 +19,7 @@
 use syntax_pos::{mk_sp, Span, DUMMY_SP, ExpnId};
 use codemap::{respan, Spanned};
 use abi::Abi;
-use ext::mtwt::SyntaxContext;
+use ext::hygiene::SyntaxContext;
 use parse::token::{self, keywords, InternedString};
 use print::pprust;
 use ptr::P;
index 767d1ddb8e24d85dab976603c9b7cd086188b3ad..18342f2e38c1be8c51be9d662fed96c24ef83e7a 100644 (file)
@@ -11,7 +11,7 @@
 use ast::{Block, Crate, Ident, Mac_, Name, PatKind};
 use ast::{MacStmtStyle, Stmt, StmtKind, ItemKind};
 use ast;
-use ext::mtwt::Mark;
+use ext::hygiene::Mark;
 use attr::{self, HasAttrs};
 use attr::AttrMetaMethods;
 use codemap::{dummy_spanned, ExpnInfo, NameAndSpan, MacroBang, MacroAttribute};
diff --git a/src/libsyntax/ext/hygiene.rs b/src/libsyntax/ext/hygiene.rs
new file mode 100644 (file)
index 0000000..521930f
--- /dev/null
@@ -0,0 +1,151 @@
+// Copyright 2012-2014 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.
+
+//! Machinery for hygienic macros, inspired by the MTWT[1] paper.
+//!
+//! [1] Matthew Flatt, Ryan Culpepper, David Darais, and Robert Bruce Findler.
+//! 2012. *Macros that work together: Compile-time bindings, partial expansion,
+//! and definition contexts*. J. Funct. Program. 22, 2 (March 2012), 181-216.
+//! DOI=10.1017/S0956796812000093 http://dx.doi.org/10.1017/S0956796812000093
+
+use std::cell::RefCell;
+use std::collections::HashMap;
+use std::fmt;
+
+/// A SyntaxContext represents a chain of macro expansions (represented by marks).
+#[derive(Clone, Copy, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable, Default)]
+pub struct SyntaxContext(u32);
+
+#[derive(Copy, Clone)]
+pub struct SyntaxContextData {
+    pub outer_mark: Mark,
+    pub prev_ctxt: SyntaxContext,
+}
+
+/// A mark represents a unique id associated with a macro expansion.
+#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, Default)]
+pub struct Mark(u32);
+
+impl Mark {
+    pub fn fresh() -> Self {
+        HygieneData::with(|data| {
+            let next_mark = Mark(data.next_mark.0 + 1);
+            ::std::mem::replace(&mut data.next_mark, next_mark)
+        })
+    }
+}
+
+struct HygieneData {
+    syntax_contexts: Vec<SyntaxContextData>,
+    markings: HashMap<(SyntaxContext, Mark), SyntaxContext>,
+    next_mark: Mark,
+}
+
+impl HygieneData {
+    fn new() -> Self {
+        HygieneData {
+            syntax_contexts: vec![SyntaxContextData {
+                outer_mark: Mark(0), // the null mark
+                prev_ctxt: SyntaxContext(0), // the empty context
+            }],
+            markings: HashMap::new(),
+            next_mark: Mark(1),
+        }
+    }
+
+    fn with<T, F: FnOnce(&mut HygieneData) -> T>(f: F) -> T {
+        thread_local! {
+            static HYGIENE_DATA: RefCell<HygieneData> = RefCell::new(HygieneData::new());
+        }
+        HYGIENE_DATA.with(|data| f(&mut *data.borrow_mut()))
+    }
+}
+
+pub fn reset_hygiene_data() {
+    HygieneData::with(|data| *data = HygieneData::new())
+}
+
+impl SyntaxContext {
+    pub const fn empty() -> Self {
+        SyntaxContext(0)
+    }
+
+    pub fn data(self) -> SyntaxContextData {
+        HygieneData::with(|data| data.syntax_contexts[self.0 as usize])
+    }
+
+    /// Extend a syntax context with a given mark
+    pub fn apply_mark(self, mark: Mark) -> SyntaxContext {
+        // Applying the same mark twice is a no-op
+        let ctxt_data = self.data();
+        if mark == ctxt_data.outer_mark {
+            return ctxt_data.prev_ctxt;
+        }
+
+        HygieneData::with(|data| {
+            let syntax_contexts = &mut data.syntax_contexts;
+            *data.markings.entry((self, mark)).or_insert_with(|| {
+                syntax_contexts.push(SyntaxContextData {
+                    outer_mark: mark,
+                    prev_ctxt: self,
+                });
+                SyntaxContext(syntax_contexts.len() as u32 - 1)
+            })
+        })
+    }
+
+   /// If `ident` is macro expanded, return the source ident from the macro definition
+   /// and the mark of the expansion that created the macro definition.
+   pub fn source(self) -> (Self /* source context */, Mark /* source macro */) {
+        let macro_def_ctxt = self.data().prev_ctxt.data();
+        (macro_def_ctxt.prev_ctxt, macro_def_ctxt.outer_mark)
+   }
+}
+
+impl fmt::Debug for SyntaxContext {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        write!(f, "#{}", self.0)
+    }
+}
+
+#[cfg(test)]
+mod tests {
+    use ast::{EMPTY_CTXT, Mrk, SyntaxContext};
+    use super::{apply_mark_internal, new_sctable_internal, Mark, SCTable};
+
+    // extend a syntax context with a sequence of marks given
+    // in a vector. v[0] will be the outermost mark.
+    fn unfold_marks(mrks: Vec<Mrk> , tail: SyntaxContext, table: &SCTable)
+                    -> SyntaxContext {
+        mrks.iter().rev().fold(tail, |tail:SyntaxContext, mrk:&Mrk|
+                   {apply_mark_internal(*mrk,tail,table)})
+    }
+
+    #[test] fn unfold_marks_test() {
+        let mut t = new_sctable_internal();
+
+        assert_eq!(unfold_marks(vec!(3,7),EMPTY_CTXT,&mut t),SyntaxContext(2));
+        {
+            let table = t.table.borrow();
+            assert!((*table)[1] == Mark(7,EMPTY_CTXT));
+            assert!((*table)[2] == Mark(3,SyntaxContext(1)));
+        }
+    }
+
+    #[test]
+    fn hashing_tests () {
+        let mut t = new_sctable_internal();
+        assert_eq!(apply_mark_internal(12,EMPTY_CTXT,&mut t),SyntaxContext(1));
+        assert_eq!(apply_mark_internal(13,EMPTY_CTXT,&mut t),SyntaxContext(2));
+        // using the same one again should result in the same index:
+        assert_eq!(apply_mark_internal(12,EMPTY_CTXT,&mut t),SyntaxContext(1));
+        // I'm assuming that the rename table will behave the same....
+    }
+}
diff --git a/src/libsyntax/ext/mtwt.rs b/src/libsyntax/ext/mtwt.rs
deleted file mode 100644 (file)
index c4af4a1..0000000
+++ /dev/null
@@ -1,151 +0,0 @@
-// Copyright 2012-2014 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.
-
-//! Machinery for hygienic macros, as described in the MTWT[1] paper.
-//!
-//! [1] Matthew Flatt, Ryan Culpepper, David Darais, and Robert Bruce Findler.
-//! 2012. *Macros that work together: Compile-time bindings, partial expansion,
-//! and definition contexts*. J. Funct. Program. 22, 2 (March 2012), 181-216.
-//! DOI=10.1017/S0956796812000093 http://dx.doi.org/10.1017/S0956796812000093
-
-use std::cell::RefCell;
-use std::collections::HashMap;
-use std::fmt;
-
-/// A SyntaxContext represents a chain of macro expansions (represented by marks).
-#[derive(Clone, Copy, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable, Default)]
-pub struct SyntaxContext(u32);
-
-#[derive(Copy, Clone)]
-pub struct SyntaxContextData {
-    pub outer_mark: Mark,
-    pub prev_ctxt: SyntaxContext,
-}
-
-/// A mark represents a unique id associated with a macro expansion.
-#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, Default)]
-pub struct Mark(u32);
-
-impl Mark {
-    pub fn fresh() -> Self {
-        HygieneData::with(|data| {
-            let next_mark = Mark(data.next_mark.0 + 1);
-            ::std::mem::replace(&mut data.next_mark, next_mark)
-        })
-    }
-}
-
-struct HygieneData {
-    syntax_contexts: Vec<SyntaxContextData>,
-    markings: HashMap<(SyntaxContext, Mark), SyntaxContext>,
-    next_mark: Mark,
-}
-
-impl HygieneData {
-    fn new() -> Self {
-        HygieneData {
-            syntax_contexts: vec![SyntaxContextData {
-                outer_mark: Mark(0), // the null mark
-                prev_ctxt: SyntaxContext(0), // the empty context
-            }],
-            markings: HashMap::new(),
-            next_mark: Mark(1),
-        }
-    }
-
-    fn with<T, F: FnOnce(&mut HygieneData) -> T>(f: F) -> T {
-        thread_local! {
-            static HYGIENE_DATA: RefCell<HygieneData> = RefCell::new(HygieneData::new());
-        }
-        HYGIENE_DATA.with(|data| f(&mut *data.borrow_mut()))
-    }
-}
-
-pub fn reset_hygiene_data() {
-    HygieneData::with(|data| *data = HygieneData::new())
-}
-
-impl SyntaxContext {
-    pub const fn empty() -> Self {
-        SyntaxContext(0)
-    }
-
-    pub fn data(self) -> SyntaxContextData {
-        HygieneData::with(|data| data.syntax_contexts[self.0 as usize])
-    }
-
-    /// Extend a syntax context with a given mark
-    pub fn apply_mark(self, mark: Mark) -> SyntaxContext {
-        // Applying the same mark twice is a no-op
-        let ctxt_data = self.data();
-        if mark == ctxt_data.outer_mark {
-            return ctxt_data.prev_ctxt;
-        }
-
-        HygieneData::with(|data| {
-            let syntax_contexts = &mut data.syntax_contexts;
-            *data.markings.entry((self, mark)).or_insert_with(|| {
-                syntax_contexts.push(SyntaxContextData {
-                    outer_mark: mark,
-                    prev_ctxt: self,
-                });
-                SyntaxContext(syntax_contexts.len() as u32 - 1)
-            })
-        })
-    }
-
-   /// If `ident` is macro expanded, return the source ident from the macro definition
-   /// and the mark of the expansion that created the macro definition.
-   pub fn source(self) -> (Self /* source context */, Mark /* source macro */) {
-        let macro_def_ctxt = self.data().prev_ctxt.data();
-        (macro_def_ctxt.prev_ctxt, macro_def_ctxt.outer_mark)
-   }
-}
-
-impl fmt::Debug for SyntaxContext {
-    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
-        write!(f, "#{}", self.0)
-    }
-}
-
-#[cfg(test)]
-mod tests {
-    use ast::{EMPTY_CTXT, Mrk, SyntaxContext};
-    use super::{apply_mark_internal, new_sctable_internal, Mark, SCTable};
-
-    // extend a syntax context with a sequence of marks given
-    // in a vector. v[0] will be the outermost mark.
-    fn unfold_marks(mrks: Vec<Mrk> , tail: SyntaxContext, table: &SCTable)
-                    -> SyntaxContext {
-        mrks.iter().rev().fold(tail, |tail:SyntaxContext, mrk:&Mrk|
-                   {apply_mark_internal(*mrk,tail,table)})
-    }
-
-    #[test] fn unfold_marks_test() {
-        let mut t = new_sctable_internal();
-
-        assert_eq!(unfold_marks(vec!(3,7),EMPTY_CTXT,&mut t),SyntaxContext(2));
-        {
-            let table = t.table.borrow();
-            assert!((*table)[1] == Mark(7,EMPTY_CTXT));
-            assert!((*table)[2] == Mark(3,SyntaxContext(1)));
-        }
-    }
-
-    #[test]
-    fn hashing_tests () {
-        let mut t = new_sctable_internal();
-        assert_eq!(apply_mark_internal(12,EMPTY_CTXT,&mut t),SyntaxContext(1));
-        assert_eq!(apply_mark_internal(13,EMPTY_CTXT,&mut t),SyntaxContext(2));
-        // using the same one again should result in the same index:
-        assert_eq!(apply_mark_internal(12,EMPTY_CTXT,&mut t),SyntaxContext(1));
-        // I'm assuming that the rename table will behave the same....
-    }
-}
index 8febf1c49ec2badeb618ed632b4c661168da73d4..5ad1744418890b21f46e0b68139f04bf5386ce51 100644 (file)
@@ -127,7 +127,7 @@ pub mod ext {
     pub mod base;
     pub mod build;
     pub mod expand;
-    pub mod mtwt;
+    pub mod hygiene;
     pub mod quote;
     pub mod source_util;