Skip to content

Figure out how we talk about "errors" or "warnings" without falling into the "specifying tool behavior" trap #73

Closed

Description

@kevinb9n

I'm still trying to home in on a useful mental model for clarifying what the boundaries should be around what we specify vs. what we leave checker-dependent. Since Mike's visit I've been trying (somewhat) to recast my thinking around "code specification, not code analysis".

So I suppose this would lead us to try to talk less about errors and warnings per se. But I do think that we can defensibly speak in terms of three distinct levels of correctness for the reasons I'm about to explain, and we will need some terminology for those three levels (like "error/warning/okay", or "error/strictly-error/okay", or something).

So here's my thought. When we say things like "error/warning" we're not really trying to dictate how a checker must surface a problem. We can look at it much more simply: t's more that our annotation specifications implicitly determine which situations arising from their use represent logical contradictions. For example, we might say the reason why you can't override void foo(@Nullable Foo foo) with @Override void foo(@NotNull Foo foo) is that you've created a logical contradiction: the method can't permit null, but if I just upcast suddenly the null can get in. [note: I disown this particular example in #111]

What does this mean for unspec? So far, I still feel very good about rooting it conceptually on the ternary boolean. The direct result of that is that the question above of "is this a logical contradiction" itself now can take on three truth values. For the previous example, it is True that it is a logical contradiction; if the two annotations are reversed then it is False that it is a logical contradiction... and finally, if we are overriding an unspec param with a non-null one, then "is that a logical contradiction?" evaluates to Unknown.

So

  1. Can we get with this conceptual framework?
  2. What shorthand terms can we converge on?

Activity

  1. cpovirk commented on Oct 11, 2019

    @cpovirk
    Collaborator

    For example, we might say the reason why you can't override void foo(@Nullable Foo foo) with @Override void foo(@NotNull Foo foo) is that you've created a logical contradiction: the method can't permit null, but if I just upcast suddenly the null can get in.

    (Minor point for anyone new to these discussions: It's probably simpler to think of the analogous situation on return types, given that we aren't expecting to support contravariant parameter types, at least not yet.)

    1. Can we get with this conceptual framework?
    2. What shorthand terms can we converge on?

    I think I'm happy reading the phrase "It is an error to do x" as always followed by the qualifier "(unless the checker author doesn't want it to be)." Do you think it's important to go deeper than that? (Maybe this will come out when we see Mike's notes?)

    I wonder if identifying "logical contradictions" is a step further than what we really want to do. For example:

    interface Top {
      @NotNull String foo();
    }
    
    interface Middle extends Top {
      @NullUnspecified String foo();
    }
    
    interface Bottom extends Middle {
      @Nullable String foo();
    }

    This is a logical contradiction, but it's likely that our specification will call it two cases of "unknown if there's a contradiction." I assume that we could detect the contradiction, but it's not clear that it's worth the checker complexity (or the possible performance hit, which might(??) get worse in systems with strict-deps checking). But if our spec isn't handling this, then is our spec really about looking for logical contradictions? We've sometimes spoken of writing a "bug checker" more than a "fully sound logical system," so part of what we're doing is deciding what code is "suspicious enough" to generate a warning or an error. That suggests that we aren't looking for logical contradictions per se.

    [edit: Of course the whole point here is that our spec could call this a logical contradiction even if checkers don't implement it. That's fine, but is it really worth our trouble to specify -- and the extra complexity it will create in the specification -- if we don't think it will be worth implementing?]

    Another example: I think that it's most natural to think of assigning @NullUnspecified to @NullUnspecified as "unknown if there's a logical contradiction," but it sounds like you'd like that to be "not a logical contradiction." Maybe you can convince me that it's not really a logical contradiction, but I think your argument has been more that it's not practically useful to issue warnings in that case, not that it's logically sound.

    Having just written 300+ words about this, I will say: I'm not sure I'm personally that invested in our phrasing here. But it sounds like there might be some reason to be invested that I am just not aware of yet, so I'm happy to be convinced.

  2. kevinb9n commented on Oct 17, 2019

    @kevinb9n
    CollaboratorAuthor

    I think I'm happy reading the phrase "It is an error to do x" as always followed by the qualifier "(unless the checker author doesn't want it to be)."

    I think I'm proposing a different way of looking at this: when we say the phrase "it is an error", we are not saying that checker authors are supposed to report it as an error. We are simply saying that it IS an error, just like saying that 2 + 2 = 5 is an error. What the checker wants to do about that, we might not have to specify at all, because they their natural incentives will probably be good.

    We might end up wanting to go further at some point, such as specifying suppression strings. We can pull that off, I think. What we call errors are just logical contradictions of specification, but we can assign a name to each of these, and specify that the user's suppression of that name communicates their acknowledgment and acceptance of that logical contradiction... after which point the tool's natural motivation would be to suppress the error.

  3. cpovirk commented on Oct 17, 2019

    @cpovirk
    Collaborator

    Sorry, I think I understood what you were saying but did not write clearly at all.

    I meant to present...

    I think I'm happy reading the phrase "It is an error to do x" as always followed by the qualifier "(unless the checker author doesn't want it to be)."

    ...as a separate proposal from yours. I'm trying to understand what advantages we get by defining things as "logical contradictions" or "in error" instead of straight-up calling them "errors" or "illegal" (that can optionally be implemented as specified, implemented in an improved way, or not implemented at all).

    A possible disadvantage of defining "logical contradictions" is that it suggests (to me, at least) that we're trying to be sound/thorough, when for a variety of reasons we're not. It feels strange to say "It is a logical contradiction to do x, y, or z" when we know there are many other logical contradictions that we're not listing. (Bad analogy [edit: see below]: throw null and int n = 1 / 0 will both cause the runtime to throw an exception. Depending on your compiler and settings, each might or might not compile successfully. It would feel strange to me to call one "logically unsound" and not the other.)

    Still, I'm not opposed to talking about "<some word that suggests 'error-level'> logical contradictions" and "<some word that suggests 'warning-level'> logical contradictions" (and using the shorthand of "error" and "warning" for them). But I think there's some deeper goal here than I'm missing. And that's probably fine: This terminology is pretty low on my list of concerns. But if I am missing some deeper point, I should probably figure it out sooner or later :)

    [edit: It's an even worse analogy than I'd thought, since it's easy to imagine writing a type system that checks only nullness or only zero-ness. Maybe a better (but still bad) analogy is int i = null vs. throw null. javac forbids one but not the other, even though in theory both could compile and throw NullPointerException. javac's behavior is more about spec simplicity and history than about soundness.]

  4. kevinb9n commented on Oct 23, 2019

    @kevinb9n
    CollaboratorAuthor

    I'm trying to understand what advantages we get by defining things as "logical contradictions" or "in error" instead of straight-up calling them "errors" or "illegal" (that can optionally be implemented as specified, implemented in an improved way, or not implemented at all).

    I think it's maybe only a slight difference of mindset and terminology. What we want is a clear way of thinking about the project and its purpose that we can refer to whenever we have confusion over where to draw an exact boundary between what's specified and what isn't.

    When we met with Mike, one of his main suggestions was to try thinking of the nature of our project as being fundamentally about specification, not about analysis at all. The analysis happens to require more specification, and that's the part we fill in, but then we stop, and let the analyses do with the information we provide as they please. I think that mindset is what I've been trying to get at since the beginning, and I think it's usefully clarifying.

    I don't think we want to actually have to bring this awkward phrase "logical contradiction" into conversation often, and we should adopt a meaning for either "error" or "illegal" that serves in its stead. I was just thinking that most of these errors should arise from cases of trying to specify something that fundamentally doesn't make logical sense.

    A possible disadvantage of defining "logical contradictions" is that it suggests (to me, at least) that we're trying to be sound/thorough, when for a variety of reasons we're not.

    I was thinking kind of opposite to this: that the least sound you can be is to only complain about outright paradoxes, and soundness would involve so much more.

    But I think there's some deeper goal here than I'm missing.

    I don't think so. This is just part of the general desire to get to some kind of framework for thinking about what deserves to be specified and what doesn't.

  5. cpovirk commented on Oct 24, 2019

    @cpovirk
    Collaborator

    OK, thanks. I think I'm happy to shift to being an observer on this issue. If it later looks like I can help with terminology, or if someone says something that clarifies some deeper issue for me, I'm sure you'll hear from me again :)

  6. cpovirk commented on Nov 8, 2019

    @cpovirk
    Collaborator

    I'm not sure if this belongs in a different bug, but to address @NullnessUnspecified warnings specifically: A policy that I'm coming to like is the one implied by my mental model (the model that's sounding like it may be equivalent to existential types):

    Any type that has @NullnessUnspecified is a type that "should" be annotated with some nullness. (In the simple case, it's currently something like @NullnessUnspecified String, which "should" be either @NotNull String or @Nullable String.) Someday, we can even hope, it will be annotated with that nullness.

    Given that, the meaning of a warning is: "When one or more @NullnessUnspecified types are annotated with 'real' nullness values, this operation could produce an error."

    There are probably some subtleties to this. For example, we might choose to warn on operations that could never be errors themselves but that enable errors later on -- though, all else being equal, that seems less desirable than waiting until the actual dangerous operation.

    (After that, we still have to define "error" and any other types of warnings that we might want (e.g., for arrays [edit: or for raw types]).)

    Conveniently, this policy implies the answer that I want to #69 :) But maybe it could be refined to avoid some of the worst fallout from that policy? Like, maybe we could say that, as long as a symbol is defined in the same file that we're checking, then we assume that we don't need to worry that it will change to the "wrong" nullness?

  7. cpovirk commented on Nov 13, 2019

    @cpovirk
    Collaborator

    On the subject of @NullnessUnspecified, I wanted to also add: Our annotations will likely not be powerful enough to support every use case, so users may write APIs whose nullness is impossible to express with those annotations. Naturally, this is a problem when they try to annotate their code. But even if they don't annotate their code, then there might be a problem: We might make unsound assumptions about their code, like:

  8. stephan-herrmann commented on Nov 26, 2019

    @stephan-herrmann

    From @kevinb9n on Oct. 17:

    We might end up wanting to go further at some point, such as specifying suppression strings ...

    Are you referring to @SuppressWarnings tokens? I'm all in favor.

    Eclipse has a dual strategy: lots of individual options in the UI (not only for suppression but for classification into [error/warning/info/ignore]), but many of them grouped to the same @SuppressWarnings token (which then also appears as a command line option). I would be willing to enable (and standardize) more fine grained suppression.

    Just as a historical note: time ago I was happy to find this in JLS:

    For other kinds of warnings, compiler vendors should document the strings they support for @SuppressWarnings. Vendors are encouraged to cooperate to ensure that the same names work across multiple compilers.

    Unfortunately, my attempts to reach out to Oracle on this behalf did not bear any fruit, but sure, in this group we already have the cooperation, so things look better here.

  9. kevinb9n commented on Nov 26, 2019

    @kevinb9n
    CollaboratorAuthor

    Very glad you're supportive. See #55, which I think I'll retitle now.

  10. cpovirk commented on Apr 8, 2020

    @cpovirk
    Collaborator

    How would people feel about the following terminology...?

    • "mismatch" for what we've been calling "error"
    • "not enough information" for what we've been calling "warning"
  11. added this to the 1.0 milestone on Oct 13, 2021
  12. added
    meta
    on Oct 18, 2021
  13. kevinb9n commented on Feb 7, 2022

    @kevinb9n
    CollaboratorAuthor

    This discussion seems largely outdated and I don't think we benefit from keeping it open for any particular purpose.

  14. removed
    meta
    on Dec 1, 2022
  15. modified the milestones: 1.0, 0.3 on Dec 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions