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

Error on unused lets #1163

Merged
merged 5 commits into from Mar 15, 2024
Merged

Error on unused lets #1163

merged 5 commits into from Mar 15, 2024

Conversation

johnynek
Copy link
Owner

@johnynek johnynek commented Mar 6, 2024

No description provided.

@@ -1218,7 +1218,7 @@ final class SourceConverter(

private def anonNameStrings(): Iterator[String] =
rankn.Type.allBinders.iterator
.map(_.name)
.map { bn => "_" + bn.name }
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 is a weird hidden hack: we are making names that are not parseable to make synthetic names.

Probably a better solution is to just make a new Bindable type called Synthetic, that has no Parser, so it is never the result of a parsing rather than backdoor it here.

val exports: Node = Left(pack.exports)
val roots: List[Node] =
(exports ::
pack.program.lets.collect { case (b, _, _) if b.asString.startsWith("_") => Right(b) } :::
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 should really be collecting all synthentic names and ignoring any synthetic name.

This probably should not be a root, just filtered from the errors. synthetic names are used to rewrite:

# top level
(a, b) = foo

into:

_a = foo
a = match _a:
  case (a, _): a
b = match _a:
  case (_, b): b

so, the only case where _a would be unused is for constructs like:

_ = foo(1)

where we intend this idiom to exist only to check that foo(1) type-checks, but can then be removed from runtime.

@codecov-commenter
Copy link

codecov-commenter commented Mar 11, 2024

Codecov Report

Attention: Patch coverage is 94.82759% with 3 lines in your changes are missing coverage. Please review.

Project coverage is 91.52%. Comparing base (04a0e87) to head (fc46ced).
Report is 7 commits behind head on main.

Files Patch % Lines
...c/main/scala/org/bykn/bosatsu/PackageCustoms.scala 90.00% 3 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1163      +/-   ##
==========================================
+ Coverage   91.32%   91.52%   +0.20%     
==========================================
  Files          96       96              
  Lines       11846    12009     +163     
  Branches     2675     2690      +15     
==========================================
+ Hits        10818    10991     +173     
+ Misses       1028     1018      -10     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

private type VSet = Set[(PackageName, Identifier)]
private type VState[X] = State[VSet, X]

private def usedGlobals[A](te: TypedExpr[A]): VState[TypedExpr[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.

This should be moved to TypedExpr.

@@ -59,6 +62,39 @@ object PackageCustoms {
pack.copy(imports = i)
}

private type VSet = Set[(PackageName, Identifier)]
Copy link
Owner Author

Choose a reason for hiding this comment

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

Identifier should be changed to Bindable for unused names.

Copy link
Owner Author

Choose a reason for hiding this comment

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

We don't check that types are used. There should be a similar check for a type that is never used.


NonEmptyList.fromList(unused) match {
case None => Validated.unit
case Some(value) =>
Copy link
Owner Author

Choose a reason for hiding this comment

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

We should add a test to exercise the error message from this.

@@ -1593,6 +1595,12 @@ object SourceConverter {
def addError[A](r: Result[A], err: Error): Result[A] =
parallelIor.<*(r)(failure(err))

def maybeError[A](r: Result[A], opt: Option[Error]): Result[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.

This wasn't used

@@ -3338,7 +3373,7 @@ def foo1(fn) -> Int:
def foo2(fn: List[forall a. a -> a]) -> Int:
fn.foldLeft(0, (x, _) -> x.add(1))

count = foo1(single(id))
count0 = foo1(single(id))
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 is good. We now see that this original count was useless.

@johnynek johnynek merged commit 2e3f354 into main Mar 15, 2024
9 checks passed
@johnynek johnynek deleted the oscar/20240305_error_unused_lets branch March 15, 2024 17:37
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

2 participants