Skip to content

Create LocalVariable#3862

Merged
philberty merged 1 commit into
Rust-GCC:masterfrom
powerboat9:reduce-ptr
Nov 13, 2025
Merged

Create LocalVariable#3862
philberty merged 1 commit into
Rust-GCC:masterfrom
powerboat9:reduce-ptr

Conversation

@powerboat9

Copy link
Copy Markdown
Collaborator

This should make it easier for us to move away from leaking pointers to Bvariable everywhere. Since LocalVariable has a single field of type tree, it should be the same size as a pointer to Bvariable, making the switch to LocalVariable wherever possible strictly an improvement.

This should make it easier for us to move away from leaking pointers to
Bvariable everywhere. Since LocalVariable has a single field of type
tree, it should be the same size as a pointer to Bvariable, making the
switch to LocalVariable wherever possible strictly an improvement.

gcc/rust/ChangeLog:

	* backend/rust-compile-expr.cc (CompileExpr::visit): Implicitly
	convert LocalVariable to pointer to Bvariable.
	* rust-backend.h (local_variable): Return LocalVariable.
	(parameter_variable): Likewise.
	(static_chain_variable): Likewise.
	(temporary_variable): Likewise.
	* rust-gcc.cc (local_variable): Likewise.
	(parameter_variable): Likewise.
	(static_chain_variable): Likewise.
	(temporary_variable): Likewise.
	(LocalVariable::get_tree): New function.
	(LocalVariable::error_variable): Likewise.
	* rust-gcc.h (class LocalVariable): New class.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
@powerboat9

powerboat9 commented Jun 28, 2025

Copy link
Copy Markdown
Collaborator Author

I have a patch which converts Bvariable * to Bvariable/tl::optional<Bvariable> ~everywhere, but it touches a lot of files and breaks something, so I figure I'll start small.

Comment thread gcc/rust/rust-gcc.cc
{
*pstatement = error_mark_node;
return Bvariable::error_variable ();
return LocalVariable::error_variable ();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a fan of error state hidden within a single class. Couldn't we return an Expected<LocalVariable> ?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably, though I'd like to leave that for another PR

@philberty philberty left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm not quite sure what the point of this is for. the variable magic here. The get_tree call handles this wierd case I would be almost more interested in seeing if we even need that transmute in he Bvariable get tree at all or rename Bvariable entirely to Variable or something not sure why go went with Bvariable as a naming convention but it was great for bootstrapping this frontend.

Or we should really go through the rust-gcc wrapper and get rid of all the stuf we arent using which i am pretty sure is a fair bit now there were bugs in there that was annoying to find recently like build array type

@powerboat9

Copy link
Copy Markdown
Collaborator Author

I'd think it would make sense to merge this as-is, as it seems like a good stepping stone towards removing Bvariable and addresses some memory leaks.

@philberty philberty left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright in the spirit if moving to a better memory management lets merge it.

@philberty philberty added this pull request to the merge queue Nov 13, 2025
Merged via the queue into Rust-GCC:master with commit 87936c8 Nov 13, 2025
13 checks passed
@powerboat9 powerboat9 deleted the reduce-ptr branch November 13, 2025 23:42
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.

3 participants