Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace Path with CallPath in module.rs #4700

Open
esdrubal opened this issue Jun 22, 2023 · 0 comments
Open

Replace Path with CallPath in module.rs #4700

esdrubal opened this issue Jun 22, 2023 · 0 comments
Labels
code quality compiler: frontend Everything to do with type checking, control flow analysis, and everything between parsing and IRgen

Comments

@esdrubal
Copy link
Contributor

Methods star_import, star_import_with_reexports, self_import, variant_import, variant_star_import can be changed to receive CallPath instead of Path.

pub(crate) fn star_import(
&mut self,
src: &Path,
dst: &Path,
engines: &Engines,
) -> CompileResult<()> {

The added CallPath should also bundle the is_absolute added by #4697.
Also consider changing use_synonyms to use a CallPath.

@esdrubal esdrubal added code quality compiler: frontend Everything to do with type checking, control flow analysis, and everything between parsing and IRgen labels Jun 22, 2023
IGI-111 pushed a commit that referenced this issue Jun 11, 2024
…Decode (#6044)

## Description

Fixes #5500 . Also fixes the issue that caused one of @xunilrj 's tests
to fail.

The callpaths generated for struct declarations have so far been
incorrect. The `shadowed_glob_imports` test case shows how this causes a
compilation error when there is a name clash between a star imported
struct and a locally declared struct. This causes a number of issues, in
particular that the generated trait impls of `AbiEncode` and `AbiDecode`
can refer to the wrong type or to a type that doesn't exist.

The incorrect paths were the result of a combination of two bugs:
1. The `is_external` flag on the containing modules was often set
incorrectly. In particular, `core` often had `is_external = false`,
leading to the package name being added to the path of anything declared
in `core`.
2. When typechecking a struct/enum declaration we would look up paths in
the current environment before the name of the struct/enum was bound in
the environment. If a type with the same name had already been imported
this lookup would result in a path to the import source module rather
than the path to current module (which is obviously where the
struct/enum is located).

This PR fixes both bugs:
1. When initializing the root namespace we now ensure that all modules
that have already been added are marked with `is_external = true`. This
happens in `Namespace::init_root()`.
2. When typechecking a type declaration we generate the callpath
directly from the name of the type and the path of the current module.
This happens in `CallPath::ident_to_fullpath()`.

Step 1 unfortunately adds an extra cloning step in the `namespace`
module, but I don't think it's avoidable at the moment. To avoid this
extra cloning step we would need to have a better way of building the
external module structure than we currently have. #5498 tracks this and
other issues.

The improved callpath generation should move us a step closer towards
fixing #4700.

## 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] If my change requires substantial documentation changes, I have
[requested support from the DevRel
team](https://github.com/FuelLabs/devrel-requests/issues/new/choose)
- [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.

---------

Co-authored-by: Igor Rončević <ironcev@hotmail.com>
Co-authored-by: João Matos <joao@tritao.eu>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code quality compiler: frontend Everything to do with type checking, control flow analysis, and everything between parsing and IRgen
Projects
None yet
Development

No branches or pull requests

1 participant