Skip to content

Found keeps a ternary that its own path condition decides #523

Closed

Description

@CatarinaGamboa

In study exercise A1_09, Found keeps a ternary that its own path condition already decides.

Example

The baseline message:

found newMode == BORDERLESS && (previousMode == BORDERLESS && newMode != BORDERLESS ? display(host) == notDisplayable : (previousMode != BORDERLESS && newMode == BORDERLESS ? display(host) == notDisplayable : display(host) == displayable)) but expected display(host) == notDisplayable

Under newMode == BORDERLESS, this is just previousMode != BORDERLESS ? display(host) == notDisplayable : display(host) == displayable.

Three plausible attempts at a fix make the message worse:

  • Partial fix, adding else if (newMode == BORDERLESS) host.dispose();: three nested ternaries under newMode == FULLSCREEN.
  • host.dispose() only in case BORDERLESS: two levels of ternary under newMode == FULLSCREEN.
  • host.setVisible(false) before setUndecorated. A novice reads "notDisplayable" as "not visible", so this attempt is very plausible. It gives a Found of about 700 characters: a disjunction of the three setVisible alternatives, each repeating the whole ternary, with host@22 versions.

Cause

The display pipeline (rj_language/opt/VCSimplification and its passes, then VCRelevantFacts) never uses a top-level conjunct such as newMode == BORDERLESS to rewrite the rest of Found. VCFunctionSubstitution and VCFolding only fold closed literals.

Proposed fix

Add a display pass:

  1. For each top-level conjunct x == C, where C is an enum constant or a literal, substitute C for x in the other conjuncts.
  2. Fold C == C, and C1 == C2 for distinct constants of the same enum.
  3. Then fold true ? a : b, false ? a : b and false && ….

Where folding is not syntactic, the pass could instead ask Z3, for each ternary test, whether the top-level conjuncts imply or refute it.

There is no soundness risk for the verdict, since this is display only. The one risk is folding two static final ints that share a value, so the pass should fold only enum constants or tests that Z3 has checked.

For the setVisible(false) case, the pass should also factor out the common conjuncts of the disjuncts. #501 then removes the host@22 versions.

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

    study

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions