Skip to content

Conversation

CohenArthur
Copy link
Member

This adds a new visitor for visiting unique_ptr members and possibly reseating them, for example when desugaring a while-let loop to a regular loop expression.

I think we could use this for ExpandVisitor but it's not as easy since we also do cfg stripping in there, which may remove elements from vectors.

Also, I'm not sure if the name is right - I was debating between PointerVisitor, ReseatVisitor and ExternalVisitor. other ideas welcome

@powerboat9
Copy link
Collaborator

If we want to use this for ExpandVisitor (which I think would be a good idea) it'd have to have support for replacing nodes with 0 <= N other nodes, instead of just doing 1->1 mappings

@powerboat9
Copy link
Collaborator

Maybe add something like virtual void reseat_multi (std::vector<std::unique_ptr<AST::Expr>> &vec) {}?

@CohenArthur
Copy link
Member Author

CohenArthur commented Aug 18, 2025

Note that we'd also need some way to expand inner attributes which might be a little more difficult. I'd like to use this visitor for ExpandVisitor as well but it's proving a little difficult

@CohenArthur CohenArthur force-pushed the pointer-visitor branch 3 times, most recently from 9c57f7a to c883208 Compare August 25, 2025 14:31
gcc/rust/ChangeLog:

	* Make-lang.in: Compile it.
	* ast/rust-builtin-ast-nodes.h: Add missing methods for getting pointers.
	* ast/rust-expr.h: Likewise.
	* ast/rust-item.h: Likewise.
	* ast/rust-path.h: Likewise.
	* ast/rust-pattern.h: Likewise.
	* ast/rust-type.h: Likewise.
	* ast/rust-ast-pointer-visitor.cc: New file.
	* ast/rust-ast-pointer-visitor.h: New file.
gcc/rust/ChangeLog:

	* ast/rust-expression-yeast.cc (ExpressionYeast::dispatch): Rename to...
	(ExpressionYeast::reseat): ...this.
	(ExpressionYeast::visit): Remove.
	* ast/rust-expression-yeast.h: Inherit from PointerVisitor, override reseat instead
	of declaring dispatch.
@CohenArthur
Copy link
Member Author

actually I don't think we need anything with inner attributes, but we need to think about this since expanding multiple children may also delete nodes. for now I have something working where ExpandVisitor inherits from this so let's just keep it simple and see how we can improve it later on

@CohenArthur CohenArthur added this pull request to the merge queue Aug 26, 2025
Merged via the queue into Rust-GCC:master with commit 445fd35 Aug 26, 2025
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants