Remove pointers from the Sway IR. #3663
Merged
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.
Argh, this is hard
This is the result of several attempts (made over several weeks) to attack #2819 and is only the very first stage.
Aggregate
andextract_value
/insert_value
, replacing them with proper pointer types and GEP. This was great, but was too hard to make work with the ASM generation. There are too many assumptions around reference types vs copy types and what is a 'pointer' or not for a change like this to go in yet.The problem
get_ptr
was a bit nasty, as we use it to get the address of locals, but also to cast them to different types and also to index, a bit like GEP will.Also, using
Pointer
forref mut
function args was a mistake as they were designed only for local variables.Solution
This PR does as little as possible. The baby steps approach is absolutely required for this task and this is the first one.
To remove any ambiguity around how pointers should work this PR removes them altogether from IR, as they were actually not strictly doing anything. In particular it removes
Pointer
fromType
andget_ptr
is nowget_local
which is actually what 'pointers' were.We will re-introduce pointers as actual types in an upcoming PR.
So now we have
get_local
which does nothing more than get a local variable address. Casting and indexing has been shunted to a newcast_ptr
instruction as a stopgap. When we introduce GEP we can removecast_ptr
, or at least formalise it into a better/general cast.This PR also uses the newer quad storage operations which support multiple slots, so the
get_ptr
-style indexing isn't actually required AFAICT.Future stages
Type
into an arena and removeAggregate
. This is another ambiguity around 'reference types' which needs to be removed. The IR should not have any concept of copy types or reference types. This is a Sway thing and isn't portable to different back-ends.Pointer
as an actualType
. This will let us be explicit and strict about memory accesses and genuinely remove the notion of 'reference types'. We should consider opaque pointers as an alternative to pointer casting, which is required for dealing with storage slots and arrays ofb256
s.extract_value
andinsert_value
with GEP.