Skip to content
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

Tuple Types #156

Closed
sezna opened this issue Aug 18, 2021 · 8 comments
Closed

Tuple Types #156

sezna opened this issue Aug 18, 2021 · 8 comments
Labels
big this task is hard and will take a while compiler General compiler. Should eventually become more specific as the issue is triaged enhancement New feature or request

Comments

@sezna
Copy link
Contributor

sezna commented Aug 18, 2021

Tuple types, as they behave in Rust, should exist in our language. This issue tracks the parsing, type-checking, and code generation of tuple types.

@sezna sezna added enhancement New feature or request compiler General compiler. Should eventually become more specific as the issue is triaged labels Aug 18, 2021
@emilyaherbert emilyaherbert self-assigned this Sep 21, 2021
@emilyaherbert
Copy link
Contributor

Attempting this one...

@sezna sezna added the big this task is hard and will take a while label Sep 22, 2021
@emilyaherbert
Copy link
Contributor

Writing up a plan of attack:

  1. Parsing. We will need to add support for n-ary tuple creation let tuple = (1,2,3,); as well as tuple access tuple.0 + tuple.1. This will involve adding a new test to the test cases and modify this (https://github.com/FuelLabs/sway/blob/master/core_lang/src/hll.pest. We will also need to add a case here:

    that parses the individual parts of the tuple and stores it in a new tuple variant:
    pub enum Expression<'sc> {

  2. Type checking. Type checking will require that we add a new case here:

    that checks the types of the individual parts of the tuple and creates a TypedExpression with a new tuple variant:

  3. Code generation. Code generation, I am a little lost as to how to begin. I know that I will need to add a new case here:

    but after that I am a little lost...

@sezna
Copy link
Contributor Author

sezna commented Sep 22, 2021

In addition to these, there's also dead code analysis on the tuple type to identify unused tuple fields.

I think tuple types should just be serialized inline in memory on the stack, where e.g. x.1 accesses the 0th offset from the pointer x, x.2 accesses *x + sizeof(x.1) (offset to the second item) etc.

Alternatively, we could store every tuple field in a separate register and treat tuples as syntactic sugar over simply having multiple variables. I personally think the former idea, rather than the latter, is a cleaner and more sensible implementation.

@sezna
Copy link
Contributor Author

sezna commented Sep 22, 2021

Also, if we use the pointer and inline memory approach, we could reuse structs for dead code analysis and code generation since structs do the exact same thing.

@emilyaherbert emilyaherbert linked a pull request Sep 22, 2021 that will close this issue
@otrho
Copy link
Contributor

otrho commented Sep 23, 2021

Alternatively, we could store every tuple field in a separate register and treat tuples as syntactic sugar over simply having multiple variables. I personally think the former idea, rather than the latter, is a cleaner and more sensible implementation.

We should use the most sensible (i.e., not prematurely optimised) approach IMO, because breaking things out into registers can be done if needed by optimisation passes later. So I agree with using the former.

@emilyaherbert emilyaherbert removed their assignment Oct 13, 2021
@emilyaherbert
Copy link
Contributor

@canndrew is this closed?

@sezna
Copy link
Contributor Author

sezna commented Jan 4, 2022

I think it could remain open until destructuring is complete? Since tuple fields are inaccessible as of now, the tuples feature isn't fully ready

@sezna
Copy link
Contributor Author

sezna commented Jan 13, 2022

Closing and opening a new issue, against my own words above ^

@sezna sezna closed this as completed Jan 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
big this task is hard and will take a while compiler General compiler. Should eventually become more specific as the issue is triaged enhancement New feature or request
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants