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

Add a compiler pass to analyze non-existing imported symbols #6726

Merged
merged 20 commits into from
May 22, 2023

Conversation

Akirathan
Copy link
Member

@Akirathan Akirathan commented May 17, 2023

Fixes #5936

Pull Request Description

Add diagnosis for unresolved symbols in from ... import sym1, sym2, ... statements.

Important Notes

  • Adds a new compiler pass, ImportSymbolAnalysis, that checks these statements and iterates through the symbols and checks if all the symbols can be resolved.
    • Works with BindingsMap metadata.
  • Add ImportExportTest that creates various modules with various imports/exports and checks their generated BindingMap.

Checklist

Please ensure that the following checklist has been satisfied before submitting the PR:

  • The documentation has been updated, if necessary.
  • Screenshots/screencasts have been attached, if there are any visual changes. For interactive or animated visual changes, a screencast is preferred.
  • All code follows the
    Scala,
    Java,
    and
    Rust
    style guides. In case you are using a language not listed above, follow the Rust style guide.
  • All code has been tested:
    • Unit tests have been written where possible.
    • If GUI codebase was changed, the GUI was tested when built using ./run ide build.

@Akirathan Akirathan marked this pull request as ready for review May 17, 2023 16:51
@Akirathan Akirathan self-assigned this May 17, 2023
@Akirathan Akirathan added the CI: No changelog needed Do not require a changelog entry for this PR. label May 17, 2023
Copy link
Member

@JaroslavTulach JaroslavTulach left a comment

Choose a reason for hiding this comment

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

As far as I can tell this is a bugfix - e.g. something we can integrate without risking stability of the overall system.

* Checks whether the exported symbols and defined entities metadata of the modules
* are correct.
*/
class ImportExportTest
Copy link
Member

Choose a reason for hiding this comment

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

I'd prefer the new tests to be written in Java than Scala, but be it...

Copy link
Member Author

Choose a reason for hiding this comment

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

The reason why I chose Scala instead of Java for this particular test is that in this test, we traverse the IR and its metadata and that is way easier to do in Scala - since all the associated definitions are in Scala. I find IR manipulation in Java very clumsy, not even mentioning that IntelliJ is incapable of proper symbol resolution in such cases.

Copy link
Member Author

Choose a reason for hiding this comment

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

A screenshot of IJ of ErrorCompilerTest.java that directly manipulates with IR:

image

Copy link
Member

Choose a reason for hiding this comment

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

I am always pleased seeing other IDEs having problems understanding Java. I like to point out that NetBeans is WYSIWYG - it understands the source code exactly the same way as javac does unlike the other IDEs.

Copy link
Member

Choose a reason for hiding this comment

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

Regardless of my silly jokes about IDEs, I believe writing such an amount of new Scala code isn't justified.

The test isn't using anything from existing testing infrastructure - e.g. it is not modification of existing Scala code. In such case the general direction is to: move away from Scala.

Copy link
Member Author

Choose a reason for hiding this comment

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

I understand the general policy of moving away from Scala. However, code that accesses IR and checks its metadata is a major pain in the ass to write in Java. Accessing anything from IR.scala in Java is very difficult, and takes longer time to write. Even if we manage somehow to set up IntelliJ to provide proper symbol completion for Scala case objects and other nice Scala stuff from Java, how is one supposed to know that to access a case object one has to access .$MODULE$ field of some IR$Scope$Module$Import$ImportExportResaon$ class?

I am 100% in agreement with moving away from Scala one time. But IMHO as long as we don't migrate IR.scala to Java, it is not worth writing tests that traverse IR in Java. Any other code that does not access IR and its metadata, and just evaluates a module and checks its output (like PrintTest), I will happily code in Java.

Copy link
Collaborator

@hubertp hubertp left a comment

Choose a reason for hiding this comment

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

Much easier to review, thanks.

@@ -621,8 +621,8 @@ def commit_to_str(commit: Commit) -> str:


if __name__ == '__main__':
default_since = datetime.now() - timedelta(days=14)
default_until = datetime.now()
default_since: date = (datetime.now() - timedelta(days=14)).date()
Copy link
Collaborator

Choose a reason for hiding this comment

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

sneaky ;)

Copy link
Member Author

Choose a reason for hiding this comment

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

That is a small fix to make this script usable in my systemd daily job.

} else {
List(imp)
}
case None => List(imp)
Copy link
Collaborator

Choose a reason for hiding this comment

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

So if we don't find the import we return.. the import? Shouldn't that return an error?

Copy link
Member Author

Choose a reason for hiding this comment

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

I am not sure, to be honest. Usually, bindingMap.resolvedImports.find(_.importDef == imp) finds something. The only case when this will return None, is when ImportResolver was not run previously, which might happen, e.g., in a testing environment. What do you think? Should that return an error?

Previously, I had there bindingMap.resolvedImports.find(_.importDef == imp).getOrElse(throw new CompilerError(...), but that failed in the testing environment.

@Akirathan Akirathan added the CI: Keep up to date Automatically update this PR to the latest develop. label May 19, 2023
@Akirathan Akirathan removed the CI: Keep up to date Automatically update this PR to the latest develop. label May 19, 2023
@Akirathan
Copy link
Member Author

Akirathan commented May 19, 2023

There is a huge amount of java.net.SocketException stemming from org.scalatest.tools.SocketReporter.apply - for example in https://github.com/enso-org/enso/actions/runs/5024009492/jobs/9009255245?pr=6726#step:10:5773

Seems like transient issue. Restarting the jobs.

GitHub
Hybrid visual and textual functional programming. Contribute to enso-org/enso development by creating an account on GitHub.

@Akirathan Akirathan merged commit 2b1e5cd into develop May 22, 2023
@Akirathan Akirathan deleted the wip/akirathan/simple-import-from-error-5936 branch May 22, 2023 08:41
Procrat added a commit that referenced this pull request May 23, 2023
* develop:
  Link to new 101 tutorial and not deprecated one. (#6793)
  Add logs section to the bug template (#6798)
  Fix #6521: Main module function calls shouldn't use project namespace (#6719)
  Add project creation time to project metadata (#6780)
  Add a compiler pass to analyze non-existing imported symbols (#6726)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI: No changelog needed Do not require a changelog entry for this PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Importing a nonexistent module/type using from syntax does not yield any errors
4 participants