malli icon indicating copy to clipboard operation
malli copied to clipboard

Predicate registry doesn't work with ProGuard

Open Deraen opened this issue 3 years ago • 3 comments

Somehow, running AOT compiled project through ProGuard breaks any predicate schemas.

Caused by: clojure.lang.ExceptionInfo: :malli.core/invalid-schema {:schema #object[clojure.core$boolean_QMARK_ 0x1ba77d6e "clojure.core$boolean_QMARK_@1ba77d6e"]}

{:schema #object[clojure.core$boolean_QMARK_ 0x1ba77d6e "clojure.core$boolean_QMARK_@1ba77d6e"]} {:type :malli.core/invalid-schema, :message :malli.core/invalid-schema, :data {:schema #object[clojure.core$boolean_QMARK_ 0x1ba77d6e "clojure.core$boolean_QMARK_@1ba77d6e"]}, :reitit.exception/cause #error {
 :cause ":malli.core/invalid-schema {:schema #object[clojure.core$boolean_QMARK_ 0x1ba77d6e \"clojure.core$boolean_QMARK_@1ba77d6e\"]}"
 :data {:type :malli.core/invalid-schema, :message :malli.core/invalid-schema, :data {:schema #object[clojure.core$boolean_QMARK_ 0x1ba77d6e "clojure.core$boolean_QMARK_@1ba77d6e"]}}
 :via
 [{:type clojure.lang.ExceptionInfo
   :message ":malli.core/invalid-schema {:schema #object[clojure.core$boolean_QMARK_ 0x1ba77d6e \"clojure.core$boolean_QMARK_@1ba77d6e\"]}"
   :data {:type :malli.core/invalid-schema, :message :malli.core/invalid-schema, :data {:schema #object[clojure.core$boolean_QMARK_ 0x1ba77d6e "clojure.core$boolean_QMARK_@1ba77d6e"]}}
   :at [malli.core$_fail_BANG_ invokeStatic "core.cljc" 119]}]
 :trace
 [[malli.core$_fail_BANG_ invokeStatic "core.cljc" 119]
  [malli.core$_fail_BANG_ invoke "core.cljc" 117]
  [malli.core$_schema invokeStatic "core.cljc" 265]
  [malli.core$_schema invoke "core.cljc" 262]
  [malli.core$schema invokeStatic "core.cljc" 1631]
  [malli.core$schema invoke "core.cljc" 1614]
  [malli.core$_parse_entries$_parse__22979$fn__22989 invoke "core.cljc" 215]
  [malli.core$_comp$fn__22907 invoke "core.cljc" 155]
  [malli.core$_update invokeStatic "core.cljc" 171]
  [malli.core$_update invoke "core.cljc" 171]
  [malli.core$_parse_entries$_parse__22979 invoke "core.cljc" 215]

Possibly this is related to how predicate registry is built dynamically from the vars: https://github.com/metosin/malli/blob/master/src/malli/core.cljc#L2053-L2060

And after ProGuard runs the "static" references to Clojure core functions in the project code no longer match the values in the registry? (All classes are rewritten to fix references to classes being obfuscated?)

Workarounds:

  • string? -> :string
  • bytes? -> 'bytes? (missing keyword schema for bytes)

Keyword schemas work. Symbols also work, probably because the ProGuard doesn't touch the symbol value in the project, and the symbol value is still resolvable from the dynamically created predicate registry? At least symbol is resolved to a Schema, but the -simple-schema will use deref var value as :pred, and I'm not sure if that still exists after ProGuard? Didn't try really validating values against the schemas yet.

Not sure if we want to even fix this, but this should be documented. It might make sense to disable the predicate registry if the project is going to use ProGuard.

Deraen avatar Oct 29 '21 08:10 Deraen

We could change https://github.com/metosin/malli/blob/master/src/malli/core.cljc#L2053-L2060 not to list the Vars, but to have a symbol fn pairs, e.g

[#'any? #'some?  ...]

; => 
[['any? any?] ['some? some?] ...]

not sure if that helps, but could.

ikitommi avatar Oct 30 '21 06:10 ikitommi

If the symbol resolved into function value in -register-var, I doubt it matters if the data in the list is symbol or var.

(I doubt this is a good "first issue" to work on.)

Deraen avatar Oct 30 '21 09:10 Deraen

Disclosure: I'm not a malli user, but I do static analysis on malli syntax.

I'm not a big fan of this feature (equating the pointer identity of @#'int? with :int). Might it also break if you instrumented these predicates?

eg.,

(def BeforeInstr int?)
(defn f []
  (s/validate BeforeInstr 1))
;; psuedocode
(s/instrument clojure.core/int?)
(s/check f)

frenchy64 avatar Mar 24 '22 14:03 frenchy64