about summary refs log tree commit diff
diff options
context:
space:
mode:
authorcsmoe <csmoe@msn.com>2019-09-19 03:02:08 +0000
committercsmoe <csmoe@msn.com>2019-09-19 03:17:34 +0000
commit2fd4c27c329d85a69a6b585d217e48b4d500477e (patch)
tree7abb4388be80e473e29c68891d6908996fa74416
parent528379121ceb5fca5382b4337be7ac064890ec8c (diff)
add is_async_fn query
-rw-r--r--src/librustc/query/mod.rs4
-rw-r--r--src/librustc_metadata/cstore_impl.rs1
-rw-r--r--src/librustc_metadata/decoder.rs9
-rw-r--r--src/librustc_metadata/encoder.rs4
-rw-r--r--src/librustc_metadata/schema.rs1
5 files changed, 19 insertions, 0 deletions
diff --git a/src/librustc/query/mod.rs b/src/librustc/query/mod.rs
index c7260945295..c4f62df12b7 100644
--- a/src/librustc/query/mod.rs
+++ b/src/librustc/query/mod.rs
@@ -244,6 +244,10 @@ rustc_queries! {
             desc { |tcx| "checking if item is const fn: `{}`", tcx.def_path_str(key) }
         }
 
+        query is_async_fn(key: DefId) -> hir::IsAsync {
+            desc { |tcx| "checking if the function is async: `{}`", tcx.def_path_str(key) }
+        }
+
         /// Returns `true` if calls to the function may be promoted.
         ///
         /// This is either because the function is e.g., a tuple-struct or tuple-variant
diff --git a/src/librustc_metadata/cstore_impl.rs b/src/librustc_metadata/cstore_impl.rs
index a1e3bbcbf8e..6db3bfd8880 100644
--- a/src/librustc_metadata/cstore_impl.rs
+++ b/src/librustc_metadata/cstore_impl.rs
@@ -133,6 +133,7 @@ provide! { <'tcx> tcx, def_id, other, cdata,
     fn_sig => { cdata.fn_sig(def_id.index, tcx) }
     inherent_impls => { cdata.get_inherent_implementations_for_type(tcx, def_id.index) }
     is_const_fn_raw => { cdata.is_const_fn_raw(def_id.index) }
+    is_async_fn { cdata.fn_asyncness(def_id.index) }
     is_foreign_item => { cdata.is_foreign_item(def_id.index) }
     static_mutability => { cdata.static_mutability(def_id.index) }
     def_kind => { cdata.def_kind(def_id.index) }
diff --git a/src/librustc_metadata/decoder.rs b/src/librustc_metadata/decoder.rs
index 75d72617047..6cc5c409e13 100644
--- a/src/librustc_metadata/decoder.rs
+++ b/src/librustc_metadata/decoder.rs
@@ -1208,6 +1208,15 @@ impl<'a, 'tcx> CrateMetadata {
         constness == hir::Constness::Const
     }
 
+    pub fn is_async_fn(&self, id: DefIndex) -> bool {
+        let asyncness = match self.entry(id).kind {
+            EntryKind::Fn(data) => data.decode(self).asyncness,
+            EntryKind::Method(data) => data.decode(self).fn_data.asyncness,
+            _ => hir::IsAsync::NotAsync,
+        };
+        asyncness == hir::IsAsync::Async
+    }
+
     pub fn is_foreign_item(&self, id: DefIndex) -> bool {
         match self.entry(id).kind {
             EntryKind::ForeignImmStatic |
diff --git a/src/librustc_metadata/encoder.rs b/src/librustc_metadata/encoder.rs
index f430f01542e..439763810ec 100644
--- a/src/librustc_metadata/encoder.rs
+++ b/src/librustc_metadata/encoder.rs
@@ -885,6 +885,7 @@ impl EncodeContext<'tcx> {
                         }
                     };
                     FnData {
+                        asyncness: hir::IsAsync::NotAsync,
                         constness: hir::Constness::NotConst,
                         param_names,
                         sig: self.lazy(&tcx.fn_sig(def_id)),
@@ -982,6 +983,7 @@ impl EncodeContext<'tcx> {
             ty::AssocKind::Method => {
                 let fn_data = if let hir::ImplItemKind::Method(ref sig, body) = ast_item.node {
                     FnData {
+                        asyncness: sig.header.asyncness,
                         constness: sig.header.constness,
                         param_names: self.encode_fn_param_names_for_body(body),
                         sig: self.lazy(&tcx.fn_sig(def_id)),
@@ -1128,6 +1130,7 @@ impl EncodeContext<'tcx> {
             }
             hir::ItemKind::Fn(_, header, .., body) => {
                 let data = FnData {
+                    asyncness: header.asyncness,
                     constness: header.constness,
                     param_names: self.encode_fn_param_names_for_body(body),
                     sig: self.lazy(tcx.fn_sig(def_id)),
@@ -1675,6 +1678,7 @@ impl EncodeContext<'tcx> {
         let kind = match nitem.node {
             hir::ForeignItemKind::Fn(_, ref names, _) => {
                 let data = FnData {
+                    asyncness: hir::IsAsync::NotAsync,
                     constness: hir::Constness::NotConst,
                     param_names: self.encode_fn_param_names(names),
                     sig: self.lazy(tcx.fn_sig(def_id)),
diff --git a/src/librustc_metadata/schema.rs b/src/librustc_metadata/schema.rs
index 1a5f0e17ba7..92534ab056a 100644
--- a/src/librustc_metadata/schema.rs
+++ b/src/librustc_metadata/schema.rs
@@ -295,6 +295,7 @@ pub struct MacroDef {
 
 #[derive(RustcEncodable, RustcDecodable)]
 pub struct FnData<'tcx> {
+    pub asyncness: hir::IsAsync,
     pub constness: hir::Constness,
     pub param_names: Lazy<[ast::Name]>,
     pub sig: Lazy<ty::PolyFnSig<'tcx>>,