Error formatting macro: pagetree: java.lang.NullPointerException

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Problem

Typed Clojure uses local type argument synthesis to automatically synthesise type arguments to polymorphic functions. Some inference cases are hard to synthesise, which usually cause the inference engine to fail.

These cases require manual annotation of type arguments, which are potentially different at every function application.

Typed Clojure runs forms through the Clojure analyser, and parses the results of analysis.

I need a mechanism to communicate to Typed Clojure on a per-function-call basis.

Solution

Modify the analyser to preserve metadata attached to function calls.

Current Behaviour

Particular reader metadata keys are hardcoded to survive analysis, such as :tag.

Analysing this form loses any mention of :a, but keeps :tag in a special field in the result of analysis.

Code Block
^{:tag Number, :a MyArg} (float? 1)

Proposal

Modify the analyser to add a metadata field for function invocations.

Attached example patch.

Not convenient communicating to analysis

  • Only specific reader metadata survives analysis
    • Usually related to compilation or debugging
    • :tag, :line, :static
    • Can only attach in specific contexts
      • parameters
      • local bindings
  • Makes it difficult communicating to tools that utilise the results of analysis
  • Example: attaching metadata to function calls

    • ^{:my-m 1} (float? 1)
    • :my-m is irretrievable from analysis
    • Problem: cannot expect to attach metadata to macro calls or inlining functions.
  • Any other examples?
  • Use case: annotating polymorphic function calls with type arguments in Typed Clojure
    • ^{:inst [Integer Integer]} (my-poly arg1 arg2)