diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index e047437eb7e..e8b80dfbb9d 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -62,6 +62,12 @@ jobs: runs-on: macos-latest env: CROSS_CONFIG: ${{ github.workspace }}/.github/Cross.toml + CACHED_PATHS: | + ~/.cargo/bin/ + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ + target/ strategy: matrix: target: [x86_64-apple-darwin, aarch64-apple-darwin] @@ -79,14 +85,10 @@ jobs: echo "SDKROOT=$(xcrun -sdk macosx$(sw_vers -productVersion) --show-sdk-path)" >> $GITHUB_ENV echo "MACOSX_DEPLOYMENT_TARGET=$(xcrun -sdk macosx$(sw_vers -productVersion) --show-sdk-platform-version)" >> $GITHUB_ENV - - uses: actions/cache@v3 + - uses: actions/cache/restore@v3 + id: cache with: - path: | - ~/.cargo/bin/ - ~/.cargo/registry/index/ - ~/.cargo/registry/cache/ - ~/.cargo/git/db/ - target/ + path: ${{ env.CACHED_PATHS }} key: ${{ matrix.target }}-cargo-${{ hashFiles('**/Cargo.lock') }} - name: Download artifact @@ -106,6 +108,13 @@ jobs: run: | cargo build --package nargo_cli --release --target ${{ matrix.target }} --no-default-features --features plonk_bn254_wasm + - uses: actions/cache/save@v3 + # Don't create cache entries for the merge queue. + if: ${{ steps.cache.outputs.cache-hit != 'true' && github.event_name != 'merge_group' }} + with: + path: ${{ env.CACHED_PATHS }} + key: ${{ steps.cache.outputs.cache-primary-key }} + - name: Package artifacts run: | mkdir dist @@ -144,6 +153,12 @@ jobs: runs-on: ubuntu-22.04 env: CROSS_CONFIG: ${{ github.workspace }}/.github/Cross.toml + CACHED_PATHS: | + ~/.cargo/bin/ + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ + target/ strategy: fail-fast: false matrix: @@ -161,14 +176,10 @@ jobs: with: ref: ${{ inputs.tag || env.GITHUB_REF }} - - uses: actions/cache@v3 + - uses: actions/cache/restore@v3 + id: cache with: - path: | - ~/.cargo/bin/ - ~/.cargo/registry/index/ - ~/.cargo/registry/cache/ - ~/.cargo/git/db/ - target/ + path: ${{ env.CACHED_PATHS }} key: ${{ matrix.target }}-cargo-${{ hashFiles('**/Cargo.lock') }} - name: Download artifact @@ -189,6 +200,13 @@ jobs: cargo install cross --force --git https://github.com/cross-rs/cross cross build --package nargo_cli --release --target=${{ matrix.target }} --no-default-features --features plonk_bn254_wasm + - uses: actions/cache/save@v3 + # Don't create cache entries for the merge queue. + if: ${{ steps.cache.outputs.cache-hit != 'true' && github.event_name != 'merge_group' }} + with: + path: ${{ env.CACHED_PATHS }} + key: ${{ steps.cache.outputs.cache-primary-key }} + - name: Package artifacts run: | mkdir dist @@ -227,6 +245,12 @@ jobs: runs-on: windows-2022 env: CROSS_CONFIG: ${{ github.workspace }}/.github/Cross.toml + CACHED_PATHS: | + ~/.cargo/bin/ + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ + target/ strategy: matrix: target: [x86_64-pc-windows-msvc] @@ -237,14 +261,10 @@ jobs: with: ref: ${{ inputs.tag || env.GITHUB_REF }} - - uses: actions/cache@v3 + - uses: actions/cache/restore@v3 + id: cache with: - path: | - ~/.cargo/bin/ - ~/.cargo/registry/index/ - ~/.cargo/registry/cache/ - ~/.cargo/git/db/ - target/ + path: ${{ env.CACHED_PATHS }} key: ${{ matrix.target }}-cargo-${{ hashFiles('**/Cargo.lock') }} - name: Download artifact @@ -264,6 +284,13 @@ jobs: run: | cargo build --package nargo_cli --release --target ${{ matrix.target }} --no-default-features --features plonk_bn254_wasm + - uses: actions/cache/save@v3 + # Don't create cache entries for the merge queue. + if: ${{ steps.cache.outputs.cache-hit != 'true' && github.event_name != 'merge_group' }} + with: + path: ${{ env.CACHED_PATHS }} + key: ${{ steps.cache.outputs.cache-primary-key }} + - name: Package artifacts run: | mkdir dist diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 300f47fcd08..23a6716ab59 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -14,6 +14,8 @@ jobs: name: Test on ${{ matrix.os }} runs-on: ${{ matrix.runner }} timeout-minutes: 30 + env: + CACHED_PATH: /tmp/nix-cache strategy: fail-fast: false @@ -37,20 +39,20 @@ jobs: name: barretenberg - name: Restore nix store cache - id: nix-store-cache - uses: actions/cache@v3 + uses: actions/cache/restore@v3 + id: cache with: - path: /tmp/nix-cache + path: ${{ env.CACHED_PATH }} key: ${{ runner.os }}-flake-${{ hashFiles('*.lock') }} # Based on https://github.com/marigold-dev/deku/blob/b5016f0cf4bf6ac48db9111b70dd7fb49b969dfd/.github/workflows/build.yml#L26 - name: Copy cache into nix store - if: steps.nix-store-cache.outputs.cache-hit == 'true' + if: steps.cache.outputs.cache-hit == 'true' # We don't check the signature because we're the one that created the cache run: | - for narinfo in /tmp/nix-cache/*.narinfo; do + for narinfo in ${{ env.CACHED_PATH }}/*.narinfo; do path=$(head -n 1 "$narinfo" | awk '{print $2}') - nix copy --no-check-sigs --from "file:///tmp/nix-cache" "$path" + nix copy --no-check-sigs --from "file://${{ env.CACHED_PATH }}" "$path" done - name: Run `nix flake check` @@ -58,6 +60,13 @@ jobs: nix flake check -L - name: Export cache from nix store - if: steps.nix-store-cache.outputs.cache-hit != 'true' + if: ${{ always() && steps.cache.outputs.cache-hit != 'true' && github.event_name != 'merge_group' }} run: | - nix copy --to "file:///tmp/nix-cache?compression=zstd¶llel-compression=true" .#native-cargo-artifacts + nix copy --to "file://${{ env.CACHED_PATH }}?compression=zstd¶llel-compression=true" .#native-cargo-artifacts + + - uses: actions/cache/save@v3 + # Write a cache entry even if the tests fail but don't create any for the merge queue. + if: ${{ always() && steps.cache.outputs.cache-hit != 'true' && github.event_name != 'merge_group' }} + with: + path: ${{ env.CACHED_PATH }} + key: ${{ steps.cache.outputs.cache-primary-key }} diff --git a/.github/workflows/wasm.yml b/.github/workflows/wasm.yml index 7d429accdbf..f052e9eb071 100644 --- a/.github/workflows/wasm.yml +++ b/.github/workflows/wasm.yml @@ -49,19 +49,22 @@ jobs: build-nargo: needs: [build-barretenberg] runs-on: ubuntu-22.04 + env: + CACHED_PATHS: | + ~/.cargo/bin/ + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ + target/ steps: - name: Checkout Noir repo uses: actions/checkout@v3 - - uses: actions/cache@v3 + - uses: actions/cache/restore@v3 + id: cache with: - path: | - ~/.cargo/bin/ - ~/.cargo/registry/index/ - ~/.cargo/registry/cache/ - ~/.cargo/git/db/ - target/ + path: ${{ env.CACHED_PATHS }} key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} - name: Download artifact @@ -79,6 +82,13 @@ jobs: run: | cargo build --package nargo_cli --release --no-default-features --features plonk_bn254_wasm + - uses: actions/cache/save@v3 + # Don't create cache entries for the merge queue. + if: ${{ steps.cache.outputs.cache-hit != 'true' && github.event_name != 'merge_group' }} + with: + path: ${{ env.CACHED_PATHS }} + key: ${{ steps.cache.outputs.cache-primary-key }} + - name: Package artifacts run: | mkdir dist @@ -94,6 +104,9 @@ jobs: build-wasm: runs-on: ubuntu-latest + env: + CACHED_PATH: /tmp/nix-cache + steps: - name: Checkout sources uses: actions/checkout@v3 @@ -104,10 +117,39 @@ jobs: nix_path: nixpkgs=channel:nixos-22.11 github_access_token: ${{ secrets.GITHUB_TOKEN }} + - name: Restore nix store cache + uses: actions/cache/restore@v3 + id: cache + with: + path: ${{ env.CACHED_PATH }} + key: ${{ runner.os }}-flake-wasm-${{ hashFiles('*.lock') }} + + # Based on https://github.com/marigold-dev/deku/blob/b5016f0cf4bf6ac48db9111b70dd7fb49b969dfd/.github/workflows/build.yml#L26 + - name: Copy cache into nix store + if: steps.cache.outputs.cache-hit == 'true' + # We don't check the signature because we're the one that created the cache + run: | + for narinfo in ${{ env.CACHED_PATH }}/*.narinfo; do + path=$(head -n 1 "$narinfo" | awk '{print $2}') + nix copy --no-check-sigs --from "file://${{ env.CACHED_PATH }}" "$path" + done + - name: Build wasm package run: | nix build -L .#wasm + - name: Export cache from nix store + if: ${{ steps.cache.outputs.cache-hit != 'true' && github.event_name != 'merge_group' }} + run: | + nix copy --to "file://${{ env.CACHED_PATH }}?compression=zstd¶llel-compression=true" .#noir-wasm-cargo-artifacts + + - uses: actions/cache/save@v3 + # Don't create cache entries for the merge queue. + if: ${{ steps.cache.outputs.cache-hit != 'true' && github.event_name != 'merge_group' }} + with: + path: ${{ env.CACHED_PATH }} + key: ${{ steps.cache.outputs.cache-primary-key }} + - name: Dereference symlink run: echo "UPLOAD_PATH=$(readlink -f result)" >> $GITHUB_ENV diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 582db2fa7f4..8c7bf663c11 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "0.10.2" + ".": "0.10.3" } diff --git a/CHANGELOG.md b/CHANGELOG.md index 582ac754e35..eb93c131b04 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,19 @@ # Changelog +## [0.10.3](https://github.com/noir-lang/noir/compare/v0.10.2...v0.10.3) (2023-08-16) + + +### Features + +* Allow calling higher-order functions with closures ([#2335](https://github.com/noir-lang/noir/issues/2335)) ([75fd3e0](https://github.com/noir-lang/noir/commit/75fd3e0e27f16fb0aa5f8b01cefe78e04f867726)) +* **lsp:** Add `Compile` code lens for `main` function and contracts ([#2309](https://github.com/noir-lang/noir/issues/2309)) ([5fe69c6](https://github.com/noir-lang/noir/commit/5fe69c6eeef0b7ed2e4df9c3a80627f54c75a355)) +* **lsp:** Add `Execute` code lens for `main` functions ([#2330](https://github.com/noir-lang/noir/issues/2330)) ([5aa59e0](https://github.com/noir-lang/noir/commit/5aa59e0f3c4b3e6e14330d1f0e45ec912f562892)) + + +### Bug Fixes + +* Display warning if last expression of block is unused ([#2314](https://github.com/noir-lang/noir/issues/2314)) ([8110136](https://github.com/noir-lang/noir/commit/81101362ccba787a44c6d48c0378696cb16f0acb)) + ## [0.10.2](https://github.com/noir-lang/noir/compare/v0.10.1...v0.10.2) (2023-08-16) diff --git a/Cargo.lock b/Cargo.lock index b9c125f2340..b8589888b8a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -210,7 +210,7 @@ dependencies = [ [[package]] name = "arena" -version = "0.10.2" +version = "0.10.3" dependencies = [ "generational-arena", ] @@ -1399,7 +1399,7 @@ dependencies = [ [[package]] name = "fm" -version = "0.10.2" +version = "0.10.3" dependencies = [ "cfg-if", "codespan-reporting", @@ -1934,7 +1934,7 @@ dependencies = [ [[package]] name = "iter-extended" -version = "0.10.2" +version = "0.10.3" [[package]] name = "itertools" @@ -2181,7 +2181,7 @@ checksum = "7843ec2de400bcbc6a6328c958dc38e5359da6e93e72e37bc5246bf1ae776389" [[package]] name = "nargo" -version = "0.10.2" +version = "0.10.3" dependencies = [ "acvm", "base64", @@ -2200,7 +2200,7 @@ dependencies = [ [[package]] name = "nargo_cli" -version = "0.10.2" +version = "0.10.3" dependencies = [ "acvm", "acvm-backend-barretenberg", @@ -2242,7 +2242,7 @@ dependencies = [ [[package]] name = "nargo_toml" -version = "0.10.2" +version = "0.10.3" dependencies = [ "dirs", "fm", @@ -2268,7 +2268,7 @@ dependencies = [ [[package]] name = "noir_lsp" -version = "0.10.2" +version = "0.10.3" dependencies = [ "acvm", "async-lsp", @@ -2289,7 +2289,7 @@ dependencies = [ [[package]] name = "noir_wasm" -version = "0.10.2" +version = "0.10.3" dependencies = [ "acvm", "build-data", @@ -2307,7 +2307,7 @@ dependencies = [ [[package]] name = "noirc_abi" -version = "0.10.2" +version = "0.10.3" dependencies = [ "acvm", "iter-extended", @@ -2321,7 +2321,7 @@ dependencies = [ [[package]] name = "noirc_driver" -version = "0.10.2" +version = "0.10.3" dependencies = [ "acvm", "base64", @@ -2336,7 +2336,7 @@ dependencies = [ [[package]] name = "noirc_errors" -version = "0.10.2" +version = "0.10.3" dependencies = [ "chumsky", "codespan", @@ -2347,7 +2347,7 @@ dependencies = [ [[package]] name = "noirc_evaluator" -version = "0.10.2" +version = "0.10.3" dependencies = [ "acvm", "im", @@ -2361,7 +2361,7 @@ dependencies = [ [[package]] name = "noirc_frontend" -version = "0.10.2" +version = "0.10.3" dependencies = [ "acvm", "arena", diff --git a/Cargo.toml b/Cargo.toml index e47cb2ab600..7561248d2f1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,7 +18,7 @@ default-members = ["crates/nargo_cli"] [workspace.package] # x-release-please-start-version -version = "0.10.2" +version = "0.10.3" # x-release-please-end authors = ["The Noir Team "] edition = "2021" diff --git a/crates/lsp/src/lib.rs b/crates/lsp/src/lib.rs index 1fe0565da40..d8b572db349 100644 --- a/crates/lsp/src/lib.rs +++ b/crates/lsp/src/lib.rs @@ -27,8 +27,13 @@ use noirc_frontend::hir::FunctionNameMatch; use serde_json::Value as JsonValue; use tower::Service; +const ARROW: &str = "▶\u{fe0e}"; const TEST_COMMAND: &str = "nargo.test"; -const TEST_CODELENS_TITLE: &str = "▶\u{fe0e} Run Test"; +const TEST_CODELENS_TITLE: &str = "Run Test"; +const COMPILE_COMMAND: &str = "nargo.compile"; +const COMPILE_CODELENS_TITLE: &str = "Compile"; +const EXECUTE_COMMAND: &str = "nargo.execute"; +const EXECUTE_CODELENS_TITLE: &str = "Execute"; // State for the LSP gets implemented on this struct and is internal to the implementation pub struct LspState { @@ -185,7 +190,7 @@ fn on_code_lens_request( for package in &workspace { let (mut context, crate_id) = prepare_package(package); - // We ignore the warnings and errors produced by compilation for producing codelenses + // We ignore the warnings and errors produced by compilation for producing code lenses // because we can still get the test functions even if compilation fails let _ = check_crate(&mut context, crate_id, false); @@ -209,8 +214,8 @@ fn on_code_lens_request( let range = byte_span_to_range(files, file_id.as_usize(), location.span.into()) .unwrap_or_default(); - let command = Command { - title: TEST_CODELENS_TITLE.into(), + let test_command = Command { + title: format!("{ARROW} {TEST_CODELENS_TITLE}"), command: TEST_COMMAND.into(), arguments: Some(vec![ "--program-dir".into(), @@ -222,9 +227,158 @@ fn on_code_lens_request( ]), }; - let lens = CodeLens { range, command: command.into(), data: None }; + let test_lens = CodeLens { range, command: Some(test_command), data: None }; - lenses.push(lens); + lenses.push(test_lens); + } + + if package.is_binary() { + if let Some(main_func_id) = context.get_main_function(&crate_id) { + let location = context.function_meta(&main_func_id).name.location; + let file_id = location.file; + + // Ignore diagnostics for any file that wasn't the file we saved + // TODO: In the future, we could create "related" diagnostics for these files + // TODO: This currently just appends the `.nr` file extension that we store as a constant, + // but that won't work if we accept other extensions + if fm.path(file_id).with_extension(FILE_EXTENSION) != file_path { + continue; + } + + let range = byte_span_to_range(files, file_id.as_usize(), location.span.into()) + .unwrap_or_default(); + + let compile_command = Command { + title: format!("{ARROW} {COMPILE_CODELENS_TITLE}"), + command: COMPILE_COMMAND.into(), + arguments: Some(vec![ + "--program-dir".into(), + format!("{}", workspace.root_dir.display()).into(), + "--package".into(), + format!("{}", package.name).into(), + ]), + }; + + let compile_lens = CodeLens { range, command: Some(compile_command), data: None }; + + lenses.push(compile_lens); + + let execute_command = Command { + title: EXECUTE_CODELENS_TITLE.to_string(), + command: EXECUTE_COMMAND.into(), + arguments: Some(vec![ + "--program-dir".into(), + format!("{}", workspace.root_dir.display()).into(), + "--package".into(), + format!("{}", package.name).into(), + ]), + }; + + let execute_lens = CodeLens { range, command: Some(execute_command), data: None }; + + lenses.push(execute_lens); + } + } + + if package.is_contract() { + // Currently not looking to deduplicate this since we don't have a clear decision on if the Contract stuff is staying + for contract in context.get_all_contracts(&crate_id) { + let location = contract.location; + let file_id = location.file; + + // Ignore diagnostics for any file that wasn't the file we saved + // TODO: In the future, we could create "related" diagnostics for these files + // TODO: This currently just appends the `.nr` file extension that we store as a constant, + // but that won't work if we accept other extensions + if fm.path(file_id).with_extension(FILE_EXTENSION) != file_path { + continue; + } + + let range = byte_span_to_range(files, file_id.as_usize(), location.span.into()) + .unwrap_or_default(); + + let compile_command = Command { + title: format!("{ARROW} {COMPILE_CODELENS_TITLE}"), + command: COMPILE_COMMAND.into(), + arguments: Some(vec![ + "--program-dir".into(), + format!("{}", workspace.root_dir.display()).into(), + "--package".into(), + format!("{}", package.name).into(), + ]), + }; + + let compile_lens = CodeLens { range, command: Some(compile_command), data: None }; + + lenses.push(compile_lens); + } + } + + if package.is_binary() { + if let Some(main_func_id) = context.get_main_function(&crate_id) { + let location = context.function_meta(&main_func_id).name.location; + let file_id = location.file; + + // Ignore diagnostics for any file that wasn't the file we saved + // TODO: In the future, we could create "related" diagnostics for these files + // TODO: This currently just appends the `.nr` file extension that we store as a constant, + // but that won't work if we accept other extensions + if fm.path(file_id).with_extension(FILE_EXTENSION) != file_path { + continue; + } + + let range = byte_span_to_range(files, file_id.as_usize(), location.span.into()) + .unwrap_or_default(); + + let command = Command { + title: format!("{ARROW} {COMPILE_CODELENS_TITLE}"), + command: COMPILE_COMMAND.into(), + arguments: Some(vec![ + "--program-dir".into(), + format!("{}", workspace.root_dir.display()).into(), + "--package".into(), + format!("{}", package.name).into(), + ]), + }; + + let lens = CodeLens { range, command: command.into(), data: None }; + + lenses.push(lens); + } + } + + if package.is_contract() { + // Currently not looking to deduplicate this since we don't have a clear decision on if the Contract stuff is staying + for contract in context.get_all_contracts(&crate_id) { + let location = contract.location; + let file_id = location.file; + + // Ignore diagnostics for any file that wasn't the file we saved + // TODO: In the future, we could create "related" diagnostics for these files + // TODO: This currently just appends the `.nr` file extension that we store as a constant, + // but that won't work if we accept other extensions + if fm.path(file_id).with_extension(FILE_EXTENSION) != file_path { + continue; + } + + let range = byte_span_to_range(files, file_id.as_usize(), location.span.into()) + .unwrap_or_default(); + + let command = Command { + title: format!("{ARROW} {COMPILE_CODELENS_TITLE}"), + command: COMPILE_COMMAND.into(), + arguments: Some(vec![ + "--program-dir".into(), + format!("{}", workspace.root_dir.display()).into(), + "--package".into(), + format!("{}", package.name).into(), + ]), + }; + + let lens = CodeLens { range, command: command.into(), data: None }; + + lenses.push(lens); + } } } @@ -365,6 +519,9 @@ fn on_did_save_text_document( } } + // We need to refresh lenses when we compile since that's the only time they can be accurately reflected + let _ = state.client.code_lens_refresh(()); + let _ = state.client.publish_diagnostics(PublishDiagnosticsParams { uri: params.text_document.uri, version: None, diff --git a/crates/noirc_frontend/src/hir/def_map/mod.rs b/crates/noirc_frontend/src/hir/def_map/mod.rs index f264d3f40b8..2dc8c5ec96f 100644 --- a/crates/noirc_frontend/src/hir/def_map/mod.rs +++ b/crates/noirc_frontend/src/hir/def_map/mod.rs @@ -148,7 +148,7 @@ impl CrateDefMap { let functions = module.value_definitions().filter_map(|id| id.as_function()).collect(); let name = self.get_module_path(id, module.parent); - Some(Contract { name, functions }) + Some(Contract { name, location: module.location, functions }) } else { None } @@ -194,6 +194,7 @@ impl CrateDefMap { pub struct Contract { /// To keep `name` semi-unique, it is prefixed with the names of parent modules via CrateDefMap::get_module_path pub name: String, + pub location: Location, pub functions: Vec, } diff --git a/crates/noirc_frontend/src/hir/type_check/expr.rs b/crates/noirc_frontend/src/hir/type_check/expr.rs index 41d98438024..ac49dd01fe3 100644 --- a/crates/noirc_frontend/src/hir/type_check/expr.rs +++ b/crates/noirc_frontend/src/hir/type_check/expr.rs @@ -837,11 +837,13 @@ impl<'interner> TypeChecker<'interner> { } for (param, (arg, _, arg_span)) in fn_params.iter().zip(callsite_args) { - self.unify(arg, param, || TypeCheckError::TypeMismatch { - expected_typ: param.to_string(), - expr_typ: arg.to_string(), - expr_span: *arg_span, - }); + if arg.try_unify_allow_incompat_lambdas(param).is_err() { + self.errors.push(TypeCheckError::TypeMismatch { + expected_typ: param.to_string(), + expr_typ: arg.to_string(), + expr_span: *arg_span, + }); + } } fn_ret.clone() diff --git a/crates/noirc_frontend/src/hir/type_check/mod.rs b/crates/noirc_frontend/src/hir/type_check/mod.rs index a047b417b32..4a09139c99c 100644 --- a/crates/noirc_frontend/src/hir/type_check/mod.rs +++ b/crates/noirc_frontend/src/hir/type_check/mod.rs @@ -63,28 +63,33 @@ pub fn type_check_func(interner: &mut NodeInterner, func_id: FuncId) -> Vec Result<(), UnificationError> { + use Type::*; + use TypeVariableKind::*; + + match (self, other) { + (TypeVariable(binding, Normal), other) | (other, TypeVariable(binding, Normal)) => { + if let TypeBinding::Bound(link) = &*binding.borrow() { + return link.try_unify_allow_incompat_lambdas(other); + } + + other.try_bind_to(binding) + } + (Function(params_a, ret_a, _), Function(params_b, ret_b, _)) => { + if params_a.len() == params_b.len() { + for (a, b) in params_a.iter().zip(params_b.iter()) { + a.try_unify_allow_incompat_lambdas(b)?; + } + + // no check for environments here! + ret_b.try_unify_allow_incompat_lambdas(ret_a) + } else { + Err(UnificationError) + } + } + _ => self.try_unify(other), + } + } + + /// Similar to `unify` but if the check fails this will attempt to coerce the /// argument to the target type. When this happens, the given expression is wrapped in /// a new expression to convert its type. E.g. `array` -> `array.as_slice()` /// @@ -923,7 +951,7 @@ impl Type { // If we have an array and our target is a slice if matches!(size1, Type::Constant(_)) && matches!(size2, Type::NotConstant) { // Still have to ensure the element types match. - // Don't need to issue an error here if not, it will be done in make_subtype_of_with_coercions + // Don't need to issue an error here if not, it will be done in unify_with_coercions if element1.try_unify(element2).is_ok() { convert_array_expression_to_slice(expression, this, target, interner); return true; diff --git a/crates/wasm/package.json b/crates/wasm/package.json index bb8ca45a288..b01e36d27b1 100644 --- a/crates/wasm/package.json +++ b/crates/wasm/package.json @@ -3,7 +3,7 @@ "collaborators": [ "The Noir Team " ], - "version": "0.10.2", + "version": "0.10.3", "license": "(MIT OR Apache-2.0)", "main": "./nodejs/noir_wasm.js", "types": "./web/noir_wasm.d.ts", @@ -24,11 +24,11 @@ "test:browser": "web-test-runner" }, "peerDependencies": { - "@noir-lang/noir-source-resolver": "1.1.2" + "@noir-lang/noir-source-resolver": "^1.1.3" }, "devDependencies": { "@esm-bundle/chai": "^4.3.4-fix.0", - "@noir-lang/noir-source-resolver": "1.1.2", + "@noir-lang/noir-source-resolver": "^1.1.3", "@web/dev-server-esbuild": "^0.3.6", "@web/test-runner": "^0.15.3", "@web/test-runner-playwright": "^0.10.0", diff --git a/flake.nix b/flake.nix index df7db00433a..5514dc767df 100644 --- a/flake.nix +++ b/flake.nix @@ -117,7 +117,7 @@ sharedArgs = { # x-release-please-start-version - version = "0.10.2"; + version = "0.10.3"; # x-release-please-end src = pkgs.lib.cleanSourceWith { @@ -254,6 +254,7 @@ # We expose the `*-cargo-artifacts` derivations so we can cache our cargo dependencies in CI inherit native-cargo-artifacts; inherit wasm-cargo-artifacts; + inherit noir-wasm-cargo-artifacts; }; # TODO(#1197): Look into installable apps with Nix flakes