Skip to content
Snippets Groups Projects

Fix typing of constants

Merged Daniel Bauer requested to merge hyteg/pystencils:bauerd/fix-const-typing into backend-rework
1 unresolved thread

This is an umbrella MR combining a few small changes:

  • Fixes typing of constants. If a typed Constant inside of an untyped ConstantExpr was encountered, the typification used to fail (see new test).
  • Strengthens test_typify_integer_binops now that arbitrary expressions can be deferred.
  • Increases the information content of two error messages.
  • Fixes a typo.

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
  • added Bug label

  • Daniel Bauer requested review from @da15siwa

    requested review from @da15siwa

  • assigned to @he66coqe

    • Thanks; this actually uncovers a more subtle bug in AST cloning: when cloning a PsConstantExpr, its wrapper PsConstant is not cloned along with it, so both copies refer to the same constant. Then one of them gets typified, which unintentionally carries over to the other. Gonna fix that right away.

    • Feel free to fix the root cause :thumbsup:.

      Still, should it be allowed to give the typifier an untyped PsConstantExpr wrapping a typed PsConstant? I do not see why not.

    • I'm gonna look into it, but ideally that should never happen.

      Anyway, allowing PsConstant.apply_type to change the current constant object is probably a big pitfall, too, since PsConstant DOES override __eq__ for content-equality.

    • Please register or sign in to reply
  • I admit that it is very non-obvious. The expression stems from one of our real applications which is how I found it.

    It gets frozen to:

    PsMul(PsSub(PsMul(Constant(-1: <untyped>), Symbol(PsSymbol(x, None))), Symbol(PsSymbol(y, None))), PsSub(PsMul(Constant(-1: <untyped>), Symbol(PsSymbol(x, None))), Symbol(PsSymbol(y, None))))

    Now the typifier runs over this tree as follows (each line is the argument to visit_expr):

    PsMul(PsSub(PsMul(Constant(-1: <untyped>), Symbol(PsSymbol(x, None))), Symbol(PsSymbol(y, None))), PsSub(PsMul(Constant(-1: <untyped>), Symbol(PsSymbol(x, None))), Symbol(PsSymbol(y, None))))
    PsSub(PsMul(Constant(-1: <untyped>), Symbol(PsSymbol(x, None))), Symbol(PsSymbol(y, None)))
    PsMul(Constant(-1: <untyped>), Symbol(PsSymbol(x, None)))
    Constant(-1: <untyped>)
    Symbol(PsSymbol(x, None))
    Symbol(PsSymbol(y, None))
    PsSub(PsMul(Constant(-1.0: const float), Symbol(PsSymbol(x, float))), Symbol(PsSymbol(y, float)))
    PsMul(Constant(-1.0: const float), Symbol(PsSymbol(x, float)))
    Constant(-1.0: const float)

    Notice how PsMul(Constant(-1: <untyped>), Symbol(PsSymbol(x, None))) appears twice in the tree. I suspect that both occurences reference the same PsConstant Python object. After typing the first expression, the dtype of both PsConstants changes from <untyped> to const float. However, the second PsCostantExpr is not typed, yet. This happens next and the typifier was not able to handle an untyped PsConstantExpr containing a typed PsConstant.

  • Frederik Hennig mentioned in commit d2cfa5a0

    mentioned in commit d2cfa5a0

  • merged

Please register or sign in to reply