-
Notifications
You must be signed in to change notification settings - Fork 17
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
Why access the heap... #68
Comments
Heh, you aren't missing anything. This is exactly what we don't allow with "const heap". The "const heap" only exists at compile-time. All such "heap" values will get turned into static allocations. There will be no automatic conversion between compile time heap values and runtime heap values. Instead you have to use some form of cloning or "to_owned" to get a runtime copy that you have ownership of. The reason we want a heap at compile-time is that we don't want to limit people to ArrayVec, but want you to be able to "just" use a Vec, as long as you don't end up with a |
Thanks. Per your example, I would think that I suppose a more correct treatment might be...
I wonder how feasible it is to simply convert dynamic types to their constant equivalent when they are assigned to |
this would work out of the box, the big question is how we differentiate between the "bad" and the "good" constants. how do we prevent the user from having a |
I think you might have solved it. Namely, simply restrict the types that may be I suppose the trait system could be used to classify
|
well, we discussed this to death in #20 and https://rust-lang.zulipchat.com/#narrow/stream/146212-t-compiler.2Fconst-eval/topic/Questions.20regarding.20Heap.20allocation.20in.20const.20eval/near/216632678 and there are problems with a lot of designs that we came up with. I forget what the current status is. Someone was working on experimenting with it, but life happened. We do need |
My skim of the discussion discovered In my view, Since the permissible types of The evaluation of the code constructing the |
String is fixed size, it's a pointer and two integers, the problem is that it is !Copy and will thus be moved without cloning.
we could try to come up with an unsafe "constify trait" that offers a method that is called before giving you access, but I don't see how we can do that backwards compatilby. users can already define their own types and put them into constants |
The mutability of On a separate note, the library available to
|
I'm going to close this issue. Thanks for keeping the discussion out of the main issue, that issue is clogged enough already. |
Still a newbie so bear with me...
Not sure why heap access is necessary or even desirable for
const
andstatic
's values. That they are binary embedded values seems like a very tight abstraction where compile time evaluation is merely another way to building such values (byte patterns) as part of the binary construction process. In particular, alignment and other runtime constraints aren't truly relevant but if they are they can be easily accommodated by dedicated code. For instance, converting abyte array
to ani64
can have code to align on construction or conversion since both the value and the shape of the result are known. Ultimately, the heap, stack, and registers are strictly runtime resources and making them otherwise complicates the load, align, and execute at entry point abstraction. It also doesn't make sense in terms of libraries for it to somehow populate the heap at load time. However, I may be missing something...Additionally, when
const
andstatic
's only affect the binary then what they can do in generating results becomes conceptually unlimited only by time and security considerations, though all such constructed values must now be access by reference. Interestingly,static mut
becomes a possible way to have self modifying binaries.The text was updated successfully, but these errors were encountered: