Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tc type check #1

Draft
wants to merge 83 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
83 commits
Select commit Hold shift + click to select a range
4740028
wip
frenchy64 Apr 1, 2022
b39a7f8
ann
frenchy64 Apr 1, 2022
abbef3c
decouple
frenchy64 Apr 1, 2022
22a4a8f
check-ns-test
frenchy64 Apr 1, 2022
7bedcaf
Merge branch 'master' of github.com:metosin/malli into tc-type-check
frenchy64 Apr 1, 2022
a5255bf
todos
frenchy64 Apr 1, 2022
64524c0
:as-alias
frenchy64 Apr 1, 2022
4e9a717
tweaks
frenchy64 Apr 1, 2022
4681e35
mv
frenchy64 Apr 1, 2022
d1f44d6
wip
frenchy64 Apr 1, 2022
3c13e7a
wip
frenchy64 Apr 1, 2022
218422e
wip
frenchy64 Apr 1, 2022
9347486
check composite pred
frenchy64 Apr 3, 2022
7d77fe1
bump
frenchy64 Apr 3, 2022
6d0fb85
wip
frenchy64 Apr 4, 2022
91c4c21
wip
frenchy64 Apr 4, 2022
0e180bd
wip
frenchy64 Apr 4, 2022
1df9cc3
wip
frenchy64 Apr 4, 2022
8fd4528
wip
frenchy64 Apr 4, 2022
aeec33b
wip
frenchy64 Apr 4, 2022
b840cb6
bump
frenchy64 Apr 8, 2022
07e3a31
bump
frenchy64 Apr 8, 2022
266e7bb
mali.registry done
frenchy64 Apr 8, 2022
d767381
fix
frenchy64 Apr 8, 2022
aa643f4
wip
frenchy64 Apr 8, 2022
1ce8560
wip
frenchy64 Apr 8, 2022
6314840
wip
frenchy64 Apr 8, 2022
0982be7
fix cycle
frenchy64 Apr 8, 2022
7b6e682
wip
frenchy64 Apr 9, 2022
b04afde
wip
frenchy64 Apr 9, 2022
6512004
try
frenchy64 Apr 9, 2022
68b4ae6
bump
frenchy64 Apr 11, 2022
eedca92
found bug
frenchy64 Apr 11, 2022
5c68081
progress
frenchy64 Apr 11, 2022
b9d3a68
stuck
frenchy64 Apr 11, 2022
b0db21a
revert
frenchy64 Apr 12, 2022
320b9fe
Fix cat{n} unparser with invalid value
frenchy64 Apr 12, 2022
b757cc6
use -reduce-kv-valid annotation
frenchy64 Apr 12, 2022
fe75a5e
wip
frenchy64 Apr 13, 2022
57b758e
bump
frenchy64 Apr 13, 2022
2e049c7
use :?
frenchy64 Apr 16, 2022
7a5b0ea
:->
frenchy64 Apr 16, 2022
ee159a0
wip
frenchy64 Apr 16, 2022
f09324d
parameterize ?KR
frenchy64 Apr 16, 2022
a56b885
notes
frenchy64 Apr 16, 2022
35924c1
fix
frenchy64 Apr 16, 2022
2f17f53
bump
frenchy64 Apr 17, 2022
034a3eb
wip
frenchy64 Apr 17, 2022
fb3e4b6
bump
frenchy64 Apr 17, 2022
af1ed71
wip
frenchy64 Apr 17, 2022
2412a59
wip
frenchy64 Apr 17, 2022
4b6433e
wip
frenchy64 Apr 17, 2022
5ccc13a
wip
frenchy64 Apr 17, 2022
a0c5d7d
wip
frenchy64 Apr 17, 2022
2ddccca
wip
frenchy64 Apr 17, 2022
c025d5c
wip
frenchy64 Apr 17, 2022
0cd514b
wip
frenchy64 Apr 17, 2022
a96cd18
wip
frenchy64 Apr 17, 2022
fba79fb
wip
frenchy64 Apr 18, 2022
500bffa
bump
frenchy64 May 3, 2022
ae4ca50
progress
frenchy64 May 3, 2022
a5dd336
bump
frenchy64 May 3, 2022
4cc3adb
as-alias
frenchy64 May 4, 2022
eb0d9ef
Merge branch 'master' of github.com:frenchy64/malli into tc-type-check
frenchy64 May 4, 2022
1b5b3be
bump clojure
frenchy64 May 4, 2022
a785bb3
main
frenchy64 May 5, 2022
c97c7ee
wip
frenchy64 May 5, 2022
437f39c
add type checker job
frenchy64 May 5, 2022
a35db93
fix
frenchy64 May 5, 2022
b81d832
rm check
frenchy64 May 5, 2022
81ac69a
fix
frenchy64 May 5, 2022
2f41470
save power
frenchy64 May 5, 2022
5f77b56
fix
frenchy64 May 5, 2022
01e1149
rm require
frenchy64 May 5, 2022
2a2bf8f
as-alias
frenchy64 May 21, 2022
66e1b0c
Merge branch 'master' of github.com:metosin/malli into tc-type-check
frenchy64 May 21, 2022
d047bff
bump
frenchy64 May 21, 2022
833a5f6
wip
frenchy64 May 21, 2022
437c5fc
fix
frenchy64 May 22, 2022
af3d091
wip
frenchy64 May 22, 2022
5f0abce
setup
frenchy64 May 23, 2022
8c5ca26
split
frenchy64 May 23, 2022
b9c5ab2
fix
frenchy64 May 23, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions .github/workflows/clojure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ jobs:
matrix:
# Supported Java versions: LTS releases and latest
# TODO: Add 18 when available
jdk: [8, 11, 17]
clojure: [10, 11]
#jdk: [8, 11, 17]
jdk: [17]
#clojure: [10, 11]
clojure: [11]

name: Clojure ${{ matrix.clojure }} (Java ${{ matrix.jdk }})

Expand All @@ -35,6 +37,32 @@ jobs:
- name: Run tests
run: CLOJURE_ALIAS=clojure-${{ matrix.clojure }} bin/kaocha

build-typed:
strategy:
matrix:
this_split: [0, 1]

name: Typed Clojure

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Setup Java 17
uses: actions/setup-java@v2.5.0
with:
distribution: zulu
java-version: 17
cache: maven
- name: Setup Clojure
uses: DeLaGuardo/setup-clojure@master
with:
cli: latest
- name: Type check
run: bin/typed :split "[$THIS_SPLIT 2]"
env:
THIS_SPLIT: ${{ matrix.this_split }}

build-cljs:
name: ClojureScript

Expand Down
3 changes: 3 additions & 0 deletions bin/typed
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

clojure -X:test:typed "$@"
12 changes: 9 additions & 3 deletions deps.edn
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{:paths ["src" "resources"]
:aliases {:test {:extra-paths ["test"]
:extra-deps {com.gfredericks/test.chuck {:mvn/version "0.2.13"}
lambdaisland/kaocha {:mvn/version "1.63.998"}
lambdaisland/kaocha {:mvn/version "1.66.1034"}
lambdaisland/kaocha-cljs {:mvn/version "1.0.107"}
org.babashka/sci {:mvn/version "0.3.1"}
lambdaisland/kaocha-junit-xml {:mvn/version "0.0.76"}
Expand All @@ -17,7 +17,13 @@
lambdaisland/deep-diff {:mvn/version "0.0-47"}
com.bhauman/spell-spec {:mvn/version "0.1.2"}
org.clojure/spec-alpha2 {:git/url "https://github.com/clojure/spec-alpha2.git"
:sha "99456b1856a6fd934e2c30b17920bd790dd81775"}}}
:sha "99456b1856a6fd934e2c30b17920bd790dd81775"}
org.typedclojure/typed.clojure {:git/url "https://github.com/typedclojure/typedclojure.git"
:git/sha "7d8ca07c2e97e1152b0230a20cb7dccd8ca9f8c6"}}}
:typed {:exec-fn typed.clojure.main/exec
:exec-args {:dirs ["src"]
:watch-dirs ["src" "test" "resources"]
:refresh-dirs ["src" "test"]}}
:cljs-test-runner {:extra-deps {olical/cljs-test-runner {:mvn/version "3.8.0"}}
:extra-paths ["test" "cljs-test-runner-out/gen"]
:main-opts ["-m" "cljs-test-runner.main" "-d" "test"]}
Expand Down Expand Up @@ -58,7 +64,7 @@
"-Dclojure.compiler.direct-linking=true"]}
:clojure-10 {:extra-deps {org.clojure/clojure {:mvn/version "1.10.3"}}}
:clojure-11 {}}
:deps {org.clojure/clojure {:mvn/version "1.11.0-rc1"}
:deps {org.clojure/clojure {:mvn/version "1.11.1"}
borkdude/dynaload {:mvn/version "0.2.2"}
borkdude/edamame {:mvn/version "0.0.19"}
org.clojure/test.check {:mvn/version "1.1.1"}
Expand Down
1 change: 1 addition & 0 deletions resources/typedclojure_config.cljc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{:ann [malli.impl.typedclojure-ann]}
2 changes: 1 addition & 1 deletion src/malli/clj_kondo.cljc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(ns malli.clj-kondo
(ns ^:typed.clojure/ignore malli.clj-kondo
#?(:cljs (:require-macros [malli.clj-kondo]))
(:require [fipp.edn :as fipp]
[malli.core :as m]
Expand Down
22 changes: 14 additions & 8 deletions src/malli/core.cljc
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
(ns malli.core
(ns ^:typed.clojure/ignore malli.core
(:refer-clojure :exclude [eval type -deref deref -lookup -key])
#?(:cljs (:require-macros malli.core))
(:require #?(:clj [clojure.walk :as walk])
[clojure.core :as c]
[malli.impl.regex :as re]
[malli.impl.util :as miu]
[malli.registry :as mr]
[malli.sci :as ms])
[malli.sci :as ms]
[typed.clojure :as-alias t])
#?(:clj (:import (clojure.lang Associative IPersistentCollection MapEntry IPersistentVector LazilyPersistentVector PersistentArrayMap)
(java.util.concurrent.atomic AtomicReference)
(java.util.regex Pattern))))
Expand Down Expand Up @@ -83,7 +84,7 @@
(-regex-unparser [this] "returns the raw internal regex unparser implementation")
(-regex-parser [this] "returns the raw internal regex parser implementation")
(-regex-transformer [this transformer method options] "returns the raw internal regex transformer implementation")
(-regex-min-max [this] "returns size of the sequence as [min max] vector. nil max means unbuond."))
(-regex-min-max [this] "returns size of the sequence as {:min .. :max ..} map. nil max means unbound."))

(defn -ref-schema? [x] (#?(:clj instance?, :cljs implements?) malli.core.RefSchema x))
(defn -entry-parser? [x] (#?(:clj instance?, :cljs implements?) malli.core.EntryParser x))
Expand All @@ -92,6 +93,7 @@
(defn -ast? [x] (#?(:clj instance?, :cljs implements?) malli.core.AST x))
(defn -transformer? [x] (#?(:clj instance?, :cljs implements?) malli.core.Transformer x))

;; TODO support extend-type in cljs checker
(extend-type #?(:clj Object, :cljs default)
RegexSchema
(-regex-op? [_] false)
Expand Down Expand Up @@ -123,8 +125,8 @@

(-regex-min-max [_] {:min 1, :max 1}))

#?(:clj (defmethod print-method ::into-schema [v ^java.io.Writer w] (.write w (str "#IntoSchema{:type " (pr-str (-type ^IntoSchema v)) "}"))))
#?(:clj (defmethod print-method ::schema [v ^java.io.Writer w] (.write w (pr-str (-form ^Schema v)))))
#?(:clj ^::t/ignore (defmethod print-method ::into-schema [v ^java.io.Writer w] (.write w (str "#IntoSchema{:type " (pr-str (-type v)) "}"))))
#?(:clj ^::t/ignore (defmethod print-method ::schema [v ^java.io.Writer w] (.write w (pr-str (-form v)))))

;;
;; impl
Expand All @@ -148,7 +150,11 @@
(defn -guard [pred tf] (when tf (fn [x] (if (pred x) (tf x) x))))

(defn -unlift-keys [m prefix]
(reduce-kv #(if (= (name prefix) (namespace %2)) (assoc %1 (keyword (name %2)) %3) %1) {} m))
(reduce-kv (fn [^{::t/- (t/Map t/Ident x)} %1
^{::t/- t/Ident} %2
^{::t/- x} %3]
(if (= (name prefix) (namespace %2)) (assoc %1 (keyword (name %2)) %3) %1))
{} m))

(defn ^:no-doc -check-children? [] true)

Expand Down Expand Up @@ -193,7 +199,7 @@

(defn -equals [x y] (or (identical? x y) (= x y)))

(defn -vmap ([os] (miu/-vmap identity os)) ([f os] (miu/-vmap f os)))
(defn -vmap ([os] (miu/-vmap ^{::t/inst [x]} identity os)) ([f os] (miu/-vmap f os)))

(defn -memoize [f]
(let [value #?(:clj (AtomicReference. nil), :cljs (atom nil))]
Expand Down Expand Up @@ -247,7 +253,7 @@

(defn -registry {:arglists '([] [{:keys [registry]}])}
([] default-registry)
([opts] (or (when opts (mr/registry (opts :registry))) default-registry)))
([opts] (or (when opts (mr/registry (:registry opts))) default-registry)))

(defn -property-registry [m options f]
(let [options (assoc options ::allow-invalid-refs true)]
Expand Down
2 changes: 1 addition & 1 deletion src/malli/destructure.cljc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(ns malli.destructure
(ns ^:typed.clojure/ignore malli.destructure
(:require [clojure.walk :as walk]
[malli.core :as m]
[malli.impl.util :as miu]))
Expand Down
2 changes: 1 addition & 1 deletion src/malli/dev.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(ns malli.dev
(ns ^:typed.clojure/ignore malli.dev
(:require [malli.clj-kondo :as clj-kondo]
[malli.core :as m]
[malli.dev.pretty :as pretty]
Expand Down
2 changes: 1 addition & 1 deletion src/malli/dev/cljs.cljc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(ns malli.dev.cljs
(ns ^:typed.clojure/ignore malli.dev.cljs
#?(:cljs (:require-macros [malli.dev.cljs]))
#?(:cljs (:require [malli.instrument.cljs]
[malli.dev.pretty :as pretty]))
Expand Down
2 changes: 1 addition & 1 deletion src/malli/dev/pretty.cljc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(ns malli.dev.pretty
(ns ^:typed.clojure/ignore malli.dev.pretty
(:require [malli.core :as m]
[malli.dev.virhe :as v]
[malli.error :as me]))
Expand Down
2 changes: 1 addition & 1 deletion src/malli/dev/virhe.cljc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(ns malli.dev.virhe
(ns ^:typed.clojure/ignore malli.dev.virhe
"initial code for https://github.com/metosin/virhe"
(:require [arrangement.core]
[fipp.edn]
Expand Down
2 changes: 1 addition & 1 deletion src/malli/dot.cljc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(ns malli.dot
(ns ^:typed.clojure/ignore malli.dot
(:require [clojure.string :as str]
[malli.core :as m]
[malli.registry :as mr]
Expand Down
2 changes: 1 addition & 1 deletion src/malli/edn.cljc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(ns malli.edn
(ns ^:typed.clojure/ignore malli.edn
(:refer-clojure :exclude [read-string])
(:require [edamame.core :as edamame]
[malli.core :as m]))
Expand Down
2 changes: 1 addition & 1 deletion src/malli/error.cljc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(ns malli.error
(ns ^:typed.clojure/ignore malli.error
(:require [clojure.string :as str]
[malli.core :as m]
[malli.util :as mu]))
Expand Down
2 changes: 1 addition & 1 deletion src/malli/experimental.cljc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(ns malli.experimental
(ns ^:typed.clojure/ignore malli.experimental
(:refer-clojure :exclude [defn])
#?(:cljs (:require-macros malli.experimental))
(:require [clojure.core :as c]
Expand Down
2 changes: 1 addition & 1 deletion src/malli/experimental/lite.cljc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(ns malli.experimental.lite
(ns ^:typed.clojure/ignore malli.experimental.lite
(:refer-clojure :exclude [set vector and or])
(:require [malli.core :as m]))

Expand Down
2 changes: 1 addition & 1 deletion src/malli/generator.cljc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(ns malli.generator
(ns ^:typed.clojure/ignore malli.generator
(:require [clojure.spec.gen.alpha :as ga]
[clojure.string :as str]
[clojure.test.check :as check]
Expand Down
Loading