Skip to content

Conversation

@SolalPirelli
Copy link
Contributor

I was looking through some compiler files to understand what's going on, and noticed some stuff that could be cleaned up.

Some of this is just stuff IntelliJ highlighted, like typos and dead imports.

}

/** Produces a string index, which is a list of `sections`, i.e
/** Produces a string index, which is a list of `sections`, i.e.,
Copy link
Contributor

Choose a reason for hiding this comment

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

💯

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this was one of my PhD advisor's pet peeves, I've been conditioned to fix it 😬


package object tools {

/** Cached single-element list of Nil. (Whether this helps performance has not been tested) */
Copy link
Contributor

Choose a reason for hiding this comment

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

It's not just for performance, but easier to read and write. I miss literalUnit if I have to write Literal(Constant(())).

Also see your other comment that makes a performance claim.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Easier than Nil :: Nil yeah, but compared to List(Nil) ?

val content = source.content()
val (start, end) =
if content.lift(span.end - 1).exists(_ == '`') then
if content.lift(span.end - 1).contains('`') then
Copy link
Contributor

Choose a reason for hiding this comment

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

These are not generally the same because of type-unsafe contains. I might get a compiler warning on ==.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, I misread the direction of that generic constraint... is there a reason why contains does this? (I know Java has a lot of this kind of behavior)


import core.Types.WildcardType

/** Common values hoisted out for performance */
Copy link
Contributor

Choose a reason for hiding this comment

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

I see the performance claim was here.

val e = if msg == null then AssertionError() else AssertionError("assertion failed: " + msg)
e.setStackTrace(Array())
throw e

Copy link
Contributor

Choose a reason for hiding this comment

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

this caught my eye the other day for some reason! LOC have unseen costs if it makes you pause.

targetScript: String = "",
compiler: Boolean = false,
quiet: Boolean = false,
colors: Boolean = false,
Copy link
Contributor

Choose a reason for hiding this comment

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

I would not know if this is used anywhere (in a build tool), but I would be cautious. It used to be easier to know "how is the compiler launched".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If it is used, we'll get some feedback early enough, right? I asked around for who uses MainGenericCompiler and was told other tools mostly call the compiler directly as a library.

@som-snytt
Copy link
Contributor

som-snytt commented Jan 8, 2026

Thanks, I enjoy tidying! -Wunused:imports -rewrite will edit imports. I refrained from submitting #22316

My general comment would be that "absolutizing" imports is only noise. import collection.mutable is natural and easy to read.

I would avoid touching cc, because why make someone rebase and maybe resolve a conflict over an import?

Removing all unused imports is strictly worse. import Decorators.*, util.chaining.* in particular, which may be used just for debug, but restoring them every time you do a println debug is anti-productive.

I think private[foo] is useful for crafting public API (std lib) but looks strange when overused. It becomes noisy instead of expressive. But I did not examine what was done here.

@SolalPirelli
Copy link
Contributor Author

My general comment would be that "absolutizing" imports is only noise. import collection.mutable is natural and easy to read.

Fair enough, I was trying to better understand which files depend on which modules and found it easier to see which imports are stdlib vs the compiler's own stuff, but I can revert.

@SolalPirelli SolalPirelli force-pushed the solal/cleanup branch 3 times, most recently from 258f33f to ad3bd74 Compare January 9, 2026 15:27
@SolalPirelli SolalPirelli marked this pull request as ready for review January 13, 2026 15:05
@SolalPirelli SolalPirelli requested a review from bracevac January 14, 2026 13:05
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.

4 participants