Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivations
For the interpreter I'm writing at https://github.com/soteria-tools/soteria, I need to special case
Literal::Strquite heavily, since a string is not "just" a literal, but rather a reference to an allocation containing a string; this means that aLiteral::Stractually hides an allocation, unlike all other literals.It would be nice if the representation of strings was less fake in some way, by making the existence of this allocation and reference clearer.
This PR
Add a
--string-globalsflag, that removes all string literals and replaces them with a reference to a array ofu8. More precisely, the following substitution happens:into
Right now the
arrvalue is defined using aRawConstantExpr::RawMemory, for a more compact representation; in a previous commit I did it with an array aggregate, but that is much more verbose and less compact.Another option I haven't done, that may be better, is that we decide that when
--string-globalsis toggled,Literal::Strdoesn't represent a&strbut astr(or rather, a[u8; N], whereNis the length of the string). This makes the [U]LLBC more readable and is a more compact representation, but it means we have a value that has two meanings depending on a flag, which is maybe not ideal.Let me know what you think; I'm happy to change this as needed :)
A last option is that we just change the meaning of
Literal::Strto be the actual[u8]behind it, and we convert allLiteral::Strs toConstantExpr::Ref(ConstantExpr(Literal::Str)); however that means you have locals storing thestr, which is an unsized type, so that doesn't work.