Skip to content

Commit

Permalink
Merge branch 'master' into xunilrj/fix-subs-type
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaBatty authored Sep 11, 2024
2 parents 918612a + 11d8f54 commit ee5c7bc
Show file tree
Hide file tree
Showing 59 changed files with 1,568 additions and 153 deletions.
16 changes: 7 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -478,14 +478,11 @@ jobs:
toolchain: ${{ env.RUST_VERSION }}
- uses: Swatinem/rust-cache@v2

- name: Install cargo-deps
run: cargo install cargo-deps

# We require this check to avoid cyclic dependencies between 'fuels' and 'forc-pkg'.
# Detailed explanation is found in the echo below.
- name: Check 'forc-pkg' dependencies for 'fuels' crates
run: |
deps=$(cargo deps --manifest-path forc-pkg/Cargo.toml)
deps=$(cargo tree --manifest-path forc-pkg/Cargo.toml)
case "$deps" in
*fuels*)
Expand Down Expand Up @@ -544,15 +541,16 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install toolchain
uses: dtolnay/rust-toolchain@master
- name: Setup Rust and cargo-nextest
uses: moonrepo/setup-rust@v0
with:
toolchain: ${{ env.RUST_VERSION }}
- uses: Swatinem/rust-cache@v2
channel: stable
cache-target: release
bins: cargo-nextest
- name: Run sway-lsp tests sequentially
env:
RUST_BACKTRACE: full
run: cargo test --locked --release -p sway-lsp -- --nocapture --test-threads=1
run: cargo nextest run --locked --release -p sway-lsp --no-capture --profile ci --config-file sway-lsp/tests/nextest.toml
cargo-test-workspace:
runs-on: ubuntu-latest
steps:
Expand Down
24 changes: 16 additions & 8 deletions docs/book/src/lsp/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,13 @@ _Source:_ [completion.rs](https://github.com/FuelLabs/sway/blob/master/sway-lsp/

Suggests code to follow partially written statements for functions and variables.

## Diagnostics

_Source:_ [diagnostic.rs](https://github.com/FuelLabs/sway/blob/master/sway-lsp/src/capabilities/diagnostic.rs)

Displays compiler warnings and errors inline.
## Go to Definition

## Syntax Highlighting
Jumps to the definition of a symbol from its usage.

_Source:_ [highlight.rs](https://github.com/FuelLabs/sway/blob/master/sway-lsp/src/capabilities/highlight.rs)
## Find All References

Highlights code based on type and context.
Locates all occurrences of a symbol throughout the project.

## Hover

Expand All @@ -42,6 +38,18 @@ _Source:_ [rename.rs](https://github.com/FuelLabs/sway/blob/master/sway-lsp/src/

Renames a symbol everywhere in the workspace.

## Diagnostics

_Source:_ [diagnostic.rs](https://github.com/FuelLabs/sway/blob/master/sway-lsp/src/capabilities/diagnostic.rs)

Displays compiler warnings and errors inline.

## Syntax Highlighting

_Source:_ [highlight.rs](https://github.com/FuelLabs/sway/blob/master/sway-lsp/src/capabilities/highlight.rs)

Highlights code based on type and context.

## Run

_Source:_ [runnable.rs](https://github.com/FuelLabs/sway/blob/master/sway-lsp/src/capabilities/runnable.rs)
Expand Down
23 changes: 16 additions & 7 deletions docs/book/src/testing/testing-with-rust.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,21 @@ Let's have a look at the result:
$ tree .
├── Cargo.toml
├── Forc.toml
├── build.rs
├── src
│   └── main.sw
└── tests
└── harness.rs
```

We have two new files!
We have three new files!

- The `Cargo.toml` is the manifest for our new test harness and specifies the
required dependencies including `fuels` the Fuel Rust SDK.
- The `tests/harness.rs` contains some boilerplate test code to get us started,
though doesn't call any contract methods just yet.
- The `build.rs` is a build script that compiles the Sway project with `forc build`
whenever `cargo test` is run.

### 4. Build the forc project

Expand All @@ -111,6 +114,7 @@ $ tree
├── Cargo.toml
├── Forc.lock
├── Forc.toml
├── build.rs
├── out
│   └── debug
│   ├── my-fuel-project-abi.json
Expand Down Expand Up @@ -176,10 +180,13 @@ following:
```rust,ignore
use fuels::{prelude::*, types::ContractId};
// Load ABI from JSON
abigen!(TestContract, "out/debug/my-fuel-project-abi.json");
// Load abi from json
abigen!(Contract(
name = "MyContract",
abi = "out/debug/my-fuel-project-abi.json"
));
async fn get_contract_instance() -> (TestContract, ContractId) {
async fn get_contract_instance() -> (MyContract<WalletUnlocked>, ContractId) {
// Launch a local network and deploy the contract
let mut wallets = launch_custom_provider_and_get_wallets(
WalletsConfig::new(
Expand All @@ -188,8 +195,10 @@ async fn get_contract_instance() -> (TestContract, ContractId) {
Some(1_000_000_000), /* Amount per coin */
),
None,
None,
)
.await;
.await
.unwrap();
let wallet = wallets.pop().unwrap();
let id = Contract::load_from(
Expand All @@ -202,11 +211,11 @@ async fn get_contract_instance() -> (TestContract, ContractId) {
),
)
.unwrap()
.deploy(&wallet, TxParameters::default())
.deploy(&wallet, TxPolicies::default())
.await
.unwrap();
let instance = TestContract::new(id.to_string(), wallet);
let instance = MyContract::new(id.clone(), wallet);
(instance, id.into())
}
Expand Down
6 changes: 3 additions & 3 deletions forc-plugins/forc-client/proxy_abi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

This folder contains pre-built version of the owned proxy contract, its abi and `storage-slots.json` file.

*contract url*: [sway-standard-implementation/src-14/owned_proxy](https://github.com/FuelLabs/sway-standard-implementations/tree/61fd4ad8f69d21cec0d5cd8135bdc4495e0c125c).
*commit hash*: `61fd4ad8f69d21cec0d5cd8135bdc4495e0c125c`
*forc version*: `v0.63.3`
*contract url*: [sway-standard-implementation/src-14/owned_proxy](https://github.com/FuelLabs/sway-standard-implementations/tree/174f5ed9c79c23a6aaf5db906fe27ecdb29c22eb).
*commit hash*: `174f5ed9c79c23a6aaf5db906fe27ecdb29c22eb`
*forc version*: `v0.63.5`
*build command*: `forc build --release`
4 changes: 2 additions & 2 deletions forc-plugins/forc-client/proxy_abi/proxy_contract-abi.json
Original file line number Diff line number Diff line change
Expand Up @@ -713,12 +713,12 @@
{
"name": "INITIAL_TARGET",
"concreteTypeId": "0d79387ad3bacdc3b7aad9da3a96f4ce60d9a1b6002df254069ad95a3931d5c8",
"offset": 13616
"offset": 13368
},
{
"name": "INITIAL_OWNER",
"concreteTypeId": "192bc7098e2fe60635a9918afb563e4e5419d386da2bdbf0d716b4bc8549802c",
"offset": 13568
"offset": 13320
}
]
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
[
{
"key": "35fa5b7532d53cf687e13e3db014eaf208c5b8c534ab693dd7090d5e02675f3e",
"key": "7bb458adc1d118713319a5baa00a2d049dd64d2916477d2688d76970c898cd55",
"value": "0000000000000000000000000000000000000000000000000000000000000000"
},
{
"key": "35fa5b7532d53cf687e13e3db014eaf208c5b8c534ab693dd7090d5e02675f3f",
"key": "7bb458adc1d118713319a5baa00a2d049dd64d2916477d2688d76970c898cd56",
"value": "0000000000000000000000000000000000000000000000000000000000000000"
},
{
"key": "7bb458adc1d118713319a5baa00a2d049dd64d2916477d2688d76970c898cd55",
"key": "bb79927b15d9259ea316f2ecb2297d6cc8851888a98278c0a2e03e1a091ea754",
"value": "0000000000000000000000000000000000000000000000000000000000000000"
},
{
"key": "7bb458adc1d118713319a5baa00a2d049dd64d2916477d2688d76970c898cd56",
"key": "bb79927b15d9259ea316f2ecb2297d6cc8851888a98278c0a2e03e1a091ea755",
"value": "0000000000000000000000000000000000000000000000000000000000000000"
}
]
]
Binary file modified forc-plugins/forc-client/proxy_abi/proxy_contract.bin
Binary file not shown.
7 changes: 3 additions & 4 deletions forc-plugins/forc-client/src/op/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,7 @@ async fn deploy_new_proxy(
) -> Result<ContractId> {
fuels::macros::abigen!(Contract(
name = "ProxyContract",
abi = r#"
{
abi = r#"{
"programType": "contract",
"specVersion": "1",
"encodingVersion": "1",
Expand Down Expand Up @@ -921,12 +920,12 @@ async fn deploy_new_proxy(
{
"name": "INITIAL_TARGET",
"concreteTypeId": "0d79387ad3bacdc3b7aad9da3a96f4ce60d9a1b6002df254069ad95a3931d5c8",
"offset": 13616
"offset": 13368
},
{
"name": "INITIAL_OWNER",
"concreteTypeId": "192bc7098e2fe60635a9918afb563e4e5419d386da2bdbf0d716b4bc8549802c",
"offset": 13568
"offset": 13320
}
]
}"#,
Expand Down
2 changes: 1 addition & 1 deletion forc-plugins/forc-client/tests/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ async fn test_deploy_fresh_proxy() {
.unwrap(),
proxy: Some(
ContractId::from_str(
"9c50c6837ba29508ad1b0fb01953892031218b5a08be73925ca5c0148e00a186",
"8eae70214f55d25a65608bd288a5863e7187fcf65705143ee1a45fd228dacc19",
)
.unwrap(),
),
Expand Down
29 changes: 18 additions & 11 deletions sway-core/src/abi_generation/fuel_abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,17 +181,24 @@ pub fn generate_program_abi(
configurables: Some(configurables),
}
}
TyProgramKind::Library { .. } => program_abi::ProgramABI {
program_type: "library".to_string(),
spec_version,
encoding_version,
metadata_types: vec![],
concrete_types: vec![],
functions: vec![],
logged_types: None,
messages_types: None,
configurables: None,
},
TyProgramKind::Library { .. } => {
let logged_types =
generate_logged_types(handler, ctx, engines, metadata_types, concrete_types)?;
let messages_types =
generate_messages_types(handler, ctx, engines, metadata_types, concrete_types)?;

program_abi::ProgramABI {
program_type: "library".to_string(),
spec_version,
encoding_version,
metadata_types: metadata_types.to_vec(),
concrete_types: concrete_types.to_vec(),
functions: vec![],
logged_types: Some(logged_types),
messages_types: Some(messages_types),
configurables: None,
}
}
};

standardize_json_abi_types(&mut program_abi);
Expand Down
20 changes: 19 additions & 1 deletion sway-core/src/language/ty/expression/expression_variant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1007,7 +1007,9 @@ impl TypeCheckAnalysis for TyExpressionVariant {
) -> Result<(), ErrorEmitted> {
match self {
TyExpressionVariant::Literal(_) => {}
TyExpressionVariant::FunctionApplication { fn_ref, .. } => {
TyExpressionVariant::FunctionApplication {
fn_ref, arguments, ..
} => {
let fn_decl_id = ctx.get_normalized_fn_node_id(fn_ref.id());

let fn_node = ctx.get_node_for_fn_decl(&fn_decl_id);
Expand All @@ -1021,6 +1023,22 @@ impl TypeCheckAnalysis for TyExpressionVariant {
let _ = fn_decl_id.type_check_analyze(handler, ctx);
}
}

// Unify arguments that are still not concrete
let decl = ctx.engines.de().get(fn_ref.id());

use crate::type_system::unify::unifier::*;
let unifier = Unifier::new(ctx.engines, "", UnifyKind::Default);

for (decl_param, arg) in decl.parameters.iter().zip(arguments.iter()) {
unifier.unify(
handler,
arg.1.return_type,
decl_param.type_argument.type_id,
&Span::dummy(),
false,
);
}
}
TyExpressionVariant::LazyOperator { lhs, rhs, .. } => {
lhs.type_check_analyze(handler, ctx)?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,7 @@ pub(crate) fn type_check_method_application(
let arg_handler = Handler::default();
let arg_opt = ty::TyExpression::type_check(&arg_handler, ctx, arg).ok();

// Check this type needs a second pass
let has_errors = arg_handler.has_errors();
let is_not_concrete = arg_opt
.as_ref()
.map(|x| {
x.return_type
.extract_inner_types(engines, IncludeSelf::Yes)
.iter()
.any(|x| !x.is_concrete(engines, TreatNumericAs::Abstract))
})
.unwrap_or_default();
let needs_second_pass = has_errors || is_not_concrete;
let needs_second_pass = arg_handler.has_errors();

if index == 0 {
// We want to emit errors in the self parameter and ignore TraitConstraintNotSatisfied with Placeholder
Expand Down
Loading

0 comments on commit ee5c7bc

Please sign in to comment.