]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Reinject Self parameter in new resolver
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Wed, 7 Feb 2024 11:51:28 +0000 (12:51 +0100)
committerP-E-P <32375388+P-E-P@users.noreply.github.com>
Tue, 26 Mar 2024 17:35:02 +0000 (17:35 +0000)
The old resolver injected a Self generic parameter in order to help the
trait solver. This is clearly sketchy at best and should be fixed in
the future.

gcc/rust/ChangeLog:

* resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit): Add
Self generic parameter injection and a warning.
* resolve/rust-toplevel-name-resolver-2.0.h: Add function prototype.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h

index f65ec77331ceb5ddce2de7b1e3c5d857b92c264b..80b142678b95e0f4f1e160e90d253492402f41b8 100644 (file)
@@ -186,6 +186,29 @@ TopLevel::visit (AST::Module &module)
     Analysis::Mappings::get ()->insert_ast_module (&module);
 }
 
+void
+TopLevel::visit (AST::Trait &trait)
+{
+  // FIXME: This Self injection is dodgy. It even lead to issues with metadata
+  // export in the past (#2349). We cannot tell appart injected parameters from
+  // regular ones. Dumping generic parameters highlights this Self in metadata,
+  // during debug or proc macro collection. This is clearly a hack.
+  //
+  // For now I'll keep it here in the new name resolver even if it should
+  // probably not be there. We need to find another way to solve this.
+  // Maybe an additional attribute to Trait ?
+  //
+  // From old resolver:
+  //// we need to inject an implicit self TypeParam here
+  //// FIXME: which location should be used for Rust::Identifier `Self`?
+  AST::TypeParam *implicit_self
+    = new AST::TypeParam ({"Self"}, trait.get_locus ());
+  trait.insert_implict_self (
+    std::unique_ptr<AST::GenericParam> (implicit_self));
+
+  DefaultResolver::visit (trait);
+}
+
 template <typename PROC_MACRO>
 static void
 insert_macros (std::vector<PROC_MACRO> &macros, NameResolutionContext &ctx)
index f5e224fa04996178d89a52c6dd32618357cbf381..e226c79dfbcdffe6896612bced87f4a21cd79a88 100644 (file)
@@ -88,6 +88,7 @@ private:
   std::unordered_map<NodeId, NodeId> node_forwarding;
 
   void visit (AST::Module &module) override;
+  void visit (AST::Trait &trait) override;
   void visit (AST::MacroRulesDefinition &macro) override;
   void visit (AST::Function &function) override;
   void visit (AST::BlockExpr &expr) override;