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
Error on unused lets #1163
Conversation
@@ -1218,7 +1218,7 @@ final class SourceConverter( | |||
|
|||
private def anonNameStrings(): Iterator[String] = | |||
rankn.Type.allBinders.iterator | |||
.map(_.name) | |||
.map { bn => "_" + bn.name } |
There was a problem hiding this comment.
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) } ::: |
There was a problem hiding this comment.
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 ReportAttention: Patch coverage is
❗ 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. |
private type VSet = Set[(PackageName, Identifier)] | ||
private type VState[X] = State[VSet, X] | ||
|
||
private def usedGlobals[A](te: TypedExpr[A]): VState[TypedExpr[A]] = |
There was a problem hiding this comment.
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)] |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) => |
There was a problem hiding this comment.
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] = |
There was a problem hiding this comment.
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)) |
There was a problem hiding this comment.
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.
No description provided.