-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
Implements the Never !
types as a TypeInfo bottom type.
#5602
Conversation
1e3a257
to
f8ca1c7
Compare
We now parse the `!` as a TypeInfo::Never, and remove the usage of empty enums as Never type in our code. This commit removes completely the DeterministicallyAborts and TypeCheckUnificationContext. The DeterministicallyAborts can be removed because the Never TypeInfo is now propagated using the type checker. Code blocks that return, break, continue, or call an expression that returns Never, are marked as Never. Partially fixes #5562.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do so love PRs with negative line totals. Getting rid of all this complex logic in favor of a defined type is nice. The end result looks a lot cleaner.
But I'm about to ruin it by asking you to write some documentation for it.
!
is a fairly complex concept and the book should absolutely cover it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome!! Can you please check the questions regarding the coercion and equality on the IR level?
Also, assuming how crucial Never
is for the type system, I would expect new dedicated tests. E.g., testing coercion rules could be an example, having !
as a type in different positions, e.g., as a function parameter, etc.
BDW solving #5560 would be a great test of the new type system (as a separate PR of course). I wouldn't be surprised if the bug is no more reproducible on this branch 😄 |
@IGI-111 Completely agree about the need for the docs! But want to selfishly ask if the documentation could be a part of a separate PR if that will speed up the merge of this PR. I was doing changes in the |
Okay sure, if that blocks some other work we can split it into another PR. |
Added docs for Never type to the Sway book.
Added more coercion positive and negative tests. About the |
Benchmark for bb163e2Click to view benchmark
|
Benchmark for 057388cClick to view benchmark
|
e429daa
to
bd61bf7
Compare
Benchmark for d7eaee9Click to view benchmark
|
As it happens this issue blocks the one I'm currently working on, so it would be nice to have it merged asap. |
Benchmark for ae537d3Click to view benchmark
|
…#5631) ## Description Fixes #5616 and #5622. When generating the IR for constant and variable declarations the name being declared is not added to the local environment if the initializer cannot be compiled. This can happen when initializing a constant using a non-constant expression. Since the name isn't added to the environment, and since we attempt to continue compilation after an error, any attempt to use the name later in the code will cause the name to not be found, which in turn causes the IR converter to throw an ICE because it assumes that all used names are in scope. This PR fixes the issue by not throwing the initializer error until the name has been added to the environment. Note that 1. The initializer must be compiled before the name is added to the environment. The name should not be in scope during its own initialization. 2. #5602 is blocking a more elegant solution to this problem. The lack of a `Never` type means that the call to `convert_resolved_typeid` may fail if the initializer diverges, and since that call must be made before the new name can be added to the environment we check for termination first. The order of operations is therefore currently a) compile the initializer, then b) check that the initializer did not result in an error and did not diverge, then c) resolve the type of the name being declared, then d) add the name to the environment, and finally e) throw an error if the initializer resulted in an error. Once the `Never` type is introduced we can move the terminator check to the end of that sequence. ## Checklist - [x] I have linked to any relevant issues. - [x] I have commented my code, particularly in hard-to-understand areas. - [x] I have updated the documentation where relevant (API docs, the reference, and the Sway book). - [x] I have added tests that prove my fix is effective or that my feature works. - [x] I have added (or requested a maintainer to add) the necessary `Breaking*` or `New Feature` labels where relevant. - [x] I have done my best to ensure that my PR adheres to [the Fuel Labs Code Review Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md). - [x] I have requested a review from the relevant team or maintainers.
Description
We now parse the
!
as a TypeInfo::Never, and remove the usage of empty enums as Never type in our code.This commit removes completely the DeterministicallyAborts and TypeCheckUnificationContext.
The DeterministicallyAborts can be removed because the Never TypeInfo is now propagated using the type checker. Code blocks that return, break, continue, or call an expression that returns Never, are marked as Never.
Partially fixes #5562.
Checklist
Breaking*
orNew Feature
labels where relevant.