-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
## Description This PR fixes a problem with `std::Bytes`, `std::Vec` and `std::String` buffer ownership. It also fixes a problem with buffer overflow when encoding huge types. ## Buffer Ownership Currently, types like `Bytes`, `Vec` and `String` do not guarantee ownership of their buffer. That means that we can very easily alias the underlying buffer and change its mutability by simply creating a new instance. For example: ```sway let some_slice = ...; let buffer = Bytes::from(some_slice); let mut buffer2 = buffer.clone(); // Now I can change `some_slice` ``` ## Type Inference bug I also had to fix a small problem with the type inference of method applications. The problem is that sometimes the type check does not return an error on the first pass, but the type is still not concrete. For example `x.get(0) == Some(2)`, becomes `eq(x.get(0), Some(2))`. After the first pass, `x.get(0)` is correctly inferred to be `Option<u8>`; but `Some(2)` is only typed as `Option<Numeric>`. This happens because the first pass starts with `TypeInfo::Unknown`. We can use the argument types here because they may still be non-concrete types like "Self". What the fix is doing is that it checks if the inferred type `is_concrete`, assuming that `Numeric` is not. This will make "Some(2)" be type-checked again at the second pass, after monomorphization and be correctly typed as "Option<u8>". ## IR Verification errors This PR also improves the error message for IR verification. Now the error is shown inside the printed IR.  ## Script to update contract-ids (optional) At `test/update-contract-ids.sh` there is a small script that automatically updates contract ids. Unfortunately, given the indirect nature of contract calls, it is impossible for the script to know which contract it needs to compile. So we need to specify the path to the contract. We also need to pass the compiler flags, because in some cases we use `debug` profile, and in others we use `release`. ```sway const FUEL_COIN_CONTRACT_ID = 0x1a88d0982d216958d18378b6784614b75868a542dc05f8cc85cf3da44268c76c; // AUTO-CONTRACT-ID ../../test_contracts/test_fuel_coin_contract --release ``` In the example above, the path and flags are appended in the bash script. I failed trying to inject commands, so I think the append is safe. I can remove this from the PR, if we find that this is not the solution we want at the moment. ## Checklist - [ ] I have linked to any relevant issues. - [ ] I have commented my code, particularly in hard-to-understand areas. - [ ] I have updated the documentation where relevant (API docs, the reference, and the Sway book). - [ ] If my change requires substantial documentation changes, I have [requested support from the DevRel team](https://github.com/FuelLabs/devrel-requests/issues/new/choose) - [ ] I have added tests that prove my fix is effective or that my feature works. - [ ] I have added (or requested a maintainer to add) the necessary `Breaking*` or `New Feature` labels where relevant. - [ ] 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). - [ ] I have requested a review from the relevant team or maintainers.
- Loading branch information
Showing
33 changed files
with
644 additions
and
210 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.