From 0eaa3a6da94e7ee760ff2528a7db29a7b793d17c Mon Sep 17 00:00:00 2001 From: IGI-111 Date: Thu, 9 Mar 2023 09:14:52 +0100 Subject: [PATCH] Standardized module structure (#4232) ## Description Implement RFC 0006, fix #4191. Remove the `dep` reseved keyword in favor of `mod`. Change path resolution for submodules to use an adjascent file at the root and a folder named after the current module in other cases. Remove the need for an argument to `library`, the LSP now points to empty spans at the top of module files. The library names are now determined by the file name, or the package name at the top level. ## 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. --- docs/book/src/advanced/traits.md | 2 +- docs/book/src/sway-program-types/libraries.md | 48 ++++--- .../src/code/examples/fizzbuzz/src/lib.sw | 2 +- .../code/language/built-ins/arrays/src/lib.sw | 2 +- .../language/built-ins/booleans/src/lib.sw | 2 +- .../code/language/built-ins/bytes/src/lib.sw | 2 +- .../built-ins/enums/src/basic_enum.sw | 2 +- .../built-ins/enums/src/enum_of_enums.sw | 2 +- .../built-ins/enums/src/enum_of_structs.sw | 2 +- .../code/language/built-ins/enums/src/main.sw | 6 +- .../language/built-ins/numerics/src/lib.sw | 2 +- .../language/built-ins/strings/src/lib.sw | 2 +- .../language/built-ins/structs/src/lib.sw | 2 +- .../code/language/built-ins/tuples/src/lib.sw | 2 +- .../src/code/language/comments/src/lib.sw | 2 +- .../src/code/language/control_flow/src/lib.sw | 2 +- .../code/language/functions/src/explicit.sw | 2 +- .../code/language/functions/src/implicit.sw | 2 +- .../src/code/language/functions/src/lib.sw | 6 +- .../contracts/interface/src/lib.sw | 2 +- .../libraries/external/my_library/src/lib.sw | 2 +- .../external/my_other_library/src/lib.sw | 2 +- .../libraries/internal/my_library/src/lib.sw | 4 +- .../internal/my_library/src/my_library.sw | 2 +- .../style-guide/annotations/src/lib.sw | 2 +- .../language/style-guide/enums/src/lib.sw | 2 +- .../language/style-guide/getters/src/lib.sw | 2 +- .../style-guide/letter_casing/src/lib.sw | 2 +- .../style-guide/struct_shorthand/src/lib.sw | 2 +- .../src/code/language/variables/src/lib.sw | 2 +- .../misc/advanced-concepts/enums/src/lib.sw | 2 +- .../code/misc/known-issues/arrays/src/lib.sw | 2 +- .../code/misc/known-issues/strings/src/lib.sw | 2 +- .../src/code/operations/assertions/src/lib.sw | 4 +- .../src/code/operations/assertions/src/req.sw | 2 +- .../operations/asset_operations/src/lib.sw | 2 +- .../src/code/operations/call_data/src/lib.sw | 2 +- .../contract_calling/interface/src/lib.sw | 2 +- .../src/code/operations/hashing/src/lib.sw | 2 +- .../src/code/operations/logging/src/lib.sw | 2 +- .../src/code/operations/namespace/src/lib.sw | 2 +- .../language/program-types/libraries/index.md | 2 +- .../program-types/libraries/internal.md | 2 +- examples/cei_analysis/src/main.sw | 2 +- examples/cei_analysis/src/other_contract.sw | 2 +- examples/enums/src/basic_enum.sw | 2 +- examples/enums/src/enum_of_enums.sw | 2 +- examples/enums/src/enum_of_structs.sw | 2 +- examples/enums/src/enums_avoid.sw | 5 +- examples/enums/src/enums_preferred.sw | 5 +- examples/enums/src/main.sw | 11 +- examples/identity/src/abi.sw | 2 +- examples/identity/src/errors.sw | 2 +- examples/identity/src/main.sw | 4 +- examples/structs/src/data_structures.sw | 2 +- examples/structs/src/main.sw | 4 +- examples/tuples/src/main.sw | 2 +- examples/wallet_abi/src/main.sw | 2 +- forc-pkg/src/pkg.rs | 78 +++++++++--- forc-plugins/forc-doc/src/doc.rs | 2 +- forc/src/ops/forc_init.rs | 2 +- forc/src/utils/defaults.rs | 7 +- sway-ast/src/dependency.rs | 29 ----- sway-ast/src/item/mod.rs | 4 +- sway-ast/src/keywords.rs | 2 +- sway-ast/src/lib.rs | 4 +- sway-ast/src/module.rs | 28 ++--- sway-ast/src/priv_prelude.rs | 2 +- sway-ast/src/submodule.rs | 14 +++ sway-core/src/language/lexed/mod.rs | 11 +- sway-core/src/language/module.rs | 4 +- .../src/language/parsed/expression/mod.rs | 2 +- .../src/language/parsed/include_statement.rs | 8 +- sway-core/src/language/parsed/mod.rs | 2 +- sway-core/src/language/parsed/module.rs | 16 +-- sway-core/src/language/parsed/program.rs | 5 +- .../src/language/ty/declaration/storage.rs | 2 +- sway-core/src/language/ty/module.rs | 16 +-- sway-core/src/language/ty/program.rs | 22 ++-- sway-core/src/lib.rs | 119 +++++++++++------- .../semantic_analysis/ast_node/code_block.rs | 6 +- .../ast_node/declaration/function.rs | 8 +- .../ast_node/declaration/impl_trait.rs | 2 +- .../match_expression/typed/typed_scrutinee.rs | 2 +- .../ast_node/expression/typed_expression.rs | 10 +- sway-core/src/semantic_analysis/module.rs | 14 +-- .../src/semantic_analysis/namespace/module.rs | 10 +- .../semantic_analysis/namespace/namespace.rs | 13 +- .../semantic_analysis/namespace/trait_map.rs | 12 +- .../semantic_analysis/node_dependencies.rs | 2 +- sway-core/src/semantic_analysis/program.rs | 4 +- .../semantic_analysis/type_check_context.rs | 5 +- .../to_parsed_lang/convert_parse_tree.rs | 52 ++++---- sway-core/src/type_system/mod.rs | 6 +- sway-core/src/type_system/unify.rs | 8 +- sway-error/src/error.rs | 2 +- sway-lib-core/src/lib.sw | 14 +-- sway-lib-core/src/never.sw | 2 +- sway-lib-core/src/ops.sw | 10 +- sway-lib-core/src/prelude.sw | 2 +- sway-lib-core/src/primitives.sw | 2 +- sway-lib-core/src/raw_ptr.sw | 2 +- sway-lib-core/src/raw_slice.sw | 4 +- sway-lib-std/src/address.sw | 2 +- sway-lib-std/src/alloc.sw | 2 +- sway-lib-std/src/assert.sw | 2 +- sway-lib-std/src/auth.sw | 2 +- sway-lib-std/src/b256.sw | 2 +- sway-lib-std/src/b512.sw | 2 +- sway-lib-std/src/block.sw | 2 +- sway-lib-std/src/bytes.sw | 2 +- sway-lib-std/src/call_frames.sw | 2 +- sway-lib-std/src/constants.sw | 2 +- sway-lib-std/src/context.sw | 2 +- sway-lib-std/src/contract_id.sw | 2 +- sway-lib-std/src/convert.sw | 2 +- sway-lib-std/src/ecr.sw | 2 +- sway-lib-std/src/error_signals.sw | 2 +- sway-lib-std/src/external.sw | 2 +- sway-lib-std/src/flags.sw | 2 +- sway-lib-std/src/hash.sw | 2 +- sway-lib-std/src/identity.sw | 2 +- sway-lib-std/src/inputs.sw | 2 +- sway-lib-std/src/intrinsics.sw | 2 +- sway-lib-std/src/lib.sw | 78 ++++++------ sway-lib-std/src/logging.sw | 2 +- sway-lib-std/src/low_level_call.sw | 2 +- sway-lib-std/src/math.sw | 2 +- sway-lib-std/src/message.sw | 2 +- sway-lib-std/src/option.sw | 2 +- sway-lib-std/src/outputs.sw | 2 +- sway-lib-std/src/prelude.sw | 2 +- sway-lib-std/src/registers.sw | 2 +- sway-lib-std/src/result.sw | 2 +- sway-lib-std/src/revert.sw | 2 +- sway-lib-std/src/storage.sw | 2 +- sway-lib-std/src/token.sw | 2 +- sway-lib-std/src/tx.sw | 2 +- sway-lib-std/src/u128.sw | 2 +- sway-lib-std/src/u256.sw | 2 +- sway-lib-std/src/vec.sw | 2 +- sway-lib-std/src/vm.sw | 4 + sway-lib-std/src/vm/evm.sw | 4 + sway-lib-std/src/vm/evm/ecr.sw | 2 +- sway-lib-std/src/vm/evm/evm_address.sw | 2 +- sway-lib-std/src/vm/evm/mod.sw | 4 - sway-lib-std/src/vm/mod.sw | 3 - sway-lsp/src/core/token.rs | 4 +- sway-lsp/src/traverse/lexed_tree.rs | 4 +- sway-lsp/src/traverse/parsed_tree.rs | 29 ++--- sway-lsp/src/traverse/typed_tree.rs | 49 +++----- sway-lsp/src/utils/keyword_docs.rs | 6 +- sway-lsp/tests/fixtures/completion/Forc.toml | 1 + .../tests/fixtures/tokens/consts/src/main.sw | 4 +- .../fixtures/tokens/consts/src/more_consts.sw | 2 +- .../tests/fixtures/tokens/fields/src/foo.sw | 2 +- .../tests/fixtures/tokens/fields/src/main.sw | 2 +- .../tokens/modules/src/dir_mod/mod.sw | 1 - .../tests/fixtures/tokens/modules/src/lib.sw | 5 +- .../fixtures/tokens/modules/src/test_mod.sw | 4 +- .../tokens/modules/src/test_mod/deep_mod.sw | 1 + .../fixtures/tokens/paths/src/deep_mod.sw | 4 +- .../tokens/paths/src/deep_mod/deeper_mod.sw | 2 +- .../tests/fixtures/tokens/paths/src/main.sw | 4 +- .../fixtures/tokens/paths/src/test_mod.sw | 2 +- .../tests/fixtures/tokens/traits/src/main.sw | 4 +- .../fixtures/tokens/traits/src/traits.sw | 4 +- sway-lsp/tests/lib.rs | 86 +++++++------ sway-parse/src/attribute.rs | 2 +- sway-parse/src/dependency.rs | 28 ----- sway-parse/src/item/mod.rs | 10 +- sway-parse/src/keywords.rs | 4 +- sway-parse/src/lib.rs | 2 +- sway-parse/src/module.rs | 8 +- sway-parse/src/submodule.rs | 16 +++ sway-types/src/ident.rs | 16 +-- swayfmt/src/module/dependency.rs | 54 -------- swayfmt/src/module/item.rs | 4 +- swayfmt/src/module/mod.rs | 24 ++-- swayfmt/src/module/submodule.rs | 30 +++++ swayfmt/tests/mod.rs | 40 +++--- .../configurables_in_lib/src/lib.sw | 2 +- .../configurables_in_lib/src/main.sw | 2 +- .../cyclic_dependency/dependency_a/src/lib.sw | 2 +- .../cyclic_dependency/dependency_b/src/lib.sw | 2 +- .../should_fail/dep_annotated/src/bar.sw | 2 +- .../should_fail/dep_annotated/src/baz.sw | 2 +- .../should_fail/dep_annotated/src/foo.sw | 2 +- .../should_fail/dep_annotated/src/main.sw | 6 +- .../should_fail/dep_annotated/test.toml | 4 +- .../src/a_dependency.sw | 2 +- .../dependency_not_at_beginning/src/main.sw | 2 +- .../dependency_not_at_beginning/test.toml | 2 +- .../dependency_parsing_error/Forc.lock | 3 - .../dependency_parsing_error/Forc.toml | 6 - .../json_abi_oracle.json | 1 - .../src/a_dependency.sw | 4 - .../dependency_parsing_error/src/bar.sw | 3 - .../dependency_parsing_error/src/inner/bar.sw | 6 - .../src/inner/double_inner/double_bar.sw | 6 - .../dependency_parsing_error/src/main.sw | 17 --- .../src/nested_dependency/bar/bar.sw | 6 - .../dependency_parsing_error/test.toml | 5 - .../enum_variant_unit/src/lib_a.sw | 4 +- .../src/{ => lib_a}/inner_lib.sw | 2 +- .../should_fail/enum_variant_unit/src/main.sw | 2 +- .../should_fail/generic_traits/src/helpers.sw | 2 +- .../should_fail/generic_traits/src/main.sw | 2 +- .../src/lib_a.sw | 6 +- .../src/{ => lib_a}/inner_lib.sw | 2 +- .../src/main.sw | 2 +- .../generics_not_supported/src/lib_a.sw | 6 +- .../src/{ => lib_a}/inner_lib.sw | 4 +- .../generics_not_supported/src/main.sw | 2 +- .../impl_private_method/src/lib.sw | 4 +- .../impl_private_method/src/main.sw | 4 +- .../infinite_dependencies/src/a_dependency.sw | 4 +- .../src/a_dependency/a_dependency.sw | 1 + .../infinite_dependencies/src/b_dependency.sw | 2 - .../infinite_dependencies/src/main.sw | 4 +- .../invalid_fully_qualified_type/src/foo.sw | 2 +- .../invalid_fully_qualified_type/src/main.sw | 2 +- .../item_used_without_import/src/bar.sw | 2 +- .../item_used_without_import/src/main.sw | 2 +- .../src/adt_tests.sw | 2 +- .../src/complex_tests.sw | 2 +- .../src/main.sw | 6 +- .../src/primitive_tests.sw | 2 +- .../src/main.sw | 4 +- .../src/module0.sw | 2 +- .../src/module1.sw | 4 +- .../src/main.sw | 4 +- .../src/module0.sw | 2 +- .../src/module1.sw | 2 +- .../src/main.sw | 2 +- .../src/other_contract.sw | 2 +- .../src/main.sw | 2 +- .../src/wallet.sw | 2 +- .../src/wallet_abi.sw | 2 +- .../src/main.sw | 2 +- .../src/wallet.sw | 2 +- .../src/wallet_abi.sw | 2 +- .../src/main.sw | 2 +- .../src/wallet.sw | 2 +- .../src/wallet_abi.sw | 2 +- .../predicate_while_dep/src/loop.sw | 2 +- .../predicate_while_dep/src/main.sw | 2 +- .../primitive_type_argument/src/foo.sw | 4 +- .../src/{bar/baz.sw => foo/bar.sw} | 2 +- .../primitive_type_argument/src/main.sw | 4 +- .../primitive_type_argument/test.toml | 2 +- .../src/main.sw | 4 +- .../src/pkga.sw | 4 +- .../src/bar.sw | 2 +- .../src/foo.sw | 2 +- .../src/main.sw | 8 +- .../src/bar.sw | 2 +- .../src/baz.sw | 2 +- .../src/foo.sw | 2 +- .../src/main.sw | 6 +- .../reserved_identifiers/src/main.sw | 2 +- .../should_fail/shadow_import/src/bar.sw | 2 +- .../should_fail/shadow_import/src/main.sw | 2 +- .../shadowed_consts_and_vars/src/lib.sw | 2 +- .../shadowed_consts_and_vars/src/main.sw | 2 +- .../shadowed_consts_and_vars_alias/src/lib.sw | 2 +- .../src/main.sw | 2 +- .../shadowed_types_and_traits/src/lib.sw | 2 +- .../shadowed_types_and_traits/src/main.sw | 2 +- .../src/lib.sw | 2 +- .../src/main.sw | 2 +- .../should_fail/star_import_alias/src/bar.sw | 2 +- .../should_fail/star_import_alias/src/main.sw | 2 +- .../storage_in_library/src/inner.sw | 2 +- .../should_fail/storage_in_library/src/lib.sw | 2 +- .../storage_in_library/src/main.sw | 2 +- .../storage_ops_in_library/src/do_storage.sw | 2 +- .../storage_ops_in_library/src/main.sw | 2 +- .../supertraits_for_abis_ownable1/src/main.sw | 2 +- .../src/ownable.sw | 2 +- .../supertraits_for_abis_ownable2/src/main.sw | 2 +- .../src/ownable.sw | 2 +- .../src/main.sw | 2 +- .../traits_with_call_paths/src/main.sw | 4 +- .../traits_with_call_paths/src/my_a.sw | 2 +- .../traits_with_call_paths/src/my_add.sw | 2 +- .../dca/library/fn_params_free/src/main.sw | 2 +- .../dca/library/fn_params_impl/src/main.sw | 2 +- .../dca/library/fn_params_trait/src/main.sw | 2 +- .../library/unused_priv_free_fn/src/main.sw | 2 +- .../library/unused_pub_free_fn/src/main.sw | 2 +- .../multiple_enums_same_name/src/colors1.sw | 2 +- .../multiple_enums_same_name/src/colors2.sw | 2 +- .../dca/multiple_enums_same_name/src/main.sw | 4 +- .../dca/multiple_fns_same_name/src/colors1.sw | 2 +- .../dca/multiple_fns_same_name/src/colors2.sw | 2 +- .../dca/multiple_fns_same_name/src/main.sw | 4 +- .../should_pass/dca/unused_enum/src/enum.sw | 2 +- .../should_pass/dca/unused_enum/src/main.sw | 4 +- .../should_pass/dca/unused_enum/src/utils.sw | 5 +- .../should_pass/dca/unused_fields/src/main.sw | 2 +- .../dca/unused_fields/src/utils.sw | 2 +- .../should_pass/dca/unused_trait/src/main.sw | 4 +- .../should_pass/dca/unused_trait/src/trait.sw | 2 +- .../should_pass/dca/unused_trait/src/utils.sw | 5 +- .../workspace_building/test_lib/src/lib.sw | 2 +- .../src/{a_dependency.sw => foo.sw} | 2 +- .../language/aliased_imports/src/main.sw | 2 +- .../src/consts.sw | 2 +- .../const_decl_and_use_in_library/src/main.sw | 2 +- .../const_decl_in_library/src/earth.sw | 2 +- .../const_decl_in_library/src/heaven.sw | 2 +- .../const_decl_in_library/src/hell.sw | 2 +- .../const_decl_in_library/src/main.sw | 6 +- .../const_decl_with_call_path/src/main.sw | 2 +- .../const_decl_with_call_path/src/test_lib.sw | 2 +- .../language/dependencies/Forc.lock | 8 -- .../language/dependencies/Forc.toml | 8 -- .../dependencies/json_abi_oracle.json | 25 ---- .../language/dependencies/src/a_dependency.sw | 6 - .../language/dependencies/src/bar.sw | 2 - .../language/dependencies/src/inner/bar.sw | 8 -- .../src/inner/double_inner/double_bar.sw | 6 - .../language/dependencies/src/main.sw | 21 ---- .../src/nested_dependency/bar/bar.sw | 6 - .../language/dependencies/test.toml | 4 - .../language/generic_traits/src/main.sw | 6 +- .../language/generic_traits/src/my_double.sw | 2 +- .../language/generic_traits/src/my_point.sw | 2 +- .../language/generic_traits/src/my_triple.sw | 2 +- .../generic_type_inference/src/main.sw | 2 +- .../generic_type_inference/src/utils.sw | 2 +- .../src/asset.sw | 2 +- .../src/context.sw | 2 +- .../import_method_from_other_file/src/main.sw | 6 +- .../src/utils.sw | 2 +- .../language/import_trailing_comma/src/lib.sw | 2 +- .../import_trailing_comma/src/main.sw | 4 +- .../src/data_structures.sw | 4 +- .../src/eq_impls.sw | 6 +- .../src/main.sw | 6 +- .../language/multi_item_import/src/bar.sw | 4 +- .../src/{inner => bar}/double_bar.sw | 2 +- .../language/multi_item_import/src/main.sw | 2 +- .../primitive_type_argument/src/foo.sw | 4 +- .../primitive_type_argument/src/foo/bar.sw | 3 + .../src/{ => foo}/bar/baz.sw | 4 +- .../src/{bar => foo/bar/baz}/quux.sw | 2 +- .../primitive_type_argument/src/main.sw | 8 +- .../language/raw_identifiers/src/main.sw | 2 +- .../shadowed_glob_imports/src/lib.sw | 2 +- .../shadowed_glob_imports/src/main.sw | 2 +- .../language/test_attribute/src/main.sw | 2 +- .../test_multiple_attributes/src/main.sw | 2 +- .../trait_import_with_star/src/main.sw | 2 +- .../trait_import_with_star/src/shiftable.sw | 2 +- .../typeinfo_custom_callpath/src/foo.sw | 4 +- .../typeinfo_custom_callpath/src/main.sw | 2 +- .../typeinfo_custom_callpath2/src/foo.sw | 4 +- .../typeinfo_custom_callpath2/src/main.sw | 2 +- .../src/foo.sw | 4 +- .../src/main.sw | 2 +- .../src/{b_dependency.sw => bar.sw} | 4 +- .../src/{c_dependency.sw => baz.sw} | 2 +- .../src/{a_dependency.sw => foo.sw} | 2 +- .../language/use_full_path_names/src/main.sw | 6 +- .../src/main.sw | 2 +- .../src/wallet.sw | 2 +- .../src/wallet_abi.sw | 2 +- .../src/main.sw | 2 +- .../src/wallet.sw | 2 +- .../src/wallet_abi.sw | 2 +- .../payable_non_zero_coins/src/main.sw | 2 +- .../payable_non_zero_coins/src/wallet.sw | 2 +- .../payable_non_zero_coins/src/wallet_abi.sw | 2 +- .../should_pass/stdlib/chess/src/huge_enum.sw | 2 +- .../should_pass/stdlib/chess/src/main.sw | 2 +- .../stdlib/option/src/data_structures.sw | 2 +- .../should_pass/stdlib/option/src/main.sw | 4 +- .../should_pass/stdlib/option/src/tests.sw | 6 +- .../stdlib/result/src/data_structures.sw | 2 +- .../should_pass/stdlib/result/src/main.sw | 4 +- .../should_pass/stdlib/result/src/tests.sw | 8 +- .../supertraits_for_abis_ownable/src/main.sw | 2 +- .../src/ownable.sw | 2 +- .../test_abis/abi_with_tuples/src/main.sw | 4 +- .../array_of_structs_abi/src/main.sw | 2 +- .../test_abis/auth_testing_abi/src/main.sw | 2 +- .../test_abis/balance_test_abi/src/main.sw | 2 +- .../test_abis/basic_storage_abi/src/main.sw | 2 +- .../test_abis/context_testing_abi/src/main.sw | 2 +- .../test_abis/get_storage_key_abi/src/main.sw | 2 +- .../test_abis/increment_abi/src/main.sw | 2 +- .../nested_struct_args_abi/src/main.sw | 2 +- .../test_abis/storage_access_abi/src/main.sw | 2 +- .../test_abis/test_fuel_coin_abi/src/main.sw | 2 +- .../src/{folder1 => }/dep_1.sw | 4 +- .../src/{folder2 => }/dep_2.sw | 4 +- .../abi_with_same_name_types/src/main.sw | 4 +- .../test_contracts/multiple_impl/src/main.sw | 4 +- .../multiple_impl/src/testlib.sw | 2 +- .../multiple_impl/src/testlib2.sw | 2 +- .../return_struct/json_abi_oracle.json | 2 +- .../return_struct/src/data_structures.sw | 4 +- .../return_struct/src/interface.sw | 8 +- .../test_contracts/return_struct/src/main.sw | 6 +- .../contract_with_nested_libs/src/inner.sw | 4 +- .../src/{ => inner}/inner2.sw | 2 +- .../contract_with_nested_libs/src/main.sw | 2 +- .../unit_tests/lib_multi_test/src/lib.sw | 2 +- .../unit_tests/lib_single_test/src/lib.sw | 2 +- .../unit_tests/nested_libs/src/inner.sw | 4 +- .../nested_libs/src/{ => inner}/inner2.sw | 2 +- .../unit_tests/nested_libs/src/lib.sw | 4 +- .../predicate_with_nested_libs/src/inner.sw | 4 +- .../src/{ => inner}/inner2.sw | 2 +- .../predicate_with_nested_libs/src/main.sw | 2 +- .../script_with_nested_libs/src/inner.sw | 4 +- .../src/{ => inner}/inner2.sw | 2 +- .../script_with_nested_libs/src/main.sw | 2 +- .../unit_tests/should_revert/src/lib.sw | 2 +- .../workspace_test/lib_multi_test/src/lib.sw | 2 +- test/src/ir_generation/mod.rs | 1 + .../auth_testing_abi/src/main.sw | 2 +- .../test_artifacts/block_test_abi/src/main.sw | 2 +- .../call_frames_test_abi/src/main.sw | 2 +- .../context_testing_abi/src/main.sw | 2 +- .../test_artifacts/evm_test_abi/src/main.sw | 2 +- .../test_artifacts/methods_abi/src/main.sw | 2 +- .../parsing_logs_test_abi/src/main.sw | 2 +- 430 files changed, 994 insertions(+), 1171 deletions(-) delete mode 100644 sway-ast/src/dependency.rs create mode 100644 sway-ast/src/submodule.rs create mode 100644 sway-lib-std/src/vm.sw create mode 100644 sway-lib-std/src/vm/evm.sw delete mode 100644 sway-lib-std/src/vm/evm/mod.sw delete mode 100644 sway-lib-std/src/vm/mod.sw delete mode 100644 sway-lsp/tests/fixtures/tokens/modules/src/dir_mod/mod.sw create mode 100644 sway-lsp/tests/fixtures/tokens/modules/src/test_mod/deep_mod.sw delete mode 100644 sway-parse/src/dependency.rs create mode 100644 sway-parse/src/submodule.rs delete mode 100644 swayfmt/src/module/dependency.rs create mode 100644 swayfmt/src/module/submodule.rs delete mode 100644 test/src/e2e_vm_tests/test_programs/should_fail/dependency_parsing_error/Forc.lock delete mode 100644 test/src/e2e_vm_tests/test_programs/should_fail/dependency_parsing_error/Forc.toml delete mode 100644 test/src/e2e_vm_tests/test_programs/should_fail/dependency_parsing_error/json_abi_oracle.json delete mode 100644 test/src/e2e_vm_tests/test_programs/should_fail/dependency_parsing_error/src/a_dependency.sw delete mode 100644 test/src/e2e_vm_tests/test_programs/should_fail/dependency_parsing_error/src/bar.sw delete mode 100644 test/src/e2e_vm_tests/test_programs/should_fail/dependency_parsing_error/src/inner/bar.sw delete mode 100644 test/src/e2e_vm_tests/test_programs/should_fail/dependency_parsing_error/src/inner/double_inner/double_bar.sw delete mode 100644 test/src/e2e_vm_tests/test_programs/should_fail/dependency_parsing_error/src/main.sw delete mode 100644 test/src/e2e_vm_tests/test_programs/should_fail/dependency_parsing_error/src/nested_dependency/bar/bar.sw delete mode 100644 test/src/e2e_vm_tests/test_programs/should_fail/dependency_parsing_error/test.toml rename test/src/e2e_vm_tests/test_programs/should_fail/enum_variant_unit/src/{ => lib_a}/inner_lib.sw (90%) rename test/src/e2e_vm_tests/test_programs/should_fail/generics_multiple_type_arguments/src/{ => lib_a}/inner_lib.sw (75%) rename test/src/e2e_vm_tests/test_programs/should_fail/generics_not_supported/src/{ => lib_a}/inner_lib.sw (59%) create mode 120000 test/src/e2e_vm_tests/test_programs/should_fail/infinite_dependencies/src/a_dependency/a_dependency.sw delete mode 100644 test/src/e2e_vm_tests/test_programs/should_fail/infinite_dependencies/src/b_dependency.sw rename test/src/e2e_vm_tests/test_programs/should_fail/primitive_type_argument/src/{bar/baz.sw => foo/bar.sw} (77%) rename test/src/e2e_vm_tests/test_programs/should_pass/language/aliased_imports/src/{a_dependency.sw => foo.sw} (72%) delete mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/dependencies/Forc.lock delete mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/dependencies/Forc.toml delete mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/dependencies/json_abi_oracle.json delete mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/dependencies/src/a_dependency.sw delete mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/dependencies/src/bar.sw delete mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/dependencies/src/inner/bar.sw delete mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/dependencies/src/inner/double_inner/double_bar.sw delete mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/dependencies/src/main.sw delete mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/dependencies/src/nested_dependency/bar/bar.sw delete mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/dependencies/test.toml rename test/src/e2e_vm_tests/test_programs/should_pass/language/multi_item_import/src/{inner => bar}/double_bar.sw (85%) create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/primitive_type_argument/src/foo/bar.sw rename test/src/e2e_vm_tests/test_programs/should_pass/language/primitive_type_argument/src/{ => foo}/bar/baz.sw (73%) rename test/src/e2e_vm_tests/test_programs/should_pass/language/primitive_type_argument/src/{bar => foo/bar/baz}/quux.sw (85%) rename test/src/e2e_vm_tests/test_programs/should_pass/language/use_full_path_names/src/{b_dependency.sw => bar.sw} (68%) rename test/src/e2e_vm_tests/test_programs/should_pass/language/use_full_path_names/src/{c_dependency.sw => baz.sw} (75%) rename test/src/e2e_vm_tests/test_programs/should_pass/language/use_full_path_names/src/{a_dependency.sw => foo.sw} (72%) rename test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/abi_with_same_name_types/src/{folder1 => }/dep_1.sw (86%) rename test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/abi_with_same_name_types/src/{folder2 => }/dep_2.sw (86%) rename test/src/e2e_vm_tests/test_programs/should_pass/unit_tests/contract_with_nested_libs/src/{ => inner}/inner2.sw (90%) rename test/src/e2e_vm_tests/test_programs/should_pass/unit_tests/nested_libs/src/{ => inner}/inner2.sw (90%) rename test/src/e2e_vm_tests/test_programs/should_pass/unit_tests/predicate_with_nested_libs/src/{ => inner}/inner2.sw (85%) rename test/src/e2e_vm_tests/test_programs/should_pass/unit_tests/script_with_nested_libs/src/{ => inner}/inner2.sw (90%) diff --git a/docs/book/src/advanced/traits.md b/docs/book/src/advanced/traits.md index 4e2c9b885ef..e721674838e 100644 --- a/docs/book/src/advanced/traits.md +++ b/docs/book/src/advanced/traits.md @@ -77,7 +77,7 @@ ABI supertraits are intended to make contract implementations compositional, all Often, libraries and APIs have interfaces that are abstracted over a type that implements a certain trait. It is up to the consumer of the interface to implement that trait for the type they wish to use with the interface. For example, let's take a look at a trait and an interface built off of it. ```sway -library games; +library; pub enum Suit { Hearts: (), diff --git a/docs/book/src/sway-program-types/libraries.md b/docs/book/src/sway-program-types/libraries.md index 614fe073fc7..74459ca0282 100644 --- a/docs/book/src/sway-program-types/libraries.md +++ b/docs/book/src/sway-program-types/libraries.md @@ -7,17 +7,17 @@ Libraries in Sway are files used to define new common behavior. The most promine Libraries are defined using the `library` keyword at the beginning of a file, followed by a name so that they can be imported. ```sway -library my_library; +library; // library code ``` A good reference library to use when learning library design is the [Sway Standard Library](../introduction/standard_library.html). For example, the standard library offers an [implementation](https://github.com/FuelLabs/sway/blob/master/sway-lib-std/src/option.sw) of `enum Option` which is a generic type that represents either the existence of a value using the variant `Some(..)` or a value's absence using the variant `None`. The [Sway file implementing `Option`](https://github.com/FuelLabs/sway/blob/master/sway-lib-std/src/option.sw) has the following structure: -- The `library` keyword followed by the name of the library: +- The `library` keyword: ```sway -library option; +library; ``` - A `use` statement that imports `revert` from another library _inside_ the standard library: @@ -63,26 +63,39 @@ name = "my_library" which denotes the authors, an entry file, the name by which it can be imported, and any dependencies. -For large libraries, it is recommended to have a `lib.sw` entry point re-export all other sub-libraries. For example, the `lib.sw` of the standard library looks like: +For large libraries, it is recommended to have a `lib.sw` entry point re-export all other sub-libraries. + +The `mod` keyword registers a submodule, making its items (such as functions and structs) accessible from the parent library. +If used at the top level it will refer to a file in the `src` folder and in other cases in a folder named after the library in which it is defined. + +For example, the `lib.sw` of the standard library looks like: ```sway -library std; +library; -dep block; -dep storage; -dep constants; +mod block; +mod storage; +mod constants; +mod vm; // .. Other deps ``` -with other libraries contained in the `src` folder, like the block library (inside of `block.sw`): +with other libraries contained in the `src` folder, like the vm library (inside of `src/vm.sw`): ```sway -library block; +library; -// Implementation of the `block` library +mod evm; +// ... ``` -The `dep` keyword in the main library includes a dependency on another library, making all of its items (such as functions and structs) accessible from the main library. The `dep` keyword simply makes the library a dependency and fully accessible within the current context. +and it's own sub-library evm located in `src/vm/evm.sw`: + +```sway +library; + +// ... +``` ## Using Libraries @@ -90,7 +103,8 @@ There are two types of Sway libraries, based on their location and how they can ### Internal Libraries -Internal libraries are located within the project's `src` directory alongside `main.sw` as shown below: +Internal libraries are located within the project's `src` directory alongside +`main.sw` or in the appropriate folders as shown below: ```bash $ tree @@ -99,16 +113,18 @@ $ tree ├── Forc.toml └── src ├── internal_lib.sw - └── main.sw + ├── main.sw + └── internal_lib + └── nested_lib.sw ``` As `internal_lib` is an internal library, it can be imported into `main.sw` as follows: -- Use the `dep` keyword followed by the library name to make the internal library a dependancy +- Use the `mod` keyword followed by the library name to make the internal library a dependancy - Use the `use` keyword with a `::` separating the name of the library and the imported item(s) ```sway -dep internal_lib; // Assuming the library name in `internal_lib.sw` is `internal_lib` +mod internal_lib; // Assuming the library name in `internal_lib.sw` is `internal_lib` use internal_lib::mint; diff --git a/docs/reference/src/code/examples/fizzbuzz/src/lib.sw b/docs/reference/src/code/examples/fizzbuzz/src/lib.sw index 9c8388bc5d1..16e79f3716d 100644 --- a/docs/reference/src/code/examples/fizzbuzz/src/lib.sw +++ b/docs/reference/src/code/examples/fizzbuzz/src/lib.sw @@ -1,4 +1,4 @@ -library fizzbuzz; +library; // ANCHOR: state enum State { diff --git a/docs/reference/src/code/language/built-ins/arrays/src/lib.sw b/docs/reference/src/code/language/built-ins/arrays/src/lib.sw index 1ef18e51b23..e66eb3f8ea9 100644 --- a/docs/reference/src/code/language/built-ins/arrays/src/lib.sw +++ b/docs/reference/src/code/language/built-ins/arrays/src/lib.sw @@ -1,4 +1,4 @@ -library arrays; +library; // ANCHOR: syntax fn syntax() { diff --git a/docs/reference/src/code/language/built-ins/booleans/src/lib.sw b/docs/reference/src/code/language/built-ins/booleans/src/lib.sw index 005f0711070..a6497a985c6 100644 --- a/docs/reference/src/code/language/built-ins/booleans/src/lib.sw +++ b/docs/reference/src/code/language/built-ins/booleans/src/lib.sw @@ -1,4 +1,4 @@ -library booleans; +library; // ANCHOR: syntax fn returns_true() -> bool { diff --git a/docs/reference/src/code/language/built-ins/bytes/src/lib.sw b/docs/reference/src/code/language/built-ins/bytes/src/lib.sw index 0148b87d4d6..854f4653e33 100644 --- a/docs/reference/src/code/language/built-ins/bytes/src/lib.sw +++ b/docs/reference/src/code/language/built-ins/bytes/src/lib.sw @@ -1,4 +1,4 @@ -library bytes; +library; fn syntax() { // ANCHOR: syntax diff --git a/docs/reference/src/code/language/built-ins/enums/src/basic_enum.sw b/docs/reference/src/code/language/built-ins/enums/src/basic_enum.sw index 2f88f32e61e..f3aed8fe0b3 100644 --- a/docs/reference/src/code/language/built-ins/enums/src/basic_enum.sw +++ b/docs/reference/src/code/language/built-ins/enums/src/basic_enum.sw @@ -1,4 +1,4 @@ -library basic_enum; +library; // ANCHOR: definition enum Color { diff --git a/docs/reference/src/code/language/built-ins/enums/src/enum_of_enums.sw b/docs/reference/src/code/language/built-ins/enums/src/enum_of_enums.sw index fc7082957aa..0e9fbe55f17 100644 --- a/docs/reference/src/code/language/built-ins/enums/src/enum_of_enums.sw +++ b/docs/reference/src/code/language/built-ins/enums/src/enum_of_enums.sw @@ -1,4 +1,4 @@ -library enum_of_enums; +library; // ANCHOR: content enum UserError { diff --git a/docs/reference/src/code/language/built-ins/enums/src/enum_of_structs.sw b/docs/reference/src/code/language/built-ins/enums/src/enum_of_structs.sw index 0c1bf63254d..510e9f1b3a6 100644 --- a/docs/reference/src/code/language/built-ins/enums/src/enum_of_structs.sw +++ b/docs/reference/src/code/language/built-ins/enums/src/enum_of_structs.sw @@ -1,4 +1,4 @@ -library enum_of_structs; +library; // ANCHOR: content struct Item { diff --git a/docs/reference/src/code/language/built-ins/enums/src/main.sw b/docs/reference/src/code/language/built-ins/enums/src/main.sw index 7e100bb87b1..c6256de3272 100644 --- a/docs/reference/src/code/language/built-ins/enums/src/main.sw +++ b/docs/reference/src/code/language/built-ins/enums/src/main.sw @@ -1,4 +1,4 @@ -library enums; +library; -dep basic_enum; -dep enum_of_structs; +mod basic_enum; +mod enum_of_structs; diff --git a/docs/reference/src/code/language/built-ins/numerics/src/lib.sw b/docs/reference/src/code/language/built-ins/numerics/src/lib.sw index 9c3e05e7332..dafda18ac68 100644 --- a/docs/reference/src/code/language/built-ins/numerics/src/lib.sw +++ b/docs/reference/src/code/language/built-ins/numerics/src/lib.sw @@ -1,4 +1,4 @@ -library numerics; +library; fn syntax() { // ANCHOR: syntax diff --git a/docs/reference/src/code/language/built-ins/strings/src/lib.sw b/docs/reference/src/code/language/built-ins/strings/src/lib.sw index a45914b280c..ce9dc59e527 100644 --- a/docs/reference/src/code/language/built-ins/strings/src/lib.sw +++ b/docs/reference/src/code/language/built-ins/strings/src/lib.sw @@ -1,4 +1,4 @@ -library strings; +library; fn explicit() { // ANCHOR: explicit diff --git a/docs/reference/src/code/language/built-ins/structs/src/lib.sw b/docs/reference/src/code/language/built-ins/structs/src/lib.sw index ce4ddf81012..2c98bcdd286 100644 --- a/docs/reference/src/code/language/built-ins/structs/src/lib.sw +++ b/docs/reference/src/code/language/built-ins/structs/src/lib.sw @@ -1,4 +1,4 @@ -library structs; +library; // ANCHOR: definition struct Foo { diff --git a/docs/reference/src/code/language/built-ins/tuples/src/lib.sw b/docs/reference/src/code/language/built-ins/tuples/src/lib.sw index 5a5b1faa8e4..5fc14436ccf 100644 --- a/docs/reference/src/code/language/built-ins/tuples/src/lib.sw +++ b/docs/reference/src/code/language/built-ins/tuples/src/lib.sw @@ -1,4 +1,4 @@ -library tuples; +library; fn syntax() { // ANCHOR: declare diff --git a/docs/reference/src/code/language/comments/src/lib.sw b/docs/reference/src/code/language/comments/src/lib.sw index 05bf87cf867..a41236fb7e1 100644 --- a/docs/reference/src/code/language/comments/src/lib.sw +++ b/docs/reference/src/code/language/comments/src/lib.sw @@ -1,4 +1,4 @@ -library comments; +library; fn comment() { // ANCHOR: comment diff --git a/docs/reference/src/code/language/control_flow/src/lib.sw b/docs/reference/src/code/language/control_flow/src/lib.sw index 6f9aca523f5..cbd6bbdb8ca 100644 --- a/docs/reference/src/code/language/control_flow/src/lib.sw +++ b/docs/reference/src/code/language/control_flow/src/lib.sw @@ -1,4 +1,4 @@ -library control_flow; +library; fn conditional() { // ANCHOR: conditional diff --git a/docs/reference/src/code/language/functions/src/explicit.sw b/docs/reference/src/code/language/functions/src/explicit.sw index 5d69d9855c5..a78e1e897cc 100644 --- a/docs/reference/src/code/language/functions/src/explicit.sw +++ b/docs/reference/src/code/language/functions/src/explicit.sw @@ -1,4 +1,4 @@ -library explicit; +library; // ANCHOR: main fn main() -> bool { diff --git a/docs/reference/src/code/language/functions/src/implicit.sw b/docs/reference/src/code/language/functions/src/implicit.sw index 52f8e3cd6f3..3defa869af8 100644 --- a/docs/reference/src/code/language/functions/src/implicit.sw +++ b/docs/reference/src/code/language/functions/src/implicit.sw @@ -1,4 +1,4 @@ -library implicit; +library; // ANCHOR: main fn main() -> bool { diff --git a/docs/reference/src/code/language/functions/src/lib.sw b/docs/reference/src/code/language/functions/src/lib.sw index 07b1afe0059..9514af46eb5 100644 --- a/docs/reference/src/code/language/functions/src/lib.sw +++ b/docs/reference/src/code/language/functions/src/lib.sw @@ -1,7 +1,7 @@ -library functions; +library; -dep explicit; -dep implicit; +mod explicit; +mod implicit; // ANCHOR: definition fn my_function(my_parameter: u64 /* ... */) -> u64 { diff --git a/docs/reference/src/code/language/program-types/contracts/interface/src/lib.sw b/docs/reference/src/code/language/program-types/contracts/interface/src/lib.sw index 819378ccbe2..0b99dcf60dc 100644 --- a/docs/reference/src/code/language/program-types/contracts/interface/src/lib.sw +++ b/docs/reference/src/code/language/program-types/contracts/interface/src/lib.sw @@ -1,4 +1,4 @@ -library interface; +library; abi Wallet { /// When the BASE_ASSET is sent to this function the internal contract balance is incremented diff --git a/docs/reference/src/code/language/program-types/libraries/external/my_library/src/lib.sw b/docs/reference/src/code/language/program-types/libraries/external/my_library/src/lib.sw index d2c775b1827..4909ffaae08 100644 --- a/docs/reference/src/code/language/program-types/libraries/external/my_library/src/lib.sw +++ b/docs/reference/src/code/language/program-types/libraries/external/my_library/src/lib.sw @@ -1,4 +1,4 @@ -library my_library; +library; use my_other_library::quix; diff --git a/docs/reference/src/code/language/program-types/libraries/external/my_other_library/src/lib.sw b/docs/reference/src/code/language/program-types/libraries/external/my_other_library/src/lib.sw index bf814ea7562..d70efd681e8 100644 --- a/docs/reference/src/code/language/program-types/libraries/external/my_other_library/src/lib.sw +++ b/docs/reference/src/code/language/program-types/libraries/external/my_other_library/src/lib.sw @@ -1,3 +1,3 @@ -library my_other_library; +library; pub fn quix() {} diff --git a/docs/reference/src/code/language/program-types/libraries/internal/my_library/src/lib.sw b/docs/reference/src/code/language/program-types/libraries/internal/my_library/src/lib.sw index 75748cdce2c..b1baf1b1d65 100644 --- a/docs/reference/src/code/language/program-types/libraries/internal/my_library/src/lib.sw +++ b/docs/reference/src/code/language/program-types/libraries/internal/my_library/src/lib.sw @@ -1,6 +1,6 @@ -library lib; +library; -dep my_library; +mod my_library; use my_library::bar; diff --git a/docs/reference/src/code/language/program-types/libraries/internal/my_library/src/my_library.sw b/docs/reference/src/code/language/program-types/libraries/internal/my_library/src/my_library.sw index 6f78eb6000f..0de733fc013 100644 --- a/docs/reference/src/code/language/program-types/libraries/internal/my_library/src/my_library.sw +++ b/docs/reference/src/code/language/program-types/libraries/internal/my_library/src/my_library.sw @@ -1,6 +1,6 @@ // ANCHOR: library // ANCHOR: module -library my_library; +library; // ANCHOR_END: module // Cannot import because the `pub` keyword is missing diff --git a/docs/reference/src/code/language/style-guide/annotations/src/lib.sw b/docs/reference/src/code/language/style-guide/annotations/src/lib.sw index f95121bb91e..6b5179d43ae 100644 --- a/docs/reference/src/code/language/style-guide/annotations/src/lib.sw +++ b/docs/reference/src/code/language/style-guide/annotations/src/lib.sw @@ -1,4 +1,4 @@ -library annotations; +library; // ANCHOR: type_annotation fn execute() { diff --git a/docs/reference/src/code/language/style-guide/enums/src/lib.sw b/docs/reference/src/code/language/style-guide/enums/src/lib.sw index c3aa73aaf5e..b2c2ab2e3fd 100644 --- a/docs/reference/src/code/language/style-guide/enums/src/lib.sw +++ b/docs/reference/src/code/language/style-guide/enums/src/lib.sw @@ -1,4 +1,4 @@ -library enums; +library; pub enum Error { StateError: StateError, diff --git a/docs/reference/src/code/language/style-guide/getters/src/lib.sw b/docs/reference/src/code/language/style-guide/getters/src/lib.sw index a9a9cc3e783..ac7e90ce7fa 100644 --- a/docs/reference/src/code/language/style-guide/getters/src/lib.sw +++ b/docs/reference/src/code/language/style-guide/getters/src/lib.sw @@ -1,4 +1,4 @@ -library getters; +library; // ANCHOR: avoid fn get_maximum_deposit() -> u64 { diff --git a/docs/reference/src/code/language/style-guide/letter_casing/src/lib.sw b/docs/reference/src/code/language/style-guide/letter_casing/src/lib.sw index 5d9672ef23d..4987bd809f3 100644 --- a/docs/reference/src/code/language/style-guide/letter_casing/src/lib.sw +++ b/docs/reference/src/code/language/style-guide/letter_casing/src/lib.sw @@ -1,5 +1,5 @@ // ANCHOR: module -library letter_casing; +library; // ANCHOR_END: module // ANCHOR: const const MAXIMUM_DEPOSIT = 10; diff --git a/docs/reference/src/code/language/style-guide/struct_shorthand/src/lib.sw b/docs/reference/src/code/language/style-guide/struct_shorthand/src/lib.sw index 15813e07d8b..17048cf4387 100644 --- a/docs/reference/src/code/language/style-guide/struct_shorthand/src/lib.sw +++ b/docs/reference/src/code/language/style-guide/struct_shorthand/src/lib.sw @@ -1,4 +1,4 @@ -library struct_shorthand; +library; // ANCHOR: struct_shorthand_definition struct Structure { diff --git a/docs/reference/src/code/language/variables/src/lib.sw b/docs/reference/src/code/language/variables/src/lib.sw index b7abd3c6473..886202b239d 100644 --- a/docs/reference/src/code/language/variables/src/lib.sw +++ b/docs/reference/src/code/language/variables/src/lib.sw @@ -1,4 +1,4 @@ -library variables; +library; fn mutable() { // ANCHOR: mutable diff --git a/docs/reference/src/code/misc/advanced-concepts/enums/src/lib.sw b/docs/reference/src/code/misc/advanced-concepts/enums/src/lib.sw index 11371fdf219..7506bbd2603 100644 --- a/docs/reference/src/code/misc/advanced-concepts/enums/src/lib.sw +++ b/docs/reference/src/code/misc/advanced-concepts/enums/src/lib.sw @@ -1,4 +1,4 @@ -library enums; +library; // ANCHOR: u64_example pub enum T { diff --git a/docs/reference/src/code/misc/known-issues/arrays/src/lib.sw b/docs/reference/src/code/misc/known-issues/arrays/src/lib.sw index 8ee6b45901d..5799ac1774d 100644 --- a/docs/reference/src/code/misc/known-issues/arrays/src/lib.sw +++ b/docs/reference/src/code/misc/known-issues/arrays/src/lib.sw @@ -1,4 +1,4 @@ -library arrays; +library; // ANCHOR: syntax fn syntax() { diff --git a/docs/reference/src/code/misc/known-issues/strings/src/lib.sw b/docs/reference/src/code/misc/known-issues/strings/src/lib.sw index f344dd19583..ece532c83b2 100644 --- a/docs/reference/src/code/misc/known-issues/strings/src/lib.sw +++ b/docs/reference/src/code/misc/known-issues/strings/src/lib.sw @@ -1,4 +1,4 @@ -library strings; +library; fn single_quotes() { // ANCHOR: single_quotes diff --git a/docs/reference/src/code/operations/assertions/src/lib.sw b/docs/reference/src/code/operations/assertions/src/lib.sw index fba9cb950e0..aab2efe36a5 100644 --- a/docs/reference/src/code/operations/assertions/src/lib.sw +++ b/docs/reference/src/code/operations/assertions/src/lib.sw @@ -1,6 +1,6 @@ -library assertions; +library; -dep req; +mod req; // ANCHOR: assert fn subtract(a: u64, b: u64) -> u64 { diff --git a/docs/reference/src/code/operations/assertions/src/req.sw b/docs/reference/src/code/operations/assertions/src/req.sw index b88785a5b90..06de67e37bf 100644 --- a/docs/reference/src/code/operations/assertions/src/req.sw +++ b/docs/reference/src/code/operations/assertions/src/req.sw @@ -1,4 +1,4 @@ -library req; +library; // ANCHOR: require fn subtract(a: u64, b: u64) -> u64 { diff --git a/docs/reference/src/code/operations/asset_operations/src/lib.sw b/docs/reference/src/code/operations/asset_operations/src/lib.sw index b0aa6663a5b..4fc31f28882 100644 --- a/docs/reference/src/code/operations/asset_operations/src/lib.sw +++ b/docs/reference/src/code/operations/asset_operations/src/lib.sw @@ -1,4 +1,4 @@ -library asset_operations; +library; // ANCHOR: mint_import use std::token::mint; diff --git a/docs/reference/src/code/operations/call_data/src/lib.sw b/docs/reference/src/code/operations/call_data/src/lib.sw index 65b9663e69f..711a4cd27f3 100644 --- a/docs/reference/src/code/operations/call_data/src/lib.sw +++ b/docs/reference/src/code/operations/call_data/src/lib.sw @@ -1,4 +1,4 @@ -library call_data; +library; // ANCHOR: import_sender use std::auth::msg_sender; diff --git a/docs/reference/src/code/operations/contract_calling/interface/src/lib.sw b/docs/reference/src/code/operations/contract_calling/interface/src/lib.sw index fa61951c14c..2593e051231 100644 --- a/docs/reference/src/code/operations/contract_calling/interface/src/lib.sw +++ b/docs/reference/src/code/operations/contract_calling/interface/src/lib.sw @@ -1,4 +1,4 @@ -library interface; +library; abi Vault { fn deposit(); diff --git a/docs/reference/src/code/operations/hashing/src/lib.sw b/docs/reference/src/code/operations/hashing/src/lib.sw index 9ec702e1646..acddc274d92 100644 --- a/docs/reference/src/code/operations/hashing/src/lib.sw +++ b/docs/reference/src/code/operations/hashing/src/lib.sw @@ -1,4 +1,4 @@ -library hashing; +library; // ANCHOR: import_sha256 use std::hash::sha256; diff --git a/docs/reference/src/code/operations/logging/src/lib.sw b/docs/reference/src/code/operations/logging/src/lib.sw index 040198a80c2..a5a87cc682a 100644 --- a/docs/reference/src/code/operations/logging/src/lib.sw +++ b/docs/reference/src/code/operations/logging/src/lib.sw @@ -1,4 +1,4 @@ -library logging; +library; // ANCHOR: logging fn log_data(number: u64) { diff --git a/docs/reference/src/code/operations/namespace/src/lib.sw b/docs/reference/src/code/operations/namespace/src/lib.sw index 3c9f96e0615..50e85ac8044 100644 --- a/docs/reference/src/code/operations/namespace/src/lib.sw +++ b/docs/reference/src/code/operations/namespace/src/lib.sw @@ -1,4 +1,4 @@ -library namespace; +library; // ANCHOR: address pub struct Address { diff --git a/docs/reference/src/documentation/language/program-types/libraries/index.md b/docs/reference/src/documentation/language/program-types/libraries/index.md index ec2c5b6995d..509c9ba3e65 100644 --- a/docs/reference/src/documentation/language/program-types/libraries/index.md +++ b/docs/reference/src/documentation/language/program-types/libraries/index.md @@ -4,7 +4,7 @@ A library is used to contain code that performs common operations in order to pr ## Definition -Libraries are defined using the `library` keyword at the beginning of a file followed by a name so that they can be identified and imported. +Libraries are defined using the `library` keyword at the beginning of a file. ```sway {{#include ../../../../code/language/program-types/libraries/internal/my_library/src/my_library.sw:module}} diff --git a/docs/reference/src/documentation/language/program-types/libraries/internal.md b/docs/reference/src/documentation/language/program-types/libraries/internal.md index a3e537a8bb4..3fb2e7b1653 100644 --- a/docs/reference/src/documentation/language/program-types/libraries/internal.md +++ b/docs/reference/src/documentation/language/program-types/libraries/internal.md @@ -14,7 +14,7 @@ $ tree To be able to use our library `my_library.sw` in `lib.sw` there are two steps to take: -1. Bring our library into scope by using the `dep` keyword followed by the library name +1. Bring our library into scope by using the `mod` keyword followed by the library name 2. Use the `use` keyword to selectively import various items from the library ```sway diff --git a/examples/cei_analysis/src/main.sw b/examples/cei_analysis/src/main.sw index 332b49f5735..4da5241b340 100644 --- a/examples/cei_analysis/src/main.sw +++ b/examples/cei_analysis/src/main.sw @@ -1,6 +1,6 @@ contract; -dep other_contract; +mod other_contract; use other_contract::*; diff --git a/examples/cei_analysis/src/other_contract.sw b/examples/cei_analysis/src/other_contract.sw index 612069bd599..0e6b1edcce3 100644 --- a/examples/cei_analysis/src/other_contract.sw +++ b/examples/cei_analysis/src/other_contract.sw @@ -1,4 +1,4 @@ -library other_contract; +library; abi OtherContract { #[payable] diff --git a/examples/enums/src/basic_enum.sw b/examples/enums/src/basic_enum.sw index 6775d5fb03f..7f6e01b752f 100644 --- a/examples/enums/src/basic_enum.sw +++ b/examples/enums/src/basic_enum.sw @@ -1,4 +1,4 @@ -library basic_enum; +library; // Declare the enum enum Color { diff --git a/examples/enums/src/enum_of_enums.sw b/examples/enums/src/enum_of_enums.sw index 525d7a553e7..ab6add4ea8a 100644 --- a/examples/enums/src/enum_of_enums.sw +++ b/examples/enums/src/enum_of_enums.sw @@ -1,4 +1,4 @@ -library enum_of_enums; +library; pub enum Error { StateError: StateError, diff --git a/examples/enums/src/enum_of_structs.sw b/examples/enums/src/enum_of_structs.sw index e1a70778378..e74aa3528a4 100644 --- a/examples/enums/src/enum_of_structs.sw +++ b/examples/enums/src/enum_of_structs.sw @@ -1,4 +1,4 @@ -library enum_of_structs; +library; struct Item { price: u64, diff --git a/examples/enums/src/enums_avoid.sw b/examples/enums/src/enums_avoid.sw index d83e2db43e7..daf7fdb06cd 100644 --- a/examples/enums/src/enums_avoid.sw +++ b/examples/enums/src/enums_avoid.sw @@ -1,7 +1,6 @@ -library enums_avoid; +library; -dep enum_of_enums; -use enum_of_enums::{Error, StateError, UserError}; +use ::enum_of_enums::{Error, StateError, UserError}; fn avoid() { let error1 = Error::StateError(StateError::Void); diff --git a/examples/enums/src/enums_preferred.sw b/examples/enums/src/enums_preferred.sw index bb14e262bab..bc3bf885295 100644 --- a/examples/enums/src/enums_preferred.sw +++ b/examples/enums/src/enums_preferred.sw @@ -1,7 +1,6 @@ -library enums_preferred; +library; -dep enum_of_enums; -use enum_of_enums::{StateError, UserError}; +use ::enum_of_enums::{StateError, UserError}; fn preferred() { let error1 = StateError::Void; diff --git a/examples/enums/src/main.sw b/examples/enums/src/main.sw index 11fde68eae7..b6804891143 100644 --- a/examples/enums/src/main.sw +++ b/examples/enums/src/main.sw @@ -1,6 +1,7 @@ -library enums; +library; -dep basic_enum; -dep enums_avoid; -dep enums_preferred; -dep enum_of_structs; +mod basic_enum; +mod enum_of_structs; +mod enum_of_enums; +mod enums_avoid; +mod enums_preferred; diff --git a/examples/identity/src/abi.sw b/examples/identity/src/abi.sw index 36edd6a2961..01020f95910 100644 --- a/examples/identity/src/abi.sw +++ b/examples/identity/src/abi.sw @@ -1,4 +1,4 @@ -library r#abi; +library; abi IdentityExample { #[storage(read)] diff --git a/examples/identity/src/errors.sw b/examples/identity/src/errors.sw index 1b17a68760f..23640cea492 100644 --- a/examples/identity/src/errors.sw +++ b/examples/identity/src/errors.sw @@ -1,4 +1,4 @@ -library errors; +library; pub enum MyError { UnauthorizedUser: Identity, diff --git a/examples/identity/src/main.sw b/examples/identity/src/main.sw index 0315047f6c5..7b485a3ccc9 100644 --- a/examples/identity/src/main.sw +++ b/examples/identity/src/main.sw @@ -1,7 +1,7 @@ contract; -dep r#abi; -dep errors; +mod r#abi; +mod errors; use abi::IdentityExample; use errors::MyError; diff --git a/examples/structs/src/data_structures.sw b/examples/structs/src/data_structures.sw index daf8da6bfb4..69d100fcab9 100644 --- a/examples/structs/src/data_structures.sw +++ b/examples/structs/src/data_structures.sw @@ -1,4 +1,4 @@ -library data_structures; +library; // Declare a struct type pub struct Foo { diff --git a/examples/structs/src/main.sw b/examples/structs/src/main.sw index 10ffcce8fb7..108320a409d 100644 --- a/examples/structs/src/main.sw +++ b/examples/structs/src/main.sw @@ -1,6 +1,6 @@ -library utils; +library; -dep data_structures; +mod data_structures; use data_structures::{Foo, Line, Point, TupleInStruct}; fn hardcoded_instantiation() -> Foo { diff --git a/examples/tuples/src/main.sw b/examples/tuples/src/main.sw index 1736b43e5d4..c714f96c375 100644 --- a/examples/tuples/src/main.sw +++ b/examples/tuples/src/main.sw @@ -1,4 +1,4 @@ -library tuples; +library; fn tuple() { // You can declare the types youself diff --git a/examples/wallet_abi/src/main.sw b/examples/wallet_abi/src/main.sw index d1dd032516d..d4617722862 100644 --- a/examples/wallet_abi/src/main.sw +++ b/examples/wallet_abi/src/main.sw @@ -1,5 +1,5 @@ // ANCHOR: abi_library -library wallet_abi; +library; // ANCHOR: abi abi Wallet { diff --git a/forc-pkg/src/pkg.rs b/forc-pkg/src/pkg.rs index dd5b85f8b9e..4243bc9f7c7 100644 --- a/forc-pkg/src/pkg.rs +++ b/forc-pkg/src/pkg.rs @@ -658,7 +658,7 @@ impl BuildPlan { info!(" Creating a new `Forc.lock` file. (Cause: {})", cause); let member_names = manifests .iter() - .map(|(_, manifest)| manifest.project.name.clone()) + .map(|(_, manifest)| manifest.project.name.to_string()) .collect(); crate::lock::print_diff(&member_names, &lock_diff); let string = toml::ser::to_string_pretty(&new_lock) @@ -815,7 +815,11 @@ fn member_nodes(g: &Graph) -> impl Iterator + '_ { fn validate_graph(graph: &Graph, manifests: &MemberManifestFiles) -> Result> { let mut member_pkgs: HashMap<&String, &PackageManifestFile> = manifests.iter().collect(); let member_nodes: Vec<_> = member_nodes(graph) - .filter_map(|n| member_pkgs.remove(&graph[n].name).map(|pkg| (n, pkg))) + .filter_map(|n| { + member_pkgs + .remove(&graph[n].name.to_string()) + .map(|pkg| (n, pkg)) + }) .collect(); // If no member nodes, the graph is either empty or corrupted. Remove all edges. @@ -959,7 +963,7 @@ fn dep_path( // Otherwise, check if it comes from a patch. for (_, patch_map) in node_manifest.patches() { - if let Some(Dependency::Detailed(details)) = patch_map.get(dep_name) { + if let Some(Dependency::Detailed(details)) = patch_map.get(&dep_name.to_string()) { if let Some(ref rel_path) = details.path { if let Ok(path) = node_manifest.dir().join(rel_path).canonicalize() { if path.exists() { @@ -997,7 +1001,7 @@ fn remove_deps( ) { // Retrieve the project nodes for workspace members. let member_nodes: HashSet<_> = member_nodes(graph) - .filter(|&n| member_names.contains(&graph[n].name)) + .filter(|&n| member_names.contains(&graph[n].name.to_string())) .collect(); // Before removing edges, sort the nodes in order of dependency for the node removal pass. @@ -1344,14 +1348,17 @@ fn fetch_deps( ) .collect(); for (dep_name, dep, dep_kind) in deps { - let name = dep.package().unwrap_or(&dep_name).to_string(); + let name = dep.package().unwrap_or(&dep_name); let parent_manifest = &manifest_map[&parent_id]; let source = - Source::from_manifest_dep_patched(parent_manifest, &name, &dep, member_manifests) + Source::from_manifest_dep_patched(parent_manifest, name, &dep, member_manifests) .context("Failed to source dependency")?; // If we haven't yet fetched this dependency, fetch it, pin it and add it to the graph. - let dep_pkg = Pkg { name, source }; + let dep_pkg = Pkg { + name: name.to_string(), + source, + }; let dep_node = match fetched.entry(dep_pkg) { hash_map::Entry::Occupied(entry) => *entry.get(), hash_map::Entry::Vacant(entry) => { @@ -1503,9 +1510,7 @@ pub fn dependency_namespace( let mut namespace = namespace::Module::default_with_constants(engines, constants)?; let node_idx = &graph[node]; - namespace.name = Some(Ident::new_no_span(Box::leak( - node_idx.name.clone().into_boxed_str(), - ))); + namespace.name = Some(Ident::new_no_span(node_idx.name.clone())); // Add direct dependencies. let mut core_added = false; @@ -1553,10 +1558,18 @@ pub fn dependency_namespace( } } - namespace.star_import_with_reexports(&[CORE, PRELUDE].map(Ident::new_no_span), &[], engines); + namespace.star_import_with_reexports( + &[CORE, PRELUDE].map(|s| Ident::new_no_span(s.into())), + &[], + engines, + ); if has_std_dep(graph, node) { - namespace.star_import_with_reexports(&[STD, PRELUDE].map(Ident::new_no_span), &[], engines); + namespace.star_import_with_reexports( + &[STD, PRELUDE].map(|s| Ident::new_no_span(s.into())), + &[], + engines, + ); } Ok(namespace) @@ -1621,6 +1634,7 @@ pub fn compile_ast( build_target: BuildTarget, build_profile: &BuildProfile, namespace: namespace::Module, + package_name: &str, ) -> Result> { let source = manifest.entry_string()?; let sway_build_config = sway_build_config( @@ -1629,7 +1643,13 @@ pub fn compile_ast( build_target, build_profile, )?; - let ast_res = sway_core::compile_to_ast(engines, source, namespace, Some(&sway_build_config)); + let ast_res = sway_core::compile_to_ast( + engines, + source, + namespace, + Some(&sway_build_config), + package_name, + ); Ok(ast_res) } @@ -1697,7 +1717,7 @@ pub fn compile( // First, compile to an AST. We'll update the namespace and check for JSON ABI output. let ast_res = time_expr!( "compile to ast", - compile_ast(engines, manifest, *target, profile, namespace)? + compile_ast(engines, manifest, *target, profile, namespace, &pkg.name)? ); let typed_program = match ast_res.value.as_ref() { None => return fail(&ast_res.warnings, &ast_res.errors), @@ -2048,7 +2068,7 @@ pub fn build_with_options(build_options: BuildOpts) -> Result { match curr_manifest { Some(pkg_manifest) => { let built_pkg = built_workspace - .remove(&pkg_manifest.project.name) + .remove(&pkg_manifest.project.name.to_string()) .expect("package didn't exist in workspace"); Ok(Built::Package(Box::new(built_pkg))) } @@ -2270,9 +2290,18 @@ pub fn build( }; let (mut built_package, namespace) = compile_pkg(node, &mut source_map, compile_pkg_context)?; - if let TreeType::Library { ref name } = built_package.tree_type { + if let TreeType::Library = built_package.tree_type { let mut namespace = namespace::Module::from(namespace); - namespace.name = Some(name.clone()); + namespace.name = Some(Ident::new_no_span(pkg.name.clone())); + namespace.span = Some( + Span::new( + manifest.entry_string()?, + 0, + 0, + Some(manifest.entry_path().into()), + ) + .unwrap(), + ); lib_namespace_map.insert(node, namespace); } source_map.insert_dependency(manifest.dir()); @@ -2461,7 +2490,7 @@ pub fn check( Some(modules) => modules, }; - let ast_result = sway_core::parsed_to_ast(engines, &parsed, dep_namespace, None); + let ast_result = sway_core::parsed_to_ast(engines, &parsed, dep_namespace, None, &pkg.name); warnings.extend(ast_result.warnings); errors.extend(ast_result.errors); @@ -2474,9 +2503,18 @@ pub fn check( Some(typed_program) => typed_program, }; - if let TreeType::Library { name } = typed_program.kind.tree_type() { + if let TreeType::Library = typed_program.kind.tree_type() { let mut namespace = typed_program.root.namespace.clone(); - namespace.name = Some(name.clone()); + namespace.name = Some(Ident::new_no_span(pkg.name.clone())); + namespace.span = Some( + Span::new( + manifest.entry_string()?, + 0, + 0, + Some(manifest.entry_path().into()), + ) + .unwrap(), + ); lib_namespace_map.insert(node, namespace); } diff --git a/forc-plugins/forc-doc/src/doc.rs b/forc-plugins/forc-doc/src/doc.rs index 96b3eba416e..ae1895ad9c3 100644 --- a/forc-plugins/forc-doc/src/doc.rs +++ b/forc-plugins/forc-doc/src/doc.rs @@ -112,7 +112,7 @@ impl Document { let mut new_submodule_prefix = module_prefix.to_owned(); new_submodule_prefix .module_prefixes - .push(typed_submodule.library_name.as_str().to_owned()); + .push(typed_submodule.mod_name_span.as_str().to_owned()); for ast_node in &typed_submodule.module.all_nodes { if let TyAstNodeContent::Declaration(ref decl) = ast_node.content { let desc = Descriptor::from_typed_decl( diff --git a/forc/src/ops/forc_init.rs b/forc/src/ops/forc_init.rs index 64841323987..336e3fbbd38 100644 --- a/forc/src/ops/forc_init.rs +++ b/forc/src/ops/forc_init.rs @@ -139,7 +139,7 @@ pub fn init(command: InitCommand) -> Result<()> { .join("src") .join(constants::LIB_ENTRY), // Library names cannot have `-` in them because the Sway compiler does not allow that - defaults::default_library(&project_name.replace('-', "_")), + defaults::default_library(), )?, InitType::Package(ProgramType::Predicate) => fs::write( Path::new(&project_dir) diff --git a/forc/src/utils/defaults.rs b/forc/src/utils/defaults.rs index 2346703566e..1c45257b864 100644 --- a/forc/src/utils/defaults.rs +++ b/forc/src/utils/defaults.rs @@ -47,13 +47,12 @@ fn main() { .into() } -pub(crate) fn default_library(project_name: &str) -> String { - format!( - "library {project_name}; +pub(crate) fn default_library() -> String { + "library; // anything `pub` here will be exported as a part of this library's API " - ) + .into() } pub(crate) fn default_predicate() -> String { diff --git a/sway-ast/src/dependency.rs b/sway-ast/src/dependency.rs deleted file mode 100644 index 5b79a0b4f76..00000000000 --- a/sway-ast/src/dependency.rs +++ /dev/null @@ -1,29 +0,0 @@ -use crate::priv_prelude::*; - -#[derive(Clone, Debug)] -pub struct Dependency { - pub dep_token: DepToken, - pub path: DependencyPath, - pub semicolon_token: SemicolonToken, -} - -impl Spanned for Dependency { - fn span(&self) -> Span { - Span::join(self.dep_token.span(), self.semicolon_token.span()) - } -} - -#[derive(Clone, Debug)] -pub struct DependencyPath { - pub prefix: Ident, - pub suffixes: Vec<(ForwardSlashToken, Ident)>, -} - -impl Spanned for DependencyPath { - fn span(&self) -> Span { - match self.suffixes.last() { - Some((_forward_slash_token, suffix)) => Span::join(self.prefix.span(), suffix.span()), - None => self.prefix.span(), - } - } -} diff --git a/sway-ast/src/item/mod.rs b/sway-ast/src/item/mod.rs index f94c5717358..e9c8476eba2 100644 --- a/sway-ast/src/item/mod.rs +++ b/sway-ast/src/item/mod.rs @@ -25,7 +25,7 @@ impl Spanned for Item { #[allow(clippy::large_enum_variant)] #[derive(Clone, Debug)] pub enum ItemKind { - Dependency(Dependency), + Submodule(Submodule), Use(ItemUse), Struct(ItemStruct), Enum(ItemEnum), @@ -41,7 +41,7 @@ pub enum ItemKind { impl Spanned for ItemKind { fn span(&self) -> Span { match self { - ItemKind::Dependency(item_dep) => item_dep.span(), + ItemKind::Submodule(item_mod) => item_mod.span(), ItemKind::Use(item_use) => item_use.span(), ItemKind::Struct(item_struct) => item_struct.span(), ItemKind::Enum(item_enum) => item_enum.span(), diff --git a/sway-ast/src/keywords.rs b/sway-ast/src/keywords.rs index 92e6f972fe8..a49801b51c3 100644 --- a/sway-ast/src/keywords.rs +++ b/sway-ast/src/keywords.rs @@ -49,7 +49,7 @@ define_keyword!(ScriptToken, "script"); define_keyword!(ContractToken, "contract"); define_keyword!(PredicateToken, "predicate"); define_keyword!(LibraryToken, "library"); -define_keyword!(DepToken, "dep"); +define_keyword!(ModToken, "mod"); define_keyword!(PubToken, "pub"); define_keyword!(UseToken, "use"); define_keyword!(AsToken, "as"); diff --git a/sway-ast/src/lib.rs b/sway-ast/src/lib.rs index a1addf94a7a..e57a0998dbf 100644 --- a/sway-ast/src/lib.rs +++ b/sway-ast/src/lib.rs @@ -1,7 +1,6 @@ pub mod assignable; pub mod attribute; pub mod brackets; -pub mod dependency; pub mod expr; pub mod generics; pub mod intrinsics; @@ -14,6 +13,7 @@ pub mod pattern; mod priv_prelude; pub mod punctuated; pub mod statement; +pub mod submodule; pub mod token; pub mod ty; pub mod where_clause; @@ -22,7 +22,6 @@ pub use crate::{ assignable::Assignable, attribute::AttributeDecl, brackets::{AngleBrackets, Braces, Parens}, - dependency::Dependency, expr::{ asm::{AsmBlock, AsmRegisterDeclaration}, op_code::Instruction, @@ -51,6 +50,7 @@ pub use crate::{ pattern::{Pattern, PatternStructField}, punctuated::Punctuated, statement::{Statement, StatementLet}, + submodule::Submodule, ty::Ty, where_clause::{WhereBound, WhereClause}, }; diff --git a/sway-ast/src/module.rs b/sway-ast/src/module.rs index 2dc2d0bbf66..21d70c6e8b5 100644 --- a/sway-ast/src/module.rs +++ b/sway-ast/src/module.rs @@ -8,10 +8,10 @@ pub struct Module { } impl Module { - pub fn dependencies(&self) -> impl Iterator { + pub fn submodules(&self) -> impl Iterator { self.items.iter().filter_map(|i| { - if let ItemKind::Dependency(dep) = &i.value { - Some(dep) + if let ItemKind::Submodule(submod) = &i.value { + Some(submod) } else { None } @@ -33,19 +33,10 @@ impl Spanned for Module { #[derive(Clone, Debug)] pub enum ModuleKind { - Script { - script_token: ScriptToken, - }, - Contract { - contract_token: ContractToken, - }, - Predicate { - predicate_token: PredicateToken, - }, - Library { - library_token: LibraryToken, - name: Ident, - }, + Script { script_token: ScriptToken }, + Contract { contract_token: ContractToken }, + Predicate { predicate_token: PredicateToken }, + Library { library_token: LibraryToken }, } impl Spanned for ModuleKind { @@ -54,10 +45,7 @@ impl Spanned for ModuleKind { Self::Script { script_token } => script_token.span(), Self::Contract { contract_token } => contract_token.span(), Self::Predicate { predicate_token } => predicate_token.span(), - Self::Library { - library_token, - name, - } => Span::join(library_token.span(), name.span()), + Self::Library { library_token } => library_token.span(), } } } diff --git a/sway-ast/src/priv_prelude.rs b/sway-ast/src/priv_prelude.rs index 77a622ebdb8..ba3d773e20b 100644 --- a/sway-ast/src/priv_prelude.rs +++ b/sway-ast/src/priv_prelude.rs @@ -3,7 +3,6 @@ pub use { assignable::Assignable, attribute::{Annotated, Attribute, AttributeDecl}, brackets::{AngleBrackets, Braces, Parens, SquareBrackets}, - dependency::Dependency, expr::{ asm::{AsmBlock, AsmImmediate}, op_code::Instruction, @@ -30,6 +29,7 @@ pub use { pattern::Pattern, punctuated::Punctuated, statement::{Statement, StatementLet}, + submodule::Submodule, token::{Delimiter, Group, Punct, PunctKind, Spacing, TokenStream, TokenTree}, ty::Ty, where_clause::{WhereBound, WhereClause}, diff --git a/sway-ast/src/submodule.rs b/sway-ast/src/submodule.rs new file mode 100644 index 00000000000..5afa01eb057 --- /dev/null +++ b/sway-ast/src/submodule.rs @@ -0,0 +1,14 @@ +use crate::priv_prelude::*; + +#[derive(Clone, Debug)] +pub struct Submodule { + pub mod_token: ModToken, + pub name: Ident, + pub semicolon_token: SemicolonToken, +} + +impl Spanned for Submodule { + fn span(&self) -> Span { + Span::join(self.mod_token.span(), self.semicolon_token.span()) + } +} diff --git a/sway-core/src/language/lexed/mod.rs b/sway-core/src/language/lexed/mod.rs index 06afde06ddf..2e6a30a85fc 100644 --- a/sway-core/src/language/lexed/mod.rs +++ b/sway-core/src/language/lexed/mod.rs @@ -1,9 +1,8 @@ mod program; -use crate::language::DepName; +use crate::language::ModName; pub use program::LexedProgram; use sway_ast::Module; -use sway_types::Ident; /// A module and its submodules in the form of a tree. #[derive(Debug, Clone)] @@ -11,15 +10,13 @@ pub struct LexedModule { /// The content of this module in the form of a [Module]. pub tree: Module, /// Submodules introduced within this module using the `dep` syntax in order of declaration. - pub submodules: Vec<(DepName, LexedSubmodule)>, + pub submodules: Vec<(ModName, LexedSubmodule)>, } -/// A library module that was declared as a `dep` of another module. +/// A library module that was declared as a `mod` of another module. /// -/// Only submodules are guaranteed to be a `library` and have a `library_name`. +/// Only submodules are guaranteed to be a `library`. #[derive(Debug, Clone)] pub struct LexedSubmodule { - /// The name of a submodule, parsed from the `library` declaration within the module itself. - pub library_name: Ident, pub module: LexedModule, } diff --git a/sway-core/src/language/module.rs b/sway-core/src/language/module.rs index 644b38d852f..f19832b2367 100644 --- a/sway-core/src/language/module.rs +++ b/sway-core/src/language/module.rs @@ -2,6 +2,6 @@ use sway_types::Ident; /// The name used within a module to refer to one of its submodules. /// -/// If an alias was given to the `dep`, this will be the alias. If not, this is the submodule's +/// If an alias was given to the `mod`, this will be the alias. If not, this is the submodule's /// library name. -pub type DepName = Ident; +pub type ModName = Ident; diff --git a/sway-core/src/language/parsed/expression/mod.rs b/sway-core/src/language/parsed/expression/mod.rs index 0de29d5d540..7a51bb969ed 100644 --- a/sway-core/src/language/parsed/expression/mod.rs +++ b/sway-core/src/language/parsed/expression/mod.rs @@ -247,7 +247,7 @@ pub(crate) struct Op { impl Op { pub fn to_var_name(&self) -> Ident { - Ident::new_with_override(self.op_variant.as_str(), self.span.clone()) + Ident::new_with_override(self.op_variant.as_str().to_string(), self.span.clone()) } } diff --git a/sway-core/src/language/parsed/include_statement.rs b/sway-core/src/language/parsed/include_statement.rs index 710e96ee1c8..1c48a3085c3 100644 --- a/sway-core/src/language/parsed/include_statement.rs +++ b/sway-core/src/language/parsed/include_statement.rs @@ -1,10 +1,8 @@ -use sway_types::{ident::Ident, span::Span}; +use sway_types::span::Span; #[derive(Clone, Debug)] pub struct IncludeStatement { - pub(crate) _alias: Option, - #[allow(dead_code)] // this span may be used for errors in the future, although it is not right now. - pub(crate) span: Span, - pub(crate) _path_span: Span, + pub(crate) _span: Span, + pub(crate) _mod_name_span: Span, } diff --git a/sway-core/src/language/parsed/mod.rs b/sway-core/src/language/parsed/mod.rs index 748654dda7b..c4bffc7324a 100644 --- a/sway-core/src/language/parsed/mod.rs +++ b/sway-core/src/language/parsed/mod.rs @@ -57,7 +57,7 @@ pub enum AstNodeContent { /// An implicit return expression is an [Expression] at the end of a code block which has no /// semicolon, denoting that it is the [Expression] to be returned from that block. ImplicitReturnExpression(Expression), - /// A statement of the form `dep foo::bar;` which imports/includes another source file. + /// A statement of the form `mod foo::bar;` which imports/includes another source file. IncludeStatement(IncludeStatement), } diff --git a/sway-core/src/language/parsed/module.rs b/sway-core/src/language/parsed/module.rs index 5b2d7d45c36..17f2114351c 100644 --- a/sway-core/src/language/parsed/module.rs +++ b/sway-core/src/language/parsed/module.rs @@ -1,7 +1,7 @@ -use crate::{language::DepName, transform}; +use crate::{language::ModName, transform}; use super::ParseTree; -use sway_types::{Ident, Span}; +use sway_types::Span; /// A module and its submodules in the form of a tree. #[derive(Debug, Clone)] @@ -9,17 +9,17 @@ pub struct ParseModule { /// The content of this module in the form of a `ParseTree`. pub tree: ParseTree, /// Submodules introduced within this module using the `dep` syntax in order of declaration. - pub submodules: Vec<(DepName, ParseSubmodule)>, + pub submodules: Vec<(ModName, ParseSubmodule)>, pub attributes: transform::AttributesMap, + /// an empty span at the beginning of the file containing the module + pub span: Span, } -/// A library module that was declared as a `dep` of another module. +/// A library module that was declared as a `mod` of another module. /// -/// Only submodules are guaranteed to be a `library` and have a `library_name`. +/// Only submodules are guaranteed to be a `library`. #[derive(Debug, Clone)] pub struct ParseSubmodule { - /// The name of a submodule, parsed from the `library` declaration within the module itself. - pub library_name: Ident, pub module: ParseModule, - pub dependency_path_span: Span, + pub mod_name_span: Span, } diff --git a/sway-core/src/language/parsed/program.rs b/sway-core/src/language/parsed/program.rs index 862b1f90f22..0763f1fc9f5 100644 --- a/sway-core/src/language/parsed/program.rs +++ b/sway-core/src/language/parsed/program.rs @@ -1,5 +1,4 @@ use super::ParseModule; -use sway_types::Ident; /// A parsed, but not yet type-checked, Sway program. /// @@ -18,7 +17,7 @@ pub enum TreeType { Predicate, Script, Contract, - Library { name: Ident }, + Library, } impl std::fmt::Display for TreeType { @@ -30,7 +29,7 @@ impl std::fmt::Display for TreeType { Self::Predicate => "predicate", Self::Script => "script", Self::Contract => "contract", - Self::Library { .. } => "library", + Self::Library => "library", } ) } diff --git a/sway-core/src/language/ty/declaration/storage.rs b/sway-core/src/language/ty/declaration/storage.rs index 3a8845a3878..514437c2793 100644 --- a/sway-core/src/language/ty/declaration/storage.rs +++ b/sway-core/src/language/ty/declaration/storage.rs @@ -56,7 +56,7 @@ impl TyStorageDeclaration { attributes: transform::AttributesMap, ) -> Self { TyStorageDeclaration { - name: Ident::new_with_override("storage", span.clone()), + name: Ident::new_with_override("storage".to_string(), span.clone()), fields, span, attributes, diff --git a/sway-core/src/language/ty/module.rs b/sway-core/src/language/ty/module.rs index b657409cb4b..c6da79a8e0f 100644 --- a/sway-core/src/language/ty/module.rs +++ b/sway-core/src/language/ty/module.rs @@ -1,16 +1,17 @@ -use sway_types::{Ident, Span}; +use sway_types::Span; use crate::{ decl_engine::{DeclEngine, DeclRef, DeclRefFunction}, language::ty::*, - language::DepName, + language::ModName, semantic_analysis::namespace, transform, }; #[derive(Clone, Debug)] pub struct TyModule { - pub submodules: Vec<(DepName, TySubmodule)>, + pub span: Span, + pub submodules: Vec<(ModName, TySubmodule)>, pub namespace: namespace::Module, pub all_nodes: Vec, pub attributes: transform::AttributesMap, @@ -18,18 +19,17 @@ pub struct TyModule { #[derive(Clone, Debug)] pub struct TySubmodule { - pub library_name: Ident, pub module: TyModule, - pub dependency_path_span: Span, + pub mod_name_span: Span, } /// Iterator type for iterating over submodules. /// /// Used rather than `impl Iterator` to enable recursive submodule iteration. pub struct SubmodulesRecursive<'module> { - submods: std::slice::Iter<'module, (DepName, TySubmodule)>, + submods: std::slice::Iter<'module, (ModName, TySubmodule)>, current: Option<( - &'module (DepName, TySubmodule), + &'module (ModName, TySubmodule), Box>, )>, } @@ -69,7 +69,7 @@ impl TyModule { } impl<'module> Iterator for SubmodulesRecursive<'module> { - type Item = &'module (DepName, TySubmodule); + type Item = &'module (ModName, TySubmodule); fn next(&mut self) -> Option { loop { self.current = match self.current.take() { diff --git a/sway-core/src/language/ty/program.rs b/sway-core/src/language/ty/program.rs index ceac1643e4d..edad60721f9 100644 --- a/sway-core/src/language/ty/program.rs +++ b/sway-core/src/language/ty/program.rs @@ -28,7 +28,7 @@ impl TyProgram { engines: Engines<'_>, root: &TyModule, kind: parsed::TreeType, - module_span: Span, + package_name: &str, ) -> CompileResult<( TyProgramKind, Vec, @@ -48,10 +48,8 @@ impl TyProgram { Self::validate_root( engines, &submodule.module, - parsed::TreeType::Library { - name: submodule.library_name.clone(), - }, - submodule.library_name.span().clone(), + parsed::TreeType::Library, + package_name, ), continue, warnings, @@ -204,18 +202,20 @@ impl TyProgram { TyProgramKind::Contract { abi_entries } } - parsed::TreeType::Library { name } => { + parsed::TreeType::Library => { if !configurables.is_empty() { errors.push(CompileError::ConfigurableInLibrary { span: configurables[0].name.span(), }); } - TyProgramKind::Library { name } + TyProgramKind::Library { + name: package_name.to_string(), + } } parsed::TreeType::Predicate => { // A predicate must have a main function and that function must return a boolean. if mains.is_empty() { - errors.push(CompileError::NoPredicateMainFunction(module_span)); + errors.push(CompileError::NoPredicateMainFunction(root.span.clone())); return err(vec![], errors); } if mains.len() > 1 { @@ -238,7 +238,7 @@ impl TyProgram { parsed::TreeType::Script => { // A script must have exactly one main function. if mains.is_empty() { - errors.push(CompileError::NoScriptMainFunction(module_span)); + errors.push(CompileError::NoScriptMainFunction(root.span.clone())); return err(vec![], errors); } if mains.len() > 1 { @@ -429,7 +429,7 @@ pub enum TyProgramKind { abi_entries: Vec, }, Library { - name: Ident, + name: String, }, Predicate { main_function: TyFunctionDeclaration, @@ -444,7 +444,7 @@ impl TyProgramKind { pub fn tree_type(&self) -> parsed::TreeType { match self { TyProgramKind::Contract { .. } => parsed::TreeType::Contract, - TyProgramKind::Library { name } => parsed::TreeType::Library { name: name.clone() }, + TyProgramKind::Library { .. } => parsed::TreeType::Library, TyProgramKind::Predicate { .. } => parsed::TreeType::Predicate, TyProgramKind::Script { .. } => parsed::TreeType::Script, } diff --git a/sway-core/src/lib.rs b/sway-core/src/lib.rs index 5dc74250a7c..133a89f8af8 100644 --- a/sway-core/src/lib.rs +++ b/sway-core/src/lib.rs @@ -80,16 +80,15 @@ pub fn parse( None => parse_in_memory(h, engines, input), // When a `BuildConfig` is given, // the module source may declare `dep`s that must be parsed from other files. - Some(config) => parse_module_tree(h, engines, input, config.canonical_root_module()).map( - |(kind, lexed, parsed)| { + Some(config) => parse_module_tree(h, engines, input, config.canonical_root_module(), None) + .map(|(kind, lexed, parsed)| { let lexed = lexed::LexedProgram { kind: kind.clone(), root: lexed, }; let parsed = parsed::ParseProgram { kind, root: parsed }; (lexed, parsed) - }, - ), + }), }) } @@ -158,6 +157,7 @@ fn parse_in_memory( let submodules = Default::default(); let attributes = module_attrs_to_map(handler, &module.attribute_list)?; let root = parsed::ParseModule { + span: span::Span::dummy(), tree, submodules, attributes, @@ -182,56 +182,52 @@ struct Submodules { fn parse_submodules( handler: &Handler, engines: Engines<'_>, + module_name: Option<&str>, module: &sway_ast::Module, module_dir: &Path, ) -> Submodules { // Assume the happy path, so there'll be as many submodules as dependencies, but no more. - let mut lexed_submods = Vec::with_capacity(module.dependencies().count()); + let mut lexed_submods = Vec::with_capacity(module.submodules().count()); let mut parsed_submods = Vec::with_capacity(lexed_submods.capacity()); - module.dependencies().for_each(|dep| { + module.submodules().for_each(|submod| { // Read the source code from the dependency. // If we cannot, record as an error, but continue with other files. - let dep_path = Arc::new(module_path(module_dir, dep)); - let dep_str: Arc = match std::fs::read_to_string(&*dep_path) { + let submod_path = Arc::new(module_path(module_dir, module_name, submod)); + let submod_str: Arc = match std::fs::read_to_string(&*submod_path) { Ok(s) => Arc::from(s), Err(e) => { handler.emit_err(CompileError::FileCouldNotBeRead { - span: dep.path.span(), - file_path: dep_path.to_string_lossy().to_string(), + span: submod.name.span(), + file_path: submod_path.to_string_lossy().to_string(), stringified_error: e.to_string(), }); return; } }; - if let Ok((kind, lexed_module, parse_module)) = - parse_module_tree(handler, engines, dep_str.clone(), dep_path.clone()) - { - let library_name = match kind { - parsed::TreeType::Library { name } => name, - _ => { - let span = span::Span::new(dep_str, 0, 0, Some(dep_path)).unwrap(); - handler.emit_err(CompileError::ImportMustBeLibrary { span }); - return; - } - }; - // NOTE: Typed `IncludStatement`'s include an `alias` field, however its only - // constructor site is always `None`. If we introduce dep aliases in the future, this - // is where we should use it. - let dep_alias = None; - let dep_name = dep_alias.unwrap_or_else(|| library_name.clone()); + if let Ok((kind, lexed_module, parse_module)) = parse_module_tree( + handler, + engines, + submod_str.clone(), + submod_path.clone(), + Some(submod.name.as_str()), + ) { + if !matches!(kind, parsed::TreeType::Library) { + let span = span::Span::new(submod_str, 0, 0, Some(submod_path)).unwrap(); + handler.emit_err(CompileError::ImportMustBeLibrary { span }); + return; + } + let parse_submodule = parsed::ParseSubmodule { - library_name: library_name.clone(), module: parse_module, - dependency_path_span: dep.path.span(), + mod_name_span: submod.name.span(), }; let lexed_submodule = lexed::LexedSubmodule { - library_name, module: lexed_module, }; - lexed_submods.push((dep_name.clone(), lexed_submodule)); - parsed_submods.push((dep_name, parse_submodule)); + lexed_submods.push((submod.name.clone(), lexed_submodule)); + parsed_submods.push((submod.name.clone(), parse_submodule)); } }); @@ -248,14 +244,15 @@ fn parse_module_tree( engines: Engines<'_>, src: Arc, path: Arc, + module_name: Option<&str>, ) -> Result<(parsed::TreeType, lexed::LexedModule, parsed::ParseModule), ErrorEmitted> { // Parse this module first. let module_dir = path.parent().expect("module file has no parent directory"); - let module = sway_parse::parse_file(handler, src, Some(path.clone()))?; + let module = sway_parse::parse_file(handler, src.clone(), Some(path.clone()))?; // Parse all submodules before converting to the `ParseTree`. // This always recovers on parse errors for the file itself by skipping that file. - let submodules = parse_submodules(handler, engines, &module.value, module_dir); + let submodules = parse_submodules(handler, engines, module_name, &module.value, module_dir); // Convert from the raw parsed module to the `ParseTree` ready for type-check. let (kind, tree) = to_parsed_lang::convert_parse_tree( @@ -271,6 +268,7 @@ fn parse_module_tree( submodules: submodules.lexed, }; let parsed = parsed::ParseModule { + span: span::Span::new(src, 0, 0, Some(path)).unwrap(), tree, submodules: submodules.parsed, attributes, @@ -278,12 +276,22 @@ fn parse_module_tree( Ok((kind, lexed, parsed)) } -fn module_path(parent_module_dir: &Path, dep: &sway_ast::Dependency) -> PathBuf { - parent_module_dir - .iter() - .chain(dep.path.span().as_str().split('/').map(AsRef::as_ref)) - .collect::() - .with_extension(sway_types::constants::DEFAULT_FILE_EXTENSION) +fn module_path( + parent_module_dir: &Path, + parent_module_name: Option<&str>, + submod: &sway_ast::Submodule, +) -> PathBuf { + if let Some(parent_name) = parent_module_name { + parent_module_dir + .join(parent_name) + .join(submod.name.to_string()) + .with_extension(sway_types::constants::DEFAULT_FILE_EXTENSION) + } else { + // top level module + parent_module_dir + .join(submod.name.to_string()) + .with_extension(sway_types::constants::DEFAULT_FILE_EXTENSION) + } } pub struct CompiledAsm(pub FinalizedAsm); @@ -293,13 +301,14 @@ pub fn parsed_to_ast( parse_program: &parsed::ParseProgram, initial_namespace: namespace::Module, build_config: Option<&BuildConfig>, + package_name: &str, ) -> CompileResult { // Type check the program. let CompileResult { value: typed_program_opt, mut warnings, mut errors, - } = ty::TyProgram::type_check(engines, parse_program, initial_namespace); + } = ty::TyProgram::type_check(engines, parse_program, initial_namespace, package_name); let mut typed_program = match typed_program_opt { Some(typed_program) => typed_program, None => return err(warnings, errors), @@ -403,6 +412,7 @@ pub fn compile_to_ast( input: Arc, initial_namespace: namespace::Module, build_config: Option<&BuildConfig>, + package_name: &str, ) -> CompileResult { // Parse the program to a concrete syntax tree (CST). let CompileResult { @@ -424,7 +434,13 @@ pub fn compile_to_ast( } // Type check (+ other static analysis) the CST to a typed AST. - let typed_res = parsed_to_ast(engines, &parse_program, initial_namespace, build_config); + let typed_res = parsed_to_ast( + engines, + &parse_program, + initial_namespace, + build_config, + package_name, + ); errors.extend(typed_res.errors); warnings.extend(typed_res.warnings); let typed_program = match typed_res.value { @@ -447,8 +463,15 @@ pub fn compile_to_asm( input: Arc, initial_namespace: namespace::Module, build_config: BuildConfig, + package_name: &str, ) -> CompileResult { - let ast_res = compile_to_ast(engines, input, initial_namespace, Some(&build_config)); + let ast_res = compile_to_ast( + engines, + input, + initial_namespace, + Some(&build_config), + package_name, + ); ast_to_asm(engines, &ast_res, &build_config) } @@ -560,8 +583,15 @@ pub fn compile_to_bytecode( initial_namespace: namespace::Module, build_config: BuildConfig, source_map: &mut SourceMap, + package_name: &str, ) -> CompileResult { - let asm_res = compile_to_asm(engines, input, initial_namespace, build_config); + let asm_res = compile_to_asm( + engines, + input, + initial_namespace, + build_config, + package_name, + ); asm_to_bytecode(asm_res, source_map) } @@ -641,8 +671,7 @@ fn module_dead_code_analysis<'eng: 'cfg, 'cfg>( .submodules .iter() .fold(init_res, |res, (_, submodule)| { - let name = submodule.library_name.clone(); - let tree_type = parsed::TreeType::Library { name }; + let tree_type = parsed::TreeType::Library; res.flat_map(|_| { module_dead_code_analysis(engines, &submodule.module, &tree_type, graph) }) diff --git a/sway-core/src/semantic_analysis/ast_node/code_block.rs b/sway-core/src/semantic_analysis/ast_node/code_block.rs index 498ce93a960..377a76da57e 100644 --- a/sway-core/src/semantic_analysis/ast_node/code_block.rs +++ b/sway-core/src/semantic_analysis/ast_node/code_block.rs @@ -57,10 +57,10 @@ impl ty::TyCodeBlock { .unwrap_or_else(|| { if node_deterministically_aborts { let never_mod_path = vec![ - Ident::new_with_override("core", span.clone()), - Ident::new_with_override("never", span.clone()), + Ident::new_with_override("core".into(), span.clone()), + Ident::new_with_override("never".into(), span.clone()), ]; - let never_ident = Ident::new_with_override("Never", span.clone()); + let never_ident = Ident::new_with_override("Never".into(), span.clone()); let never_decl_opt = ctx .namespace diff --git a/sway-core/src/semantic_analysis/ast_node/declaration/function.rs b/sway-core/src/semantic_analysis/ast_node/declaration/function.rs index a458216ba60..731f3bd5b6a 100644 --- a/sway-core/src/semantic_analysis/ast_node/declaration/function.rs +++ b/sway-core/src/semantic_analysis/ast_node/declaration/function.rs @@ -212,7 +212,7 @@ fn test_function_selector_behavior() { let decl = ty::TyFunctionDeclaration { purity: Default::default(), - name: Ident::new_no_span("foo"), + name: Ident::new_no_span("foo".into()), implementing_type: None, body: ty::TyCodeBlock { contents: vec![] }, parameters: vec![], @@ -234,12 +234,12 @@ fn test_function_selector_behavior() { let decl = ty::TyFunctionDeclaration { purity: Default::default(), - name: Ident::new_with_override("bar", Span::dummy()), + name: Ident::new_with_override("bar".into(), Span::dummy()), implementing_type: None, body: ty::TyCodeBlock { contents: vec![] }, parameters: vec![ ty::TyFunctionParameter { - name: Ident::new_no_span("foo"), + name: Ident::new_no_span("foo".into()), is_reference: false, is_mutable: false, mutability_span: Span::dummy(), @@ -248,7 +248,7 @@ fn test_function_selector_behavior() { .into(), }, ty::TyFunctionParameter { - name: Ident::new_no_span("baz"), + name: Ident::new_no_span("baz".into()), is_reference: false, is_mutable: false, mutability_span: Span::dummy(), diff --git a/sway-core/src/semantic_analysis/ast_node/declaration/impl_trait.rs b/sway-core/src/semantic_analysis/ast_node/declaration/impl_trait.rs index ea4ea3ddb81..fa8fe07be6b 100644 --- a/sway-core/src/semantic_analysis/ast_node/declaration/impl_trait.rs +++ b/sway-core/src/semantic_analysis/ast_node/declaration/impl_trait.rs @@ -446,7 +446,7 @@ impl ty::TyImplTrait { prefixes: vec![], suffix: match &type_engine.get(implementing_for.type_id) { TypeInfo::Custom { call_path, .. } => call_path.suffix.clone(), - _ => Ident::new_with_override("r#Self", implementing_for.span()), + _ => Ident::new_with_override("r#Self".into(), implementing_for.span()), }, is_absolute: false, }; diff --git a/sway-core/src/semantic_analysis/ast_node/expression/match_expression/typed/typed_scrutinee.rs b/sway-core/src/semantic_analysis/ast_node/expression/match_expression/typed/typed_scrutinee.rs index d48a440708e..dbeea0d4efa 100644 --- a/sway-core/src/semantic_analysis/ast_node/expression/match_expression/typed/typed_scrutinee.rs +++ b/sway-core/src/semantic_analysis/ast_node/expression/match_expression/typed/typed_scrutinee.rs @@ -21,7 +21,7 @@ impl ty::TyScrutinee { let dummy_type_param = TypeParameter { type_id, initial_type_id: type_id, - name_ident: BaseIdent::new_with_override("_", span.clone()), + name_ident: BaseIdent::new_with_override("_".into(), span.clone()), trait_constraints: vec![], trait_constraints_span: Span::dummy(), }; diff --git a/sway-core/src/semantic_analysis/ast_node/expression/typed_expression.rs b/sway-core/src/semantic_analysis/ast_node/expression/typed_expression.rs index da89e02a520..142f279169e 100644 --- a/sway-core/src/semantic_analysis/ast_node/expression/typed_expression.rs +++ b/sway-core/src/semantic_analysis/ast_node/expression/typed_expression.rs @@ -57,8 +57,8 @@ impl ty::TyExpression { let call_path = CallPath { prefixes: vec![ - Ident::new_with_override("core", span.clone()), - Ident::new_with_override("ops", span.clone()), + Ident::new_with_override("core".into(), span.clone()), + Ident::new_with_override("ops".into(), span.clone()), ], suffix: Op { op_variant: OpVariant::Equals, @@ -1526,10 +1526,10 @@ impl ty::TyExpression { inner: MethodName::FromTrait { call_path: CallPath { prefixes: vec![ - Ident::new_with_override("core", span.clone()), - Ident::new_with_override("ops", span.clone()), + Ident::new_with_override("core".into(), span.clone()), + Ident::new_with_override("ops".into(), span.clone()), ], - suffix: Ident::new_with_override("index", span.clone()), + suffix: Ident::new_with_override("index".into(), span.clone()), is_absolute: true, }, }, diff --git a/sway-core/src/semantic_analysis/module.rs b/sway-core/src/semantic_analysis/module.rs index 7b9b9a47ea1..38001340257 100644 --- a/sway-core/src/semantic_analysis/module.rs +++ b/sway-core/src/semantic_analysis/module.rs @@ -1,6 +1,6 @@ use crate::{ error::*, - language::{parsed::*, ty, DepName}, + language::{parsed::*, ty, ModName}, semantic_analysis::*, }; @@ -13,6 +13,7 @@ impl ty::TyModule { submodules, tree, attributes, + span, } = parsed; // Type-check submodules first in order of declaration. @@ -38,6 +39,7 @@ impl ty::TyModule { submodules_res.flat_map(|submodules| { typed_nodes_res.map(|all_nodes| Self { + span: span.clone(), submodules, namespace: ctx.namespace.module().clone(), all_nodes, @@ -64,20 +66,18 @@ impl ty::TyModule { impl ty::TySubmodule { pub fn type_check( parent_ctx: TypeCheckContext, - dep_name: DepName, + mod_name: ModName, submodule: &ParseSubmodule, ) -> CompileResult { let ParseSubmodule { - library_name, module, - dependency_path_span, + mod_name_span, } = submodule; - parent_ctx.enter_submodule(dep_name, |submod_ctx| { + parent_ctx.enter_submodule(mod_name, module.span.clone(), |submod_ctx| { let module_res = ty::TyModule::type_check(submod_ctx, module); module_res.map(|module| ty::TySubmodule { - library_name: library_name.clone(), module, - dependency_path_span: dependency_path_span.clone(), + mod_name_span: mod_name_span.clone(), }) }) } diff --git a/sway-core/src/semantic_analysis/namespace/module.rs b/sway-core/src/semantic_analysis/namespace/module.rs index 1a512255044..d420495a3a3 100644 --- a/sway-core/src/semantic_analysis/namespace/module.rs +++ b/sway-core/src/semantic_analysis/namespace/module.rs @@ -24,7 +24,7 @@ use sway_types::{span::Span, ConfigTimeConstant, Spanned}; /// A single `Module` within a Sway project. /// /// A `Module` is most commonly associated with an individual file of Sway code, e.g. a top-level -/// script/predicate/contract file or some library dependency whether introduced via `dep` or the +/// script/predicate/contract file or some library dependency whether introduced via `mod` or the /// `[dependencies]` table of a `forc` manifest. /// /// A `Module` contains a set of all items that exist within the lexical scope via declaration or @@ -34,16 +34,18 @@ pub struct Module { /// Submodules of the current module represented as an ordered map from each submodule's name /// to the associated `Module`. /// - /// Submodules are normally introduced in Sway code with the `dep foo;` syntax where `foo` is + /// Submodules are normally introduced in Sway code with the `mod foo;` syntax where `foo` is /// some library dependency that we include as a submodule. /// /// Note that we *require* this map to be ordered to produce deterministic codegen results. pub(crate) submodules: im::OrdMap, /// The set of symbols, implementations, synonyms and aliases present within this module. items: Items, - /// Name of the module, package name for root module, library name for other modules. - /// Library name used is the same as declared in `library name;`. + /// Name of the module, package name for root module, module name for other modules. + /// Module name used is the same as declared in `mod name;`. pub name: Option, + /// Empty span at the beginning of the file implementing the module + pub span: Option, } impl Module { diff --git a/sway-core/src/semantic_analysis/namespace/namespace.rs b/sway-core/src/semantic_analysis/namespace/namespace.rs index e6af72d8bdb..f072b39ed0c 100644 --- a/sway-core/src/semantic_analysis/namespace/namespace.rs +++ b/sway-core/src/semantic_analysis/namespace/namespace.rs @@ -323,17 +323,22 @@ impl Namespace { /// [SubmoduleNamespace] type. When dropped, the [SubmoduleNamespace] resets the `mod_path` /// back to the original path so that we can continue type-checking the current module after /// finishing with the dependency. - pub(crate) fn enter_submodule(&mut self, dep_name: Ident) -> SubmoduleNamespace { + pub(crate) fn enter_submodule( + &mut self, + mod_name: Ident, + module_span: Span, + ) -> SubmoduleNamespace { let init = self.init.clone(); - self.submodules.entry(dep_name.to_string()).or_insert(init); + self.submodules.entry(mod_name.to_string()).or_insert(init); let submod_path: Vec<_> = self .mod_path .iter() .cloned() - .chain(Some(dep_name.clone())) + .chain(Some(mod_name.clone())) .collect(); let parent_mod_path = std::mem::replace(&mut self.mod_path, submod_path); - self.name = Some(dep_name); + self.name = Some(mod_name); + self.span = Some(module_span); SubmoduleNamespace { namespace: self, parent_mod_path, diff --git a/sway-core/src/semantic_analysis/namespace/trait_map.rs b/sway-core/src/semantic_analysis/namespace/trait_map.rs index 7a25049b3e4..2f5db32558b 100644 --- a/sway-core/src/semantic_analysis/namespace/trait_map.rs +++ b/sway-core/src/semantic_analysis/namespace/trait_map.rs @@ -370,7 +370,7 @@ impl TraitMap { /// /// `data.sw`: /// ```ignore - /// library data; + /// library; /// /// enum MyResult { /// Ok: T, @@ -403,7 +403,7 @@ impl TraitMap { /// ```ignore /// script; /// - /// dep data; + /// mod data; /// /// use data::Data; /// @@ -490,7 +490,7 @@ impl TraitMap { /// /// `my_double.sw`: /// ```ignore - /// library my_double; + /// library; /// /// pub trait MyDouble { /// fn my_double(self, input: T) -> T; @@ -499,7 +499,7 @@ impl TraitMap { /// /// `my_point.sw`: /// ```ignore - /// library my_point; + /// library; /// /// use ::my_double::MyDouble; /// @@ -519,8 +519,8 @@ impl TraitMap { /// ```ignore /// script; /// - /// dep my_double; - /// dep my_point; + /// mod my_double; + /// mod my_point; /// /// use my_point::MyPoint; /// diff --git a/sway-core/src/semantic_analysis/node_dependencies.rs b/sway-core/src/semantic_analysis/node_dependencies.rs index fcb2b7a98af..a09c17138b4 100644 --- a/sway-core/src/semantic_analysis/node_dependencies.rs +++ b/sway-core/src/semantic_analysis/node_dependencies.rs @@ -769,7 +769,7 @@ fn decl_name(type_engine: &TypeEngine, decl: &Declaration) -> Option { - let trait_name = Ident::new_with_override("self", decl.implementing_for.span()); + let trait_name = Ident::new_with_override("self".into(), decl.implementing_for.span()); impl_sym( trait_name, &type_engine.get(decl.implementing_for.type_id), diff --git a/sway-core/src/semantic_analysis/program.rs b/sway-core/src/semantic_analysis/program.rs index c659f447d5f..abb923b2003 100644 --- a/sway-core/src/semantic_analysis/program.rs +++ b/sway-core/src/semantic_analysis/program.rs @@ -19,15 +19,15 @@ impl ty::TyProgram { engines: Engines<'_>, parsed: &ParseProgram, initial_namespace: namespace::Module, + package_name: &str, ) -> CompileResult { let mut namespace = Namespace::init_root(initial_namespace); let ctx = TypeCheckContext::from_root(&mut namespace, engines).with_kind(parsed.kind.clone()); let ParseProgram { root, kind } = parsed; - let mod_span = root.tree.span.clone(); let mod_res = ty::TyModule::type_check(ctx, root); mod_res.flat_map(|root| { - let res = Self::validate_root(engines, &root, kind.clone(), mod_span); + let res = Self::validate_root(engines, &root, kind.clone(), package_name); res.map(|(kind, declarations, configurables)| Self { kind, root, diff --git a/sway-core/src/semantic_analysis/type_check_context.rs b/sway-core/src/semantic_analysis/type_check_context.rs index d0ee10ce365..fd57fffdfc9 100644 --- a/sway-core/src/semantic_analysis/type_check_context.rs +++ b/sway-core/src/semantic_analysis/type_check_context.rs @@ -139,14 +139,15 @@ impl<'a> TypeCheckContext<'a> { /// Returns the result of the given `with_submod_ctx` function. pub fn enter_submodule( self, - dep_name: Ident, + mod_name: Ident, + module_span: Span, with_submod_ctx: impl FnOnce(TypeCheckContext) -> T, ) -> T { // We're checking a submodule, so no need to pass through anything other than the // namespace. However, we will likely want to pass through the type engine and declaration // engine here once they're added. let Self { namespace, .. } = self; - let mut submod_ns = namespace.enter_submodule(dep_name); + let mut submod_ns = namespace.enter_submodule(mod_name, module_span); let submod_ctx = TypeCheckContext::from_module_namespace( &mut submod_ns, Engines::new(self.type_engine, self.decl_engine), diff --git a/sway-core/src/transform/to_parsed_lang/convert_parse_tree.rs b/sway-core/src/transform/to_parsed_lang/convert_parse_tree.rs index f3725a09f51..bccbfe613a0 100644 --- a/sway-core/src/transform/to_parsed_lang/convert_parse_tree.rs +++ b/sway-core/src/transform/to_parsed_lang/convert_parse_tree.rs @@ -10,13 +10,13 @@ use sway_ast::{ expr::{ReassignmentOp, ReassignmentOpVariant}, ty::TyTupleDescriptor, AbiCastArgs, AngleBrackets, AsmBlock, Assignable, AttributeDecl, Braces, CodeBlockContents, - CommaToken, Dependency, DoubleColonToken, Expr, ExprArrayDescriptor, ExprStructField, - ExprTupleDescriptor, FnArg, FnArgs, FnSignature, GenericArgs, GenericParams, IfCondition, - IfExpr, Instruction, Intrinsic, Item, ItemAbi, ItemConfigurable, ItemConst, ItemEnum, ItemFn, - ItemImpl, ItemKind, ItemStorage, ItemStruct, ItemTrait, ItemTraitItem, ItemUse, LitInt, - LitIntType, MatchBranchKind, Module, ModuleKind, Parens, PathExpr, PathExprSegment, PathType, + CommaToken, DoubleColonToken, Expr, ExprArrayDescriptor, ExprStructField, ExprTupleDescriptor, + FnArg, FnArgs, FnSignature, GenericArgs, GenericParams, IfCondition, IfExpr, Instruction, + Intrinsic, Item, ItemAbi, ItemConfigurable, ItemConst, ItemEnum, ItemFn, ItemImpl, ItemKind, + ItemStorage, ItemStruct, ItemTrait, ItemTraitItem, ItemUse, LitInt, LitIntType, + MatchBranchKind, Module, ModuleKind, Parens, PathExpr, PathExprSegment, PathType, PathTypeSegment, Pattern, PatternStructField, PubToken, Punctuated, QualifiedPathRoot, - Statement, StatementLet, Traits, Ty, TypeField, UseTree, WhereClause, + Statement, StatementLet, Submodule, Traits, Ty, TypeField, UseTree, WhereClause, }; use sway_error::convert_parse_tree_error::ConvertParseTreeError; use sway_error::handler::{ErrorEmitted, Handler}; @@ -58,7 +58,7 @@ pub fn convert_module_kind(kind: &ModuleKind) -> TreeType { ModuleKind::Script { .. } => TreeType::Script, ModuleKind::Contract { .. } => TreeType::Contract, ModuleKind::Predicate { .. } => TreeType::Predicate, - ModuleKind::Library { name, .. } => TreeType::Library { name: name.clone() }, + ModuleKind::Library { .. } => TreeType::Library, } } @@ -106,7 +106,7 @@ fn item_to_ast_nodes( let span = item.span(); let contents = match item.value { - ItemKind::Dependency(dependency) => { + ItemKind::Submodule(submodule) => { // Check that Dependency is not annotated if attributes.contains_key(&AttributeKind::DocComment) { let error = ConvertParseTreeError::CannotDocCommentDependency { @@ -133,13 +133,13 @@ fn item_to_ast_nodes( // Check that Dependency comes after only other Dependencies let emit_expected_dep_at_beginning = || { let error = ConvertParseTreeError::ExpectedDependencyAtBeginning { - span: dependency.span(), + span: submodule.span(), }; handler.emit_err(error.into()); }; match prev_item { Some(Annotated { - value: ItemKind::Dependency(_), + value: ItemKind::Submodule(_), .. }) => (), Some(_) => emit_expected_dep_at_beginning(), @@ -148,7 +148,7 @@ fn item_to_ast_nodes( if !is_root { emit_expected_dep_at_beginning(); } - let incl_stmt = dependency_to_include_statement(&dependency); + let incl_stmt = submodule_to_include_statement(&submodule); vec![AstNodeContent::IncludeStatement(incl_stmt)] } ItemKind::Use(item_use) => item_use_to_use_statements(context, handler, item_use)? @@ -1703,10 +1703,8 @@ fn expr_to_expression( MATCH_RETURN_VAR_NAME_PREFIX, context.next_match_expression_return_var_unique_suffix(), ); - let var_decl_name = Ident::new_with_override( - Box::leak(match_return_var_name.into_boxed_str()), - var_decl_span.clone(), - ); + let var_decl_name = + Ident::new_with_override(match_return_var_name, var_decl_span.clone()); let var_decl_exp = Expression { kind: ExpressionKind::Variable(var_decl_name.clone()), @@ -2109,10 +2107,10 @@ fn op_call( inner: MethodName::FromTrait { call_path: CallPath { prefixes: vec![ - Ident::new_with_override("core", op_span.clone()), - Ident::new_with_override("ops", op_span.clone()), + Ident::new_with_override("core".into(), op_span.clone()), + Ident::new_with_override("ops".into(), op_span.clone()), ], - suffix: Ident::new_with_override(name, op_span.clone()), + suffix: Ident::new_with_override(name.into(), op_span.clone()), is_absolute: true, }, }, @@ -2936,7 +2934,7 @@ fn statement_let_to_ast_nodes( mutable, name, } => (reference, mutable, name), - Pattern::Wildcard { .. } => (None, None, Ident::new_no_span("_")), + Pattern::Wildcard { .. } => (None, None, Ident::new_no_span("_".into())), _ => unreachable!(), }; if reference.is_some() { @@ -2989,10 +2987,8 @@ fn statement_let_to_ast_nodes( DESTRUCTURE_PREFIX, context.next_destructured_struct_unique_suffix() ); - let destructure_name = Ident::new_with_override( - Box::leak(destructured_name.into_boxed_str()), - path.prefix.name.span(), - ); + let destructure_name = + Ident::new_with_override(destructured_name, path.prefix.name.span()); // Parse the type ascription and the type ascription span. // In the event that the user did not provide a type ascription, @@ -3082,8 +3078,7 @@ fn statement_let_to_ast_nodes( TUPLE_NAME_PREFIX, context.next_destructured_tuple_unique_suffix() ); - let tuple_name = - Ident::new_with_override(Box::leak(tuple_name.into_boxed_str()), span.clone()); + let tuple_name = Ident::new_with_override(tuple_name, span.clone()); // Parse the type ascription and the type ascription span. // In the event that the user did not provide a type ascription, @@ -3174,11 +3169,10 @@ fn statement_let_to_ast_nodes( ) } -fn dependency_to_include_statement(dependency: &Dependency) -> IncludeStatement { +fn submodule_to_include_statement(dependency: &Submodule) -> IncludeStatement { IncludeStatement { - _alias: None, - span: dependency.span(), - _path_span: dependency.path.span(), + _span: dependency.span(), + _mod_name_span: dependency.name.span(), } } diff --git a/sway-core/src/type_system/mod.rs b/sway-core/src/type_system/mod.rs index bbd14c18ff5..3f511e564f9 100644 --- a/sway-core/src/type_system/mod.rs +++ b/sway-core/src/type_system/mod.rs @@ -47,9 +47,9 @@ fn generic_enum_resolution() { let decl_engine = DeclEngine::default(); let sp = Span::dummy(); - let generic_name = Ident::new_with_override("T", sp.clone()); - let a_name = Ident::new_with_override("a", sp.clone()); - let result_name = Ident::new_with_override("Result", sp.clone()); + let generic_name = Ident::new_with_override("T".into(), sp.clone()); + let a_name = Ident::new_with_override("a".into(), sp.clone()); + let result_name = Ident::new_with_override("Result".into(), sp.clone()); /* Result<_> { diff --git a/sway-core/src/type_system/unify.rs b/sway-core/src/type_system/unify.rs index 6e281fddd26..a4aa31de9ff 100644 --- a/sway-core/src/type_system/unify.rs +++ b/sway-core/src/type_system/unify.rs @@ -328,7 +328,7 @@ impl<'a> Unifier<'a> { NumericCastCompatResult::CastableWithWarning(warn) => { vec![CompileWarning { span: span.clone(), - warning_content: warn, + warning_content: *warn, }] } NumericCastCompatResult::Compatible => { @@ -502,10 +502,10 @@ fn numeric_cast_compat( | (Sixteen, ThirtyTwo) | (Sixteen, SixtyFour) | (ThirtyTwo, SixtyFour) => { - NumericCastCompatResult::CastableWithWarning(Warning::LossOfPrecision { + NumericCastCompatResult::CastableWithWarning(Box::new(Warning::LossOfPrecision { initial_type: old_size, cast_to: new_size, - }) + })) } // Upcasting is ok, so everything else is ok. _ => NumericCastCompatResult::Compatible, @@ -514,5 +514,5 @@ fn numeric_cast_compat( enum NumericCastCompatResult { Compatible, - CastableWithWarning(Warning), + CastableWithWarning(Box), } diff --git a/sway-error/src/error.rs b/sway-error/src/error.rs index c630c2ab07d..87f0b3bc7f5 100644 --- a/sway-error/src/error.rs +++ b/sway-error/src/error.rs @@ -320,7 +320,7 @@ pub enum CompileError { file_path: String, stringified_error: String, }, - #[error("This imported file must be a library. It must start with \"library \", where \"name\" is the name of the library this file contains.")] + #[error("This imported file must be a library. It must start with \"library;\"")] ImportMustBeLibrary { span: Span }, #[error("An enum instantiaton cannot contain more than one value. This should be a single value of type {ty}.")] MoreThanOneEnumInstantiator { span: Span, ty: String }, diff --git a/sway-lib-core/src/lib.sw b/sway-lib-core/src/lib.sw index 8403a4f0d58..8b41dd50254 100644 --- a/sway-lib-core/src/lib.sw +++ b/sway-lib-core/src/lib.sw @@ -1,8 +1,8 @@ -library core; +library; -dep primitives; -dep raw_ptr; -dep raw_slice; -dep ops; -dep never; -dep prelude; +mod primitives; +mod raw_ptr; +mod raw_slice; +mod ops; +mod never; +mod prelude; diff --git a/sway-lib-core/src/never.sw b/sway-lib-core/src/never.sw index 57beb6981cb..6bcbc798117 100644 --- a/sway-lib-core/src/never.sw +++ b/sway-lib-core/src/never.sw @@ -1,4 +1,4 @@ -library never; +library; use ::ops::{Eq, Not, Ord}; diff --git a/sway-lib-core/src/ops.sw b/sway-lib-core/src/ops.sw index 302fae40fe1..a9d75d4b4c1 100644 --- a/sway-lib-core/src/ops.sw +++ b/sway-lib-core/src/ops.sw @@ -1,4 +1,4 @@ -library ops; +library; use ::primitives::*; @@ -121,7 +121,7 @@ pub trait Mod { impl Mod for u64 { fn modulo(self, other: Self) -> Self { asm(r1: self, r2: other, r3) { - mod r3 r1 r2; + r#mod r3 r1 r2; r3: u64 } } @@ -130,7 +130,7 @@ impl Mod for u64 { impl Mod for u32 { fn modulo(self, other: Self) -> Self { asm(r1: self, r2: other, r3) { - mod r3 r1 r2; + r#mod r3 r1 r2; r3: u32 } } @@ -139,7 +139,7 @@ impl Mod for u32 { impl Mod for u16 { fn modulo(self, other: Self) -> Self { asm(r1: self, r2: other, r3) { - mod r3 r1 r2; + r#mod r3 r1 r2; r3: u16 } } @@ -148,7 +148,7 @@ impl Mod for u16 { impl Mod for u8 { fn modulo(self, other: Self) -> Self { asm(r1: self, r2: other, r3) { - mod r3 r1 r2; + r#mod r3 r1 r2; r3: u8 } } diff --git a/sway-lib-core/src/prelude.sw b/sway-lib-core/src/prelude.sw index 558dea96d50..fde25089376 100644 --- a/sway-lib-core/src/prelude.sw +++ b/sway-lib-core/src/prelude.sw @@ -1,4 +1,4 @@ -library prelude; +library; //! Defines the Sway core library prelude. //! The prelude consists of implicitly available items, diff --git a/sway-lib-core/src/primitives.sw b/sway-lib-core/src/primitives.sw index 7d32b23bb5f..037e7c03f3a 100644 --- a/sway-lib-core/src/primitives.sw +++ b/sway-lib-core/src/primitives.sw @@ -1,4 +1,4 @@ -library primitives; +library; impl u64 { /// The smallest value that can be represented by this integer type. diff --git a/sway-lib-core/src/raw_ptr.sw b/sway-lib-core/src/raw_ptr.sw index 7360b8cd13e..50bf52c7351 100644 --- a/sway-lib-core/src/raw_ptr.sw +++ b/sway-lib-core/src/raw_ptr.sw @@ -1,4 +1,4 @@ -library raw_ptr; +library; impl raw_ptr { /// Returns `true` if the pointer is null. diff --git a/sway-lib-core/src/raw_slice.sw b/sway-lib-core/src/raw_slice.sw index cdc6626e59d..3128b415737 100644 --- a/sway-lib-core/src/raw_slice.sw +++ b/sway-lib-core/src/raw_slice.sw @@ -1,6 +1,4 @@ -library raw_slice; - -dep raw_ptr; +library; use ::raw_ptr::*; diff --git a/sway-lib-std/src/address.sw b/sway-lib-std/src/address.sw index 6e1dfa45516..4d489168ef4 100644 --- a/sway-lib-std/src/address.sw +++ b/sway-lib-std/src/address.sw @@ -1,5 +1,5 @@ //! A wrapper around the `b256` type to help enhance type-safety. -library address; +library; use ::convert::From; diff --git a/sway-lib-std/src/alloc.sw b/sway-lib-std/src/alloc.sw index 29abd3e993a..9c92e3f3228 100644 --- a/sway-lib-std/src/alloc.sw +++ b/sway-lib-std/src/alloc.sw @@ -1,5 +1,5 @@ //! A library for allocating memory inspired by [Rust's std::alloc](https://doc.rust-lang.org/std/alloc/index.html). -library alloc; +library; /// Allocates zeroed memory on the heap. /// diff --git a/sway-lib-std/src/assert.sw b/sway-lib-std/src/assert.sw index 6465430fd93..147221f54a9 100644 --- a/sway-lib-std/src/assert.sw +++ b/sway-lib-std/src/assert.sw @@ -1,4 +1,4 @@ -library assert; +library; use ::logging::log; use ::revert::revert; diff --git a/sway-lib-std/src/auth.sw b/sway-lib-std/src/auth.sw index ff2b42ca797..8863ab6ceae 100644 --- a/sway-lib-std/src/auth.sw +++ b/sway-lib-std/src/auth.sw @@ -1,5 +1,5 @@ //! Functionality for determining who is calling a contract. -library auth; +library; use ::address::Address; use ::contract_id::ContractId; diff --git a/sway-lib-std/src/b256.sw b/sway-lib-std/src/b256.sw index 00c2203e9f4..f4d7994b3df 100644 --- a/sway-lib-std/src/b256.sw +++ b/sway-lib-std/src/b256.sw @@ -1,4 +1,4 @@ -library b256; +library; use ::assert::assert; use ::bytes::Bytes; diff --git a/sway-lib-std/src/b512.sw b/sway-lib-std/src/b512.sw index 1875c35da51..7e7a2bf82a7 100644 --- a/sway-lib-std/src/b512.sw +++ b/sway-lib-std/src/b512.sw @@ -1,6 +1,6 @@ //! A wrapper around two `b256` types to support the usage of 64-byte values in Sway, //! which are needed when working with public keys and signatures. -library b512; +library; use ::constants::ZERO_B256; use ::convert::From; diff --git a/sway-lib-std/src/block.sw b/sway-lib-std/src/block.sw index 76b28e4c0e7..0a990c91efd 100644 --- a/sway-lib-std/src/block.sw +++ b/sway-lib-std/src/block.sw @@ -1,5 +1,5 @@ //! Functionality for accessing block-related data. -library block; +library; /// Get the current block height. pub fn height() -> u64 { diff --git a/sway-lib-std/src/bytes.sw b/sway-lib-std/src/bytes.sw index c2f2d2d9472..1c0e50c6302 100644 --- a/sway-lib-std/src/bytes.sw +++ b/sway-lib-std/src/bytes.sw @@ -1,5 +1,5 @@ //! The `Bytes` type is used when a collection of tightly-packed arbitrary bytes is needed. -library bytes; +library; use ::{alloc::{alloc_bytes, realloc_bytes}, vec::Vec}; use ::assert::assert; diff --git a/sway-lib-std/src/call_frames.sw b/sway-lib-std/src/call_frames.sw index 669ca4481f7..02d604f85b9 100644 --- a/sway-lib-std/src/call_frames.sw +++ b/sway-lib-std/src/call_frames.sw @@ -1,6 +1,6 @@ //! Helper functions for accessing data from call frames. //! [Call frames](https://fuellabs.github.io/fuel-specs/master/vm#call-frames) store metadata across untrusted inter-contract calls. -library call_frames; +library; use ::registers::frame_ptr; use ::contract_id::ContractId; diff --git a/sway-lib-std/src/constants.sw b/sway-lib-std/src/constants.sw index ea88528cde0..717e563882d 100644 --- a/sway-lib-std/src/constants.sw +++ b/sway-lib-std/src/constants.sw @@ -1,4 +1,4 @@ -library constants; +library; use ::contract_id::ContractId; diff --git a/sway-lib-std/src/context.sw b/sway-lib-std/src/context.sw index 855fb31837a..a047950802a 100644 --- a/sway-lib-std/src/context.sw +++ b/sway-lib-std/src/context.sw @@ -1,5 +1,5 @@ //! Functionality for accessing context-specific information about the current contract or message. -library context; +library; use ::contract_id::ContractId; use ::call_frames::contract_id; diff --git a/sway-lib-std/src/contract_id.sw b/sway-lib-std/src/contract_id.sw index e4c090f6826..29b2da170a6 100644 --- a/sway-lib-std/src/contract_id.sw +++ b/sway-lib-std/src/contract_id.sw @@ -1,5 +1,5 @@ //! A wrapper around the `b256` type to help enhance type-safety. -library contract_id; +library; use ::intrinsics::size_of_val; use ::convert::From; diff --git a/sway-lib-std/src/convert.sw b/sway-lib-std/src/convert.sw index c9f569c8521..d585fab8144 100644 --- a/sway-lib-std/src/convert.sw +++ b/sway-lib-std/src/convert.sw @@ -1,5 +1,5 @@ //! Traits for conversions between types. -library convert; +library; use ::option::Option; diff --git a/sway-lib-std/src/ecr.sw b/sway-lib-std/src/ecr.sw index 6efc066e5bb..c32e1ecf20b 100644 --- a/sway-lib-std/src/ecr.sw +++ b/sway-lib-std/src/ecr.sw @@ -1,4 +1,4 @@ -library ecr; +library; use ::address::Address; use ::b512::B512; diff --git a/sway-lib-std/src/error_signals.sw b/sway-lib-std/src/error_signals.sw index c1a19029e3c..800112e59fa 100644 --- a/sway-lib-std/src/error_signals.sw +++ b/sway-lib-std/src/error_signals.sw @@ -1,5 +1,5 @@ //! Values which signify special types of errors when passed to `std::revert::revert`. -library error_signals; +library; /// Revert with this value for a failing call to `std::revert::require`. /// 18446744073709486080 diff --git a/sway-lib-std/src/external.sw b/sway-lib-std/src/external.sw index dc043cacc36..81d4420e16e 100644 --- a/sway-lib-std/src/external.sw +++ b/sway-lib-std/src/external.sw @@ -1,4 +1,4 @@ -library external; +library; use ::constants::ZERO_B256; use ::contract_id::ContractId; diff --git a/sway-lib-std/src/flags.sw b/sway-lib-std/src/flags.sw index 3eef0af55e0..a8f44581ba7 100644 --- a/sway-lib-std/src/flags.sw +++ b/sway-lib-std/src/flags.sw @@ -1,5 +1,5 @@ //! Functionality for setting and unsetting FuelVM flags to modify behavior related to the `$err` and `$of` registers. -library flags; +library; use ::registers::flags; diff --git a/sway-lib-std/src/hash.sw b/sway-lib-std/src/hash.sw index 20d4f974f51..1a4d8bc61be 100644 --- a/sway-lib-std/src/hash.sw +++ b/sway-lib-std/src/hash.sw @@ -1,4 +1,4 @@ -library hash; +library; /// Returns the `SHA-2-256` hash of `param`. pub fn sha256(param: T) -> b256 { diff --git a/sway-lib-std/src/identity.sw b/sway-lib-std/src/identity.sw index 407a1994a08..4b80a76c35b 100644 --- a/sway-lib-std/src/identity.sw +++ b/sway-lib-std/src/identity.sw @@ -1,6 +1,6 @@ //! A wrapper type with two variants, `Address` and `ContractId`. //! The use of this type allows for handling interactions with contracts and addresses in a unified manner. -library identity; +library; use ::address::Address; use ::contract_id::ContractId; diff --git a/sway-lib-std/src/inputs.sw b/sway-lib-std/src/inputs.sw index f7238c618c2..9ae7039664e 100644 --- a/sway-lib-std/src/inputs.sw +++ b/sway-lib-std/src/inputs.sw @@ -1,6 +1,6 @@ //! Getters for fields on transaction inputs. //! This includes `Input::Coins`, `Input::Messages` and `Input::Contracts`. -library inputs; +library; use ::address::Address; use ::assert::assert; diff --git a/sway-lib-std/src/intrinsics.sw b/sway-lib-std/src/intrinsics.sw index 71c6a5fd506..35ac78bfeab 100644 --- a/sway-lib-std/src/intrinsics.sw +++ b/sway-lib-std/src/intrinsics.sw @@ -1,5 +1,5 @@ //! Exposes compiler intrinsics as stdlib wrapper functions. -library intrinsics; +library; /// Returns whether a generic type `T` is a reference type or not. pub fn is_reference_type() -> bool { diff --git a/sway-lib-std/src/lib.sw b/sway-lib-std/src/lib.sw index 4bfa4eed80d..bee8a313e45 100644 --- a/sway-lib-std/src/lib.sw +++ b/sway-lib-std/src/lib.sw @@ -1,45 +1,45 @@ //! The official standard library for the Sway smart contract language. //! //! Source: https://github.com/FuelLabs/sway/tree/master/sway-lib-std -library std; +library; -dep error_signals; -dep logging; -dep revert; -dep result; -dep option; -dep convert; -dep intrinsics; -dep assert; -dep alloc; -dep contract_id; -dep constants; -dep external; -dep registers; -dep call_frames; -dep context; -dep hash; -dep b512; -dep address; -dep identity; -dep vec; -dep bytes; -dep r#storage; -dep b256; -dep tx; -dep inputs; -dep outputs; -dep auth; -dep math; -dep block; -dep token; -dep ecr; -dep vm/mod; -dep flags; -dep u128; -dep u256; -dep message; -dep prelude; -dep low_level_call; +mod error_signals; +mod logging; +mod revert; +mod result; +mod option; +mod convert; +mod intrinsics; +mod assert; +mod alloc; +mod contract_id; +mod constants; +mod external; +mod registers; +mod call_frames; +mod context; +mod hash; +mod b512; +mod address; +mod identity; +mod vec; +mod bytes; +mod r#storage; +mod b256; +mod tx; +mod inputs; +mod outputs; +mod auth; +mod math; +mod block; +mod token; +mod ecr; +mod vm; +mod flags; +mod u128; +mod u256; +mod message; +mod prelude; +mod low_level_call; use core::*; diff --git a/sway-lib-std/src/logging.sw b/sway-lib-std/src/logging.sw index 9c8620548ab..ff88504e5cf 100644 --- a/sway-lib-std/src/logging.sw +++ b/sway-lib-std/src/logging.sw @@ -1,5 +1,5 @@ //! Allows logging of arbitrary stack types, emitted as either `Log` or `Logd` receipts. -library logging; +library; /// Log any stack type. /// If the type is a reference type, `log` is used. diff --git a/sway-lib-std/src/low_level_call.sw b/sway-lib-std/src/low_level_call.sw index baa0d38ccd8..c99684193a6 100644 --- a/sway-lib-std/src/low_level_call.sw +++ b/sway-lib-std/src/low_level_call.sw @@ -1,4 +1,4 @@ -library low_level_call; +library; use ::assert::assert; use ::bytes::Bytes; diff --git a/sway-lib-std/src/math.sw b/sway-lib-std/src/math.sw index 4615732a5e6..de5d53f72a1 100644 --- a/sway-lib-std/src/math.sw +++ b/sway-lib-std/src/math.sw @@ -1,4 +1,4 @@ -library math; +library; pub trait Root { fn sqrt(self) -> Self; diff --git a/sway-lib-std/src/message.sw b/sway-lib-std/src/message.sw index e2bb4efc67b..a45906f2273 100644 --- a/sway-lib-std/src/message.sw +++ b/sway-lib-std/src/message.sw @@ -1,4 +1,4 @@ -library message; +library; use ::alloc::alloc_bytes; use ::bytes::Bytes; diff --git a/sway-lib-std/src/option.sw b/sway-lib-std/src/option.sw index 29dcda8e4cc..964c8fcd822 100644 --- a/sway-lib-std/src/option.sw +++ b/sway-lib-std/src/option.sw @@ -72,7 +72,7 @@ //! `Ok(v)` : `Result::Ok` //! `Some(v)`: `Option::Some` //! `ok_or` : `Option::ok_or` -library option; +library; use ::result::Result; use ::revert::revert; diff --git a/sway-lib-std/src/outputs.sw b/sway-lib-std/src/outputs.sw index fbc3bcc11ae..3565a895fae 100644 --- a/sway-lib-std/src/outputs.sw +++ b/sway-lib-std/src/outputs.sw @@ -1,6 +1,6 @@ //! Getters for fields on transaction outputs. //! This includes `Output::Coins`, `Input::Messages` and `Input::Contracts`. -library outputs; +library; use ::contract_id::ContractId; use ::revert::revert; diff --git a/sway-lib-std/src/prelude.sw b/sway-lib-std/src/prelude.sw index c2f22bcc25c..c2cfd46c4d9 100644 --- a/sway-lib-std/src/prelude.sw +++ b/sway-lib-std/src/prelude.sw @@ -1,7 +1,7 @@ //! Defines the Sway standard library prelude. //! The prelude consists of implicitly available items, //! for which `use` is not required. -library prelude; +library; // Blockchain types use ::address::Address; diff --git a/sway-lib-std/src/registers.sw b/sway-lib-std/src/registers.sw index 7831d3fc61b..b8589654642 100644 --- a/sway-lib-std/src/registers.sw +++ b/sway-lib-std/src/registers.sw @@ -1,6 +1,6 @@ //! Functions to expose 14 of the reserved FuelVM registers for ease of use. //! Ref: https://fuellabs.github.io/fuel-specs/master/vm#semantics -library registers; +library; /// Contains overflow & underflow of addition, subtraction, and multiplication. pub fn overflow() -> u64 { diff --git a/sway-lib-std/src/result.sw b/sway-lib-std/src/result.sw index aaa4818960a..ab8cce7d070 100644 --- a/sway-lib-std/src/result.sw +++ b/sway-lib-std/src/result.sw @@ -53,7 +53,7 @@ //! //! `unwrap` : `Result::unwrap` //! `unwrap_or`: `Result::unwrap_or` -library result; +library; use ::revert::revert; diff --git a/sway-lib-std/src/revert.sw b/sway-lib-std/src/revert.sw index 406f622468b..6cfdba72849 100644 --- a/sway-lib-std/src/revert.sw +++ b/sway-lib-std/src/revert.sw @@ -1,4 +1,4 @@ -library revert; +library; use ::logging::log; use ::error_signals::FAILED_REQUIRE_SIGNAL; diff --git a/sway-lib-std/src/storage.sw b/sway-lib-std/src/storage.sw index 8da6b671f18..65fd2d3f98c 100644 --- a/sway-lib-std/src/storage.sw +++ b/sway-lib-std/src/storage.sw @@ -1,4 +1,4 @@ -library r#storage; +library; use ::alloc::{alloc, realloc_bytes}; use ::assert::assert; diff --git a/sway-lib-std/src/token.sw b/sway-lib-std/src/token.sw index 1c3b86e9f05..f3996aaa0cc 100644 --- a/sway-lib-std/src/token.sw +++ b/sway-lib-std/src/token.sw @@ -1,5 +1,5 @@ //! Functionality for performing common operations with tokens. -library token; +library; use ::address::Address; use ::call_frames::contract_id; diff --git a/sway-lib-std/src/tx.sw b/sway-lib-std/src/tx.sw index f8f6a06da55..15223961b3e 100644 --- a/sway-lib-std/src/tx.sw +++ b/sway-lib-std/src/tx.sw @@ -1,5 +1,5 @@ //! Transaction field getters. -library tx; +library; use ::constants::ZERO_B256; use ::revert::revert; diff --git a/sway-lib-std/src/u128.sw b/sway-lib-std/src/u128.sw index c8d69dd7905..f8888416f19 100644 --- a/sway-lib-std/src/u128.sw +++ b/sway-lib-std/src/u128.sw @@ -1,4 +1,4 @@ -library u128; +library; use ::assert::assert; use ::convert::From; diff --git a/sway-lib-std/src/u256.sw b/sway-lib-std/src/u256.sw index 3239378ee08..002a636d578 100644 --- a/sway-lib-std/src/u256.sw +++ b/sway-lib-std/src/u256.sw @@ -1,4 +1,4 @@ -library u256; +library; use ::assert::assert; use ::convert::From; diff --git a/sway-lib-std/src/vec.sw b/sway-lib-std/src/vec.sw index d843ae799d0..6b3b19a569d 100644 --- a/sway-lib-std/src/vec.sw +++ b/sway-lib-std/src/vec.sw @@ -1,4 +1,4 @@ -library vec; +library; use ::alloc::{alloc, realloc}; use ::assert::assert; diff --git a/sway-lib-std/src/vm.sw b/sway-lib-std/src/vm.sw new file mode 100644 index 00000000000..f163484a1da --- /dev/null +++ b/sway-lib-std/src/vm.sw @@ -0,0 +1,4 @@ +library; + +mod evm; + diff --git a/sway-lib-std/src/vm/evm.sw b/sway-lib-std/src/vm/evm.sw new file mode 100644 index 00000000000..b2c1fd480f5 --- /dev/null +++ b/sway-lib-std/src/vm/evm.sw @@ -0,0 +1,4 @@ +library; + +mod evm_address; +mod ecr; diff --git a/sway-lib-std/src/vm/evm/ecr.sw b/sway-lib-std/src/vm/evm/ecr.sw index d7ac2cf9540..df333171910 100644 --- a/sway-lib-std/src/vm/evm/ecr.sw +++ b/sway-lib-std/src/vm/evm/ecr.sw @@ -1,4 +1,4 @@ -library ecr; +library; use ::b512::B512; use ::registers::error; diff --git a/sway-lib-std/src/vm/evm/evm_address.sw b/sway-lib-std/src/vm/evm/evm_address.sw index beb086687e3..03080e33a5e 100644 --- a/sway-lib-std/src/vm/evm/evm_address.sw +++ b/sway-lib-std/src/vm/evm/evm_address.sw @@ -1,5 +1,5 @@ //! A wrapper around the `b256` type to help enhance type-safety. -library evm_address; +library; use ::intrinsics::size_of_val; use ::convert::From; diff --git a/sway-lib-std/src/vm/evm/mod.sw b/sway-lib-std/src/vm/evm/mod.sw deleted file mode 100644 index 448806dd21f..00000000000 --- a/sway-lib-std/src/vm/evm/mod.sw +++ /dev/null @@ -1,4 +0,0 @@ -library evm; - -dep evm_address; -dep ecr; diff --git a/sway-lib-std/src/vm/mod.sw b/sway-lib-std/src/vm/mod.sw deleted file mode 100644 index 2ee3fe38446..00000000000 --- a/sway-lib-std/src/vm/mod.sw +++ /dev/null @@ -1,3 +0,0 @@ -library vm; - -dep evm/mod; diff --git a/sway-lsp/src/core/token.rs b/sway-lsp/src/core/token.rs index 28d66645cac..28d10d3fde7 100644 --- a/sway-lsp/src/core/token.rs +++ b/sway-lsp/src/core/token.rs @@ -38,7 +38,7 @@ pub enum AstToken { IncludeStatement, Intrinsic(Intrinsic), Keyword(Ident), - LibraryName(Ident), + LibrarySpan(Span), MethodApplicationExpression(MethodApplicationExpression), Scrutinee(Scrutinee), StorageField(StorageField), @@ -74,8 +74,6 @@ pub enum TypedAstToken { TypedArgument(TypeArgument), TypedParameter(TypeParameter), TypedTraitConstraint(TraitConstraint), - TypedProgramKind(ty::TyProgramKind), - TypedLibraryName(Ident), TypedIncludeStatement, TypedUseStatement(ty::TyUseStatement), Ident(Ident), diff --git a/sway-lsp/src/traverse/lexed_tree.rs b/sway-lsp/src/traverse/lexed_tree.rs index 4a46118b68b..ef31fdb0b32 100644 --- a/sway-lsp/src/traverse/lexed_tree.rs +++ b/sway-lsp/src/traverse/lexed_tree.rs @@ -54,8 +54,8 @@ fn insert_keyword(ctx: &ParseContext, span: Span) { impl Parse for ItemKind { fn parse(&self, ctx: &ParseContext) { match self { - ItemKind::Dependency(dependency) => { - insert_keyword(ctx, dependency.dep_token.span()); + ItemKind::Submodule(submod) => { + insert_keyword(ctx, submod.mod_token.span()); } ItemKind::Use(item_use) => { item_use.parse(ctx); diff --git a/sway-lsp/src/traverse/parsed_tree.rs b/sway-lsp/src/traverse/parsed_tree.rs index 4de8f9d3950..c248e616b26 100644 --- a/sway-lsp/src/traverse/parsed_tree.rs +++ b/sway-lsp/src/traverse/parsed_tree.rs @@ -25,7 +25,7 @@ use sway_core::{ Scrutinee, StorageAccessExpression, StorageDeclaration, StorageField, StructDeclaration, StructExpression, StructExpressionField, StructField, StructScrutineeField, SubfieldExpression, Supertrait, TraitDeclaration, TraitFn, - TraitItem, TreeType, TupleIndexExpression, UseStatement, VariableDeclaration, + TraitItem, TupleIndexExpression, UseStatement, VariableDeclaration, WhileLoopExpression, }, CallPathTree, Literal, @@ -50,39 +50,32 @@ impl<'a> ParsedTree<'a> { node.parse(self.ctx); } - /// Collects the library name and the module name from the dep statement + /// Collects module names from the mod statements pub fn collect_module_spans(&self, parse_program: &ParseProgram) { - if let TreeType::Library { name } = &parse_program.kind { - self.ctx.tokens.insert( - to_ident_key(name), - Token::from_parsed(AstToken::LibraryName(name.clone()), SymbolKind::Module), - ); - } self.collect_parse_module(&parse_program.root); } fn collect_parse_module(&self, parse_module: &ParseModule) { + self.ctx.tokens.insert( + to_ident_key(&Ident::new(parse_module.span.clone())), + Token::from_parsed( + AstToken::LibrarySpan(parse_module.span.clone()), + SymbolKind::Module, + ), + ); for ( _, ParseSubmodule { - library_name, module, - dependency_path_span, + mod_name_span, .. }, ) in &parse_module.submodules { self.ctx.tokens.insert( - to_ident_key(&Ident::new(dependency_path_span.clone())), + to_ident_key(&Ident::new(mod_name_span.clone())), Token::from_parsed(AstToken::IncludeStatement, SymbolKind::Module), ); - self.ctx.tokens.insert( - to_ident_key(library_name), - Token::from_parsed( - AstToken::LibraryName(library_name.clone()), - SymbolKind::Module, - ), - ); self.collect_parse_module(module); } } diff --git a/sway-lsp/src/traverse/typed_tree.rs b/sway-lsp/src/traverse/typed_tree.rs index 592b17976e6..58b6b38bf9f 100644 --- a/sway-lsp/src/traverse/typed_tree.rs +++ b/sway-lsp/src/traverse/typed_tree.rs @@ -10,7 +10,7 @@ use sway_core::{ decl_engine::InterfaceDeclId, language::{ parsed::{ImportType, Supertrait}, - ty::{self, GetDeclIdent, TyEnumVariant, TyModule, TyProgram, TyProgramKind, TySubmodule}, + ty::{self, GetDeclIdent, TyEnumVariant, TyModule, TyProgram, TySubmodule}, CallPathTree, }, namespace, @@ -40,19 +40,8 @@ impl<'a> TypedTree<'a> { }; } - /// Collects the library name and the module name from the dep statement + /// Collects module names from the mod statements pub fn collect_module_spans(&self, typed_program: &TyProgram) { - if let TyProgramKind::Library { name } = &typed_program.kind { - if let Some(mut token) = self - .ctx - .tokens - .try_get_mut(&to_ident_key(name)) - .try_unwrap() - { - token.typed = Some(TypedAstToken::TypedProgramKind(typed_program.kind.clone())); - token.type_def = Some(TypeDefinition::Ident(name.clone())); - } - } self.collect_module(&typed_program.root); } @@ -60,29 +49,19 @@ impl<'a> TypedTree<'a> { for ( _, TySubmodule { - library_name, module, - dependency_path_span, + mod_name_span, }, ) in &typed_module.submodules { if let Some(mut token) = self .ctx .tokens - .try_get_mut(&to_ident_key(&Ident::new(dependency_path_span.clone()))) + .try_get_mut(&to_ident_key(&Ident::new(mod_name_span.clone()))) .try_unwrap() { token.typed = Some(TypedAstToken::TypedIncludeStatement); - token.type_def = Some(TypeDefinition::Ident(library_name.clone())); - } - if let Some(mut token) = self - .ctx - .tokens - .try_get_mut(&to_ident_key(library_name)) - .try_unwrap() - { - token.typed = Some(TypedAstToken::TypedLibraryName(library_name.clone())); - token.type_def = Some(TypeDefinition::Ident(library_name.clone())); + token.type_def = Some(TypeDefinition::Ident(Ident::new(module.span.clone()))); } self.collect_module(module); } @@ -353,12 +332,12 @@ impl<'a> TypedTree<'a> { { token.typed = Some(TypedAstToken::TypedUseStatement(use_statement.clone())); - if let Some(name) = self + if let Some(span) = self .namespace .submodule(mod_path) - .and_then(|tgt_submod| tgt_submod.name.clone()) + .and_then(|tgt_submod| tgt_submod.span.clone()) { - token.type_def = Some(TypeDefinition::Ident(name)); + token.type_def = Some(TypeDefinition::Ident(Ident::new(span))); } } } @@ -425,12 +404,12 @@ impl<'a> TypedTree<'a> { token.typed = Some(TypedAstToken::TypedUseStatement(use_statement.clone())); - if let Some(name) = self + if let Some(span) = self .namespace .submodule(call_path) - .and_then(|tgt_submod| tgt_submod.name.clone()) + .and_then(|tgt_submod| tgt_submod.span.clone()) { - token.type_def = Some(TypeDefinition::Ident(name)); + token.type_def = Some(TypeDefinition::Ident(Ident::new(span))); } } } @@ -985,12 +964,12 @@ impl<'a> TypedTree<'a> { { token.typed = Some(TypedAstToken::Ident(ident.clone())); - if let Some(name) = self + if let Some(span) = self .namespace .submodule(mod_path) - .and_then(|tgt_submod| tgt_submod.name.clone()) + .and_then(|tgt_submod| tgt_submod.span.clone()) { - token.type_def = Some(TypeDefinition::Ident(name)); + token.type_def = Some(TypeDefinition::Ident(Ident::new(span))); } } } diff --git a/sway-lsp/src/utils/keyword_docs.rs b/sway-lsp/src/utils/keyword_docs.rs index b795005f5eb..6e78e4ce88f 100644 --- a/sway-lsp/src/utils/keyword_docs.rs +++ b/sway-lsp/src/utils/keyword_docs.rs @@ -721,8 +721,8 @@ impl KeywordDocs { }; // TODO - let dep_keyword: ItemMod = parse_quote! { - mod dep_keyword {} + let mod_keyword: ItemMod = parse_quote! { + mod mod_keyword {} }; // TODO @@ -782,7 +782,7 @@ impl KeywordDocs { contract_keyword, predicate_keyword, library_keyword, - dep_keyword, + mod_keyword, abi_keyword, storage_keyword, asm_keyword, diff --git a/sway-lsp/tests/fixtures/completion/Forc.toml b/sway-lsp/tests/fixtures/completion/Forc.toml index a34ea6ca84b..75a606a7a96 100644 --- a/sway-lsp/tests/fixtures/completion/Forc.toml +++ b/sway-lsp/tests/fixtures/completion/Forc.toml @@ -5,3 +5,4 @@ license = "Apache-2.0" name = "completion" [dependencies] +std = { path = "../../../../sway-lib-std" } diff --git a/sway-lsp/tests/fixtures/tokens/consts/src/main.sw b/sway-lsp/tests/fixtures/tokens/consts/src/main.sw index efd39d304a6..4c4586e4ca7 100644 --- a/sway-lsp/tests/fixtures/tokens/consts/src/main.sw +++ b/sway-lsp/tests/fixtures/tokens/consts/src/main.sw @@ -1,6 +1,6 @@ contract; -dep more_consts; +mod more_consts; use more_consts::{Data, Value}; /// documentation for CONSTANT_1 @@ -24,4 +24,4 @@ fn test() { // Constants defined in a different module let point = Point { x: more_consts::CONSTANT_3, y: more_consts::CONSTANT_4 }; let data = more_consts::MY_DATA1; -} \ No newline at end of file +} diff --git a/sway-lsp/tests/fixtures/tokens/consts/src/more_consts.sw b/sway-lsp/tests/fixtures/tokens/consts/src/more_consts.sw index 6e9479f112e..70cb2eecec2 100644 --- a/sway-lsp/tests/fixtures/tokens/consts/src/more_consts.sw +++ b/sway-lsp/tests/fixtures/tokens/consts/src/more_consts.sw @@ -1,4 +1,4 @@ -library more_consts; +library; struct Value { a: u32, diff --git a/sway-lsp/tests/fixtures/tokens/fields/src/foo.sw b/sway-lsp/tests/fixtures/tokens/fields/src/foo.sw index 74c84021675..4aa61a6c75c 100644 --- a/sway-lsp/tests/fixtures/tokens/fields/src/foo.sw +++ b/sway-lsp/tests/fixtures/tokens/fields/src/foo.sw @@ -1,3 +1,3 @@ -library foo; +library; pub struct Foo {} diff --git a/sway-lsp/tests/fixtures/tokens/fields/src/main.sw b/sway-lsp/tests/fixtures/tokens/fields/src/main.sw index fe47e219666..a9deadc2dfd 100644 --- a/sway-lsp/tests/fixtures/tokens/fields/src/main.sw +++ b/sway-lsp/tests/fixtures/tokens/fields/src/main.sw @@ -1,6 +1,6 @@ contract; -dep foo; +mod foo; struct A { a: Option>, diff --git a/sway-lsp/tests/fixtures/tokens/modules/src/dir_mod/mod.sw b/sway-lsp/tests/fixtures/tokens/modules/src/dir_mod/mod.sw deleted file mode 100644 index 1e9a87df4ac..00000000000 --- a/sway-lsp/tests/fixtures/tokens/modules/src/dir_mod/mod.sw +++ /dev/null @@ -1 +0,0 @@ -library dir_mod; diff --git a/sway-lsp/tests/fixtures/tokens/modules/src/lib.sw b/sway-lsp/tests/fixtures/tokens/modules/src/lib.sw index b35bc671fd3..bdb15228aa2 100644 --- a/sway-lsp/tests/fixtures/tokens/modules/src/lib.sw +++ b/sway-lsp/tests/fixtures/tokens/modules/src/lib.sw @@ -1,4 +1,3 @@ -library modules; +library; -dep test_mod; -dep dir_mod/mod; +mod test_mod; diff --git a/sway-lsp/tests/fixtures/tokens/modules/src/test_mod.sw b/sway-lsp/tests/fixtures/tokens/modules/src/test_mod.sw index c180a593408..a4cc49252d2 100644 --- a/sway-lsp/tests/fixtures/tokens/modules/src/test_mod.sw +++ b/sway-lsp/tests/fixtures/tokens/modules/src/test_mod.sw @@ -1 +1,3 @@ -library test_mod; +library; + +mod deep_mod; diff --git a/sway-lsp/tests/fixtures/tokens/modules/src/test_mod/deep_mod.sw b/sway-lsp/tests/fixtures/tokens/modules/src/test_mod/deep_mod.sw new file mode 100644 index 00000000000..316a905aa9b --- /dev/null +++ b/sway-lsp/tests/fixtures/tokens/modules/src/test_mod/deep_mod.sw @@ -0,0 +1 @@ +library; diff --git a/sway-lsp/tests/fixtures/tokens/paths/src/deep_mod.sw b/sway-lsp/tests/fixtures/tokens/paths/src/deep_mod.sw index dff92929a2b..874041a52a2 100644 --- a/sway-lsp/tests/fixtures/tokens/paths/src/deep_mod.sw +++ b/sway-lsp/tests/fixtures/tokens/paths/src/deep_mod.sw @@ -1,3 +1,3 @@ -library deep_mod; +library; -dep deep_mod/deeper_mod; +mod deeper_mod; diff --git a/sway-lsp/tests/fixtures/tokens/paths/src/deep_mod/deeper_mod.sw b/sway-lsp/tests/fixtures/tokens/paths/src/deep_mod/deeper_mod.sw index b754af4c750..081e10146bf 100644 --- a/sway-lsp/tests/fixtures/tokens/paths/src/deep_mod/deeper_mod.sw +++ b/sway-lsp/tests/fixtures/tokens/paths/src/deep_mod/deeper_mod.sw @@ -1,4 +1,4 @@ -library deeper_mod; +library; pub fn deep_fun(){} diff --git a/sway-lsp/tests/fixtures/tokens/paths/src/main.sw b/sway-lsp/tests/fixtures/tokens/paths/src/main.sw index 6ee5c9f9471..d2170afee55 100644 --- a/sway-lsp/tests/fixtures/tokens/paths/src/main.sw +++ b/sway-lsp/tests/fixtures/tokens/paths/src/main.sw @@ -1,7 +1,7 @@ contract; -dep test_mod; -dep deep_mod; +mod test_mod; +mod deep_mod; use test_mod::A; use deep_mod::deeper_mod::deep_fun as dfun; diff --git a/sway-lsp/tests/fixtures/tokens/paths/src/test_mod.sw b/sway-lsp/tests/fixtures/tokens/paths/src/test_mod.sw index 833b892ba76..eeb8e2420bd 100644 --- a/sway-lsp/tests/fixtures/tokens/paths/src/test_mod.sw +++ b/sway-lsp/tests/fixtures/tokens/paths/src/test_mod.sw @@ -1,4 +1,4 @@ -library test_mod; +library; pub fn test_fun(){} diff --git a/sway-lsp/tests/fixtures/tokens/traits/src/main.sw b/sway-lsp/tests/fixtures/tokens/traits/src/main.sw index 318c8f8d884..c1502821fdc 100644 --- a/sway-lsp/tests/fixtures/tokens/traits/src/main.sw +++ b/sway-lsp/tests/fixtures/tokens/traits/src/main.sw @@ -1,6 +1,6 @@ contract; -dep traits; +mod traits; use traits::{Test1, Test2}; @@ -8,4 +8,4 @@ trait A: Test1 {} trait B: Test1 + Test2 {} struct S {} -impl Test1 for S {} \ No newline at end of file +impl Test1 for S {} diff --git a/sway-lsp/tests/fixtures/tokens/traits/src/traits.sw b/sway-lsp/tests/fixtures/tokens/traits/src/traits.sw index 3ff445b3019..a0f90451540 100644 --- a/sway-lsp/tests/fixtures/tokens/traits/src/traits.sw +++ b/sway-lsp/tests/fixtures/tokens/traits/src/traits.sw @@ -1,4 +1,4 @@ -library traits; +library; pub trait Test1 {} -pub trait Test2 {} \ No newline at end of file +pub trait Test2 {} diff --git a/sway-lsp/tests/lib.rs b/sway-lsp/tests/lib.rs index 589715aa355..89a48bd6a79 100644 --- a/sway-lsp/tests/lib.rs +++ b/sway-lsp/tests/lib.rs @@ -265,8 +265,8 @@ async fn go_to_definition_for_fields() { req_line: 17, req_char: 10, def_line: 0, - def_start_char: 8, - def_end_char: 11, + def_start_char: 0, + def_end_char: 0, def_path: "sway-lsp/tests/fixtures/tokens/fields/src/foo.sw", }; // foo @@ -463,23 +463,31 @@ async fn go_to_definition_for_modules() { req_line: 2, req_char: 6, def_line: 0, - def_start_char: 8, - def_end_char: 16, + def_start_char: 0, + def_end_char: 0, def_path: "sway-lsp/tests/fixtures/tokens/modules/src/test_mod.sw", }; - // dep test_mod; + // mod test_mod; let _ = lsp::definition_check(&mut service, &opt_go_to, &mut i).await; + shutdown_and_exit(&mut service).await; + + let (mut service, _) = LspService::new(Backend::new); + let uri = init_and_open( + &mut service, + test_fixtures_dir().join("tokens/modules/src/test_mod.sw"), + ) + .await; let opt_go_to = GotoDefinition { req_uri: &uri, - req_line: 3, + req_line: 2, req_char: 6, def_line: 0, - def_start_char: 8, - def_end_char: 15, - def_path: "sway-lsp/tests/fixtures/tokens/modules/src/dir_mod/mod.sw", + def_start_char: 0, + def_end_char: 0, + def_path: "sway-lsp/tests/fixtures/tokens/modules/src/test_mod/deep_mod.sw", }; - // dep dir_mod/mod; + // mod deep_mod; let _ = lsp::definition_check(&mut service, &opt_go_to, &mut i).await; shutdown_and_exit(&mut service).await; @@ -499,9 +507,9 @@ async fn go_to_definition_for_paths() { req_uri: &uri, req_line: 10, req_char: 13, - def_line: 3, - def_start_char: 8, - def_end_char: 11, + def_line: 0, + def_start_char: 0, + def_end_char: 0, def_path: "sway-lib-std/src/lib.sw", }; // std @@ -515,9 +523,9 @@ async fn go_to_definition_for_paths() { req_uri: &uri, req_line: 10, req_char: 19, - def_line: 74, - def_start_char: 8, - def_end_char: 14, + def_line: 0, + def_start_char: 0, + def_end_char: 0, def_path: "sway-lib-std/src/option.sw", }; // option @@ -541,9 +549,9 @@ async fn go_to_definition_for_paths() { req_line: 12, req_char: 17, def_line: 0, - def_start_char: 8, - def_end_char: 10, - def_path: "sway-lib-std/src/vm/mod.sw", + def_start_char: 0, + def_end_char: 0, + def_path: "sway-lib-std/src/vm.sw", }; // vm let _ = lsp::definition_check(&mut service, &go_to, &mut i).await; @@ -553,9 +561,9 @@ async fn go_to_definition_for_paths() { req_line: 12, req_char: 22, def_line: 0, - def_start_char: 8, - def_end_char: 11, - def_path: "sway-lib-std/src/vm/evm/mod.sw", + def_start_char: 0, + def_end_char: 0, + def_path: "sway-lib-std/src/vm/evm.sw", }; // evm let _ = lsp::definition_check(&mut service, &go_to, &mut i).await; @@ -564,9 +572,9 @@ async fn go_to_definition_for_paths() { req_uri: &uri, req_line: 12, req_char: 27, - def_line: 1, - def_start_char: 8, - def_end_char: 19, + def_line: 0, + def_start_char: 0, + def_end_char: 0, def_path: "sway-lib-std/src/vm/evm/evm_address.sw", }; // evm_address @@ -589,8 +597,8 @@ async fn go_to_definition_for_paths() { req_line: 16, req_char: 6, def_line: 0, - def_start_char: 8, - def_end_char: 16, + def_start_char: 0, + def_end_char: 0, def_path: "sway-lsp/tests/fixtures/tokens/paths/src/test_mod.sw", }; // test_mod @@ -615,8 +623,8 @@ async fn go_to_definition_for_paths() { req_line: 17, req_char: 8, def_line: 0, - def_start_char: 8, - def_end_char: 16, + def_start_char: 0, + def_end_char: 0, def_path: "sway-lsp/tests/fixtures/tokens/paths/src/deep_mod.sw", }; // deep_mod @@ -634,8 +642,8 @@ async fn go_to_definition_for_paths() { req_line: 17, req_char: 18, def_line: 0, - def_start_char: 8, - def_end_char: 18, + def_start_char: 0, + def_end_char: 0, def_path: "sway-lsp/tests/fixtures/tokens/paths/src/deep_mod/deeper_mod.sw", }; // deeper_mod @@ -720,8 +728,8 @@ async fn go_to_definition_for_paths() { req_line: 18, req_char: 11, def_line: 0, - def_start_char: 8, - def_end_char: 14, + def_start_char: 0, + def_end_char: 0, def_path: "sway-lib-std/src/assert.sw", }; // assert @@ -732,8 +740,8 @@ async fn go_to_definition_for_paths() { req_line: 19, req_char: 13, def_line: 0, - def_start_char: 8, - def_end_char: 12, + def_start_char: 0, + def_end_char: 0, def_path: "sway-lib-core/src/lib.sw", }; // core @@ -744,8 +752,8 @@ async fn go_to_definition_for_paths() { req_line: 19, req_char: 21, def_line: 0, - def_start_char: 8, - def_end_char: 18, + def_start_char: 0, + def_end_char: 0, def_path: "sway-lib-core/src/primitives.sw", }; // primitives @@ -795,8 +803,8 @@ async fn go_to_definition_for_paths() { req_line: 24, req_char: 20, def_line: 0, - def_start_char: 8, - def_end_char: 17, + def_start_char: 0, + def_end_char: 0, def_path: "sway-lib-std/src/constants.sw", }; // constants diff --git a/sway-parse/src/attribute.rs b/sway-parse/src/attribute.rs index efded9faf34..5310f4353d9 100644 --- a/sway-parse/src/attribute.rs +++ b/sway-parse/src/attribute.rs @@ -43,7 +43,7 @@ impl Parse for Annotated { attribute: SquareBrackets::new( Punctuated::single(Attribute { name: Ident::new_with_override( - DOC_COMMENT_ATTRIBUTE_NAME, + DOC_COMMENT_ATTRIBUTE_NAME.to_string(), doc_comment.span.clone(), ), args: Some(Parens::new( diff --git a/sway-parse/src/dependency.rs b/sway-parse/src/dependency.rs deleted file mode 100644 index a339d1b4494..00000000000 --- a/sway-parse/src/dependency.rs +++ /dev/null @@ -1,28 +0,0 @@ -use crate::{Parse, ParseResult, Parser}; - -use sway_ast::dependency::{Dependency, DependencyPath}; - -impl Parse for DependencyPath { - fn parse(parser: &mut Parser) -> ParseResult { - let prefix = parser.parse()?; - let mut suffixes = Vec::new(); - while let Some(forward_slash_token) = parser.take() { - let suffix = parser.parse()?; - suffixes.push((forward_slash_token, suffix)); - } - Ok(DependencyPath { prefix, suffixes }) - } -} - -impl Parse for Dependency { - fn parse(parser: &mut Parser) -> ParseResult { - let dep_token = parser.parse()?; - let path = parser.parse()?; - let semicolon_token = parser.parse()?; - Ok(Dependency { - dep_token, - path, - semicolon_token, - }) - } -} diff --git a/sway-parse/src/item/mod.rs b/sway-parse/src/item/mod.rs index 9fb44de48d2..55f0a50a3c0 100644 --- a/sway-parse/src/item/mod.rs +++ b/sway-parse/src/item/mod.rs @@ -1,13 +1,13 @@ use crate::{Parse, ParseResult, ParseToEnd, Parser, ParserConsumed}; use sway_ast::keywords::{ - AbiToken, ClassToken, ConfigurableToken, ConstToken, DepToken, EnumToken, FnToken, ImplToken, + AbiToken, ClassToken, ConfigurableToken, ConstToken, EnumToken, FnToken, ImplToken, ModToken, MutToken, OpenAngleBracketToken, RefToken, SelfToken, SemicolonToken, StorageToken, StructToken, TraitToken, UseToken, WhereToken, }; use sway_ast::{ - Dependency, FnArg, FnArgs, FnSignature, ItemConst, ItemEnum, ItemFn, ItemKind, ItemStruct, - ItemTrait, ItemUse, TypeField, + FnArg, FnArgs, FnSignature, ItemConst, ItemEnum, ItemFn, ItemKind, ItemStruct, ItemTrait, + ItemUse, Submodule, TypeField, }; use sway_error::parser_error::ParseErrorKind; @@ -30,8 +30,8 @@ impl Parse for ItemKind { let mut visibility = parser.take(); - let kind = if let Some(item) = parser.guarded_parse::()? { - ItemKind::Dependency(item) + let kind = if let Some(item) = parser.guarded_parse::()? { + ItemKind::Submodule(item) } else if let Some(mut item) = parser.guarded_parse::()? { item.visibility = visibility.take(); ItemKind::Use(item) diff --git a/sway-parse/src/keywords.rs b/sway-parse/src/keywords.rs index f9c508992f5..dd43e46e487 100644 --- a/sway-parse/src/keywords.rs +++ b/sway-parse/src/keywords.rs @@ -39,7 +39,7 @@ keyword_impls! { ContractToken, PredicateToken, LibraryToken, - DepToken, + ModToken, PubToken, UseToken, AsToken, @@ -157,7 +157,7 @@ pub const RESERVED_KEYWORDS: phf::Set<&'static str> = phf::phf_set! { "contract", "predicate", "library", - "dep", + "mod", "pub", "use", "as", diff --git a/sway-parse/src/lib.rs b/sway-parse/src/lib.rs index 55c98e36691..a8db90e715d 100644 --- a/sway-parse/src/lib.rs +++ b/sway-parse/src/lib.rs @@ -1,6 +1,5 @@ mod attribute; mod brackets; -mod dependency; mod expr; mod generics; mod item; @@ -13,6 +12,7 @@ mod path; mod pattern; mod priv_prelude; mod punctuated; +mod submodule; mod token; mod ty; mod where_clause; diff --git a/sway-parse/src/module.rs b/sway-parse/src/module.rs index d06e2039a14..b742f7287f4 100644 --- a/sway-parse/src/module.rs +++ b/sway-parse/src/module.rs @@ -19,11 +19,7 @@ impl Parse for ModuleKind { } else if let Some(predicate_token) = parser.take() { Ok(Self::Predicate { predicate_token }) } else if let Some(library_token) = parser.take() { - let name = parser.parse()?; - Ok(Self::Library { - library_token, - name, - }) + Ok(Self::Library { library_token }) } else { Err(parser.emit_error(ParseErrorKind::ExpectedModuleKind)) } @@ -47,7 +43,7 @@ impl ParseToEnd for Annotated { attribute: SquareBrackets::new( Punctuated::single(Attribute { name: Ident::new_with_override( - DOC_COMMENT_ATTRIBUTE_NAME, + DOC_COMMENT_ATTRIBUTE_NAME.to_string(), doc_comment.span.clone(), ), args: Some(Parens::new( diff --git a/sway-parse/src/submodule.rs b/sway-parse/src/submodule.rs new file mode 100644 index 00000000000..f5dedef4afb --- /dev/null +++ b/sway-parse/src/submodule.rs @@ -0,0 +1,16 @@ +use crate::{Parse, ParseResult, Parser}; + +use sway_ast::submodule::Submodule; + +impl Parse for Submodule { + fn parse(parser: &mut Parser) -> ParseResult { + let mod_token = parser.parse()?; + let name = parser.parse()?; + let semicolon_token = parser.parse()?; + Ok(Submodule { + mod_token, + name, + semicolon_token, + }) + } +} diff --git a/sway-types/src/ident.rs b/sway-types/src/ident.rs index b934f61c708..e4cea7f1465 100644 --- a/sway-types/src/ident.rs +++ b/sway-types/src/ident.rs @@ -12,22 +12,24 @@ pub trait Named { #[derive(Debug, Clone)] pub struct BaseIdent { - name_override_opt: Option<&'static str>, + name_override_opt: Option, span: Span, is_raw_ident: bool, } impl BaseIdent { pub fn as_str(&self) -> &str { - self.name_override_opt.unwrap_or_else(|| self.span.as_str()) + self.name_override_opt + .as_deref() + .unwrap_or_else(|| self.span.as_str()) } pub fn is_raw_ident(&self) -> bool { self.is_raw_ident } - pub fn name_override_opt(&self) -> Option<&'static str> { - self.name_override_opt + pub fn name_override_opt(&self) -> Option<&str> { + self.name_override_opt.as_deref() } pub fn new(span: Span) -> Ident { @@ -56,7 +58,7 @@ impl BaseIdent { } } - pub fn new_with_override(name_override: &'static str, span: Span) -> Ident { + pub fn new_with_override(name_override: String, span: Span) -> Ident { Ident { name_override_opt: Some(name_override), span, @@ -64,7 +66,7 @@ impl BaseIdent { } } - pub fn new_no_span(name: &'static str) -> Ident { + pub fn new_no_span(name: String) -> Ident { Ident { name_override_opt: Some(name), span: Span::dummy(), @@ -138,7 +140,7 @@ impl From<&Ident> for IdentUnique { impl From<&IdentUnique> for Ident { fn from(item: &IdentUnique) -> Self { Ident { - name_override_opt: item.0.name_override_opt(), + name_override_opt: item.0.name_override_opt().map(|s| s.to_string()), span: item.0.span(), is_raw_ident: item.0.is_raw_ident(), } diff --git a/swayfmt/src/module/dependency.rs b/swayfmt/src/module/dependency.rs deleted file mode 100644 index 6a57efd9d9b..00000000000 --- a/swayfmt/src/module/dependency.rs +++ /dev/null @@ -1,54 +0,0 @@ -use crate::{ - formatter::*, - utils::map::byte_span::{ByteSpan, LeafSpans}, -}; -use std::fmt::Write; -use sway_ast::{dependency::DependencyPath, Dependency}; -use sway_types::Spanned; - -impl Format for Dependency { - fn format( - &self, - formatted_code: &mut FormattedCode, - formatter: &mut Formatter, - ) -> Result<(), FormatterError> { - write!(formatted_code, "{} ", self.dep_token.span().as_str())?; - self.path.format(formatted_code, formatter)?; - writeln!(formatted_code, "{}", self.semicolon_token.span().as_str())?; - - Ok(()) - } -} - -impl Format for DependencyPath { - fn format( - &self, - formatted_code: &mut FormattedCode, - formatter: &mut Formatter, - ) -> Result<(), FormatterError> { - self.prefix.format(formatted_code, formatter)?; - for (forward_slash_token, ident) in &self.suffixes { - write!(formatted_code, "{}", forward_slash_token.span().as_str())?; - ident.format(formatted_code, formatter)?; - } - - Ok(()) - } -} - -impl LeafSpans for Dependency { - fn leaf_spans(&self) -> Vec { - let mut collected_spans = vec![ByteSpan::from(self.dep_token.span())]; - collected_spans.append(&mut self.path.leaf_spans()); - collected_spans.push(ByteSpan::from(self.semicolon_token.span())); - collected_spans - } -} - -impl LeafSpans for DependencyPath { - fn leaf_spans(&self) -> Vec { - let mut collected_spans = self.prefix.leaf_spans(); - collected_spans.append(&mut self.suffixes.leaf_spans()); - collected_spans - } -} diff --git a/swayfmt/src/module/item.rs b/swayfmt/src/module/item.rs index b4beb1cb7d7..daf2d2060b2 100644 --- a/swayfmt/src/module/item.rs +++ b/swayfmt/src/module/item.rs @@ -11,7 +11,7 @@ impl Format for ItemKind { formatter: &mut Formatter, ) -> Result<(), FormatterError> { match self { - Dependency(item_dep) => item_dep.format(formatted_code, formatter), + Submodule(item_mod) => item_mod.format(formatted_code, formatter), Use(item_use) => item_use.format(formatted_code, formatter), Struct(item_struct) => item_struct.format(formatted_code, formatter), Enum(item_enum) => item_enum.format(formatted_code, formatter), @@ -29,7 +29,7 @@ impl Format for ItemKind { impl LeafSpans for ItemKind { fn leaf_spans(&self) -> Vec { match self { - Dependency(item_dep) => item_dep.leaf_spans(), + Submodule(item_mod) => item_mod.leaf_spans(), Struct(item_struct) => item_struct.leaf_spans(), Enum(item_enum) => item_enum.leaf_spans(), Fn(item_fn) => item_fn.leaf_spans(), diff --git a/swayfmt/src/module/mod.rs b/swayfmt/src/module/mod.rs index d68a3525ff7..bf48e88014a 100644 --- a/swayfmt/src/module/mod.rs +++ b/swayfmt/src/module/mod.rs @@ -7,8 +7,8 @@ use std::fmt::Write; use sway_ast::{Item, ItemKind, Module, ModuleKind}; use sway_types::Spanned; -pub(crate) mod dependency; pub(crate) mod item; +pub(crate) mod submodule; impl Format for Module { fn format( @@ -40,8 +40,8 @@ impl Format for Module { )?; } item.format(formatted_code, formatter)?; - if let ItemKind::Dependency { .. } = item.value { - // Do not print a newline after a dependency + if let ItemKind::Submodule { .. } = item.value { + // Do not print a newline after a submodule } else { writeln!(formatted_code)?; } @@ -69,12 +69,8 @@ impl Format for ModuleKind { ModuleKind::Predicate { predicate_token } => { write!(formatted_code, "{}", predicate_token.span().as_str())? } - ModuleKind::Library { - library_token, - name, - } => { - write!(formatted_code, "{} ", library_token.span().as_str())?; - name.format(formatted_code, _formatter)?; + ModuleKind::Library { library_token } => { + write!(formatted_code, "{}", library_token.span().as_str())?; } }; @@ -104,14 +100,8 @@ impl LeafSpans for ModuleKind { ModuleKind::Predicate { predicate_token } => { vec![ByteSpan::from(predicate_token.span())] } - ModuleKind::Library { - library_token, - name, - } => { - vec![ - ByteSpan::from(library_token.span()), - ByteSpan::from(name.span()), - ] + ModuleKind::Library { library_token } => { + vec![ByteSpan::from(library_token.span())] } } } diff --git a/swayfmt/src/module/submodule.rs b/swayfmt/src/module/submodule.rs new file mode 100644 index 00000000000..a2e5c31c6bb --- /dev/null +++ b/swayfmt/src/module/submodule.rs @@ -0,0 +1,30 @@ +use crate::{ + formatter::*, + utils::map::byte_span::{ByteSpan, LeafSpans}, +}; +use std::fmt::Write; +use sway_ast::submodule::Submodule; +use sway_types::Spanned; + +impl Format for Submodule { + fn format( + &self, + formatted_code: &mut FormattedCode, + formatter: &mut Formatter, + ) -> Result<(), FormatterError> { + write!(formatted_code, "{} ", self.mod_token.span().as_str())?; + self.name.format(formatted_code, formatter)?; + writeln!(formatted_code, "{}", self.semicolon_token.span().as_str())?; + Ok(()) + } +} + +impl LeafSpans for Submodule { + fn leaf_spans(&self) -> Vec { + vec![ + ByteSpan::from(self.mod_token.span()), + ByteSpan::from(self.name.span()), + ByteSpan::from(self.semicolon_token.span()), + ] + } +} diff --git a/swayfmt/tests/mod.rs b/swayfmt/tests/mod.rs index c530015bb3d..10d93d53344 100644 --- a/swayfmt/tests/mod.rs +++ b/swayfmt/tests/mod.rs @@ -353,14 +353,14 @@ where #[test] fn trait_and_super_trait() { check( - r#"library traits; + r#"library; trait Person{ fn name( self )->String;fn age( self )->usize; } trait Student:Person {fn university(self) -> String;} trait Programmer {fn fav_language(self) -> String;} trait CompSciStudent: Programmer+Student {fn git_username(self) -> String;} trait TraitWithGenerics where T: String {fn from(b: T) -> Self;}"#, - r#"library traits; + r#"library; trait Person { fn name(self) -> String; @@ -1009,10 +1009,10 @@ fn comments_before_module_kind() { check( r#"// something about module kind // something else about module kind -library test_module_kind_with_comments;"#, +library;"#, r#"// something about module kind // something else about module kind -library test_module_kind_with_comments; +library; "#, ); } @@ -1024,17 +1024,17 @@ fn newline_before_comments() { // something about module kind // something else about module kind -library test_module_kind_with_comments;"#, +library;"#, r#"// something about module kind // something else about module kind -library test_module_kind_with_comments; +library; "#, ); } #[test] fn destructure_structs() { check( - r#"library test_destructure_structs; + r#"library; struct Point { x: u64, @@ -1059,7 +1059,7 @@ fn struct_destructuring() { } = tuple_in_struct; } "#, - r#"library test_destructure_structs; + r#"library; struct Point { x: u64, @@ -1092,7 +1092,7 @@ fn struct_destructuring() { #[test] fn multiline_collections() { check( - r#"library test_multiline_collections; + r#"library; fn func_with_multiline_collections() { let x = ( "hello", @@ -1100,7 +1100,7 @@ fn func_with_multiline_collections() { ); } "#, - r#"library test_multiline_collections; + r#"library; fn func_with_multiline_collections() { let x = ("hello", "world"); } @@ -1154,14 +1154,14 @@ fn main() { #[test] fn parameterless_attributes() { check( - r#"library my_lib; + r#"library; abi MyContract { #[test] fn foo(); } "#, - r#"library my_lib; + r#"library; abi MyContract { #[test] @@ -1249,12 +1249,12 @@ fn main() { #[test] fn multiple_comma_separated_attributes() { check( - r#"library my_lib; + r#"library; #[test, inline(always), storage(read, write), payable] fn foo() {} "#, - r#"library my_lib; + r#"library; #[test, inline(always), storage(read, write), payable] fn foo() {} @@ -1265,14 +1265,14 @@ fn foo() {} #[test] fn stack_of_comma_separated_attributes1() { check( - r#"library my_lib; + r#"library; /// this is a doc comment #[storage(read, write), payable] #[test, inline(always)] fn foo() {} "#, - r#"library my_lib; + r#"library; /// this is a doc comment #[storage(read, write), payable] @@ -1285,7 +1285,7 @@ fn foo() {} #[test] fn stack_of_comma_separated_attributes2() { check( - r#"library my_lib; + r#"library; /// this is a doc comment #[storage(read, write)] @@ -1294,7 +1294,7 @@ fn stack_of_comma_separated_attributes2() { #[inline(always)] fn foo() {} "#, - r#"library my_lib; + r#"library; /// this is a doc comment #[storage(read, write)] @@ -1381,7 +1381,7 @@ impl MyContract for Contract { #[test] fn asm_block() { check( - r#"library my_lib; + r#"library; fn foo() { asm(r1: self, r2: other, r3, r4) { @@ -1391,7 +1391,7 @@ fn foo() { } } "#, - r#"library my_lib; + r#"library; fn foo() { asm(r1: self, r2: other, r3, r4) { diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/configurables_in_lib/src/lib.sw b/test/src/e2e_vm_tests/test_programs/should_fail/configurables_in_lib/src/lib.sw index e99e19974e4..a4eb75b4d43 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/configurables_in_lib/src/lib.sw +++ b/test/src/e2e_vm_tests/test_programs/should_fail/configurables_in_lib/src/lib.sw @@ -1,4 +1,4 @@ -library lib; +library; configurable { C0: bool = true, diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/configurables_in_lib/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_fail/configurables_in_lib/src/main.sw index dd7165f0a46..d6d49cfefca 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/configurables_in_lib/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_fail/configurables_in_lib/src/main.sw @@ -1,6 +1,6 @@ script; -dep lib; +mod lib; use lib::*; diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/cyclic_dependency/dependency_a/src/lib.sw b/test/src/e2e_vm_tests/test_programs/should_fail/cyclic_dependency/dependency_a/src/lib.sw index d085e6870ca..416bd94d6cd 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/cyclic_dependency/dependency_a/src/lib.sw +++ b/test/src/e2e_vm_tests/test_programs/should_fail/cyclic_dependency/dependency_a/src/lib.sw @@ -1,3 +1,3 @@ -library dependency_a; +library; // anything `pub` here will be exported as a part of this library's API diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/cyclic_dependency/dependency_b/src/lib.sw b/test/src/e2e_vm_tests/test_programs/should_fail/cyclic_dependency/dependency_b/src/lib.sw index 00c1f863233..416bd94d6cd 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/cyclic_dependency/dependency_b/src/lib.sw +++ b/test/src/e2e_vm_tests/test_programs/should_fail/cyclic_dependency/dependency_b/src/lib.sw @@ -1,3 +1,3 @@ -library dependency_b; +library; // anything `pub` here will be exported as a part of this library's API diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/dep_annotated/src/bar.sw b/test/src/e2e_vm_tests/test_programs/should_fail/dep_annotated/src/bar.sw index b91d3ae826e..14b31820508 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/dep_annotated/src/bar.sw +++ b/test/src/e2e_vm_tests/test_programs/should_fail/dep_annotated/src/bar.sw @@ -1,3 +1,3 @@ -library foo; +library; fn foo() -> bool { true } diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/dep_annotated/src/baz.sw b/test/src/e2e_vm_tests/test_programs/should_fail/dep_annotated/src/baz.sw index 52c79428c32..21ddbd8ac1b 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/dep_annotated/src/baz.sw +++ b/test/src/e2e_vm_tests/test_programs/should_fail/dep_annotated/src/baz.sw @@ -1,4 +1,4 @@ -library foo; +library; fn foo() -> bool { true } diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/dep_annotated/src/foo.sw b/test/src/e2e_vm_tests/test_programs/should_fail/dep_annotated/src/foo.sw index 0945d3a05f1..d2335613a3a 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/dep_annotated/src/foo.sw +++ b/test/src/e2e_vm_tests/test_programs/should_fail/dep_annotated/src/foo.sw @@ -1,3 +1,3 @@ -library foo; +library; fn foo() -> bool { true } diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/dep_annotated/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_fail/dep_annotated/src/main.sw index f80a1e00fbd..3f6aafac62f 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/dep_annotated/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_fail/dep_annotated/src/main.sw @@ -1,13 +1,13 @@ contract; -dep foo; +mod foo; /// This doc comment /// should return a parser error -dep bar; +mod bar; #[inline(never)] -pub dep baz; +pub mod baz; fn a() -> bool { 0 // Test that recovery reaches type checking. diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/dep_annotated/test.toml b/test/src/e2e_vm_tests/test_programs/should_fail/dep_annotated/test.toml index 208b13b1c2f..2bdd5e63dcc 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/dep_annotated/test.toml +++ b/test/src/e2e_vm_tests/test_programs/should_fail/dep_annotated/test.toml @@ -1,6 +1,6 @@ category = "fail" -# check: pub dep baz; +# check: pub mod baz; # nextln: $()Unnecessary visibility qualifier, `pub` is implied here. # check: /// should return a parser error @@ -10,4 +10,4 @@ category = "fail" # nextln: $()Cannot annotate a dependency. # check: 0 // Test that recovery reaches type checking. -# nextln: $()Mismatched types. \ No newline at end of file +# nextln: $()Mismatched types. diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/dependency_not_at_beginning/src/a_dependency.sw b/test/src/e2e_vm_tests/test_programs/should_fail/dependency_not_at_beginning/src/a_dependency.sw index 1c4a86150ca..1d3ccb155d9 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/dependency_not_at_beginning/src/a_dependency.sw +++ b/test/src/e2e_vm_tests/test_programs/should_fail/dependency_not_at_beginning/src/a_dependency.sw @@ -1,3 +1,3 @@ -library foo; +library; pub struct Foo { foo: str[3] } diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/dependency_not_at_beginning/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_fail/dependency_not_at_beginning/src/main.sw index 7385c087cbb..9a711a21f23 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/dependency_not_at_beginning/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_fail/dependency_not_at_beginning/src/main.sw @@ -11,5 +11,5 @@ fn main() -> bool { false } -dep a_dependency; +mod a_dependency; diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/dependency_not_at_beginning/test.toml b/test/src/e2e_vm_tests/test_programs/should_fail/dependency_not_at_beginning/test.toml index 86b47ffb915..ba8a053a767 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/dependency_not_at_beginning/test.toml +++ b/test/src/e2e_vm_tests/test_programs/should_fail/dependency_not_at_beginning/test.toml @@ -1,5 +1,5 @@ category = "fail" # Not sure if this is the originally expected error: -# check: dep a_dependency; +# check: mod a_dependency; # nextln: $()Expected dependency at the beginning before any other items. diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/dependency_parsing_error/Forc.lock b/test/src/e2e_vm_tests/test_programs/should_fail/dependency_parsing_error/Forc.lock deleted file mode 100644 index e4ac9001aa4..00000000000 --- a/test/src/e2e_vm_tests/test_programs/should_fail/dependency_parsing_error/Forc.lock +++ /dev/null @@ -1,3 +0,0 @@ -[[package]] -name = 'dependencies_parsing_error' -source = 'member' diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/dependency_parsing_error/Forc.toml b/test/src/e2e_vm_tests/test_programs/should_fail/dependency_parsing_error/Forc.toml deleted file mode 100644 index 5980822c5ab..00000000000 --- a/test/src/e2e_vm_tests/test_programs/should_fail/dependency_parsing_error/Forc.toml +++ /dev/null @@ -1,6 +0,0 @@ -[project] -authors = ["Fuel Labs "] -license = "Apache-2.0" -name = "dependencies_parsing_error" -entry = "main.sw" -implicit-std = false diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/dependency_parsing_error/json_abi_oracle.json b/test/src/e2e_vm_tests/test_programs/should_fail/dependency_parsing_error/json_abi_oracle.json deleted file mode 100644 index 0637a088a01..00000000000 --- a/test/src/e2e_vm_tests/test_programs/should_fail/dependency_parsing_error/json_abi_oracle.json +++ /dev/null @@ -1 +0,0 @@ -[] \ No newline at end of file diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/dependency_parsing_error/src/a_dependency.sw b/test/src/e2e_vm_tests/test_programs/should_fail/dependency_parsing_error/src/a_dependency.sw deleted file mode 100644 index 096def1b3e1..00000000000 --- a/test/src/e2e_vm_tests/test_programs/should_fail/dependency_parsing_error/src/a_dependency.sw +++ /dev/null @@ -1,4 +0,0 @@ -library foo; -dep bar; -dep inner/bar; -pub struct Foo { foo: str[3] } diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/dependency_parsing_error/src/bar.sw b/test/src/e2e_vm_tests/test_programs/should_fail/dependency_parsing_error/src/bar.sw deleted file mode 100644 index 21fcea2c357..00000000000 --- a/test/src/e2e_vm_tests/test_programs/should_fail/dependency_parsing_error/src/bar.sw +++ /dev/null @@ -1,3 +0,0 @@ -library bar; -//dep a_dependency; - diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/dependency_parsing_error/src/inner/bar.sw b/test/src/e2e_vm_tests/test_programs/should_fail/dependency_parsing_error/src/inner/bar.sw deleted file mode 100644 index 8ce8a6e34c8..00000000000 --- a/test/src/e2e_vm_tests/test_programs/should_fail/dependency_parsing_error/src/inner/bar.sw +++ /dev/null @@ -1,6 +0,0 @@ -library bar; -dep double_inner/double_bar; - -use double_bar::DoubleBar; - -pub struct Bar { a: u32 } diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/dependency_parsing_error/src/inner/double_inner/double_bar.sw b/test/src/e2e_vm_tests/test_programs/should_fail/dependency_parsing_error/src/inner/double_inner/double_bar.sw deleted file mode 100644 index b21aa8f7219..00000000000 --- a/test/src/e2e_vm_tests/test_programs/should_fail/dependency_parsing_error/src/inner/double_inner/double_bar.sw +++ /dev/null @@ -1,6 +0,0 @@ -library double_bar; -//use ::foo::Foo; - -pub struct DoubleBar { a: u32 } - -let baz = 43; \ No newline at end of file diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/dependency_parsing_error/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_fail/dependency_parsing_error/src/main.sw deleted file mode 100644 index d287a038a9a..00000000000 --- a/test/src/e2e_vm_tests/test_programs/should_fail/dependency_parsing_error/src/main.sw +++ /dev/null @@ -1,17 +0,0 @@ -script; -// This tests importing other files. - -dep a_dependency; -dep nested_dependency/bar/bar; - -use foo::Foo; -use ::foo::bar::{Bar, double_bar::DoubleBar}; - -fn main() -> bool { - let foo = Foo { - foo: "foo", - }; - let db = DoubleBar { a: 5u32 }; - let bar = Bar { a: 5u32 }; - false -} diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/dependency_parsing_error/src/nested_dependency/bar/bar.sw b/test/src/e2e_vm_tests/test_programs/should_fail/dependency_parsing_error/src/nested_dependency/bar/bar.sw deleted file mode 100644 index af9bc0fc0a8..00000000000 --- a/test/src/e2e_vm_tests/test_programs/should_fail/dependency_parsing_error/src/nested_dependency/bar/bar.sw +++ /dev/null @@ -1,6 +0,0 @@ -library bar; -use ::foo::Foo; - -pub struct NestedDependency { - num: u64 -} diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/dependency_parsing_error/test.toml b/test/src/e2e_vm_tests/test_programs/should_fail/dependency_parsing_error/test.toml deleted file mode 100644 index bc59bcc1856..00000000000 --- a/test/src/e2e_vm_tests/test_programs/should_fail/dependency_parsing_error/test.toml +++ /dev/null @@ -1,5 +0,0 @@ -category = "fail" - -# Not sure if this is the originally expected error: -# check: let baz = 43; -# nextln: $()Expected an item. diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/enum_variant_unit/src/lib_a.sw b/test/src/e2e_vm_tests/test_programs/should_fail/enum_variant_unit/src/lib_a.sw index e124f18f381..2d21e4540be 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/enum_variant_unit/src/lib_a.sw +++ b/test/src/e2e_vm_tests/test_programs/should_fail/enum_variant_unit/src/lib_a.sw @@ -1,5 +1,5 @@ -library lib_a; +library; -dep inner_lib; +mod inner_lib; use inner_lib::*; diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/enum_variant_unit/src/inner_lib.sw b/test/src/e2e_vm_tests/test_programs/should_fail/enum_variant_unit/src/lib_a/inner_lib.sw similarity index 90% rename from test/src/e2e_vm_tests/test_programs/should_fail/enum_variant_unit/src/inner_lib.sw rename to test/src/e2e_vm_tests/test_programs/should_fail/enum_variant_unit/src/lib_a/inner_lib.sw index f93f1b87bcf..51aea1f861a 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/enum_variant_unit/src/inner_lib.sw +++ b/test/src/e2e_vm_tests/test_programs/should_fail/enum_variant_unit/src/lib_a/inner_lib.sw @@ -1,4 +1,4 @@ -library inner_lib; +library; pub enum MyEnum { VariantA: (), diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/enum_variant_unit/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_fail/enum_variant_unit/src/main.sw index d39c04a024f..fc41fd9dffa 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/enum_variant_unit/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_fail/enum_variant_unit/src/main.sw @@ -1,6 +1,6 @@ script; -dep lib_a; +mod lib_a; fn func() -> bool { true diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/generic_traits/src/helpers.sw b/test/src/e2e_vm_tests/test_programs/should_fail/generic_traits/src/helpers.sw index 48118d84e62..ae81d44f0ea 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/generic_traits/src/helpers.sw +++ b/test/src/e2e_vm_tests/test_programs/should_fail/generic_traits/src/helpers.sw @@ -1,4 +1,4 @@ -library helpers; +library; pub trait OutOfScopeGetter { fn out_of_scope_get(self) -> D; diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/generic_traits/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_fail/generic_traits/src/main.sw index 7d58db2fe3c..7a450c7f06c 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/generic_traits/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_fail/generic_traits/src/main.sw @@ -1,6 +1,6 @@ script; -dep helpers; +mod helpers; trait Setter { fn set(self, new_value: A) -> Self; diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/generics_multiple_type_arguments/src/lib_a.sw b/test/src/e2e_vm_tests/test_programs/should_fail/generics_multiple_type_arguments/src/lib_a.sw index 221ef069dcb..2d21e4540be 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/generics_multiple_type_arguments/src/lib_a.sw +++ b/test/src/e2e_vm_tests/test_programs/should_fail/generics_multiple_type_arguments/src/lib_a.sw @@ -1,5 +1,5 @@ -library lib_a; +library; -dep inner_lib; +mod inner_lib; -use inner_lib::*; \ No newline at end of file +use inner_lib::*; diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/generics_multiple_type_arguments/src/inner_lib.sw b/test/src/e2e_vm_tests/test_programs/should_fail/generics_multiple_type_arguments/src/lib_a/inner_lib.sw similarity index 75% rename from test/src/e2e_vm_tests/test_programs/should_fail/generics_multiple_type_arguments/src/inner_lib.sw rename to test/src/e2e_vm_tests/test_programs/should_fail/generics_multiple_type_arguments/src/lib_a/inner_lib.sw index fbd0023ab5e..01f16c4880d 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/generics_multiple_type_arguments/src/inner_lib.sw +++ b/test/src/e2e_vm_tests/test_programs/should_fail/generics_multiple_type_arguments/src/lib_a/inner_lib.sw @@ -1,4 +1,4 @@ -library inner_lib; +library; pub enum MyEnum { VariantA: (), diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/generics_multiple_type_arguments/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_fail/generics_multiple_type_arguments/src/main.sw index bef1e57f2bf..6e5a30d1756 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/generics_multiple_type_arguments/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_fail/generics_multiple_type_arguments/src/main.sw @@ -1,6 +1,6 @@ script; -dep lib_a; +mod lib_a; fn main() -> u64 { diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/generics_not_supported/src/lib_a.sw b/test/src/e2e_vm_tests/test_programs/should_fail/generics_not_supported/src/lib_a.sw index 221ef069dcb..2d21e4540be 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/generics_not_supported/src/lib_a.sw +++ b/test/src/e2e_vm_tests/test_programs/should_fail/generics_not_supported/src/lib_a.sw @@ -1,5 +1,5 @@ -library lib_a; +library; -dep inner_lib; +mod inner_lib; -use inner_lib::*; \ No newline at end of file +use inner_lib::*; diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/generics_not_supported/src/inner_lib.sw b/test/src/e2e_vm_tests/test_programs/should_fail/generics_not_supported/src/lib_a/inner_lib.sw similarity index 59% rename from test/src/e2e_vm_tests/test_programs/should_fail/generics_not_supported/src/inner_lib.sw rename to test/src/e2e_vm_tests/test_programs/should_fail/generics_not_supported/src/lib_a/inner_lib.sw index 8f240ecf15f..f9f6d400104 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/generics_not_supported/src/inner_lib.sw +++ b/test/src/e2e_vm_tests/test_programs/should_fail/generics_not_supported/src/lib_a/inner_lib.sw @@ -1,4 +1,4 @@ -library inner_lib; +library; pub const C = 42; @@ -6,4 +6,4 @@ pub fn func() -> bool { true } -pub struct S2 {} \ No newline at end of file +pub struct S2 {} diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/generics_not_supported/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_fail/generics_not_supported/src/main.sw index e2c2af11758..881766a46f2 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/generics_not_supported/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_fail/generics_not_supported/src/main.sw @@ -1,6 +1,6 @@ script; -dep lib_a; +mod lib_a; fn main() -> u64 { diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/impl_private_method/src/lib.sw b/test/src/e2e_vm_tests/test_programs/should_fail/impl_private_method/src/lib.sw index 71c497f4b48..0f2827bd179 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/impl_private_method/src/lib.sw +++ b/test/src/e2e_vm_tests/test_programs/should_fail/impl_private_method/src/lib.sw @@ -1,4 +1,4 @@ -library lib; +library; pub struct MyStruct { x: u64, @@ -8,4 +8,4 @@ impl MyStruct { fn foo(self) {} fn bar() {} -} \ No newline at end of file +} diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/impl_private_method/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_fail/impl_private_method/src/main.sw index d769f7b615d..d232ab8603c 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/impl_private_method/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_fail/impl_private_method/src/main.sw @@ -1,6 +1,6 @@ script; -dep lib; +mod lib; use lib::*; @@ -9,4 +9,4 @@ fn main() { MyStruct::bar(); -} \ No newline at end of file +} diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/infinite_dependencies/src/a_dependency.sw b/test/src/e2e_vm_tests/test_programs/should_fail/infinite_dependencies/src/a_dependency.sw index 7655ea4cdaf..5a1a733d1e0 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/infinite_dependencies/src/a_dependency.sw +++ b/test/src/e2e_vm_tests/test_programs/should_fail/infinite_dependencies/src/a_dependency.sw @@ -1,2 +1,2 @@ -library foo; -dep b_dependency; +library; +mod a_dependency; diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/infinite_dependencies/src/a_dependency/a_dependency.sw b/test/src/e2e_vm_tests/test_programs/should_fail/infinite_dependencies/src/a_dependency/a_dependency.sw new file mode 120000 index 00000000000..32418ac6c5e --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/infinite_dependencies/src/a_dependency/a_dependency.sw @@ -0,0 +1 @@ +../a_dependency.sw \ No newline at end of file diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/infinite_dependencies/src/b_dependency.sw b/test/src/e2e_vm_tests/test_programs/should_fail/infinite_dependencies/src/b_dependency.sw deleted file mode 100644 index 39486b50a63..00000000000 --- a/test/src/e2e_vm_tests/test_programs/should_fail/infinite_dependencies/src/b_dependency.sw +++ /dev/null @@ -1,2 +0,0 @@ -library foo; -dep a_dependency; diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/infinite_dependencies/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_fail/infinite_dependencies/src/main.sw index be0b343a193..961cfd3916b 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/infinite_dependencies/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_fail/infinite_dependencies/src/main.sw @@ -1,8 +1,8 @@ script; // This tests importing other files. -dep a_dependency; -dep b_dependency; +mod a_dependency; +mod b_dependency; fn main() -> bool { false diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/invalid_fully_qualified_type/src/foo.sw b/test/src/e2e_vm_tests/test_programs/should_fail/invalid_fully_qualified_type/src/foo.sw index 89d0f697cfa..26c7a366077 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/invalid_fully_qualified_type/src/foo.sw +++ b/test/src/e2e_vm_tests/test_programs/should_fail/invalid_fully_qualified_type/src/foo.sw @@ -1,4 +1,4 @@ -library foo; +library; enum Foo { A: (), diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/invalid_fully_qualified_type/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_fail/invalid_fully_qualified_type/src/main.sw index e3e124d68f1..4a6efb96e27 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/invalid_fully_qualified_type/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_fail/invalid_fully_qualified_type/src/main.sw @@ -1,6 +1,6 @@ script; -dep foo; +mod foo; struct Bar { baz: foo::foo::Foo diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/item_used_without_import/src/bar.sw b/test/src/e2e_vm_tests/test_programs/should_fail/item_used_without_import/src/bar.sw index 6d6dbbd7ff1..0dd1116f79a 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/item_used_without_import/src/bar.sw +++ b/test/src/e2e_vm_tests/test_programs/should_fail/item_used_without_import/src/bar.sw @@ -1,4 +1,4 @@ -library bar; +library; pub struct Bar { a: u32, diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/item_used_without_import/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_fail/item_used_without_import/src/main.sw index b5f410fa04a..605ae06bc0d 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/item_used_without_import/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_fail/item_used_without_import/src/main.sw @@ -1,6 +1,6 @@ script; -dep bar; +mod bar; // This test should fail to compile because the import statement below is missing // use ::bar::Bar; diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/match_expressions_non_exhaustive/src/adt_tests.sw b/test/src/e2e_vm_tests/test_programs/should_fail/match_expressions_non_exhaustive/src/adt_tests.sw index dda82727c08..3579a62e3a5 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/match_expressions_non_exhaustive/src/adt_tests.sw +++ b/test/src/e2e_vm_tests/test_programs/should_fail/match_expressions_non_exhaustive/src/adt_tests.sw @@ -1,4 +1,4 @@ -library adt_tests; +library; struct Point { x: u64, diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/match_expressions_non_exhaustive/src/complex_tests.sw b/test/src/e2e_vm_tests/test_programs/should_fail/match_expressions_non_exhaustive/src/complex_tests.sw index 9926563b228..9ceaf953b5e 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/match_expressions_non_exhaustive/src/complex_tests.sw +++ b/test/src/e2e_vm_tests/test_programs/should_fail/match_expressions_non_exhaustive/src/complex_tests.sw @@ -1,4 +1,4 @@ -library complex_tests; +library; use std::result::*; diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/match_expressions_non_exhaustive/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_fail/match_expressions_non_exhaustive/src/main.sw index fa8e10ac801..4ed2e34acf1 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/match_expressions_non_exhaustive/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_fail/match_expressions_non_exhaustive/src/main.sw @@ -1,8 +1,8 @@ script; -dep primitive_tests; -dep adt_tests; -dep complex_tests; +mod primitive_tests; +mod adt_tests; +mod complex_tests; use primitive_tests::*; use adt_tests::*; diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/match_expressions_non_exhaustive/src/primitive_tests.sw b/test/src/e2e_vm_tests/test_programs/should_fail/match_expressions_non_exhaustive/src/primitive_tests.sw index fcf583d3cbb..1770eadc801 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/match_expressions_non_exhaustive/src/primitive_tests.sw +++ b/test/src/e2e_vm_tests/test_programs/should_fail/match_expressions_non_exhaustive/src/primitive_tests.sw @@ -1,4 +1,4 @@ -library primitive_tests; +library; pub fn simple_numbers_test() { let x = 0; diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/multiple_enums_with_the_same_name/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_fail/multiple_enums_with_the_same_name/src/main.sw index c3e7053448a..56d0585dac3 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/multiple_enums_with_the_same_name/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_fail/multiple_enums_with_the_same_name/src/main.sw @@ -1,7 +1,7 @@ script; -dep module0; -dep module1; +mod module0; +mod module1; fn main() { let mut x = module0::MyEnum::A; diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/multiple_enums_with_the_same_name/src/module0.sw b/test/src/e2e_vm_tests/test_programs/should_fail/multiple_enums_with_the_same_name/src/module0.sw index 0753b4cf486..46d0cee87f7 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/multiple_enums_with_the_same_name/src/module0.sw +++ b/test/src/e2e_vm_tests/test_programs/should_fail/multiple_enums_with_the_same_name/src/module0.sw @@ -1,4 +1,4 @@ -library module0; +library; pub enum MyEnum { A: () diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/multiple_enums_with_the_same_name/src/module1.sw b/test/src/e2e_vm_tests/test_programs/should_fail/multiple_enums_with_the_same_name/src/module1.sw index 5f4a80e0f79..46d0cee87f7 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/multiple_enums_with_the_same_name/src/module1.sw +++ b/test/src/e2e_vm_tests/test_programs/should_fail/multiple_enums_with_the_same_name/src/module1.sw @@ -1,5 +1,5 @@ -library module1; +library; pub enum MyEnum { A: () -} \ No newline at end of file +} diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/multiple_structs_with_the_same_name/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_fail/multiple_structs_with_the_same_name/src/main.sw index c15615b55a6..3570d16ae75 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/multiple_structs_with_the_same_name/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_fail/multiple_structs_with_the_same_name/src/main.sw @@ -1,7 +1,7 @@ script; -dep module0; -dep module1; +mod module0; +mod module1; fn main() { let mut x = module0::Thing::new(); diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/multiple_structs_with_the_same_name/src/module0.sw b/test/src/e2e_vm_tests/test_programs/should_fail/multiple_structs_with_the_same_name/src/module0.sw index 5b4b2c47e73..50f4bb864ce 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/multiple_structs_with_the_same_name/src/module0.sw +++ b/test/src/e2e_vm_tests/test_programs/should_fail/multiple_structs_with_the_same_name/src/module0.sw @@ -1,4 +1,4 @@ -library module0; +library; pub struct Thing {} diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/multiple_structs_with_the_same_name/src/module1.sw b/test/src/e2e_vm_tests/test_programs/should_fail/multiple_structs_with_the_same_name/src/module1.sw index 30a1299cb2b..50f4bb864ce 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/multiple_structs_with_the_same_name/src/module1.sw +++ b/test/src/e2e_vm_tests/test_programs/should_fail/multiple_structs_with_the_same_name/src/module1.sw @@ -1,4 +1,4 @@ -library module1; +library; pub struct Thing {} diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/non_payable_non_script_call_with_non_zero_coins/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_fail/non_payable_non_script_call_with_non_zero_coins/src/main.sw index fd7dacbde47..afbc7330e06 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/non_payable_non_script_call_with_non_zero_coins/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_fail/non_payable_non_script_call_with_non_zero_coins/src/main.sw @@ -1,6 +1,6 @@ contract; -dep other_contract; +mod other_contract; use other_contract::*; diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/non_payable_non_script_call_with_non_zero_coins/src/other_contract.sw b/test/src/e2e_vm_tests/test_programs/should_fail/non_payable_non_script_call_with_non_zero_coins/src/other_contract.sw index a9655f18b4b..80c67e7b019 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/non_payable_non_script_call_with_non_zero_coins/src/other_contract.sw +++ b/test/src/e2e_vm_tests/test_programs/should_fail/non_payable_non_script_call_with_non_zero_coins/src/other_contract.sw @@ -1,4 +1,4 @@ -library other_contract; +library; abi OtherContract { fn non_payable_method(); diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/non_payable_non_zero_coins_const/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_fail/non_payable_non_zero_coins_const/src/main.sw index 9c27b0822a6..fce88744437 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/non_payable_non_zero_coins_const/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_fail/non_payable_non_zero_coins_const/src/main.sw @@ -1,6 +1,6 @@ script; -dep wallet_abi; +mod wallet_abi; use std::constants::ZERO_B256; use wallet_abi::Wallet; diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/non_payable_non_zero_coins_const/src/wallet.sw b/test/src/e2e_vm_tests/test_programs/should_fail/non_payable_non_zero_coins_const/src/wallet.sw index e80a7914aaf..af8a50904a8 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/non_payable_non_zero_coins_const/src/wallet.sw +++ b/test/src/e2e_vm_tests/test_programs/should_fail/non_payable_non_zero_coins_const/src/wallet.sw @@ -1,6 +1,6 @@ contract; -dep wallet_abi; +mod wallet_abi; use std::{ auth::{ diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/non_payable_non_zero_coins_const/src/wallet_abi.sw b/test/src/e2e_vm_tests/test_programs/should_fail/non_payable_non_zero_coins_const/src/wallet_abi.sw index 971ec3387c9..05c08c3f2ec 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/non_payable_non_zero_coins_const/src/wallet_abi.sw +++ b/test/src/e2e_vm_tests/test_programs/should_fail/non_payable_non_zero_coins_const/src/wallet_abi.sw @@ -1,4 +1,4 @@ -library wallet_abi; +library; abi Wallet { #[payable, storage(read, write)] diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/non_payable_non_zero_coins_let_binding/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_fail/non_payable_non_zero_coins_let_binding/src/main.sw index f6fa304be83..f1b6615af59 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/non_payable_non_zero_coins_let_binding/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_fail/non_payable_non_zero_coins_let_binding/src/main.sw @@ -1,6 +1,6 @@ script; -dep wallet_abi; +mod wallet_abi; use std::constants::ZERO_B256; use wallet_abi::Wallet; diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/non_payable_non_zero_coins_let_binding/src/wallet.sw b/test/src/e2e_vm_tests/test_programs/should_fail/non_payable_non_zero_coins_let_binding/src/wallet.sw index e80a7914aaf..af8a50904a8 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/non_payable_non_zero_coins_let_binding/src/wallet.sw +++ b/test/src/e2e_vm_tests/test_programs/should_fail/non_payable_non_zero_coins_let_binding/src/wallet.sw @@ -1,6 +1,6 @@ contract; -dep wallet_abi; +mod wallet_abi; use std::{ auth::{ diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/non_payable_non_zero_coins_let_binding/src/wallet_abi.sw b/test/src/e2e_vm_tests/test_programs/should_fail/non_payable_non_zero_coins_let_binding/src/wallet_abi.sw index 971ec3387c9..05c08c3f2ec 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/non_payable_non_zero_coins_let_binding/src/wallet_abi.sw +++ b/test/src/e2e_vm_tests/test_programs/should_fail/non_payable_non_zero_coins_let_binding/src/wallet_abi.sw @@ -1,4 +1,4 @@ -library wallet_abi; +library; abi Wallet { #[payable, storage(read, write)] diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/non_payable_non_zero_coins_literal/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_fail/non_payable_non_zero_coins_literal/src/main.sw index d3a091afa33..d1a2098f019 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/non_payable_non_zero_coins_literal/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_fail/non_payable_non_zero_coins_literal/src/main.sw @@ -1,6 +1,6 @@ script; -dep wallet_abi; +mod wallet_abi; use std::constants::ZERO_B256; use wallet_abi::Wallet; diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/non_payable_non_zero_coins_literal/src/wallet.sw b/test/src/e2e_vm_tests/test_programs/should_fail/non_payable_non_zero_coins_literal/src/wallet.sw index e80a7914aaf..af8a50904a8 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/non_payable_non_zero_coins_literal/src/wallet.sw +++ b/test/src/e2e_vm_tests/test_programs/should_fail/non_payable_non_zero_coins_literal/src/wallet.sw @@ -1,6 +1,6 @@ contract; -dep wallet_abi; +mod wallet_abi; use std::{ auth::{ diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/non_payable_non_zero_coins_literal/src/wallet_abi.sw b/test/src/e2e_vm_tests/test_programs/should_fail/non_payable_non_zero_coins_literal/src/wallet_abi.sw index 971ec3387c9..05c08c3f2ec 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/non_payable_non_zero_coins_literal/src/wallet_abi.sw +++ b/test/src/e2e_vm_tests/test_programs/should_fail/non_payable_non_zero_coins_literal/src/wallet_abi.sw @@ -1,4 +1,4 @@ -library wallet_abi; +library; abi Wallet { #[payable, storage(read, write)] diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/predicate_while_dep/src/loop.sw b/test/src/e2e_vm_tests/test_programs/should_fail/predicate_while_dep/src/loop.sw index 327d7343330..f3ec1e692ec 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/predicate_while_dep/src/loop.sw +++ b/test/src/e2e_vm_tests/test_programs/should_fail/predicate_while_dep/src/loop.sw @@ -1,4 +1,4 @@ -library loop; +library; pub fn loop() -> bool { let mut x = 0; diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/predicate_while_dep/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_fail/predicate_while_dep/src/main.sw index 5784c8bc938..94dd496ef8f 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/predicate_while_dep/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_fail/predicate_while_dep/src/main.sw @@ -1,6 +1,6 @@ predicate; -dep loop; +mod loop; fn main() -> bool { loop::loop() diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/primitive_type_argument/src/foo.sw b/test/src/e2e_vm_tests/test_programs/should_fail/primitive_type_argument/src/foo.sw index 54aafe13c9d..871fba91f2b 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/primitive_type_argument/src/foo.sw +++ b/test/src/e2e_vm_tests/test_programs/should_fail/primitive_type_argument/src/foo.sw @@ -1,3 +1,3 @@ -library foo; +library; -dep bar/baz; +mod bar; diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/primitive_type_argument/src/bar/baz.sw b/test/src/e2e_vm_tests/test_programs/should_fail/primitive_type_argument/src/foo/bar.sw similarity index 77% rename from test/src/e2e_vm_tests/test_programs/should_fail/primitive_type_argument/src/bar/baz.sw rename to test/src/e2e_vm_tests/test_programs/should_fail/primitive_type_argument/src/foo/bar.sw index 98b058842cb..d7e4f2f0194 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/primitive_type_argument/src/bar/baz.sw +++ b/test/src/e2e_vm_tests/test_programs/should_fail/primitive_type_argument/src/foo/bar.sw @@ -1,4 +1,4 @@ -library baz; +library; pub struct ExampleStruct { a_field: T diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/primitive_type_argument/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_fail/primitive_type_argument/src/main.sw index 3e604a0cd3b..2656f324d63 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/primitive_type_argument/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_fail/primitive_type_argument/src/main.sw @@ -1,6 +1,6 @@ script; -dep foo; +mod foo; struct S { } @@ -12,6 +12,6 @@ impl S { fn main() -> u64 { let a = S:: { }; - let b = foo::baz::ExampleStruct:: { a_field: 5u64 }; + let b = foo::bar::ExampleStruct:: { a_field: 5u64 }; return a.f(); } diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/primitive_type_argument/test.toml b/test/src/e2e_vm_tests/test_programs/should_fail/primitive_type_argument/test.toml index 5be8c64f6a7..eb7c3e27bb9 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/primitive_type_argument/test.toml +++ b/test/src/e2e_vm_tests/test_programs/should_fail/primitive_type_argument/test.toml @@ -1,6 +1,6 @@ category = "fail" -# check: let b = foo::baz::ExampleStruct:: { a_field: 5u64 }; +# check: let b = foo::bar::ExampleStruct:: { a_field: 5u64 }; # nextln: $()Mismatched types. # nextln: $()expected: bool # nextln: $()found: u64. diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/private_function_fully_qualified/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_fail/private_function_fully_qualified/src/main.sw index 818b405ad7f..98102564a4e 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/private_function_fully_qualified/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_fail/private_function_fully_qualified/src/main.sw @@ -1,7 +1,7 @@ script; -dep pkga; +mod pkga; fn main() { pkga::foo(); -} \ No newline at end of file +} diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/private_function_fully_qualified/src/pkga.sw b/test/src/e2e_vm_tests/test_programs/should_fail/private_function_fully_qualified/src/pkga.sw index 2949e1a231c..6ecb5fa8769 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/private_function_fully_qualified/src/pkga.sw +++ b/test/src/e2e_vm_tests/test_programs/should_fail/private_function_fully_qualified/src/pkga.sw @@ -1,3 +1,3 @@ -library pkga; +library; -fn foo() { } \ No newline at end of file +fn foo() { } diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/recover_problem_in_different_file/src/bar.sw b/test/src/e2e_vm_tests/test_programs/should_fail/recover_problem_in_different_file/src/bar.sw index 808e92e8793..4478e6f9c04 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/recover_problem_in_different_file/src/bar.sw +++ b/test/src/e2e_vm_tests/test_programs/should_fail/recover_problem_in_different_file/src/bar.sw @@ -1,4 +1,4 @@ -library bar; +library; fn typing_problem_recovery_witness() -> bool { () diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/recover_problem_in_different_file/src/foo.sw b/test/src/e2e_vm_tests/test_programs/should_fail/recover_problem_in_different_file/src/foo.sw index 238a4096735..d4ef57f4dc4 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/recover_problem_in_different_file/src/foo.sw +++ b/test/src/e2e_vm_tests/test_programs/should_fail/recover_problem_in_different_file/src/foo.sw @@ -1,3 +1,3 @@ -library foo; +library; § // Should create lexer problems. diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/recover_problem_in_different_file/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_fail/recover_problem_in_different_file/src/main.sw index 94b4cd02943..1153274fc27 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/recover_problem_in_different_file/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_fail/recover_problem_in_different_file/src/main.sw @@ -1,8 +1,8 @@ script; -dep foo; -dep bar; -dep baz; -dep no_such_file; +mod foo; +mod bar; +mod baz; +mod no_such_file; fn main() {} diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/recover_unclosed_multiline_comment/src/bar.sw b/test/src/e2e_vm_tests/test_programs/should_fail/recover_unclosed_multiline_comment/src/bar.sw index 33008e01e49..be337e3921e 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/recover_unclosed_multiline_comment/src/bar.sw +++ b/test/src/e2e_vm_tests/test_programs/should_fail/recover_unclosed_multiline_comment/src/bar.sw @@ -1,4 +1,4 @@ -library foo; +library; fn foo() -> bool { 0 } // recovery witness diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/recover_unclosed_multiline_comment/src/baz.sw b/test/src/e2e_vm_tests/test_programs/should_fail/recover_unclosed_multiline_comment/src/baz.sw index 1d09d39b22f..89f3c76ea13 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/recover_unclosed_multiline_comment/src/baz.sw +++ b/test/src/e2e_vm_tests/test_programs/should_fail/recover_unclosed_multiline_comment/src/baz.sw @@ -1,4 +1,4 @@ -library foo; +library; fn foo() -> bool { 0 } // recovery witness diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/recover_unclosed_multiline_comment/src/foo.sw b/test/src/e2e_vm_tests/test_programs/should_fail/recover_unclosed_multiline_comment/src/foo.sw index b14f47c56ac..e09f934fc9b 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/recover_unclosed_multiline_comment/src/foo.sw +++ b/test/src/e2e_vm_tests/test_programs/should_fail/recover_unclosed_multiline_comment/src/foo.sw @@ -1,4 +1,4 @@ -library foo; +library; fn foo() -> bool { 0 } // recovery witness diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/recover_unclosed_multiline_comment/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_fail/recover_unclosed_multiline_comment/src/main.sw index 62ec8af8792..486956ef293 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/recover_unclosed_multiline_comment/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_fail/recover_unclosed_multiline_comment/src/main.sw @@ -1,8 +1,8 @@ contract; -dep foo; -dep bar; -dep baz; +mod foo; +mod bar; +mod baz; fn a() -> bool { 0 } // recovery witness diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/reserved_identifiers/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_fail/reserved_identifiers/src/main.sw index 00f81f2f5a9..26af0e519d4 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/reserved_identifiers/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_fail/reserved_identifiers/src/main.sw @@ -7,7 +7,7 @@ fn main() { let mut contract = 0; let mut predicate = 0; let mut library = 0; - let mut dep = 0; + let mut mod = 0; let mut pub = 0; let mut use = 0; let mut as = 0; diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/shadow_import/src/bar.sw b/test/src/e2e_vm_tests/test_programs/should_fail/shadow_import/src/bar.sw index 5ce39a93f2c..56c92229d44 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/shadow_import/src/bar.sw +++ b/test/src/e2e_vm_tests/test_programs/should_fail/shadow_import/src/bar.sw @@ -1,4 +1,4 @@ -library bar; +library; pub struct Bar1 { a: u32, diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/shadow_import/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_fail/shadow_import/src/main.sw index 21e64edf79c..eb0c18a8d56 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/shadow_import/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_fail/shadow_import/src/main.sw @@ -1,6 +1,6 @@ script; -dep bar; +mod bar; // This is okay use ::bar::{Bar1, Bar1 as Foo}; diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/shadowing/shadowed_consts_and_vars/src/lib.sw b/test/src/e2e_vm_tests/test_programs/should_fail/shadowing/shadowed_consts_and_vars/src/lib.sw index 01a5748a6b6..dff72cb60e4 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/shadowing/shadowed_consts_and_vars/src/lib.sw +++ b/test/src/e2e_vm_tests/test_programs/should_fail/shadowing/shadowed_consts_and_vars/src/lib.sw @@ -1,3 +1,3 @@ -library lib; +library; pub const X = 5; diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/shadowing/shadowed_consts_and_vars/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_fail/shadowing/shadowed_consts_and_vars/src/main.sw index d2492e88fe1..9e5b39a4edf 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/shadowing/shadowed_consts_and_vars/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_fail/shadowing/shadowed_consts_and_vars/src/main.sw @@ -1,6 +1,6 @@ script; -dep lib; +mod lib; // const shadowing an imported const use lib::X; diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/shadowing/shadowed_consts_and_vars_alias/src/lib.sw b/test/src/e2e_vm_tests/test_programs/should_fail/shadowing/shadowed_consts_and_vars_alias/src/lib.sw index 01a5748a6b6..dff72cb60e4 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/shadowing/shadowed_consts_and_vars_alias/src/lib.sw +++ b/test/src/e2e_vm_tests/test_programs/should_fail/shadowing/shadowed_consts_and_vars_alias/src/lib.sw @@ -1,3 +1,3 @@ -library lib; +library; pub const X = 5; diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/shadowing/shadowed_consts_and_vars_alias/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_fail/shadowing/shadowed_consts_and_vars_alias/src/main.sw index 82d80cf878e..387ebde41eb 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/shadowing/shadowed_consts_and_vars_alias/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_fail/shadowing/shadowed_consts_and_vars_alias/src/main.sw @@ -1,6 +1,6 @@ script; -dep lib; +mod lib; // const shadowing an imported const with alias use lib::X as Y; diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/shadowing/shadowed_types_and_traits/src/lib.sw b/test/src/e2e_vm_tests/test_programs/should_fail/shadowing/shadowed_types_and_traits/src/lib.sw index 89b28ea250a..3e7190fcf3e 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/shadowing/shadowed_types_and_traits/src/lib.sw +++ b/test/src/e2e_vm_tests/test_programs/should_fail/shadowing/shadowed_types_and_traits/src/lib.sw @@ -1,4 +1,4 @@ -library lib; +library; pub struct MyStruct1 {} pub enum MyEnum1 {} diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/shadowing/shadowed_types_and_traits/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_fail/shadowing/shadowed_types_and_traits/src/main.sw index 862a89bfede..65476ba54f9 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/shadowing/shadowed_types_and_traits/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_fail/shadowing/shadowed_types_and_traits/src/main.sw @@ -1,6 +1,6 @@ script; -dep lib; +mod lib; // Check for shadowing library imports use lib::{MyAbi1, MyEnum1, MyStruct1, MyTrait1}; diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/shadowing/shadowed_types_and_traits_alias/src/lib.sw b/test/src/e2e_vm_tests/test_programs/should_fail/shadowing/shadowed_types_and_traits_alias/src/lib.sw index 6541d9a0e7f..b27a7311af8 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/shadowing/shadowed_types_and_traits_alias/src/lib.sw +++ b/test/src/e2e_vm_tests/test_programs/should_fail/shadowing/shadowed_types_and_traits_alias/src/lib.sw @@ -1,4 +1,4 @@ -library lib; +library; pub struct MyStruct0 {} pub enum MyEnum0 {} diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/shadowing/shadowed_types_and_traits_alias/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_fail/shadowing/shadowed_types_and_traits_alias/src/main.sw index c42de9093e2..043b1b4539f 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/shadowing/shadowed_types_and_traits_alias/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_fail/shadowing/shadowed_types_and_traits_alias/src/main.sw @@ -1,6 +1,6 @@ script; -dep lib; +mod lib; // Check for shadowing library imports use lib::{MyAbi0 as MyAbi1, MyEnum0 as MyEnum1, MyStruct0 as MyStruct1, MyTrait0 as MyTrait1}; diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/star_import_alias/src/bar.sw b/test/src/e2e_vm_tests/test_programs/should_fail/star_import_alias/src/bar.sw index 6d6dbbd7ff1..0dd1116f79a 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/star_import_alias/src/bar.sw +++ b/test/src/e2e_vm_tests/test_programs/should_fail/star_import_alias/src/bar.sw @@ -1,4 +1,4 @@ -library bar; +library; pub struct Bar { a: u32, diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/star_import_alias/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_fail/star_import_alias/src/main.sw index 53184b8514f..97dc3c9374b 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/star_import_alias/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_fail/star_import_alias/src/main.sw @@ -1,6 +1,6 @@ script; -dep bar; +mod bar; // This should not compile but `use ::bar::*;` should use ::bar::{* as all}; diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/storage_in_library/src/inner.sw b/test/src/e2e_vm_tests/test_programs/should_fail/storage_in_library/src/inner.sw index 50cc825b98f..7f1cee925af 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/storage_in_library/src/inner.sw +++ b/test/src/e2e_vm_tests/test_programs/should_fail/storage_in_library/src/inner.sw @@ -1,4 +1,4 @@ -library inner; +library; // Expecting the following error: // 9 | / storage { diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/storage_in_library/src/lib.sw b/test/src/e2e_vm_tests/test_programs/should_fail/storage_in_library/src/lib.sw index 99057bf98c2..38d17d5583e 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/storage_in_library/src/lib.sw +++ b/test/src/e2e_vm_tests/test_programs/should_fail/storage_in_library/src/lib.sw @@ -1 +1 @@ -dep inner; +mod inner; diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/storage_in_library/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_fail/storage_in_library/src/main.sw index e2e53bd0604..07df1c92ced 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/storage_in_library/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_fail/storage_in_library/src/main.sw @@ -1,6 +1,6 @@ contract; -dep inner; +mod inner; abi Test { fn foo(); diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/storage_ops_in_library/src/do_storage.sw b/test/src/e2e_vm_tests/test_programs/should_fail/storage_ops_in_library/src/do_storage.sw index fc490f9f4b8..35909a57cac 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/storage_ops_in_library/src/do_storage.sw +++ b/test/src/e2e_vm_tests/test_programs/should_fail/storage_ops_in_library/src/do_storage.sw @@ -1,4 +1,4 @@ -library do_storage; +library; const KEY: b256 = 0xfafafafafafafafafafafafafafafafafafafafafafafafafafafafafafafafa; diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/storage_ops_in_library/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_fail/storage_ops_in_library/src/main.sw index fe8608d89e6..de04ba626e8 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/storage_ops_in_library/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_fail/storage_ops_in_library/src/main.sw @@ -1,6 +1,6 @@ script; -dep do_storage; +mod do_storage; fn main() { do_storage::side_effects(); diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/supertraits_for_abis_ownable1/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_fail/supertraits_for_abis_ownable1/src/main.sw index 44a5736ded7..bb0901224a1 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/supertraits_for_abis_ownable1/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_fail/supertraits_for_abis_ownable1/src/main.sw @@ -1,6 +1,6 @@ contract; -dep ownable; +mod ownable; use ownable::{Ownable, StorageHelpers}; storage { diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/supertraits_for_abis_ownable1/src/ownable.sw b/test/src/e2e_vm_tests/test_programs/should_fail/supertraits_for_abis_ownable1/src/ownable.sw index 63607d3acce..11ed2ed711c 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/supertraits_for_abis_ownable1/src/ownable.sw +++ b/test/src/e2e_vm_tests/test_programs/should_fail/supertraits_for_abis_ownable1/src/ownable.sw @@ -1,4 +1,4 @@ -library ownable; +library; pub struct OwnershipTransferred { previous_owner: b256, diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/supertraits_for_abis_ownable2/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_fail/supertraits_for_abis_ownable2/src/main.sw index b043cd58e85..e91169d178d 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/supertraits_for_abis_ownable2/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_fail/supertraits_for_abis_ownable2/src/main.sw @@ -1,6 +1,6 @@ contract; -dep ownable; +mod ownable; use ownable::{Ownable, StorageHelpers}; storage { diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/supertraits_for_abis_ownable2/src/ownable.sw b/test/src/e2e_vm_tests/test_programs/should_fail/supertraits_for_abis_ownable2/src/ownable.sw index 63607d3acce..11ed2ed711c 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/supertraits_for_abis_ownable2/src/ownable.sw +++ b/test/src/e2e_vm_tests/test_programs/should_fail/supertraits_for_abis_ownable2/src/ownable.sw @@ -1,4 +1,4 @@ -library ownable; +library; pub struct OwnershipTransferred { previous_owner: b256, diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/trait_method_signature_mismatch/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_fail/trait_method_signature_mismatch/src/main.sw index 4af1078f8a2..53b6ee5bf47 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/trait_method_signature_mismatch/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_fail/trait_method_signature_mismatch/src/main.sw @@ -1,7 +1,7 @@ // This should result in an error saying that the method signature of the // implementation does not match the declaration. -library test; +library; struct MyStruct { val: T diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/traits_with_call_paths/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_fail/traits_with_call_paths/src/main.sw index 4bfa2ab98e8..c4b40a39542 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/traits_with_call_paths/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_fail/traits_with_call_paths/src/main.sw @@ -1,7 +1,7 @@ script; -dep my_add; -dep my_a; +mod my_add; +mod my_a; impl my_add::MyAdd for u64 { fn my_add(self, other: Self) -> Self { diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/traits_with_call_paths/src/my_a.sw b/test/src/e2e_vm_tests/test_programs/should_fail/traits_with_call_paths/src/my_a.sw index b300c9fe9a9..35387529973 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/traits_with_call_paths/src/my_a.sw +++ b/test/src/e2e_vm_tests/test_programs/should_fail/traits_with_call_paths/src/my_a.sw @@ -1,4 +1,4 @@ -library my_a; +library; pub trait A { fn f(self) -> u64; diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/traits_with_call_paths/src/my_add.sw b/test/src/e2e_vm_tests/test_programs/should_fail/traits_with_call_paths/src/my_add.sw index 9eebbb9d215..17b75a7ad67 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/traits_with_call_paths/src/my_add.sw +++ b/test/src/e2e_vm_tests/test_programs/should_fail/traits_with_call_paths/src/my_add.sw @@ -1,4 +1,4 @@ -library my_add; +library; pub trait MyAdd { fn my_add(self, other: Self) -> Self; diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/dca/library/fn_params_free/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/dca/library/fn_params_free/src/main.sw index 7aa65cff759..98227b54dc4 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/dca/library/fn_params_free/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/dca/library/fn_params_free/src/main.sw @@ -1,4 +1,4 @@ -library foo; +library; struct S {} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/dca/library/fn_params_impl/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/dca/library/fn_params_impl/src/main.sw index 93964d993d3..b7573acfae6 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/dca/library/fn_params_impl/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/dca/library/fn_params_impl/src/main.sw @@ -1,4 +1,4 @@ -library foo; +library; struct S {} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/dca/library/fn_params_trait/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/dca/library/fn_params_trait/src/main.sw index e9b51db2c4c..6e62b030a9b 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/dca/library/fn_params_trait/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/dca/library/fn_params_trait/src/main.sw @@ -1,4 +1,4 @@ -library foo; +library; struct S {} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/dca/library/unused_priv_free_fn/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/dca/library/unused_priv_free_fn/src/main.sw index d868f337dcd..a02ae493256 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/dca/library/unused_priv_free_fn/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/dca/library/unused_priv_free_fn/src/main.sw @@ -1,4 +1,4 @@ -library foo; +library; fn private_fn(x: u64) -> u64 { x diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/dca/library/unused_pub_free_fn/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/dca/library/unused_pub_free_fn/src/main.sw index 41417b3616d..2d4727a0e75 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/dca/library/unused_pub_free_fn/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/dca/library/unused_pub_free_fn/src/main.sw @@ -1,3 +1,3 @@ -library foo; +library; pub fn free_fn() {} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/dca/multiple_enums_same_name/src/colors1.sw b/test/src/e2e_vm_tests/test_programs/should_pass/dca/multiple_enums_same_name/src/colors1.sw index dfc3d3b5e23..726a79242fe 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/dca/multiple_enums_same_name/src/colors1.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/dca/multiple_enums_same_name/src/colors1.sw @@ -1,4 +1,4 @@ -library colors1; +library; pub enum Colors { Red: (), diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/dca/multiple_enums_same_name/src/colors2.sw b/test/src/e2e_vm_tests/test_programs/should_pass/dca/multiple_enums_same_name/src/colors2.sw index 97602edd87c..726a79242fe 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/dca/multiple_enums_same_name/src/colors2.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/dca/multiple_enums_same_name/src/colors2.sw @@ -1,4 +1,4 @@ -library colors2; +library; pub enum Colors { Red: (), diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/dca/multiple_enums_same_name/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/dca/multiple_enums_same_name/src/main.sw index 3fc7bb1e1ea..4ec68531593 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/dca/multiple_enums_same_name/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/dca/multiple_enums_same_name/src/main.sw @@ -1,7 +1,7 @@ script; -dep colors1; -dep colors2; +mod colors1; +mod colors2; fn main() { let c1 = colors1::Colors::Red; diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/dca/multiple_fns_same_name/src/colors1.sw b/test/src/e2e_vm_tests/test_programs/should_pass/dca/multiple_fns_same_name/src/colors1.sw index 6eb07292aba..6dfbc971bc4 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/dca/multiple_fns_same_name/src/colors1.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/dca/multiple_fns_same_name/src/colors1.sw @@ -1,4 +1,4 @@ -library colors1; +library; pub fn color() { } diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/dca/multiple_fns_same_name/src/colors2.sw b/test/src/e2e_vm_tests/test_programs/should_pass/dca/multiple_fns_same_name/src/colors2.sw index 0a73b7befe6..6dfbc971bc4 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/dca/multiple_fns_same_name/src/colors2.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/dca/multiple_fns_same_name/src/colors2.sw @@ -1,4 +1,4 @@ -library colors2; +library; pub fn color() { } diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/dca/multiple_fns_same_name/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/dca/multiple_fns_same_name/src/main.sw index b7dca53a518..d8d5aab02cf 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/dca/multiple_fns_same_name/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/dca/multiple_fns_same_name/src/main.sw @@ -1,7 +1,7 @@ script; -dep colors1; -dep colors2; +mod colors1; +mod colors2; fn main() { let _ = colors1::color(); diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/dca/unused_enum/src/enum.sw b/test/src/e2e_vm_tests/test_programs/should_pass/dca/unused_enum/src/enum.sw index d55c3929f22..22b4df2145c 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/dca/unused_enum/src/enum.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/dca/unused_enum/src/enum.sw @@ -1,4 +1,4 @@ -library r#enum; +library; pub enum AnEnum { Variant: (), diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/dca/unused_enum/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/dca/unused_enum/src/main.sw index 25a1b0c858f..ef39fb605a9 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/dca/unused_enum/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/dca/unused_enum/src/main.sw @@ -1,7 +1,7 @@ script; -dep r#enum; -dep utils; +mod r#enum; +mod utils; fn main() { let _ = utils::uses_enum(); diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/dca/unused_enum/src/utils.sw b/test/src/e2e_vm_tests/test_programs/should_pass/dca/unused_enum/src/utils.sw index 2bf92959ead..5694d7f0238 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/dca/unused_enum/src/utils.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/dca/unused_enum/src/utils.sw @@ -1,7 +1,6 @@ -library utils; +library; -dep r#enum; -use r#enum::AnEnum; +use ::r#enum::AnEnum; pub fn uses_enum() -> AnEnum { AnEnum::Variant diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/dca/unused_fields/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/dca/unused_fields/src/main.sw index a2adf6c44c2..c179096b756 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/dca/unused_fields/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/dca/unused_fields/src/main.sw @@ -1,6 +1,6 @@ script; -dep utils; +mod utils; use utils::Foo; diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/dca/unused_fields/src/utils.sw b/test/src/e2e_vm_tests/test_programs/should_pass/dca/unused_fields/src/utils.sw index ae815364150..8d962535a8d 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/dca/unused_fields/src/utils.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/dca/unused_fields/src/utils.sw @@ -1,4 +1,4 @@ -library utils; +library; pub struct Foo { value: u64 diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/dca/unused_trait/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/dca/unused_trait/src/main.sw index 1a6ca79d306..2607dbb987a 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/dca/unused_trait/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/dca/unused_trait/src/main.sw @@ -1,7 +1,7 @@ script; -dep r#trait; -dep utils; +mod r#trait; +mod utils; use r#trait::Trait; diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/dca/unused_trait/src/trait.sw b/test/src/e2e_vm_tests/test_programs/should_pass/dca/unused_trait/src/trait.sw index cf12288916f..53be71b4264 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/dca/unused_trait/src/trait.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/dca/unused_trait/src/trait.sw @@ -1,4 +1,4 @@ -library r#trait; +library; pub trait Trait { } diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/dca/unused_trait/src/utils.sw b/test/src/e2e_vm_tests/test_programs/should_pass/dca/unused_trait/src/utils.sw index 58ed4c906fd..0d0bc90114c 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/dca/unused_trait/src/utils.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/dca/unused_trait/src/utils.sw @@ -1,7 +1,6 @@ -library utils; +library; -dep r#trait; -use r#trait::Trait; +use ::r#trait::Trait; pub fn uses_trait(a: T) where T: Trait { diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/forc/workspace_building/test_lib/src/lib.sw b/test/src/e2e_vm_tests/test_programs/should_pass/forc/workspace_building/test_lib/src/lib.sw index 9a3182fd923..316a905aa9b 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/forc/workspace_building/test_lib/src/lib.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/forc/workspace_building/test_lib/src/lib.sw @@ -1 +1 @@ -library test_lib; +library; diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/aliased_imports/src/a_dependency.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/aliased_imports/src/foo.sw similarity index 72% rename from test/src/e2e_vm_tests/test_programs/should_pass/language/aliased_imports/src/a_dependency.sw rename to test/src/e2e_vm_tests/test_programs/should_pass/language/aliased_imports/src/foo.sw index 459d161d9cd..38ca320e405 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/aliased_imports/src/a_dependency.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/aliased_imports/src/foo.sw @@ -1,4 +1,4 @@ -library foo; +library; pub struct Foo { foo: u64, diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/aliased_imports/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/aliased_imports/src/main.sw index 0e5432b5822..54286017a31 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/aliased_imports/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/aliased_imports/src/main.sw @@ -1,7 +1,7 @@ script; // This tests importing other files. -dep a_dependency; +mod foo; use foo::Foo as MyFoo; diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/const_decl_and_use_in_library/src/consts.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/const_decl_and_use_in_library/src/consts.sw index 1fecc4a85c7..c864ff9e70a 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/const_decl_and_use_in_library/src/consts.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/const_decl_and_use_in_library/src/consts.sw @@ -1,4 +1,4 @@ -library consts; +library; const THREE: u64 = 3; const FOUR: u64 = 4; diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/const_decl_and_use_in_library/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/const_decl_and_use_in_library/src/main.sw index 818975e0924..ecb570915c0 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/const_decl_and_use_in_library/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/const_decl_and_use_in_library/src/main.sw @@ -1,6 +1,6 @@ script; -dep consts; +mod consts; use consts::adder; diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/const_decl_in_library/src/earth.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/const_decl_in_library/src/earth.sw index c69ded43359..069ba00a9e8 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/const_decl_in_library/src/earth.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/const_decl_in_library/src/earth.sw @@ -1,3 +1,3 @@ -library earth; +library; pub const MAN = 5; diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/const_decl_in_library/src/heaven.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/const_decl_in_library/src/heaven.sw index 3873564331a..32c71548fa5 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/const_decl_in_library/src/heaven.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/const_decl_in_library/src/heaven.sw @@ -1,4 +1,4 @@ -library heaven; +library; pub const UNKNOWN_DEITY_VALUE = 0; pub const MONKEYS_GONE_HERE = true; diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/const_decl_in_library/src/hell.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/const_decl_in_library/src/hell.sw index df0f765dc01..131163599a3 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/const_decl_in_library/src/hell.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/const_decl_in_library/src/hell.sw @@ -1,3 +1,3 @@ -library hell; +library; pub const THE_DEVIL = 6; diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/const_decl_in_library/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/const_decl_in_library/src/main.sw index a5ce6c1eef0..08aec64bda0 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/const_decl_in_library/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/const_decl_in_library/src/main.sw @@ -1,8 +1,8 @@ script; -dep heaven; -dep earth; -dep hell; +mod heaven; +mod earth; +mod hell; use heaven::UNKNOWN_DEITY_VALUE; use earth::MAN; diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/const_decl_with_call_path/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/const_decl_with_call_path/src/main.sw index 0b08b9524cc..ab7d77c8bec 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/const_decl_with_call_path/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/const_decl_with_call_path/src/main.sw @@ -1,6 +1,6 @@ script; -dep test_lib; +mod test_lib; fn main() -> u64 { let x = test_lib::NUMBER; diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/const_decl_with_call_path/src/test_lib.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/const_decl_with_call_path/src/test_lib.sw index 96a39c02d13..2bdbcad65a1 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/const_decl_with_call_path/src/test_lib.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/const_decl_with_call_path/src/test_lib.sw @@ -1,3 +1,3 @@ -library test_lib; +library; pub const NUMBER: u64 = 10; diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/dependencies/Forc.lock b/test/src/e2e_vm_tests/test_programs/should_pass/language/dependencies/Forc.lock deleted file mode 100644 index fe559a73b4c..00000000000 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/dependencies/Forc.lock +++ /dev/null @@ -1,8 +0,0 @@ -[[package]] -name = 'core' -source = 'path+from-root-6DF7ACF6DF315C32' - -[[package]] -name = 'dependencies' -source = 'member' -dependencies = ['core'] diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/dependencies/Forc.toml b/test/src/e2e_vm_tests/test_programs/should_pass/language/dependencies/Forc.toml deleted file mode 100644 index e0fa9050262..00000000000 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/dependencies/Forc.toml +++ /dev/null @@ -1,8 +0,0 @@ -[project] -authors = ["Fuel Labs "] -license = "Apache-2.0" -name = "dependencies" -entry = "main.sw" - -[dependencies] -core = { path = "../../../../../../../sway-lib-core" } diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/dependencies/json_abi_oracle.json b/test/src/e2e_vm_tests/test_programs/should_pass/language/dependencies/json_abi_oracle.json deleted file mode 100644 index 03b2f150939..00000000000 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/dependencies/json_abi_oracle.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "configurables": [], - "functions": [ - { - "attributes": null, - "inputs": [], - "name": "main", - "output": { - "name": "", - "type": 0, - "typeArguments": null - } - } - ], - "loggedTypes": [], - "messagesTypes": [], - "types": [ - { - "components": null, - "type": "bool", - "typeId": 0, - "typeParameters": null - } - ] -} \ No newline at end of file diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/dependencies/src/a_dependency.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/dependencies/src/a_dependency.sw deleted file mode 100644 index b9513628d62..00000000000 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/dependencies/src/a_dependency.sw +++ /dev/null @@ -1,6 +0,0 @@ -library foo; -dep bar; -dep inner/bar; -pub struct Foo { - foo: str[3], -} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/dependencies/src/bar.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/dependencies/src/bar.sw deleted file mode 100644 index 3ddb0003d63..00000000000 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/dependencies/src/bar.sw +++ /dev/null @@ -1,2 +0,0 @@ -library bar; -//dep a_dependency; diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/dependencies/src/inner/bar.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/dependencies/src/inner/bar.sw deleted file mode 100644 index c9dcf5688e7..00000000000 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/dependencies/src/inner/bar.sw +++ /dev/null @@ -1,8 +0,0 @@ -library bar; -dep double_inner/double_bar; - -use double_bar::DoubleBar; - -pub struct Bar { - a: u32, -} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/dependencies/src/inner/double_inner/double_bar.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/dependencies/src/inner/double_inner/double_bar.sw deleted file mode 100644 index 20db24f6698..00000000000 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/dependencies/src/inner/double_inner/double_bar.sw +++ /dev/null @@ -1,6 +0,0 @@ -library double_bar; -//use ::foo::Foo; - -pub struct DoubleBar { - a: u32, -} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/dependencies/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/dependencies/src/main.sw deleted file mode 100644 index 695dea1cc05..00000000000 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/dependencies/src/main.sw +++ /dev/null @@ -1,21 +0,0 @@ -script; -// This tests importing other files. - -dep a_dependency; -dep nested_dependency/bar/bar; - -use foo::Foo; -use ::foo::bar::{Bar, double_bar::DoubleBar}; - -fn main() -> bool { - let foo = Foo { - foo: "foo", - }; - let db = ::foo::bar::double_bar::DoubleBar { - a: 5u32, - }; - let bar = Bar { - a: 5u32, - }; - false -} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/dependencies/src/nested_dependency/bar/bar.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/dependencies/src/nested_dependency/bar/bar.sw deleted file mode 100644 index eea09fd8b9c..00000000000 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/dependencies/src/nested_dependency/bar/bar.sw +++ /dev/null @@ -1,6 +0,0 @@ -library bar; -use ::foo::Foo; - -pub struct NestedDependency { - num: u64, -} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/dependencies/test.toml b/test/src/e2e_vm_tests/test_programs/should_pass/language/dependencies/test.toml deleted file mode 100644 index 916523ab45f..00000000000 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/dependencies/test.toml +++ /dev/null @@ -1,4 +0,0 @@ -category = "run" -expected_result = { action = "return", value = 0 } -validate_abi = true -expected_warnings = 2 diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/generic_traits/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/generic_traits/src/main.sw index 5bf6a5e3c1d..264ee4dbe24 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/generic_traits/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/generic_traits/src/main.sw @@ -4,9 +4,9 @@ script; // but until then, multiple methods with the same name is undefined behavior. // https://doc.rust-lang.org/rust-by-example/trait/disambiguating.html -dep my_double; -dep my_point; -dep my_triple; +mod my_double; +mod my_point; +mod my_triple; use my_point::MyPoint; use my_triple::MyTriple; diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/generic_traits/src/my_double.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/generic_traits/src/my_double.sw index 5c1b5ba113e..c1b6052b6f9 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/generic_traits/src/my_double.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/generic_traits/src/my_double.sw @@ -1,4 +1,4 @@ -library my_double; +library; pub trait MyDouble { fn my_double(self, input: T) -> T; diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/generic_traits/src/my_point.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/generic_traits/src/my_point.sw index 8aa1427a0ac..3b057fd2db3 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/generic_traits/src/my_point.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/generic_traits/src/my_point.sw @@ -1,4 +1,4 @@ -library my_point; +library; use ::my_double::MyDouble; diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/generic_traits/src/my_triple.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/generic_traits/src/my_triple.sw index 9127fa014be..90125eac2ca 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/generic_traits/src/my_triple.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/generic_traits/src/my_triple.sw @@ -1,4 +1,4 @@ -library my_triple; +library; pub trait MyTriple { fn my_triple(self, input: T) -> T; diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/generic_type_inference/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/generic_type_inference/src/main.sw index 5190178e5ff..5ce03b6fb1e 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/generic_type_inference/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/generic_type_inference/src/main.sw @@ -1,6 +1,6 @@ script; -dep utils; +mod utils; use utils::*; diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/generic_type_inference/src/utils.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/generic_type_inference/src/utils.sw index 264bf04ebe1..a01142f2add 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/generic_type_inference/src/utils.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/generic_type_inference/src/utils.sw @@ -1,4 +1,4 @@ -library utils; +library; pub fn vec_from(vals: [u32; 3]) -> Vec { let mut vec = Vec::new(); diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/import_method_from_other_file/src/asset.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/import_method_from_other_file/src/asset.sw index 55285f631ba..bea4c2d0c8f 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/import_method_from_other_file/src/asset.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/import_method_from_other_file/src/asset.sw @@ -1,4 +1,4 @@ -library asset; +library; use core::ops::Eq; diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/import_method_from_other_file/src/context.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/import_method_from_other_file/src/context.sw index 172add3f96a..23291ae8873 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/import_method_from_other_file/src/context.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/import_method_from_other_file/src/context.sw @@ -1,4 +1,4 @@ -library context; +library; pub struct Context { something: u64 } diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/import_method_from_other_file/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/import_method_from_other_file/src/main.sw index 2abe2e7c7bf..136515fc5c3 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/import_method_from_other_file/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/import_method_from_other_file/src/main.sw @@ -1,8 +1,8 @@ script; -dep context; -dep asset; -dep utils; +mod context; +mod asset; +mod utils; use context::Context; use utils::Wrapper; diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/import_method_from_other_file/src/utils.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/import_method_from_other_file/src/utils.sw index f91145e0624..6a8e6763eec 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/import_method_from_other_file/src/utils.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/import_method_from_other_file/src/utils.sw @@ -1,4 +1,4 @@ -library utils; +library; use core::ops::Eq; use ::asset::Asset; diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/import_trailing_comma/src/lib.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/import_trailing_comma/src/lib.sw index 2878e5a1e37..24b2605ab9a 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/import_trailing_comma/src/lib.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/import_trailing_comma/src/lib.sw @@ -1,4 +1,4 @@ -library A; +library; pub struct B { b: u64, diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/import_trailing_comma/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/import_trailing_comma/src/main.sw index 0f880819e99..0847458b90f 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/import_trailing_comma/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/import_trailing_comma/src/main.sw @@ -1,7 +1,7 @@ script; -dep lib; -use A::{B, C, D,}; +mod lib; +use lib::{B, C, D,}; fn main() -> u64 { let x = B { diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/import_with_different_callpaths/src/data_structures.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/import_with_different_callpaths/src/data_structures.sw index 9a33cf3ee99..6d31402d78f 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/import_with_different_callpaths/src/data_structures.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/import_with_different_callpaths/src/data_structures.sw @@ -1,4 +1,4 @@ -library data_structures; +library; pub struct SomeStruct { a: T, @@ -6,4 +6,4 @@ pub struct SomeStruct { pub enum SomeEnum { a: T, -} \ No newline at end of file +} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/import_with_different_callpaths/src/eq_impls.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/import_with_different_callpaths/src/eq_impls.sw index 363af7ab7e3..a55a1785ed0 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/import_with_different_callpaths/src/eq_impls.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/import_with_different_callpaths/src/eq_impls.sw @@ -1,8 +1,6 @@ -library eq_impls; +library; -dep data_structures; - -use data_structures::{SomeEnum, SomeStruct}; +use ::data_structures::{SomeEnum, SomeStruct}; use core::ops::Eq; impl Eq for SomeEnum { diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/import_with_different_callpaths/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/import_with_different_callpaths/src/main.sw index 9b39a3df3e8..b36d6ccf86b 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/import_with_different_callpaths/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/import_with_different_callpaths/src/main.sw @@ -1,7 +1,7 @@ script; -dep eq_impls; -dep data_structures; +mod data_structures; +mod eq_impls; use eq_impls::*; use data_structures::*; @@ -18,4 +18,4 @@ fn main() { expected.push(SomeStruct { a: 1u32 }); assert(expected == expected); -} \ No newline at end of file +} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/multi_item_import/src/bar.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/multi_item_import/src/bar.sw index 1e4890e54f0..e11c06d57e8 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/multi_item_import/src/bar.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/multi_item_import/src/bar.sw @@ -1,5 +1,5 @@ -library bar; -dep inner/double_bar; +library; +mod double_bar; pub struct Bar1 { a: u32, diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/multi_item_import/src/inner/double_bar.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/multi_item_import/src/bar/double_bar.sw similarity index 85% rename from test/src/e2e_vm_tests/test_programs/should_pass/language/multi_item_import/src/inner/double_bar.sw rename to test/src/e2e_vm_tests/test_programs/should_pass/language/multi_item_import/src/bar/double_bar.sw index ac79f9972e9..3937b5862c5 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/multi_item_import/src/inner/double_bar.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/multi_item_import/src/bar/double_bar.sw @@ -1,4 +1,4 @@ -library double_bar; +library; pub struct DoubleBar1 { a: u32, diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/multi_item_import/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/multi_item_import/src/main.sw index 0db0da1a88c..5562bcd4bdf 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/multi_item_import/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/multi_item_import/src/main.sw @@ -1,6 +1,6 @@ script; -dep bar; +mod bar; use ::bar::{Bar1 as MyBar1, Bar2, double_bar::{DoubleBar1::{self as MyDoubleBar1}, DoubleBar2::{self as MyDoubleBar2}, DoubleBar3}}; diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/primitive_type_argument/src/foo.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/primitive_type_argument/src/foo.sw index 54aafe13c9d..871fba91f2b 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/primitive_type_argument/src/foo.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/primitive_type_argument/src/foo.sw @@ -1,3 +1,3 @@ -library foo; +library; -dep bar/baz; +mod bar; diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/primitive_type_argument/src/foo/bar.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/primitive_type_argument/src/foo/bar.sw new file mode 100644 index 00000000000..df6056f61ce --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/primitive_type_argument/src/foo/bar.sw @@ -0,0 +1,3 @@ +library; + +mod baz; diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/primitive_type_argument/src/bar/baz.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/primitive_type_argument/src/foo/bar/baz.sw similarity index 73% rename from test/src/e2e_vm_tests/test_programs/should_pass/language/primitive_type_argument/src/bar/baz.sw rename to test/src/e2e_vm_tests/test_programs/should_pass/language/primitive_type_argument/src/foo/bar/baz.sw index 7e0e8964ef4..9e62aa45791 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/primitive_type_argument/src/bar/baz.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/primitive_type_argument/src/foo/bar/baz.sw @@ -1,6 +1,6 @@ -library baz; +library; -dep quux; +mod quux; pub struct ExampleStruct { a_field: T, diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/primitive_type_argument/src/bar/quux.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/primitive_type_argument/src/foo/bar/baz/quux.sw similarity index 85% rename from test/src/e2e_vm_tests/test_programs/should_pass/language/primitive_type_argument/src/bar/quux.sw rename to test/src/e2e_vm_tests/test_programs/should_pass/language/primitive_type_argument/src/foo/bar/baz/quux.sw index 88853a356ec..f35cb9a00cf 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/primitive_type_argument/src/bar/quux.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/primitive_type_argument/src/foo/bar/baz/quux.sw @@ -1,4 +1,4 @@ -library quux; +library; pub struct Quux { a: A, b: B, diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/primitive_type_argument/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/primitive_type_argument/src/main.sw index 1ff14b77fda..7f036242297 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/primitive_type_argument/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/primitive_type_argument/src/main.sw @@ -1,6 +1,6 @@ script; -dep foo; +mod foo; struct S { } @@ -12,8 +12,8 @@ impl S { fn main() -> u64 { let a = S:: { }; - let b = foo::baz::ExampleStruct:: { a_field: 5u64, b_field: true }; - use foo::baz::ExampleStruct; - let c = foo::baz::quux::Quux::, u64, str[3], u64> { a: 10, b: true, c: b, d: 10, e: "foo", f: 10 }; + let b = foo::bar::baz::ExampleStruct:: { a_field: 5u64, b_field: true }; + use foo::bar::baz::ExampleStruct; + let c = foo::bar::baz::quux::Quux::, u64, str[3], u64> { a: 10, b: true, c: b, d: 10, e: "foo", f: 10 }; return a.f(); } diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/raw_identifiers/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/raw_identifiers/src/main.sw index 9487c0610f1..2d6fb3e2b1d 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/raw_identifiers/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/raw_identifiers/src/main.sw @@ -9,7 +9,7 @@ fn main() -> u64 { let mut r#contract = 0; let mut r#predicate = 0; let mut r#library = 0; - let mut r#dep = 0; + let mut r#mod = 0; let mut r#pub = 0; let mut r#use = 0; let mut r#as = 0; diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/shadowing/shadowed_glob_imports/src/lib.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/shadowing/shadowed_glob_imports/src/lib.sw index aa93603b55c..1b56f4e904f 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/shadowing/shadowed_glob_imports/src/lib.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/shadowing/shadowed_glob_imports/src/lib.sw @@ -1,4 +1,4 @@ -library lib; +library; pub const X1 = 5; pub const X2 = 5; diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/shadowing/shadowed_glob_imports/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/shadowing/shadowed_glob_imports/src/main.sw index c6101f8da6e..06649cbd36a 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/shadowing/shadowed_glob_imports/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/shadowing/shadowed_glob_imports/src/main.sw @@ -1,6 +1,6 @@ script; -dep lib; +mod lib; // Glob import should not result in any shadowing issues use lib::*; diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/test_attribute/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/test_attribute/src/main.sw index e7c0446c125..be9ba3f84e1 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/test_attribute/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/test_attribute/src/main.sw @@ -1,4 +1,4 @@ -library test_attribute; +library; #[test] fn foo() { diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/test_multiple_attributes/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/test_multiple_attributes/src/main.sw index cf4f5a7a8d7..54cba58cf20 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/test_multiple_attributes/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/test_multiple_attributes/src/main.sw @@ -1,4 +1,4 @@ -library test_multiple_attributes; +library; #[test, inline(always)] fn foo() {} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/trait_import_with_star/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/trait_import_with_star/src/main.sw index 190eee956d6..d8c55786745 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/trait_import_with_star/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/trait_import_with_star/src/main.sw @@ -1,5 +1,5 @@ script; -dep shiftable; +mod shiftable; use shiftable::*; fn main() { diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/trait_import_with_star/src/shiftable.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/trait_import_with_star/src/shiftable.sw index bfca0c222e3..85ad01238a5 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/trait_import_with_star/src/shiftable.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/trait_import_with_star/src/shiftable.sw @@ -1,4 +1,4 @@ -library shiftable; +library; pub trait MyShift { fn my_lsh(self, other: Self) -> Self; diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/typeinfo_custom_callpath/src/foo.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/typeinfo_custom_callpath/src/foo.sw index 898bbe8b3f2..f81973cf76e 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/typeinfo_custom_callpath/src/foo.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/typeinfo_custom_callpath/src/foo.sw @@ -1,6 +1,6 @@ -library foo; +library; pub enum Foo { A: (), B: (), -} \ No newline at end of file +} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/typeinfo_custom_callpath/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/typeinfo_custom_callpath/src/main.sw index a00225284fb..0923a3e3718 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/typeinfo_custom_callpath/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/typeinfo_custom_callpath/src/main.sw @@ -1,6 +1,6 @@ script; -dep foo; +mod foo; struct Bar { baz: foo::Foo diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/typeinfo_custom_callpath2/src/foo.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/typeinfo_custom_callpath2/src/foo.sw index 898bbe8b3f2..f81973cf76e 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/typeinfo_custom_callpath2/src/foo.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/typeinfo_custom_callpath2/src/foo.sw @@ -1,6 +1,6 @@ -library foo; +library; pub enum Foo { A: (), B: (), -} \ No newline at end of file +} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/typeinfo_custom_callpath2/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/typeinfo_custom_callpath2/src/main.sw index da4d04e4f00..eb1d0be2717 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/typeinfo_custom_callpath2/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/typeinfo_custom_callpath2/src/main.sw @@ -1,6 +1,6 @@ script; -dep foo; +mod foo; struct Bar { baz: ::foo::Foo diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/typeinfo_custom_callpath_with_import/src/foo.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/typeinfo_custom_callpath_with_import/src/foo.sw index 898bbe8b3f2..f81973cf76e 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/typeinfo_custom_callpath_with_import/src/foo.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/typeinfo_custom_callpath_with_import/src/foo.sw @@ -1,6 +1,6 @@ -library foo; +library; pub enum Foo { A: (), B: (), -} \ No newline at end of file +} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/typeinfo_custom_callpath_with_import/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/typeinfo_custom_callpath_with_import/src/main.sw index e562f1b2155..be7da9f65ac 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/typeinfo_custom_callpath_with_import/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/typeinfo_custom_callpath_with_import/src/main.sw @@ -1,6 +1,6 @@ script; -dep foo; +mod foo; use foo::*; diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/use_full_path_names/src/b_dependency.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/use_full_path_names/src/bar.sw similarity index 68% rename from test/src/e2e_vm_tests/test_programs/should_pass/language/use_full_path_names/src/b_dependency.sw rename to test/src/e2e_vm_tests/test_programs/should_pass/language/use_full_path_names/src/bar.sw index 5153f9c8791..2c3b977a8f2 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/use_full_path_names/src/b_dependency.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/use_full_path_names/src/bar.sw @@ -1,5 +1,5 @@ -library bar; +library; pub enum Bar { Baz: bool, -} \ No newline at end of file +} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/use_full_path_names/src/c_dependency.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/use_full_path_names/src/baz.sw similarity index 75% rename from test/src/e2e_vm_tests/test_programs/should_pass/language/use_full_path_names/src/c_dependency.sw rename to test/src/e2e_vm_tests/test_programs/should_pass/language/use_full_path_names/src/baz.sw index 2f49d96b06b..8590a3d7384 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/use_full_path_names/src/c_dependency.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/use_full_path_names/src/baz.sw @@ -1,4 +1,4 @@ -library baz; +library; pub fn return_1() -> u32 { 1u32 diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/use_full_path_names/src/a_dependency.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/use_full_path_names/src/foo.sw similarity index 72% rename from test/src/e2e_vm_tests/test_programs/should_pass/language/use_full_path_names/src/a_dependency.sw rename to test/src/e2e_vm_tests/test_programs/should_pass/language/use_full_path_names/src/foo.sw index 7baf46e46b4..24b95b021f3 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/use_full_path_names/src/a_dependency.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/use_full_path_names/src/foo.sw @@ -1,4 +1,4 @@ -library foo; +library; pub struct Foo { foo: u32, diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/use_full_path_names/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/use_full_path_names/src/main.sw index 4f3495401b5..df440f62e58 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/use_full_path_names/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/use_full_path_names/src/main.sw @@ -1,8 +1,8 @@ script; -dep a_dependency; -dep b_dependency; -dep c_dependency; +mod foo; +mod bar; +mod baz; fn main() -> u64 { let x = foo::Foo { diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/non_payable_implicit_zero_coins/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/non_payable_implicit_zero_coins/src/main.sw index 71e9f12ebf3..751f474038d 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/non_payable_implicit_zero_coins/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/non_payable_implicit_zero_coins/src/main.sw @@ -1,6 +1,6 @@ script; -dep wallet_abi; +mod wallet_abi; use std::constants::ZERO_B256; use wallet_abi::Wallet; diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/non_payable_implicit_zero_coins/src/wallet.sw b/test/src/e2e_vm_tests/test_programs/should_pass/non_payable_implicit_zero_coins/src/wallet.sw index e80a7914aaf..af8a50904a8 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/non_payable_implicit_zero_coins/src/wallet.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/non_payable_implicit_zero_coins/src/wallet.sw @@ -1,6 +1,6 @@ contract; -dep wallet_abi; +mod wallet_abi; use std::{ auth::{ diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/non_payable_implicit_zero_coins/src/wallet_abi.sw b/test/src/e2e_vm_tests/test_programs/should_pass/non_payable_implicit_zero_coins/src/wallet_abi.sw index 971ec3387c9..05c08c3f2ec 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/non_payable_implicit_zero_coins/src/wallet_abi.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/non_payable_implicit_zero_coins/src/wallet_abi.sw @@ -1,4 +1,4 @@ -library wallet_abi; +library; abi Wallet { #[payable, storage(read, write)] diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/non_payable_zero_coins_let_binding/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/non_payable_zero_coins_let_binding/src/main.sw index ebcd30520e4..d200b4101ce 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/non_payable_zero_coins_let_binding/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/non_payable_zero_coins_let_binding/src/main.sw @@ -1,6 +1,6 @@ script; -dep wallet_abi; +mod wallet_abi; use std::constants::ZERO_B256; use wallet_abi::Wallet; diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/non_payable_zero_coins_let_binding/src/wallet.sw b/test/src/e2e_vm_tests/test_programs/should_pass/non_payable_zero_coins_let_binding/src/wallet.sw index e80a7914aaf..af8a50904a8 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/non_payable_zero_coins_let_binding/src/wallet.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/non_payable_zero_coins_let_binding/src/wallet.sw @@ -1,6 +1,6 @@ contract; -dep wallet_abi; +mod wallet_abi; use std::{ auth::{ diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/non_payable_zero_coins_let_binding/src/wallet_abi.sw b/test/src/e2e_vm_tests/test_programs/should_pass/non_payable_zero_coins_let_binding/src/wallet_abi.sw index 971ec3387c9..05c08c3f2ec 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/non_payable_zero_coins_let_binding/src/wallet_abi.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/non_payable_zero_coins_let_binding/src/wallet_abi.sw @@ -1,4 +1,4 @@ -library wallet_abi; +library; abi Wallet { #[payable, storage(read, write)] diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/payable_non_zero_coins/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/payable_non_zero_coins/src/main.sw index e7f24c8e430..c9b252d8626 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/payable_non_zero_coins/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/payable_non_zero_coins/src/main.sw @@ -1,6 +1,6 @@ script; -dep wallet_abi; +mod wallet_abi; use std::constants::ZERO_B256; use wallet_abi::Wallet; diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/payable_non_zero_coins/src/wallet.sw b/test/src/e2e_vm_tests/test_programs/should_pass/payable_non_zero_coins/src/wallet.sw index e80a7914aaf..af8a50904a8 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/payable_non_zero_coins/src/wallet.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/payable_non_zero_coins/src/wallet.sw @@ -1,6 +1,6 @@ contract; -dep wallet_abi; +mod wallet_abi; use std::{ auth::{ diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/payable_non_zero_coins/src/wallet_abi.sw b/test/src/e2e_vm_tests/test_programs/should_pass/payable_non_zero_coins/src/wallet_abi.sw index 971ec3387c9..05c08c3f2ec 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/payable_non_zero_coins/src/wallet_abi.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/payable_non_zero_coins/src/wallet_abi.sw @@ -1,4 +1,4 @@ -library wallet_abi; +library; abi Wallet { #[payable, storage(read, write)] diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/stdlib/chess/src/huge_enum.sw b/test/src/e2e_vm_tests/test_programs/should_pass/stdlib/chess/src/huge_enum.sw index 688f02b7399..a3a5dcd3af9 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/stdlib/chess/src/huge_enum.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/stdlib/chess/src/huge_enum.sw @@ -1,4 +1,4 @@ -library huge_enum; +library; pub enum Huge { a1: (), diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/stdlib/chess/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/stdlib/chess/src/main.sw index 392a6d4d789..8ccec999ed4 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/stdlib/chess/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/stdlib/chess/src/main.sw @@ -1,6 +1,6 @@ script; -dep huge_enum; +mod huge_enum; use huge_enum::*; diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/stdlib/option/src/data_structures.sw b/test/src/e2e_vm_tests/test_programs/should_pass/stdlib/option/src/data_structures.sw index e482be93f5a..0ef7e7e3346 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/stdlib/option/src/data_structures.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/stdlib/option/src/data_structures.sw @@ -1,4 +1,4 @@ -library data_structures; +library; use core::ops::*; use std::hash::sha256; diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/stdlib/option/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/stdlib/option/src/main.sw index 7c5145b3b7a..f37ed2f5bff 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/stdlib/option/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/stdlib/option/src/main.sw @@ -1,7 +1,7 @@ script; -dep data_structures; -dep tests; +mod data_structures; +mod tests; use tests::*; diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/stdlib/option/src/tests.sw b/test/src/e2e_vm_tests/test_programs/should_pass/stdlib/option/src/tests.sw index 14621129a01..5ee81bf5fec 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/stdlib/option/src/tests.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/stdlib/option/src/tests.sw @@ -1,9 +1,7 @@ -library tests; - -dep data_structures; +library; use core::ops::*; -use data_structures::*; +use ::data_structures::*; use std::hash::sha256; /* Currently need to occasionally use `sha256` to compare generic types because diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/stdlib/result/src/data_structures.sw b/test/src/e2e_vm_tests/test_programs/should_pass/stdlib/result/src/data_structures.sw index 478d3649c22..4ec9314422c 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/stdlib/result/src/data_structures.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/stdlib/result/src/data_structures.sw @@ -1,4 +1,4 @@ -library data_structures; +library; use core::ops::*; use std::hash::sha256; diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/stdlib/result/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/stdlib/result/src/main.sw index 7c5145b3b7a..f37ed2f5bff 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/stdlib/result/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/stdlib/result/src/main.sw @@ -1,7 +1,7 @@ script; -dep data_structures; -dep tests; +mod data_structures; +mod tests; use tests::*; diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/stdlib/result/src/tests.sw b/test/src/e2e_vm_tests/test_programs/should_pass/stdlib/result/src/tests.sw index 0047935d40a..95ffac21cab 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/stdlib/result/src/tests.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/stdlib/result/src/tests.sw @@ -1,8 +1,6 @@ -library tests; +library; -dep data_structures; - -use data_structures::*; +use ::data_structures::*; use core::ops::*; ///////////////////////////////////////////////////////////////////////////// @@ -126,4 +124,4 @@ pub fn test_string() { test_unwrap(s); test_unwrap_or_ok(s, "sway"); test_unwrap_or_err(s, "sway"); -} \ No newline at end of file +} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/supertraits_for_abis_ownable/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/supertraits_for_abis_ownable/src/main.sw index e887c91e2ed..42a3b66f2c4 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/supertraits_for_abis_ownable/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/supertraits_for_abis_ownable/src/main.sw @@ -1,6 +1,6 @@ contract; -dep ownable; +mod ownable; use ownable::{Ownable, StorageHelpers}; storage { diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/supertraits_for_abis_ownable/src/ownable.sw b/test/src/e2e_vm_tests/test_programs/should_pass/supertraits_for_abis_ownable/src/ownable.sw index 63607d3acce..11ed2ed711c 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/supertraits_for_abis_ownable/src/ownable.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/supertraits_for_abis_ownable/src/ownable.sw @@ -1,4 +1,4 @@ -library ownable; +library; pub struct OwnershipTransferred { previous_owner: b256, diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/test_abis/abi_with_tuples/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/test_abis/abi_with_tuples/src/main.sw index 7b50ec85345..c271b206470 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/test_abis/abi_with_tuples/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/test_abis/abi_with_tuples/src/main.sw @@ -1,4 +1,4 @@ -library abi_with_tuples; +library; pub struct Person { age: u64 @@ -12,4 +12,4 @@ pub enum Location { abi MyContract { fn bug1(param: (Person, u64)) -> bool; fn bug2(param: (Location, u64)) -> bool; -} \ No newline at end of file +} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/test_abis/array_of_structs_abi/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/test_abis/array_of_structs_abi/src/main.sw index fb831a73069..c3d2d2ae2dc 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/test_abis/array_of_structs_abi/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/test_abis/array_of_structs_abi/src/main.sw @@ -1,4 +1,4 @@ -library array_of_structs_abi; +library; pub struct Id { number: u64, diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/test_abis/auth_testing_abi/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/test_abis/auth_testing_abi/src/main.sw index 71be53ab38c..c42e905ee8f 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/test_abis/auth_testing_abi/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/test_abis/auth_testing_abi/src/main.sw @@ -1,4 +1,4 @@ -library auth_testing_abi; +library; abi AuthTesting { fn returns_gm_one() -> bool; diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/test_abis/balance_test_abi/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/test_abis/balance_test_abi/src/main.sw index 82b35796de0..216e93f67a2 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/test_abis/balance_test_abi/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/test_abis/balance_test_abi/src/main.sw @@ -1,4 +1,4 @@ -library balance_test_abi; +library; abi BalanceTest { fn get_42() -> u64; diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/test_abis/basic_storage_abi/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/test_abis/basic_storage_abi/src/main.sw index 0db10c5144b..e8ad321c2ac 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/test_abis/basic_storage_abi/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/test_abis/basic_storage_abi/src/main.sw @@ -1,4 +1,4 @@ -library basic_storage_abi; +library; pub struct Quad { v1: u64, diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/test_abis/context_testing_abi/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/test_abis/context_testing_abi/src/main.sw index b487745047f..4af281bfc8c 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/test_abis/context_testing_abi/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/test_abis/context_testing_abi/src/main.sw @@ -1,4 +1,4 @@ -library context_testing_abi; +library; abi ContextTesting { fn get_id() -> ContractId; diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/test_abis/get_storage_key_abi/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/test_abis/get_storage_key_abi/src/main.sw index c9ad46d89fe..ae82b5c54c5 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/test_abis/get_storage_key_abi/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/test_abis/get_storage_key_abi/src/main.sw @@ -1,4 +1,4 @@ -library get_storage_key_abi; +library; abi TestContract { fn from_f1() -> b256; diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/test_abis/increment_abi/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/test_abis/increment_abi/src/main.sw index 5dd83176be8..ce47906cac3 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/test_abis/increment_abi/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/test_abis/increment_abi/src/main.sw @@ -1,4 +1,4 @@ -library increment_abi; +library; abi Incrementor { #[storage(read, write)] diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/test_abis/nested_struct_args_abi/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/test_abis/nested_struct_args_abi/src/main.sw index cf8239a68e6..47189e115fa 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/test_abis/nested_struct_args_abi/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/test_abis/nested_struct_args_abi/src/main.sw @@ -1,4 +1,4 @@ -library nested_struct_args; +library; pub struct Inner { foo: u64 diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/test_abis/storage_access_abi/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/test_abis/storage_access_abi/src/main.sw index 5fae960988d..622028bc382 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/test_abis/storage_access_abi/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/test_abis/storage_access_abi/src/main.sw @@ -1,4 +1,4 @@ -library storage_access_abi; +library; pub struct S { x: u64, diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/test_abis/test_fuel_coin_abi/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/test_abis/test_fuel_coin_abi/src/main.sw index b5ba8fd14ec..7d94ed97ca9 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/test_abis/test_fuel_coin_abi/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/test_abis/test_fuel_coin_abi/src/main.sw @@ -1,4 +1,4 @@ -library test_fuel_coin_abi; +library; abi TestFuelCoin { fn mint(mint_amount: u64); diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/abi_with_same_name_types/src/folder1/dep_1.sw b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/abi_with_same_name_types/src/dep_1.sw similarity index 86% rename from test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/abi_with_same_name_types/src/folder1/dep_1.sw rename to test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/abi_with_same_name_types/src/dep_1.sw index 9d540aa8e34..84454c82c9a 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/abi_with_same_name_types/src/folder1/dep_1.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/abi_with_same_name_types/src/dep_1.sw @@ -1,4 +1,4 @@ -library dep_1; +library; pub struct MyStruct1 { bam: MyStructDuplicated, @@ -6,4 +6,4 @@ pub struct MyStruct1 { pub struct MyStructDuplicated { bam: u64, -} \ No newline at end of file +} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/abi_with_same_name_types/src/folder2/dep_2.sw b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/abi_with_same_name_types/src/dep_2.sw similarity index 86% rename from test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/abi_with_same_name_types/src/folder2/dep_2.sw rename to test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/abi_with_same_name_types/src/dep_2.sw index 7144c3c3cb4..5df27737c96 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/abi_with_same_name_types/src/folder2/dep_2.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/abi_with_same_name_types/src/dep_2.sw @@ -1,4 +1,4 @@ -library dep_2; +library; pub struct MyStruct2 { bam: MyStructDuplicated, @@ -6,4 +6,4 @@ pub struct MyStruct2 { pub struct MyStructDuplicated { bam: u64, -} \ No newline at end of file +} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/abi_with_same_name_types/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/abi_with_same_name_types/src/main.sw index a8c8a05f569..5a139749fb5 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/abi_with_same_name_types/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/abi_with_same_name_types/src/main.sw @@ -1,7 +1,7 @@ contract; -dep folder1/dep_1; -dep folder2/dep_2; +mod dep_1; +mod dep_2; use dep_1::*; use dep_2::*; diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/multiple_impl/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/multiple_impl/src/main.sw index a120207962a..040a5130417 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/multiple_impl/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/multiple_impl/src/main.sw @@ -1,7 +1,7 @@ contract; -dep testlib; -dep testlib2; +mod testlib; +mod testlib2; use testlib2::bar; abi TestContr { diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/multiple_impl/src/testlib.sw b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/multiple_impl/src/testlib.sw index 69d3484b7b5..2d5e1184375 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/multiple_impl/src/testlib.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/multiple_impl/src/testlib.sw @@ -1,4 +1,4 @@ -library testlib; +library; pub fn foo() { log(1); diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/multiple_impl/src/testlib2.sw b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/multiple_impl/src/testlib2.sw index 2b253cf415c..c80101627f9 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/multiple_impl/src/testlib2.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/multiple_impl/src/testlib2.sw @@ -1,4 +1,4 @@ -library testlib2; +library; pub fn bar() { log(2); diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/return_struct/json_abi_oracle.json b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/return_struct/json_abi_oracle.json index 1b90353e04c..a98c9efc1e5 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/return_struct/json_abi_oracle.json +++ b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/return_struct/json_abi_oracle.json @@ -61,7 +61,7 @@ }, { "components": [], - "type": "struct interface::data_structures::MyStruct", + "type": "struct data_structures::MyStruct", "typeId": 3, "typeParameters": null } diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/return_struct/src/data_structures.sw b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/return_struct/src/data_structures.sw index 0b1c91ebd5f..463358ac4e9 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/return_struct/src/data_structures.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/return_struct/src/data_structures.sw @@ -1,3 +1,3 @@ -library data_structures; +library; -pub struct MyStruct {} \ No newline at end of file +pub struct MyStruct {} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/return_struct/src/interface.sw b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/return_struct/src/interface.sw index 718ecc64a3d..41b7aa2bc2c 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/return_struct/src/interface.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/return_struct/src/interface.sw @@ -1,10 +1,8 @@ -library interface; +library; -dep data_structures; - -use data_structures::MyStruct; +use ::data_structures::MyStruct; abi MyContract { #[storage(read)] fn test_function() -> Option; -} \ No newline at end of file +} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/return_struct/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/return_struct/src/main.sw index ccabc426772..aad1b5f3895 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/return_struct/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/return_struct/src/main.sw @@ -1,7 +1,7 @@ contract; -dep interface; -dep data_structures; +mod data_structures; +mod interface; use interface::MyContract; use data_structures::MyStruct; @@ -15,4 +15,4 @@ impl MyContract for Contract { fn test_function() -> Option { storage.a.get(1) } -} \ No newline at end of file +} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/unit_tests/contract_with_nested_libs/src/inner.sw b/test/src/e2e_vm_tests/test_programs/should_pass/unit_tests/contract_with_nested_libs/src/inner.sw index 14be93d7dab..b0e33f4e364 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/unit_tests/contract_with_nested_libs/src/inner.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/unit_tests/contract_with_nested_libs/src/inner.sw @@ -1,6 +1,6 @@ -library inner; +library; -dep inner2; +mod inner2; #[test] fn test_meaning_of_life_inner() { diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/unit_tests/contract_with_nested_libs/src/inner2.sw b/test/src/e2e_vm_tests/test_programs/should_pass/unit_tests/contract_with_nested_libs/src/inner/inner2.sw similarity index 90% rename from test/src/e2e_vm_tests/test_programs/should_pass/unit_tests/contract_with_nested_libs/src/inner2.sw rename to test/src/e2e_vm_tests/test_programs/should_pass/unit_tests/contract_with_nested_libs/src/inner/inner2.sw index 3c169b02a9d..41fe7a1c6f9 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/unit_tests/contract_with_nested_libs/src/inner2.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/unit_tests/contract_with_nested_libs/src/inner/inner2.sw @@ -1,4 +1,4 @@ -library inner2; +library; #[test] fn test_meaning_of_life_inner2() { diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/unit_tests/contract_with_nested_libs/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/unit_tests/contract_with_nested_libs/src/main.sw index 257e2d11ded..940ff56d7c7 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/unit_tests/contract_with_nested_libs/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/unit_tests/contract_with_nested_libs/src/main.sw @@ -1,6 +1,6 @@ contract; -dep inner; +mod inner; abi MyContract { fn foo(); diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/unit_tests/lib_multi_test/src/lib.sw b/test/src/e2e_vm_tests/test_programs/should_pass/unit_tests/lib_multi_test/src/lib.sw index 89ad7a46eb2..c98a47706d2 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/unit_tests/lib_multi_test/src/lib.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/unit_tests/lib_multi_test/src/lib.sw @@ -1,4 +1,4 @@ -library lib_multi_test; +library; fn pow2(x: u64) -> u64 { log(x); diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/unit_tests/lib_single_test/src/lib.sw b/test/src/e2e_vm_tests/test_programs/should_pass/unit_tests/lib_single_test/src/lib.sw index 0dec6dc85aa..ce539994bde 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/unit_tests/lib_single_test/src/lib.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/unit_tests/lib_single_test/src/lib.sw @@ -1,4 +1,4 @@ -library single_lib_test; +library; #[test] fn test_meaning_of_life() { diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/unit_tests/nested_libs/src/inner.sw b/test/src/e2e_vm_tests/test_programs/should_pass/unit_tests/nested_libs/src/inner.sw index 14be93d7dab..b0e33f4e364 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/unit_tests/nested_libs/src/inner.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/unit_tests/nested_libs/src/inner.sw @@ -1,6 +1,6 @@ -library inner; +library; -dep inner2; +mod inner2; #[test] fn test_meaning_of_life_inner() { diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/unit_tests/nested_libs/src/inner2.sw b/test/src/e2e_vm_tests/test_programs/should_pass/unit_tests/nested_libs/src/inner/inner2.sw similarity index 90% rename from test/src/e2e_vm_tests/test_programs/should_pass/unit_tests/nested_libs/src/inner2.sw rename to test/src/e2e_vm_tests/test_programs/should_pass/unit_tests/nested_libs/src/inner/inner2.sw index 3c169b02a9d..41fe7a1c6f9 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/unit_tests/nested_libs/src/inner2.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/unit_tests/nested_libs/src/inner/inner2.sw @@ -1,4 +1,4 @@ -library inner2; +library; #[test] fn test_meaning_of_life_inner2() { diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/unit_tests/nested_libs/src/lib.sw b/test/src/e2e_vm_tests/test_programs/should_pass/unit_tests/nested_libs/src/lib.sw index d571190a4b6..dc26465accf 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/unit_tests/nested_libs/src/lib.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/unit_tests/nested_libs/src/lib.sw @@ -1,6 +1,6 @@ -library lib; +library; -dep inner; +mod inner; #[test] fn test_meaning_of_life() { diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/unit_tests/predicate_with_nested_libs/src/inner.sw b/test/src/e2e_vm_tests/test_programs/should_pass/unit_tests/predicate_with_nested_libs/src/inner.sw index 9dfa0ac15ce..7c80968a8c9 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/unit_tests/predicate_with_nested_libs/src/inner.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/unit_tests/predicate_with_nested_libs/src/inner.sw @@ -1,6 +1,6 @@ -library inner; +library; -dep inner2; +mod inner2; #[test] fn test_meaning_of_life_inner() { diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/unit_tests/predicate_with_nested_libs/src/inner2.sw b/test/src/e2e_vm_tests/test_programs/should_pass/unit_tests/predicate_with_nested_libs/src/inner/inner2.sw similarity index 85% rename from test/src/e2e_vm_tests/test_programs/should_pass/unit_tests/predicate_with_nested_libs/src/inner2.sw rename to test/src/e2e_vm_tests/test_programs/should_pass/unit_tests/predicate_with_nested_libs/src/inner/inner2.sw index fee105243b0..421f617f6f8 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/unit_tests/predicate_with_nested_libs/src/inner2.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/unit_tests/predicate_with_nested_libs/src/inner/inner2.sw @@ -1,4 +1,4 @@ -library inner2; +library; #[test] fn test_meaning_of_life_inner2() { diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/unit_tests/predicate_with_nested_libs/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/unit_tests/predicate_with_nested_libs/src/main.sw index 8015811190c..90029a4400c 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/unit_tests/predicate_with_nested_libs/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/unit_tests/predicate_with_nested_libs/src/main.sw @@ -1,6 +1,6 @@ script; -dep inner; +mod inner; fn main() -> bool { true } diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/unit_tests/script_with_nested_libs/src/inner.sw b/test/src/e2e_vm_tests/test_programs/should_pass/unit_tests/script_with_nested_libs/src/inner.sw index 14be93d7dab..b0e33f4e364 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/unit_tests/script_with_nested_libs/src/inner.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/unit_tests/script_with_nested_libs/src/inner.sw @@ -1,6 +1,6 @@ -library inner; +library; -dep inner2; +mod inner2; #[test] fn test_meaning_of_life_inner() { diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/unit_tests/script_with_nested_libs/src/inner2.sw b/test/src/e2e_vm_tests/test_programs/should_pass/unit_tests/script_with_nested_libs/src/inner/inner2.sw similarity index 90% rename from test/src/e2e_vm_tests/test_programs/should_pass/unit_tests/script_with_nested_libs/src/inner2.sw rename to test/src/e2e_vm_tests/test_programs/should_pass/unit_tests/script_with_nested_libs/src/inner/inner2.sw index 3c169b02a9d..41fe7a1c6f9 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/unit_tests/script_with_nested_libs/src/inner2.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/unit_tests/script_with_nested_libs/src/inner/inner2.sw @@ -1,4 +1,4 @@ -library inner2; +library; #[test] fn test_meaning_of_life_inner2() { diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/unit_tests/script_with_nested_libs/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/unit_tests/script_with_nested_libs/src/main.sw index 4d3e3c6e4b2..2b54ab2ffe1 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/unit_tests/script_with_nested_libs/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/unit_tests/script_with_nested_libs/src/main.sw @@ -1,6 +1,6 @@ script; -dep inner; +mod inner; fn main() { } diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/unit_tests/should_revert/src/lib.sw b/test/src/e2e_vm_tests/test_programs/should_pass/unit_tests/should_revert/src/lib.sw index 38cbc05758f..2c0b59959a0 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/unit_tests/should_revert/src/lib.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/unit_tests/should_revert/src/lib.sw @@ -1,4 +1,4 @@ -library should_revert; +library; #[test(should_revert)] fn should_revert_test() { diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/unit_tests/workspace_test/lib_multi_test/src/lib.sw b/test/src/e2e_vm_tests/test_programs/should_pass/unit_tests/workspace_test/lib_multi_test/src/lib.sw index 89ad7a46eb2..c98a47706d2 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/unit_tests/workspace_test/lib_multi_test/src/lib.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/unit_tests/workspace_test/lib_multi_test/src/lib.sw @@ -1,4 +1,4 @@ -library lib_multi_test; +library; fn pow2(x: u64) -> u64 { log(x); diff --git a/test/src/ir_generation/mod.rs b/test/src/ir_generation/mod.rs index 0d8dfcc1656..1e1a36315f7 100644 --- a/test/src/ir_generation/mod.rs +++ b/test/src/ir_generation/mod.rs @@ -130,6 +130,7 @@ pub(super) async fn run(filter_regex: Option<®ex::Regex>) -> Result<()> { Arc::from(sway_str), core_lib.clone(), Some(&bld_cfg), + "test_lib", ); if !typed_res.errors.is_empty() { panic!( diff --git a/test/src/sdk-harness/test_artifacts/auth_testing_abi/src/main.sw b/test/src/sdk-harness/test_artifacts/auth_testing_abi/src/main.sw index 9c131869079..0ca68b3657a 100644 --- a/test/src/sdk-harness/test_artifacts/auth_testing_abi/src/main.sw +++ b/test/src/sdk-harness/test_artifacts/auth_testing_abi/src/main.sw @@ -1,4 +1,4 @@ -library auth_testing_abi; +library; use std::auth::*; diff --git a/test/src/sdk-harness/test_artifacts/block_test_abi/src/main.sw b/test/src/sdk-harness/test_artifacts/block_test_abi/src/main.sw index 8c5b7ece30d..f34f26cec34 100644 --- a/test/src/sdk-harness/test_artifacts/block_test_abi/src/main.sw +++ b/test/src/sdk-harness/test_artifacts/block_test_abi/src/main.sw @@ -1,4 +1,4 @@ -library block_test_abi; +library; abi BlockTest { fn get_block_height() -> u64; diff --git a/test/src/sdk-harness/test_artifacts/call_frames_test_abi/src/main.sw b/test/src/sdk-harness/test_artifacts/call_frames_test_abi/src/main.sw index b1a50654bed..b18c33600f9 100644 --- a/test/src/sdk-harness/test_artifacts/call_frames_test_abi/src/main.sw +++ b/test/src/sdk-harness/test_artifacts/call_frames_test_abi/src/main.sw @@ -1,4 +1,4 @@ -library call_frames_test_abi; +library; pub struct TestStruct { value0: u64, diff --git a/test/src/sdk-harness/test_artifacts/context_testing_abi/src/main.sw b/test/src/sdk-harness/test_artifacts/context_testing_abi/src/main.sw index cac088bb933..74e28b87f01 100644 --- a/test/src/sdk-harness/test_artifacts/context_testing_abi/src/main.sw +++ b/test/src/sdk-harness/test_artifacts/context_testing_abi/src/main.sw @@ -1,4 +1,4 @@ -library context_testing_abi; +library; abi ContextTesting { #[payable] diff --git a/test/src/sdk-harness/test_artifacts/evm_test_abi/src/main.sw b/test/src/sdk-harness/test_artifacts/evm_test_abi/src/main.sw index 8470edc2679..3222be8e6de 100644 --- a/test/src/sdk-harness/test_artifacts/evm_test_abi/src/main.sw +++ b/test/src/sdk-harness/test_artifacts/evm_test_abi/src/main.sw @@ -1,4 +1,4 @@ -library evm_test_abi; +library; use std::vm::evm::evm_address::EvmAddress; diff --git a/test/src/sdk-harness/test_artifacts/methods_abi/src/main.sw b/test/src/sdk-harness/test_artifacts/methods_abi/src/main.sw index 288efc7153f..54339b24e4b 100644 --- a/test/src/sdk-harness/test_artifacts/methods_abi/src/main.sw +++ b/test/src/sdk-harness/test_artifacts/methods_abi/src/main.sw @@ -1,4 +1,4 @@ -library methods_abi; +library; abi MethodsContract { #[storage(read, write)] diff --git a/test/src/sdk-harness/test_artifacts/parsing_logs_test_abi/src/main.sw b/test/src/sdk-harness/test_artifacts/parsing_logs_test_abi/src/main.sw index 87f30b4fff4..0544fcf6dfc 100644 --- a/test/src/sdk-harness/test_artifacts/parsing_logs_test_abi/src/main.sw +++ b/test/src/sdk-harness/test_artifacts/parsing_logs_test_abi/src/main.sw @@ -1,4 +1,4 @@ -library parsing_logs; +library; abi TestContract { fn produce_logs_values() -> ();