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

Fixed export package-definitions not including cached modules #3669

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

mine-tech-oficial
Copy link

This PR closes #2898

compiler-core/src/build/package_compiler.rs Outdated Show resolved Hide resolved
compiler-core/src/build/package_compiler.rs Outdated Show resolved Hide resolved
compiler-core/src/build/package_compiler.rs Outdated Show resolved Hide resolved
Signed-off-by: Pedro H C Francisco <75535904+MineTechOficial@users.noreply.github.com>
Signed-off-by: Pedro H C Francisco <75535904+MineTechOficial@users.noreply.github.com>
@mine-tech-oficial
Copy link
Author

Do I need to write any tests? I didn't write any, just fixed the snapshots. I guess I could duplicate the already existing tests to take account cached modules.

@lpil lpil marked this pull request as draft October 7, 2024 18:09
@mine-tech-oficial mine-tech-oficial marked this pull request as ready for review October 8, 2024 19:01
compiler-core/src/build.rs Outdated Show resolved Hide resolved
compiler-core/src/build/package_loader.rs Outdated Show resolved Hide resolved
@mine-tech-oficial
Copy link
Author

mine-tech-oficial commented Oct 9, 2024 via email

@lpil
Copy link
Member

lpil commented Oct 9, 2024

Neither of those approaches are what we want.

Does the cache not have enough information to build the module interface JSON from? What's missing?

@mine-tech-oficial
Copy link
Author

mine-tech-oficial commented Oct 9, 2024 via email

@lpil
Copy link
Member

lpil commented Oct 9, 2024

Why does it need to be built from typed AST? What information do they hold that the interface JSON needs that the cache does not have?

@mine-tech-oficial
Copy link
Author

I tried adapting the from_module function of the ModuleInterface struct from the package_interface module to work with UncompiledModules (untyped ASTs) but, as it turns out, it needs the type info.
For example, here's the error cargo gives:

error[E0308]: mismatched types
   --> compiler-core/src/package_interface.rs:615:73
    |
615 | ...                   type_: from_type_helper(&arg.type_, &mut id_map),
    |                              ---------------- ^^^^^^^^^^ expected `&Type`, found `&()`
    |                              |
    |                              arguments to this function are incorrect
    |
    = note: expected reference `&type_::Type`
               found reference `&()`

@lpil lpil marked this pull request as draft October 10, 2024 13:59
@lpil
Copy link
Member

lpil commented Oct 10, 2024

The cache has all the type information for a compiled module, so you can use that.

@GearsDatapacks
Copy link
Member

From when I looked into implementing this, it seems the main limitation is type aliases. Type alias information isn't stored in the cached interface, so that would need to be accessed somehow

@mine-tech-oficial
Copy link
Author

mine-tech-oficial commented Oct 11, 2024 via email

@GearsDatapacks
Copy link
Member

You don't need UncompiledModule. If you add type aliases to it, ModuleInterface should be enough

@mine-tech-oficial
Copy link
Author

mine-tech-oficial commented Oct 12, 2024 via email

@mine-tech-oficial
Copy link
Author

I've been doing this and I've stumbled onto a problem: somehow, when the code will encode the modules to the cache, somehow the documentations have an extra newline? Do I have to somehow fix it or can I leave it like so?

@GearsDatapacks
Copy link
Member

I would say if you can reproduce the bug without your changes, then open a separate issue and let that be fixed separately. If this PR introduces that bug, then please fix it

@mine-tech-oficial
Copy link
Author

I can actually reproduce it separately, will open an issue for it then

@mine-tech-oficial
Copy link
Author

Issue opened at #3712

@mine-tech-oficial
Copy link
Author

Now it reuses as much of the cache as possible, although there is a test failing and I don't know why (need to fix). I'll open for review just to make sure any of the overall logic isn't wrong.

@mine-tech-oficial mine-tech-oficial marked this pull request as ready for review October 18, 2024 20:33
Copy link
Member

@lpil lpil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good so far! Thank you

compiler-core/build.rs Outdated Show resolved Hide resolved
compiler-core/schema.capnp Outdated Show resolved Hide resolved
compiler-core/src/analyse.rs Outdated Show resolved Hide resolved
compiler-core/src/analyse.rs Outdated Show resolved Hide resolved
compiler-core/src/build/package_compiler.rs Outdated Show resolved Hide resolved
compiler-core/src/build/project_compiler.rs Outdated Show resolved Hide resolved
compiler-core/src/build/package_compiler.rs Outdated Show resolved Hide resolved
compiler-core/src/package_interface.rs Outdated Show resolved Hide resolved
compiler-core/src/package_interface.rs Outdated Show resolved Hide resolved
@lpil lpil marked this pull request as draft October 20, 2024 11:05
@mine-tech-oficial
Copy link
Author

Uhm, apparently this kind of broke the LSP, as it isn't considering the type aliases anymore. Guess I'll also need to tweak it

@mine-tech-oficial mine-tech-oficial marked this pull request as ready for review October 21, 2024 23:14
@mine-tech-oficial
Copy link
Author

I think it should be all done now!

Copy link
Member

@lpil lpil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello! Looking good. I've left some questions inline

deprecation: deprecation.clone(),
publicity: *publicity,
// TODO: Find if the type is opaque
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this mean? Is it unfinished?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forgot about this todo 😅. Is there a problem for the code to register the type alias as a non-opaque type, just for type analysis?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not aware of any problems, but I'm not sure what you mean here.

compiler-core/src/build.rs Outdated Show resolved Hide resolved
compiler-core/src/type_.rs Show resolved Hide resolved
compiler-core/src/package_interface.rs Outdated Show resolved Hide resolved
compiler-core/src/build/package_compiler.rs Show resolved Hide resolved
compiler-core/src/build/package_compiler.rs Outdated Show resolved Hide resolved
@lpil lpil marked this pull request as draft October 29, 2024 12:08
@mine-tech-oficial
Copy link
Author

Hey @lpil, left some answers to your questions. Waiting for some answers!

@mine-tech-oficial mine-tech-oficial marked this pull request as ready for review November 15, 2024 13:09
@mine-tech-oficial
Copy link
Author

Hey @lpil, I've been trying to rewrite the type analysis so that it doesn't need to register the type aliases as types just for the analysis, but the analyze_custom_type function returns a TypeConstructor. Is it ok to return the TypeAliasConstructor (in case it's a type alias and not a "normal" type) as a non-opaque TypeConstructor?

@mine-tech-oficial
Copy link
Author

Actually I still need to discover what the parameters of the TypeConstructor would be...

@mine-tech-oficial
Copy link
Author

Hey @lpil, do you think it's ok for me to leave the PR with the odd way of registering type aliases as "normal types" just for the analysis, and removing it later (as I still couldn't find a good way to consider it separately), or do you want me to try and fix it anyway?

@GearsDatapacks
Copy link
Member

Hi @mine-tech-oficial, are you still working on this PR? If not, I'm happy to pick up the work as it would be cool to get this fixed. Thanks!

@mine-tech-oficial
Copy link
Author

@GearsDatapacks, actually for the past few weeks I didn't do much progress due to not having much time, although I was writing some code to get the labels of the parameters

@mine-tech-oficial
Copy link
Author

@lpil, now I think I only need to find the documentation (not sure how though)

@@ -90,6 +90,11 @@ struct RecordAccessor {
label @2 :Text;
}

struct FunctionArgument {
name @0 :Text;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function types don't contain names! Please remove this.

It would also be called a parameter. Things have parameters, and for those parameters they accept arguments.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So you mean that a parameter has a name/label, while an argument doesn't? In that case, I'd reuse the TypeValueConstructorParameter struct?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be fair I wasn't happy with the approach I took 😅 . Tomorrow I'll try tackling this again.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neither has names at the type level, but parameters can have names locally within a definition.

@mine-tech-oficial
Copy link
Author

Hey @lpil, I've left a comment on your answers. Waiting for you to confirm it! (no rush by the way)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

gleam export package-interface produces empty modules object
4 participants