-
Notifications
You must be signed in to change notification settings - Fork 1.1k
refactor: add isActive
to ErrorMessageID
#14965
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
Conversation
case TypeMismatchID // errorNumber: 7 | ||
case NotAMemberID // errorNumber: 8 | ||
case EarlyDefinitionsNotSupportedID // errorNumber: 9 | ||
case TopLevelImplicitClassID extends ErrorMessageID(isActive = false) // errorNumber: 10 |
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.
As far as I know this is no longer an error, however there is a message that uses this and it's actually referenced in Desugar.scala
But I'm unable to ever get it to fall into that branch.
case DoesNotConformToSelfTypeID // errorNumber: 58 | ||
case DoesNotConformToSelfTypeCantBeInstantiatedID // errorNumber: 59 | ||
case AbstractMemberMayNotHaveModifierID // errorNumber: 60 | ||
case TopLevelCantBeImplicitID extends ErrorMessageID(isActive = false) // errorNumber: 61 |
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.
Related to the other top level implicit comment this is also still referenced in one place, but I think it's dead code as I'm unable to reproduce it or get anything to touch that branch in
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.
FYI there's no longer reference to this Error #14935
case OnlyCaseClassOrCaseObjectAllowedID extends ErrorMessageID(isActive = false) // errorNumber: 79 | ||
case ExpectedTopLevelDefID extends ErrorMessageID(isActive = false) // errorNumber: 80 |
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.
I ended up added this in only for the sake of records. I don't think we should rename these, but rather mark them as active = false
if they are no longer being used. This way they can still be mentioned in the index with their number in case anyone with an old version of the compiler for some reason hits on E079
and wonders what that is.
@@ -1066,37 +1066,6 @@ import transform.SymUtils._ | |||
|""" | |||
} | |||
|
|||
class DanglingThisInPath()(using Context) extends SyntaxMsg(DanglingThisInPathID) { |
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 anywhere.
cb03899
to
17041a0
Compare
Currently there is no way to tell if a given `ErrorMessageID` is emitted at all from the compiler. While working on an index of all the IDs I keep needing to dig into the code to see if there is a message that uses an `ErrorMessageID` and then see if that message is actually used anywhere. From what I can gather so far, the ones that I've marked as `false` are no longer emitted and therefore marked `isActive = false`. refs: scala#14904
17041a0
to
73e6351
Compare
Any input on this? |
I think if an error message id is no longer used, we should just replace it with something having So I am not sure anything needs to be done here. |
I think for record purposes, using things like |
Actually, using the Taking about this reminded me that we are missing a documentation page that lists all errors by ID and gives a small description of each error. |
Correct, that was the main reason behind me working on this. I plan to port it to the documentation when it's complete, which I mentioned in the contributors forum and the referenced issue. However, there does seem to be some so far that I can't reproduce or that I think are actually referenced by dead code. |
We should generate the documentation @ckipp01 collected in index in an official part of the Scala 3 documentation. This list should be up to date with all the errors listed in ErrorMessageID.scala. A good way to make sure that the documentation is complete would be to make the IDs hold the explanations of the error messages. Not sure if those would be the same explanations that we have in Message.scala, if it is the case it would be simpler to maintain. Also see rust error index. |
Why can't we use unused IDs for new errors? I have the impressions we are generating a huge complication for nothing. I resent adding boilerplate where it is pointless, and I think this is exactly one of these cases. I am also against investing now in error message IDs or publishing them. That's a sure way for ossification! Let's invest our energy to get really great error messages instead of adding to bureaucracy! |
I think this should be reverted and discussed again. Even if we accept the premise of error message ids (which I don't) I believe this concrete implementation is not the way to do it. If you need unchanged, documented numbers for your error messages, you should not rely on comments! Much better to own up to it and write inline val PkgDuplicateSymbolID = 33 and so on. |
Don't you think it would have been a great idea to voice any of this when I created the initial discussion around this in March or maybe in April when I created the overall plan here, or any time over the last month while this PR sat here? I specifically stated in #14904:
I even outlined the specific points about |
The issue with those ids that were called unused is that they were used, this clearly leads to confusion. The only IDs that are really unused are those that we have never used in the past, hence IDs are larger than the current largest. For simplicity, we kept the ID range compact, only allowing the addition of the next consecutive ID.
It is also worth mentioning that these are user-facing IDs that the compiler emits with the message. These must be unambiguously googlable. This is why the IDs of older messages that are not emitted anymore cannot be reused. By not publishing them ourselves, we are now in the nonideal situation where this user documentation is not centralized and up to date. Part of it is now in https://github.com/ckipp01/dotty-error-index and probably more in StackOverflow. If we published it ourselves we would be able to have a consistent and complete description of the errors.
This was the initial design we used. It failed miserably due to its un-maintainability: many contributors renumbered the IDs without us noticing the problem, there were many occurrences where we go duplicated IDs due to concurrent merges, and some IDs were removed without us noticing the problem. This pushed us to use a resident enumeration-based approach where we only append new elements. Since we added this 5 years ago, we have not seen any of these mistakes happen again, the closest we got was almost reusing the mislabeled |
@ckipp01. I'm sorry. I was missing the larger context and I wrote too quickly. I was a bit irked of this being merged over my objections. If it unblocks you I am OK with the proposed changed of exposing the ID. It's just as a caveat that our error messages are nowhere near a state where we want to keep them that way! So I believe effort needs to be spent on working on the content and structure of these messages, and conversely, we should make it as easy as possible to change and refactor messages in the future. Regarding the PR, I still think it would be better to write val PkgDuplicateSymbolID = 33 instead of case PkgDuplicateSymbolID // errorNumber = 33 If we need to keep track of inactive messages we can use a set:
|
I think this was to a large degree a lack of communication what the rules about error message ids were. The enumeration-based designs also has a number of implicit rules, but now contributors know them better, it seems. How important are the precise IDs? It seems if they are important we need to make them explicit. Can't we write a comment: "only add to the end" or something like that in the header? I mean the only gain of using an enumeration rather than explicit integer vals is that I can add new values in the middle without changing the right hand sides of subsequent definitions. But that's precisely what is forbidden for error message ids. So, why use an enumeration at all? |
If precise IDs are important and we want to guard against errors in modifications I would recommend a design like this: enum ErrorMessageID(id: Int, active = true):
assert(id == ordinal)
case Msg1 extends ErrorMessageID(0)
case Msg2 extends ErrorMessageID(1)
case Msg3 extends ErrorMessageID(2, active = false)
... That way we make sure that ids correspond to ordinals and are not duplicated. WDYT? |
I think what you have outlined would be a nice minimal way to accomplish what we want, yes. As yea, precise IDs here I do think are important. With that |
Users will see something like
We have this comment ErrorMessageID.scala#L8 in the header. Did you miss it? Should we move it to a better place?
Apart from reducing the risk of adding the wrong IDs, I remember we wanted an enumeration to be able to enumerate them. Probably to be able to make the documentation tool. |
I think
or we move it to the end. Both would work IMO. @nicolasstucki I think we are converging on a design that uses an enumeration without the downsides. |
We should also see if we can make it a proper Scala enumeration. We did not do it at the time because we had not implemented them yet. |
Opened #15271 to remove |
Currently there is no way to tell if a given
ErrorMessageID
is emittedat all from the compiler. While working on an index of all the IDs I
keep needing to dig into the code to see if there is a message that uses
an
ErrorMessageID
and then see if that message is actually usedanywhere. From what I can gather so far, the ones that I've marked as
false
are no longer emitted and therefore markedisActive = false
.refs: #14904