Skip to content

Replace syntax::opt_vec with syntax::owned_slice #13016

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

Merged
merged 3 commits into from
Mar 22, 2014

Conversation

huonw
Copy link
Member

@huonw huonw commented Mar 19, 2014

Replace syntax::opt_vec with syntax::owned_slice

The owned_slice::OwnedSlice is (*T, uint) (i.e. a direct equivalent to DSTs ~[T]).

This shaves two words off the old OptVec type; and also makes substituting in other implementations easy, by removing all the mutation methods. (And also everything that's very rarely/never used.)

@huonw
Copy link
Member Author

huonw commented Mar 19, 2014

(I'll rebase later.)

@cmr a mem-bench of this would be cool too (after I rebase, of course).

@emberian
Copy link
Member

bench

Tiny win.

@alexcrichton
Copy link
Member

Could we just use Vec instead of OptVec for now, and then move towards ~[T] once DST lands?

@huonw
Copy link
Member Author

huonw commented Mar 20, 2014

I was thinking that having a type exposing only the operations that ~[T] will have will make doing the conversion much easier, and also allow us to have a library version of ~[] that's a word smaller.

@alexcrichton
Copy link
Member

I'm not a big fan of having large amounts of transitionary code lying around. This doesn't actually give us the benefits of a 2-word vector as opposed to a 3-word vector, so why not just deal with the migration later?

Migrating libsyntax/librustc to using ~[T] is a very small concern, it's the standard library that's going to be the one that will need much though.

@huonw
Copy link
Member Author

huonw commented Mar 20, 2014

I solved my segfaulting issues (#13032 :/ ) and have just pushed a version that is only 2 words. It uses a small(-ish) amount of unsafe code, but I've tried to keep it well contained, and comment the non-obvious things. In any case, there is not much of this transitionary code at all: the diff stat is negative.

If this is approved I'll squash (and rebase, etc).

Migrating libsyntax/librustc to using ~[T] is a very small concern, it's the standard library that's going to be the one that will need much though.

I don't understand what you mean by the standard library "needing much ~[T]"?

Also, as @cmr's mem-bench demonstrated, even shaving one word off this type apparently saves ~100 MB (and with this extra word removed that saving will presumably double), which I think is a reasonably large concern, given how memory hungry rustc is and the fact this is a nearly -10% reduction.

(@cmr another mem-bench?)

@emberian
Copy link
Member

bench

@emberian
Copy link
Member

ignore everything after ~50s, accidentally had an --emit asm in there (so it took forever doing codegen and then writing out the ~120MB asm file)

This is the first step to replacing OptVec with a new representation:
remove all mutability. Any mutations have to go via `Vec` and then make
to `OptVec`.

Many of the uses of OptVec are unnecessary now that Vec has no-alloc
emptiness (and have been converted to Vec): the only ones that really
need it are the AST and sty's (and so on) where there are a *lot* of
instances of them, and they're (mostly) immutable.
if self.data.is_null() { return }

// zero self
let v = mem::replace(self, OwnedSlice::empty());
Copy link
Member

Choose a reason for hiding this comment

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

You don't need to do this, it happens automatically. The null check is all you have to do.

Copy link
Member Author

Choose a reason for hiding this comment

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

I know it happens automatically in general, but this will make it still correct when we stop zeroing everything.

Copy link
Contributor

Choose a reason for hiding this comment

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

Zeroing in the destructor won't necessarily be seen from locations it was moved from anyway. If we stop zeroing, it will mean Rust needs to statically prevent a call if a type was ever possibly moved from.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, wait; I was wrong. The replace here is to be able to call the by-value .into_vec function.

Copy link
Member Author

Choose a reason for hiding this comment

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

(Updated the comment to remove the reference to zeroing)

This is a stand-in until we have a saner `~[T]` type (i.e. a proper
owned slice). It's a library version of what `~[T]` will be, i.e. an
owned pointer and a length.
syntax::opt_vec is now entirely unused, and so can go.
bors added a commit that referenced this pull request Mar 22, 2014
Replace syntax::opt_vec with syntax::owned_slice

The `owned_slice::OwnedSlice` is  `(*T, uint)` (i.e. a direct equivalent to DSTs `~[T]`).

This shaves two words off the old OptVec type; and also makes substituting in other implementations easy, by removing all the mutation methods. (And also everything that's very rarely/never used.)
@bors bors closed this Mar 22, 2014
@bors bors merged commit e33676b into rust-lang:master Mar 22, 2014
@huonw huonw deleted the new-opt-vec branch December 4, 2014 02:03
lnicola pushed a commit to lnicola/rust that referenced this pull request Aug 16, 2022
…kril

Move VSCode diagnostics workaroudn into client code
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.

6 participants