]> git.lizzy.rs Git - rust.git/commitdiff
internal: rename hypothetical -> speculative
authorAleksey Kladov <aleksey.kladov@gmail.com>
Mon, 24 May 2021 19:21:25 +0000 (22:21 +0300)
committerAleksey Kladov <aleksey.kladov@gmail.com>
Mon, 24 May 2021 19:21:25 +0000 (22:21 +0300)
Lets steal this good naming from Roslyn before I forget about it yet
again.

crates/hir/src/semantics.rs
crates/hir_expand/src/db.rs
crates/hir_ty/src/lower.rs
crates/ide_completion/src/context.rs
crates/ide_completion/src/lib.rs

index 3aa467e3ca304a5e5216f1125bc0d67f4978b5d3..8d3c43d082e7c252d436660b6685b9624859d1a7 100644 (file)
@@ -120,10 +120,10 @@ pub fn expand(&self, macro_call: &ast::MacroCall) -> Option<SyntaxNode> {
     pub fn speculative_expand(
         &self,
         actual_macro_call: &ast::MacroCall,
-        hypothetical_args: &ast::TokenTree,
+        speculative_args: &ast::TokenTree,
         token_to_map: SyntaxToken,
     ) -> Option<(SyntaxNode, SyntaxToken)> {
-        self.imp.speculative_expand(actual_macro_call, hypothetical_args, token_to_map)
+        self.imp.speculative_expand(actual_macro_call, speculative_args, token_to_map)
     }
 
     pub fn descend_into_macros(&self, token: SyntaxToken) -> SyntaxToken {
@@ -335,7 +335,7 @@ fn expand(&self, macro_call: &ast::MacroCall) -> Option<SyntaxNode> {
     fn speculative_expand(
         &self,
         actual_macro_call: &ast::MacroCall,
-        hypothetical_args: &ast::TokenTree,
+        speculative_args: &ast::TokenTree,
         token_to_map: SyntaxToken,
     ) -> Option<(SyntaxNode, SyntaxToken)> {
         let sa = self.analyze(actual_macro_call.syntax());
@@ -344,10 +344,10 @@ fn speculative_expand(
         let macro_call_id = macro_call.as_call_id(self.db.upcast(), krate, |path| {
             sa.resolver.resolve_path_as_macro(self.db.upcast(), &path)
         })?;
-        hir_expand::db::expand_hypothetical(
+        hir_expand::db::expand_speculative(
             self.db.upcast(),
             macro_call_id,
-            hypothetical_args,
+            speculative_args,
             token_to_map,
         )
     }
index 5c769c1bf2c44605855c5aca7774552263e3f66b..db9d19b0c1c1a7ff9fc3f3caafb0cd0e4b144fe3 100644 (file)
@@ -131,15 +131,15 @@ fn parse_macro_expansion(
 /// used for completion, where we want to see what 'would happen' if we insert a
 /// token. The `token_to_map` mapped down into the expansion, with the mapped
 /// token returned.
-pub fn expand_hypothetical(
+pub fn expand_speculative(
     db: &dyn AstDatabase,
     actual_macro_call: MacroCallId,
-    hypothetical_args: &ast::TokenTree,
+    speculative_args: &ast::TokenTree,
     token_to_map: SyntaxToken,
 ) -> Option<(SyntaxNode, SyntaxToken)> {
-    let (tt, tmap_1) = mbe::syntax_node_to_token_tree(hypothetical_args.syntax());
+    let (tt, tmap_1) = mbe::syntax_node_to_token_tree(speculative_args.syntax());
     let range =
-        token_to_map.text_range().checked_sub(hypothetical_args.syntax().text_range().start())?;
+        token_to_map.text_range().checked_sub(speculative_args.syntax().text_range().start())?;
     let token_id = tmap_1.token_by_range(range)?;
 
     let macro_def = {
@@ -147,12 +147,12 @@ pub fn expand_hypothetical(
         db.macro_def(loc.def)?
     };
 
-    let hypothetical_expansion = macro_def.expand(db, actual_macro_call, &tt);
+    let speculative_expansion = macro_def.expand(db, actual_macro_call, &tt);
 
     let fragment_kind = macro_fragment_kind(db, actual_macro_call);
 
     let (node, tmap_2) =
-        mbe::token_tree_to_syntax_node(&hypothetical_expansion.value, fragment_kind).ok()?;
+        mbe::token_tree_to_syntax_node(&speculative_expansion.value, fragment_kind).ok()?;
 
     let token_id = macro_def.map_id_down(token_id);
     let range = tmap_2.range_by_token(token_id)?.by_kind(token_to_map.kind())?;
@@ -325,7 +325,7 @@ fn macro_expand_with_arg(
     if let Some(eager) = &loc.eager {
         if arg.is_some() {
             return ExpandResult::str_err(
-                "hypothetical macro expansion not implemented for eager macro".to_owned(),
+                "speculative macro expansion not implemented for eager macro".to_owned(),
             );
         } else {
             return ExpandResult {
index 1645ac53356acc27476da30172cf1ad73192f009..c83933c73d492258194b3f9811b585854e686fb7 100644 (file)
@@ -1026,7 +1026,7 @@ pub(crate) fn trait_environment_query(
     };
     if let Some(AssocContainerId::TraitId(trait_id)) = container {
         // add `Self: Trait<T1, T2, ...>` to the environment in trait
-        // function default implementations (and hypothetical code
+        // function default implementations (and speculative code
         // inside consts or type aliases)
         cov_mark::hit!(trait_self_implements_self);
         let substs = TyBuilder::type_params_subst(db, trait_id);
index 1ec59ff804d602f2f17e7f275e3bc87ed118e723..2f3fb17100fc112d68b2fd3c4c297bd327e23468 100644 (file)
@@ -196,46 +196,46 @@ pub(super) fn new(
         };
 
         let mut original_file = original_file.syntax().clone();
-        let mut hypothetical_file = file_with_fake_ident.syntax().clone();
+        let mut speculative_file = file_with_fake_ident.syntax().clone();
         let mut offset = position.offset;
         let mut fake_ident_token = fake_ident_token;
 
         // Are we inside a macro call?
         while let (Some(actual_macro_call), Some(macro_call_with_fake_ident)) = (
             find_node_at_offset::<ast::MacroCall>(&original_file, offset),
-            find_node_at_offset::<ast::MacroCall>(&hypothetical_file, offset),
+            find_node_at_offset::<ast::MacroCall>(&speculative_file, offset),
         ) {
             if actual_macro_call.path().as_ref().map(|s| s.syntax().text())
                 != macro_call_with_fake_ident.path().as_ref().map(|s| s.syntax().text())
             {
                 break;
             }
-            let hypothetical_args = match macro_call_with_fake_ident.token_tree() {
+            let speculative_args = match macro_call_with_fake_ident.token_tree() {
                 Some(tt) => tt,
                 None => break,
             };
-            if let (Some(actual_expansion), Some(hypothetical_expansion)) = (
+            if let (Some(actual_expansion), Some(speculative_expansion)) = (
                 ctx.sema.expand(&actual_macro_call),
                 ctx.sema.speculative_expand(
                     &actual_macro_call,
-                    &hypothetical_args,
+                    &speculative_args,
                     fake_ident_token,
                 ),
             ) {
-                let new_offset = hypothetical_expansion.1.text_range().start();
+                let new_offset = speculative_expansion.1.text_range().start();
                 if new_offset > actual_expansion.text_range().end() {
                     break;
                 }
                 original_file = actual_expansion;
-                hypothetical_file = hypothetical_expansion.0;
-                fake_ident_token = hypothetical_expansion.1;
+                speculative_file = speculative_expansion.0;
+                fake_ident_token = speculative_expansion.1;
                 offset = new_offset;
             } else {
                 break;
             }
         }
-        ctx.fill_keyword_patterns(&hypothetical_file, offset);
-        ctx.fill(&original_file, hypothetical_file, offset);
+        ctx.fill_keyword_patterns(&speculative_file, offset);
+        ctx.fill(&original_file, speculative_file, offset);
         Some(ctx)
     }
 
index 6453492151a6fa76d25b8b74c54d135ea2c37296..1152a985023fabb9605764275d7991d02c8a8a45 100644 (file)
 /// identifier prefix/fuzzy match should be done higher in the stack, together
 /// with ordering of completions (currently this is done by the client).
 ///
-/// # Hypothetical Completion Problem
+/// # Speculative Completion Problem
 ///
 /// There's a curious unsolved problem in the current implementation. Often, you
 /// want to compute completions on a *slightly different* text document.
 /// doesn't allow such "phantom" inputs.
 ///
 /// Another case where this would be instrumental is macro expansion. We want to
-/// insert a fake ident and re-expand code. There's `expand_hypothetical` as a
+/// insert a fake ident and re-expand code. There's `expand_speculative` as a
 /// work-around for this.
 ///
 /// A different use-case is completion of injection (examples and links in doc