Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
8170945
wip
SimonTsirikov Apr 16, 2024
e0beb44
split added
SimonTsirikov Apr 23, 2024
2b9c930
fix typos
SimonTsirikov Apr 23, 2024
824f195
split fixed and tests added
May 16, 2024
527644a
multiple types fusion added
SimonTsirikov May 22, 2024
2bb88ee
refactoring fusion
SimonTsirikov May 22, 2024
a325fc6
rewrite fusion to use Vect and List1
SimonTsirikov May 22, 2024
9dabb55
draft for fusion dependencies solver
SimonTsirikov May 27, 2024
d1777a5
target type generator derivation from fused type generator added
SimonTsirikov Jun 4, 2024
355f1b3
fix tests
SimonTsirikov Jun 4, 2024
28c354b
WIP
SimonTsirikov Jun 11, 2024
5d898b3
fix ordering of arguments according to original type constructor
SimonTsirikov Jun 18, 2024
8e5e328
fix fusion
SimonTsirikov Jun 18, 2024
9df33fa
[ new ] Add the default constructor derivator
buzden Mar 27, 2023
5661fdf
[ cleanup ] Remove now became useless hints of a constructor derivator
buzden Mar 27, 2023
59307c4
[ upstream ] Use precise variant for distributions checking
buzden Jun 25, 2024
5fdf6a8
[ upstream ] Fix one test, compiler now is smarter than it was
buzden Jul 3, 2024
f788ebb
[ docs ] Make the natural language linter happier
buzden Jul 25, 2024
1a5b6ee
[ example ] Fix and refine a `pil-fun`'s test
buzden Aug 13, 2024
a68b641
[ upstream ] Make one error message to be produced faster
buzden Aug 14, 2024
299f837
[ derive ] Clean up repeating orders and log finally used ones
buzden Aug 14, 2024
3f618a2
[ example ] Add the covering sequence example
buzden Aug 14, 2024
2a8f63d
[ ux, derive ] Improve an error message of a function in a constructor
buzden Aug 14, 2024
3fa6e53
[ mcov ] Add remaining generator runners with ModelCoverage
DanMax03 Aug 16, 2024
1b7dd33
[ fix ] Fix typo in 'acquire' word
DanMax03 Aug 16, 2024
2c5f73c
[ derive ] Log used order using argument names too
buzden Aug 16, 2024
fe5a089
[ refactor ] Move special interpolations to be local implementations
buzden Aug 22, 2024
7750039
[ fix, ux ] Fix error message when type of con's param is not accessible
buzden Aug 28, 2024
01e4512
[ example ] Implement CLI options in the pil-fun example
buzden Aug 25, 2024
1f32bb7
[ test, perf ] Add couple of kinda-performance tests
buzden Aug 22, 2024
36792e7
[ test ] Add some simpler tests with implicit args of derived types
buzden Aug 28, 2024
3568653
[ upstream ] Work around `IHole`s in type signatures
buzden Aug 29, 2024
463841b
[ derive, test ] Move generator's printer to the main lib + cleanup
buzden Aug 29, 2024
e4d69ea
[ derive ] Support printing derived gens with Idris representation
buzden Aug 31, 2024
165ce71
[ gen ] Add an associative binary composition fun merging alternatives
buzden Sep 2, 2024
a2dd240
[ gen ] Add more elegant analogue for `suchThat` for fuelled generators
buzden Sep 2, 2024
b023a1d
[ gen ] Implement functions for picking one random generated value
buzden Sep 9, 2024
7f5a593
[ test ] Add tests inspired by John Hughes' RGen example
buzden Sep 9, 2024
5681a77
[ test ] Make arg-deps tests be able to take `0`-quantified arguments
buzden Sep 16, 2024
56c0dab
[ derive ] Use much simpler (syntactic) arg dependencies calculation
buzden Sep 16, 2024
f5ad405
[ test ] Add infra test with dependency on a dependent type with `_`
buzden Sep 13, 2024
6397916
[ refactor ] Simplify some code in the derivator
buzden Sep 16, 2024
c7a9660
[ refactor ] Remove useless intermediate function
buzden Sep 16, 2024
44e7f14
[ derive ] Do not pass values of arguments on which someone else depends
buzden Sep 13, 2024
ca7b648
[ derive ] Don't discard types with implciits
buzden Aug 28, 2024
f12099c
[ example ] Use implicit type arguments in `pil-fun` example
buzden Sep 17, 2024
8bfcca2
[ test ] Stabilize compilation output in tests
buzden Sep 17, 2024
5666382
[ test ] Rename and granulate some derivation performance tests
buzden Sep 19, 2024
6d3699a
[ derive, refactor, perf ] Refactor `TypeApp`, make derivation faster
buzden Sep 25, 2024
30b14fb
[ refactor ] Move `NamesInfoInTypes` into a separate module section
buzden Oct 2, 2024
d33db72
[ compat ] Be more friendly to non-friendly OSes
buzden Oct 7, 2024
2a816ca
[ compat ] Remove deprecated sphinx theme option
buzden Oct 7, 2024
4f29cdf
creation of GenSignature for fused type added
SimonTsirikov Oct 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 2 additions & 2 deletions .github/workflows/ci-deptycheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ jobs:
###################

get-test-sets:
name: Aquire test sets
name: Acquire test sets
needs:
- deptycheck-build-lib
runs-on: ubuntu-latest
Expand Down Expand Up @@ -187,7 +187,7 @@ jobs:
#################

get-examples:
name: Aquire examples
name: Acquire examples
needs:
- deptycheck-build-lib
runs-on: ubuntu-latest
Expand Down
30 changes: 30 additions & 0 deletions .github/workflows/ci-non-primary-os.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
name: Non-primary OS

on:
push:
branches:
- main
- master
tags:
- '*'
pull_request:
branches:
- main
- master

permissions:
statuses: write

concurrency:
group: ${{ github.workflow }}@${{ github.ref }}
cancel-in-progress: true

jobs:
build:
name: Clone on Windows
runs-on: windows-latest
steps:

- name: Checkout
uses: actions/checkout@v4
6 changes: 0 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -301,12 +301,6 @@ You can read more on the design of generators in [documentation](https://deptych

## Derivation of generators

<!-- idris
%hint
UsedConstructorDerivator : ConstructorDerivator
UsedConstructorDerivator = LeastEffort
-->

DepTyCheck supports automatic derivation of generators using the datatype definition.

For now, it is not tunable at all, however, it is planned to be added.
Expand Down
3 changes: 2 additions & 1 deletion deptycheck.ipkg
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ license = "MPL-2.0"
sourcedir = "src"
builddir = ".build"

version = 0.0.240616
version = 0.0.240909

modules = Deriving.DepTyCheck
, Deriving.DepTyCheck.Gen
Expand All @@ -20,6 +20,7 @@ modules = Deriving.DepTyCheck
, Deriving.DepTyCheck.Gen.Core.ConsEntry
, Deriving.DepTyCheck.Gen.Core.Util
, Deriving.DepTyCheck.Gen.Checked
, Deriving.DepTyCheck.Util.Fusion
, Deriving.DepTyCheck.Util.Logging
, Deriving.DepTyCheck.Util.Reflection
, Language.Reflection.Compat
Expand Down
1 change: 0 additions & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@
#
html_theme = "sphinx_rtd_theme"
html_theme_options = {
"display_version": True,
"prev_next_buttons_location": "bottom",
}
html_logo = "../../icons/deptycheck-lib-html-logo.png"
Expand Down
2 changes: 1 addition & 1 deletion docs/source/explanation/derivation/design/single-con.md
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ genD_idx_generated @{data_Nat} @{data_String} fuel b = data_D_giv_b fuel b
-->

In this case, generation of non-recursive constructors `JJ` and `TL` is straightforward,
the only difference is that `b` is a function argument, not a result of subgeneration.
the only difference is that `b` is a function parameter, not a result of subgeneration.

Recursive cases are not so easy.
Surely, we can first generate value `b` using derived `data_Bool` generator (as we did before for `JJ` constructor)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ thus inapplicable directly for dependent types.
Since, we focus on total generators for dependent types, we cannot rely on common hybrid approach.
Considering all said above, it is decided to go the hard way and to do derivation of generators directly,
using metaprogramming facility if Idris called *elaboration scripts*.
% TODO to add a link to Idris documentation as soon as elaboration scripts are documented.
<!--
TODO to add a link to Idris documentation as soon as elaboration scripts are documented.
-->

Thus, DepTyCheck's derivation mechanism is a fully compile-time metaprogram that analyses generated datatype and
produces generator's code which is checked for type correctness and totality right after.
1 change: 1 addition & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ The examples are the following:

- [sorted lists](sorted-list/) of natural numbers
- list and vector of strings, [both with unique elements](uniq-list/) implemented using `So` and usual `Eq` comparison
- a sequence of [unique mentions of a given subset](covering-seq/) of elements interleaved with unrelated elements
- naive possibly empty [sorted binary trees](sorted-tree-naive/) of natural numbers, implemented as if without dependent types
with added limitations on sortedness
- [indexed non-empty sorted binary trees](sorted-tree-indexed/) of natural numbers, with type indices for value bounds
Expand Down
13 changes: 13 additions & 0 deletions examples/covering-seq/covering-seq.ipkg
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package covering-seq

version = 0.1

authors = "Denis Buzdalov"

sourcedir = "src"
builddir = ".build"

depends = deptycheck

modules = Data.List.Covering
, Data.List.Covering.Gen
64 changes: 64 additions & 0 deletions examples/covering-seq/src/Data/List/Covering.idr
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
module Data.List.Covering

import public Data.Fin
import Data.String

%default total

namespace BitMask

-- BitMask n ~~ Vect n Bool
public export
data BitMask : (bits : Nat) -> Type where
Nil : BitMask 0
(::) : Bool -> BitMask n -> BitMask (S n)

export
Interpolation (BitMask n) where
interpolate [] = ""
interpolate (True ::bs) = "1\{bs}"
interpolate (False::bs) = "0\{bs}"

public export
update : Fin n -> (newValue : Bool) -> BitMask n -> BitMask n
update FZ v (_::bs) = v::bs
update (FS n) v (b::bs) = b :: update n v bs

namespace Index

public export
data AtIndex : (n : Nat) -> Fin n -> BitMask n -> Bool -> Type where
Here : AtIndex (S n) FZ (b::bs) b
There : AtIndex n i bs v -> AtIndex (S n) (FS i) (b::bs) v

public export
data AllBitsAre : (n : Nat) -> Bool -> BitMask n -> Type where
Finish : AllBitsAre Z b []
Continue : AllBitsAre n b bs -> AllBitsAre (S n) b (b::bs)

export
setBits : BitMask n -> List $ Fin n
setBits [] = []
setBits $ True ::bs = FZ :: (FS <$> setBits bs)
setBits $ False::bs = FS <$> setBits bs

-- Contains all and only mentions (hits) of values enabled in the given bitmask in any order interleaved with some arbitrary numbers (misses).
public export
data CoveringSequence : (n : Nat) -> BitMask n -> Type where
End : AllBitsAre n False bs => CoveringSequence n bs
Miss : Nat -> CoveringSequence n bs -> CoveringSequence n bs
Hit : (i : Fin n) -> AtIndex n i bs True => CoveringSequence n (update i False bs) -> CoveringSequence n bs

public export
hits : CoveringSequence n bs -> List $ Fin n
hits End = []
hits $ Miss k xs = hits xs
hits $ Hit i xs = i :: hits xs

export
Interpolation (CoveringSequence n bs) where
interpolate = joinBy " " . asList where
asList : forall n, bs. CoveringSequence n bs -> List String
asList End = []
asList $ Miss k xs = show k :: asList xs
asList $ Hit i xs = "[\{show i}]" :: asList xs
14 changes: 14 additions & 0 deletions examples/covering-seq/src/Data/List/Covering/Gen.idr
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module Data.List.Covering.Gen

import public Data.List.Covering

import public Test.DepTyCheck.Gen
import Deriving.DepTyCheck.Gen

%default total

%logging "deptycheck.derive" 5

export
genCoveringSequence : Fuel -> {n : Nat} -> (bs : BitMask n) -> Gen MaybeEmpty $ CoveringSequence n bs
genCoveringSequence = deriveGen
1 change: 1 addition & 0 deletions examples/covering-seq/tests/.clean-names
9 changes: 9 additions & 0 deletions examples/covering-seq/tests/Tests.idr
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module Tests

import Test.Golden.RunnerHelper

main : IO ()
main = goldenRunner
[ "Covering sequence data structure" `atDir` "data"
, "Generator for covering sequences" `atDir` "gens"
]
35 changes: 35 additions & 0 deletions examples/covering-seq/tests/data/simple-seqs/Main.idr
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import Data.List.Covering

%default total

MaskIIII : BitMask ?
MaskIIII = [True, True, True, True]

x0123 : CoveringSequence ? MaskIIII
x0123 = Hit 0 $ Hit 1 $ Hit 2 $ Hit 3 $ End

x0123' : CoveringSequence ? MaskIIII
x0123' = Hit 0 $ Hit 1 $ Miss 20 $ Hit 2 $ Hit 3 $ Miss 30 $ End

x2301 : CoveringSequence ? MaskIIII
x2301 = Hit 2 $ Hit 3 $ Hit 0 $ Hit 1 $ End

x2301' : CoveringSequence ? MaskIIII
x2301' = Hit 2 $ Hit 3 $ Miss 20 $ Hit 0 $ Hit 1 $ Miss 30 $ End

failing "Can't find an implementation for AtIndex"
x23012 : CoveringSequence ? MaskIIII
x23012 = Hit 2 $ Hit 3 $ Hit 0 $ Hit 1 $ Hit 2 $ End

MaskIIOI : BitMask ?
MaskIIOI = [True, True, False, True]

x013 : CoveringSequence ? MaskIIOI
x013 = Hit 0 $ Hit 1 $ Hit 3 $ End

x103 : CoveringSequence ? MaskIIOI
x103 = Hit 1 $ Hit 0 $ Hit 3 $ End

failing "Can't find an implementation for AtIndex"
badx0123 : CoveringSequence ? MaskIIOI
badx0123 = Hit 0 $ Hit 1 $ Hit 2 $ Hit 3 $ End
1 change: 1 addition & 0 deletions examples/covering-seq/tests/data/simple-seqs/expected
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1/1: Building Main (Main.idr)
6 changes: 6 additions & 0 deletions examples/covering-seq/tests/data/simple-seqs/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
rm -rf build

flock "$1" pack -q install-deps test.ipkg && \
idris2 --find-ipkg --check Main.idr

rm -rf build
3 changes: 3 additions & 0 deletions examples/covering-seq/tests/data/simple-seqs/test.ipkg
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package a-test

depends = covering-seq
27 changes: 27 additions & 0 deletions examples/covering-seq/tests/gens/covering-seqs/Main.idr
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import Data.Fuel
import Data.List
import Data.List.Lazy
import Data.List.Covering.Gen
import Data.String

import System.Random.Pure.StdGen

%default total

submain : {n : _} -> BitMask n -> IO ()
submain bs = do
putStrLn "-----------------------"
putStrLn "bitmask: \{bs}"
putStrLn "-----------------------"
let vals = unGenTryN 10 someStdGen $ genCoveringSequence (limit $ 2 * n) bs
Lazy.for_ vals $ \v => do
let hits = hits v
let verdict = if sort hits == setBits bs then "ok" else "fail, hits are: \{show hits}, expected: \{show $ setBits bs}"
putStrLn "\{v} (\{verdict})"

main : IO ()
main = do
submain [True, True, True, True]
submain [True, False, True, True]
submain [False, False, True, False]
submain [False, False, False, False]
52 changes: 52 additions & 0 deletions examples/covering-seq/tests/gens/covering-seqs/expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
-----------------------
bitmask: 1111
-----------------------
3 3 [1] [3] [2] [0] 5 (ok)
[2] [3] [1] [0] (ok)
[3] [2] [1] 1 [0] 2 (ok)
5 3 3 4 [3] [2] [1] [0] (ok)
1 6 4 2 [3] [0] [2] [1] (ok)
0 1 [3] [2] 7 [1] [0] (ok)
8 5 [3] 5 [2] 7 [1] [0] (ok)
[3] 7 [2] [1] 5 [0] 6 (ok)
[3] [2] 5 [1] [0] (ok)
[3] 4 [2] 3 [1] [0] 2 8 (ok)
-----------------------
bitmask: 1011
-----------------------
3 3 [3] 4 [2] [0] 5 (ok)
[2] [3] [0] (ok)
8 6 [0] [3] 2 [2] 6 (ok)
[3] 3 4 6 1 8 [2] [0] (ok)
[3] 5 0 [2] [0] 3 (ok)
[3] 7 7 [2] [0] (ok)
7 [3] 8 3 7 [2] [0] 7 (ok)
[3] 8 [2] 0 0 5 [0] (ok)
7 [3] [2] 3 8 8 [0] 4 (ok)
[3] 4 [2] 5 [0] 4 2 6 (ok)
-----------------------
bitmask: 0010
-----------------------
3 3 [2] 1 4 (ok)
8 7 5 2 [2] 0 3 8 (ok)
[2] 0 4 (ok)
0 8 [2] (ok)
[2] 4 (ok)
6 1 8 1 6 4 2 [2] (ok)
7 1 [2] 5 7 (ok)
8 5 [2] 7 8 7 3 (ok)
8 5 7 8 [2] 8 6 (ok)
[2] 7 5 5 (ok)
-----------------------
bitmask: 0000
-----------------------
3 3 1 4 4 (ok)
8 7 5 2 2 1 3 8 (ok)
0 4 6 8 5 (ok)
3 4 (ok)
6 1 8 (ok)
4 2 1 2 5 1 2 7 (ok)
5 7 7 7 0 (ok)
7 5 8 6 7 5 (ok)
8 7 6 2 (ok)
8 7 3 5 (ok)
6 changes: 6 additions & 0 deletions examples/covering-seq/tests/gens/covering-seqs/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
rm -rf build

flock "$1" pack -q install-deps test.ipkg && \
pack run test.ipkg

rm -rf build
6 changes: 6 additions & 0 deletions examples/covering-seq/tests/gens/covering-seqs/test.ipkg
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package a-test

depends = covering-seq

executable = a-test
main = Main
12 changes: 12 additions & 0 deletions examples/covering-seq/tests/gens/print/DerivedGen.idr
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module DerivedGen

import Data.List.Covering

import Deriving.DepTyCheck.Gen

%default total

%language ElabReflection

%logging "deptycheck.derive.print" 5
%runElab deriveGenPrinter $ Fuel -> {n : Nat} -> (bs : BitMask n) -> Gen MaybeEmpty $ CoveringSequence n bs
6 changes: 6 additions & 0 deletions examples/covering-seq/tests/gens/print/derive.ipkg
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package derive-test

authors = "Denis Buzdalov"

depends = deptycheck
, covering-seq
Loading