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

Improve strings for IR. #1113

Merged
merged 3 commits into from Mar 31, 2022
Merged

Improve strings for IR. #1113

merged 3 commits into from Mar 31, 2022

Conversation

otrho
Copy link
Contributor

@otrho otrho commented Mar 30, 2022

This was one of the final tasks on my list and now we're yet again passing E2E with IR.

I've decided to just represent strings as Vec<u8> in the IR, there's no point in trying to get tricky with UTF-8 support. UTF-8 strings will still 'work', but in IR they're serialised with escaped hex representation.

I also updated the serialiser so it doesn't write out constants which are re-used more than once. And I changed the syntax for unions to be less ambiguous.

Print any const args to `extract_value` and only print const values once
ever.
It used to be `{ ty0 | ty1 | ... }` but a single variant union would
just be `{ ty }`.  This is indistinguishable from a single field struct
or tuple so now it's `( ty0 | ty1 | ... )`.
Assume that strings are always used by reference and so their stack size
will always be that of one word.

IR treats strings as a vector of bytes to avoid UTF-8 trickiness.  They
may still be UTF-8 strings of course, but the IR doesn't care either
way.
@otrho otrho added bug Something isn't working enhancement New feature or request compiler General compiler. Should eventually become more specific as the issue is triaged compiler: ir IRgen and sway-ir including optimization passes labels Mar 30, 2022
@otrho
Copy link
Contributor Author

otrho commented Mar 30, 2022

Hrmm, looking at the diff myself and thinking the new union syntax could be confused with unit. It's all working at the moment, so () must be parsed as unit rather than an empty union... which I think is OK, but we might need to explicitly ban empty unions. They'd only come from an enum with no variants, which is not possible..?

Copy link
Contributor

@mohammadfawaz mohammadfawaz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems reasonable!

@otrho otrho merged commit 4bbccc4 into master Mar 31, 2022
@otrho otrho deleted the otrho/improve_strings_for_ir branch March 31, 2022 00:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working compiler: ir IRgen and sway-ir including optimization passes 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 this pull request may close these issues.

None yet

2 participants