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

Improve duplicate imports #1196

Merged
merged 4 commits into from
May 11, 2024
Merged

Conversation

johnynek
Copy link
Owner

I noticed if I made a duplicate import that does not exist to a name that collides with a predef name, the error message is bad.

I should add a test exercising this error message to be sure. There were two things:

  1. we didn't see both imports, just one.
  2. the predef import said "unknown source" which means that we need to handle predef separately in error messages.

@@ -25,11 +25,11 @@ object NameKind {

def externals[T](from: Package.Typed[T]): Iterable[ExternalDef[T]] = {
val prog = from.program
prog.externalDefs.to(LazyList).map { n =>
prog._1.externalDefs.to(LazyList).map { n =>
Copy link
Owner Author

Choose a reason for hiding this comment

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

Use the implicit class methods in this file

@@ -39,12 +39,6 @@ final case class Package[A, B, C, +D](
case _ => false
}

// TODO, this isn't great
Copy link
Owner Author

Choose a reason for hiding this comment

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

This was fixed

@@ -155,7 +154,7 @@ object Package {
inferred.mapProgram(_ => ()).replaceImports(Nil)

def setProgramFrom[A, B](t: Typed[A], newFrom: B): Typed[A] =
Copy link
Owner Author

Choose a reason for hiding this comment

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

Remove this and just inline it in the one place it is used.

@@ -468,7 +467,7 @@ object Package {
val tpes = Doc.text("types: ") + Doc
.intercalate(
Doc.comma + Doc.line,
pack.program.types.definedTypes.toList.map { case (_, t) =>
pack.program._1.types.definedTypes.toList.map { case (_, t) =>
Copy link
Owner Author

Choose a reason for hiding this comment

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

Use implicit class

def externalDefs: List[Identifier.Bindable] =
pack.program._1.externalDefs

def localImport(n: Identifier): Option[(Package.Interface, ImportedName[NonEmptyList[Referant[Kind.Arg]]])] =
Copy link
Owner Author

Choose a reason for hiding this comment

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

Indentation

val candidates =
nearest(iname.originalName, exportMap, 3)
.map(ident => Doc.text(ident._1.sourceCodeRepr))

val near = Doc.text(" Nearest: ") +
Copy link
Owner Author

Choose a reason for hiding this comment

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

Check that candidates is nonEmpty

@@ -313,9 +321,24 @@ object PackageMap {
Memoize.memoizeDagFuture[ResolvedU, Ior[NonEmptyList[
PackageError
], (TypeEnv[Kind.Arg], Package.Inferred)]] {
// TODO, we ignore importMap here, we only check earlier we don't
Copy link
Owner Author

Choose a reason for hiding this comment

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

Fixed this TODO


def resolvedImports: ImportMap[Package.Resolved, Unit] =
imps.traverse[cats.Id, Package.Resolved, Unit] { (p, i) =>
(nameToRes(p), i)
Copy link
Owner Author

Choose a reason for hiding this comment

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

This apply should be safe since we have constructed this ImportMap from the same source.

Add a comment with this explanation

val inferImports: FutVal[List[ImpRes]] =
imports.parTraverse(stepImport(_))
val inferImports: FutVal[ImportMap[Package.Interface, NonEmptyList[Referant[Kind.Arg]]]] =
resolvedImports.traverse(stepImport(_, _))
Copy link
Owner Author

Choose a reason for hiding this comment

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

Make sure this is using Parallel Applicative

@johnynek johnynek merged commit 99afa56 into main May 11, 2024
7 checks passed
@johnynek johnynek deleted the oscar/20240410_improve_bad_import_error branch May 11, 2024 23:46
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.

None yet

1 participant