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
Get rid of integer allocation #189
Comments
We can't remove the ZST allocation. If we did, we might have accidential conversions from integers to.zst pointers. I don't think it's much of an issue: zst pointers aren't handled specially as muh as integer pointers. Wrt the naming: I think we should turn primval into two nested enums, the |
So |
You may rename PrimDef to anything you want ;) MaybeVal? |
With Option it'll get messy since I think we do have some |
If we were doing this from scratch, I'd probably call the current PrimDef |
We don't use "variable" in MIR terminology for all locals. MIR trans would call it |
I see. EDIT: My point here is that the |
Local can be renamed to LocalId |
There's a reason MIR trans uses the |
Where |
The former, if I'm reading you right. It looks like it was borrowed from LLVM but it doesn't make much sense because there it's used in the C API for the types that are pointers to the C++ classes. |
By "the thing identifying a local", I mean the integer which is an index into the list of locals. From the name, that's also what I expect a That is, assuming it is even worth renaming this stuff. That's why I said "if we started from scratch" above. ;) |
Oh, no, |
Oh. That's odd naming to me... it's not a reference to a local then. I suppose they mean that it's the referent of a local. |
No it literally is cargo-culting the LLVM C API, because a SSA value is |
I don't think we need the *Ref naming scheme in miri. Let's just stay with |
Also I think renaming everything in a more sensible manner is fine. We do have RLS so any renaming should be trivial to do. |
(it's not like most renaming isn't just a multi-file regex replacement - I do those in my editor often) That scheme doesn't work for things like |
What do you mean? There's no need to rename rustc types. Also lvalue is not an ID. |
If you already have |
Uhm we don't. I got it confused with |
ah, right, |
We can't separate |
What's wrong with |
You might be able to do shenigans that end up reading it. But I can't think of any off the top of my head. |
Is that discussion available anywhere? I am asking because that would have been my suggestion: Make ZSTs always |
That was on IRC in rust-internals. search the log for eddyb saying undef I think |
Do you remember a rough date? I have no idea whether I am looking for something that happened a month ago or a year ago. A brief search of the git history didn't turn up anything. |
I have no clue. I can look in my local logs. But it was something about how zsts should never be read from anyway, so undef as zst makes more sense than a special zst value. But moving to byref to the zst alloc sounds good. |
Yeah the point is that the representation doesn't matter not that we should pick a specific one. |
It matters insofar as we better be sure that any attempt to observe it throws an error. ;)
Now you got me confused. Didn't you say above that this is how things used to be, and then they were changed, probably for a reason? |
Yea it was changed. But I think that was part of other changes that were easier with that change happening, too |
So some other things will get harder if we go back to "ZSTs are always ByRef"? |
Yes. We'll have problems with |
I've done some work in this direction: oli-obk@e59ff23 still has some problems, since the pointers in lvalue need to be able to store integers, too. |
When does that arise? Sounds like an invalid lvalue to me, couldn't that error out instantaneously? |
So you didn't end up even using a type that's just "Bytes or Ptr". Is handling the additional Undef case a problem anywhere? |
Not yet. It might even be better to include it in some situations, because dereferencing and immediately referencing a pointer with undef value should fine |
You mean like so? fn main() {
let x : *const i32 = unsafe { mem::uninitialized() };
let y = unsafe { &*x };
} So you are saying, |
Yes |
Sounds reasonable. So the |
@eddyb mentioned that there are plans to get rid of the integer allocation (
NEVER_ALLOC_ID
). This is an attempt to summarize briefly what the plan is, and to document that such a plan exists. (I suppose the "refactor" label would make sense here?)The idea is to change the "meaning" of the type
Pointer
to "pointers that actually point somewhere in memory". Every operation that also works on pointers obtained from integers should use a different type. They could either usePrimVal
(but then these methods all have to handleundef
...), or a new type that factors thePointer
andBytes
cases out ofPrimVal
, but cannot beUndef
.ptr-to-int-cast and their inverse literally become a noop on the data side. There is no longer any need to perform "normalization" in
binary_op
because all data now has a canonical representation. (The memory already does something like this, somewhat, by not adding any relocations when a pointer from the integer allocation is written to memory.)Open questions:
Pointer
or just bytes have?PrimDefVal
? I'm not good with names...The text was updated successfully, but these errors were encountered: