Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Address more comments from #226. #253

Merged
merged 2 commits into from
Feb 22, 2021
Merged

Address more comments from #226. #253

merged 2 commits into from
Feb 22, 2021

Conversation

ptersilie
Copy link
Contributor

A quick PR addressing comments from the audit (#226), so I don't loose track of what I've fixed and what not.

@@ -409,6 +409,7 @@ impl TraceCompiler {
self.stack_builder.alloc(ty.size(), ty.align())
}

/// Implements the StorageLive statement, assigning a Location the local.
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure how to parse this sentence.

Copy link
Contributor

Choose a reason for hiding this comment

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

How about:

Called when a local variable becomes live. The register allocator is invoked to make storage space for the local.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Which part is the problem? This basically tells the compiler a variable is live and assigns it a register or location on the stack. How about: Implements a local going live, assigning it to a register or, if no registers are free, to a location on the stack.

Copy link
Contributor

Choose a reason for hiding this comment

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

@vext01 I think, in general, more active descriptions are clearer.

@Lukasd Words like "implements" feel a bit like padding. I'm also not sure what "a local going live" exactly means.

Taking those thoughts together, would something like "Assign a Location to a StorageLive (i.e. finding it a register or space on the stack)." be accurate? Maybe too terse?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

StorageLive is a MIR statement, so saying we assign a location to it, doesn't sound right. We are assigning a location to the local that MIR has decided is live from that point onwards until we see a StorageDead for it.

Copy link
Contributor

Choose a reason for hiding this comment

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

It means that we don't strictly have to allocate a local until its first use, and could in fact remove the function in question altogether.

It might result in better allocation results overall. Consider the following:

live($1)
if (...) {
   $1 = call foo(...)
   call blah($1)
} else {
  // don't use $1
}

If we trace the else branch, then right now, then the trace would allocate space for, but never use $1. In other words, it could potentially block another variable from using a register.

If we allocate on first use, we wouldn't allocate $1 at all (in this trace), leaving it free for other locals.

But, I don't know if MIR would generate code like this...

Another question I then have is, if we don't allocate eagerly, what is the purpose of StorageLive in our bytecode?

Copy link
Contributor

Choose a reason for hiding this comment

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

Lukas and I raced, but agreed.

So perhaps StorageDead is useful for #243. But then again, we could just consider the first use of a variable as its birth?

Copy link
Contributor

Choose a reason for hiding this comment

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

I have no idea so I'm relying on you two to work this out :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

live($1)
if (...) {
   $1 = call foo(...)
   call blah($1)
} else {
  // don't use $1
}

I don't know why MIR wouldn't put the live($1) in the same block where it's assigned and used, but you never know. Although a quick test on Rust Playground seems to confirm this suspicion (which again doesn't mean MIR always does this).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 88f0a69 and a7b7aee.

@ptersilie
Copy link
Contributor Author

Ready for re-review.

@ltratt
Copy link
Contributor

ltratt commented Feb 19, 2021

If @vext01 is OK with a7b7aee then please squash.

@vext01
Copy link
Contributor

vext01 commented Feb 19, 2021

Go ahead.

@ptersilie
Copy link
Contributor Author

Squashed.

@ltratt
Copy link
Contributor

ltratt commented Feb 22, 2021

bors r+

@bors
Copy link
Contributor

bors bot commented Feb 22, 2021

Build succeeded:

@bors bors bot merged commit 5e18065 into ykjit:master Feb 22, 2021
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.

4 participants