Skip to content

[determinacy] static analysis #290

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

Draft
wants to merge 215 commits into
base: master
Choose a base branch
from
Draft

Conversation

FissoreD
Copy link
Collaborator

@FissoreD FissoreD commented Nov 26, 2024

TODO:

  • func f i:... o:... (makes things more readable sometimes)
    NOTE: in the current parser, we already have a special case when a function has no output.
    In this case the arrow in the type signature is optional
  • Variadic in dtype (no special case for , )
    Ok, but in infer_fold for constants other than comma, we could stop if the call is_wrong, in comma
    we should continue since the cut could make the predicate again deterministic
  • review builtins -> todo: stdlib_map and stdlib_set: their main constructor carries a prediate which may impact the determinacy of calls to add, remove etc...
    A similar example below:
    kind k type.
    type k0 (func -> fprop) -> k.
    func fst-proj k -> (func -> fprop).
    fst-proj (k0 F) F.
    pred g.
    
    func give-rel -> prop.
    give-rel g.
    
    func f.
    f :- fst-proj (k0 give-rel) X, X Y, Y. % Note that Y is not a function, but it is difficult to detect
  • cleanup env
  • What is the type of this p in this code:
    pred p.
    func p.
    func g.
    g :- p.
    Should we consider that p is a function or a relation?
  • in pp_args in data.ml, should I check that all inputs are before all outputs?
  • change determinacy of Arithmetic tests
  • findall signature is not precise enough: it is functional and it returns a list of functional prop if the input is functional
  • Difficult case:
    func map (func A -> B), list A -> list B.
    pred divisor i:int, o:int.
    
    func give-div list int -> (list(list int)).
    give-div L L1 :- map (x\y\x y) [map divisor L] L1. % here map is wrongly called in the list, 
                                                       % i.e. x should be rel
  • In the spilling (it is also true in master) the type inside Spill is wrong. E.g. if t = (Spill({ty;it},_) then ty is wrong, but it.ty is ok
  • In the follwing code, we should check the output of the anonymous functions to have the determinacy expected by its signature
    func f.
    pred rel.
    
    f :-
     F = ((y\ y = rel) : (func -> fprop)),
     F R,
     R.
  • For the overlapping check in Coq, be careful about the problematic-subterms as in here: the two non unifying terms {{fun x => f (H x)}} and {{fun y => g (G y)}} are both replaced with a uvar combined with a constraint relating the uvar with the original term. Wrt overlapping check, this will cause a compilation error of the DB...
  • lambdas are of course, not the only issues for determinacy when loading clauses with implication operator.
    For example, X = f rel, X => f Y, Y with func f -> func
  • error if 2 types only differ by the mode/functionality
  • check for grafting and cut (mut excl)
  • update Elpi.md

@FissoreD FissoreD force-pushed the scoped-term-wip branch 4 times, most recently from 6cf6c26 to 597abd9 Compare November 27, 2024 14:23
@gares
Copy link
Contributor

gares commented Nov 28, 2024

please run make menhir-strip-...

@gares
Copy link
Contributor

gares commented Nov 28, 2024

overall looks good

@FissoreD FissoreD force-pushed the scoped-term-wip branch 2 times, most recently from 75009b3 to c2e5dae Compare December 3, 2024 18:47
@FissoreD FissoreD force-pushed the scoped-term-wip branch 3 times, most recently from 4dbd943 to 9ffb686 Compare December 16, 2024 16:10
@FissoreD FissoreD force-pushed the scoped-term-wip branch 5 times, most recently from 6630341 to 259241a Compare December 19, 2024 09:28
@FissoreD FissoreD force-pushed the scoped-term-wip branch 2 times, most recently from 6ff57dc to fd972ab Compare March 19, 2025 13:32
…ue_type_id

- AST has no modes
  - in the old representation
  the predicate `type p int -> prop.` did not produce a mode for p.
  - therefore, Structured.program has no more a modes field
  - we delegate the computation of modes to Scoped_Quotation_Macro.run
- flatten_arrows
  - objects with type `TArr (l, r)` where `r` has Prop as rightmost type, is
    transformed into `TPred (...)` by flatten_arrows.
  - the result of this call to flatten_arrows is used next to build modes and
    determinacy relations of predicates
- IdPos.t
  - IdPos is a new module representing unique identifiers for elpi objects.
  - using integers is not possible due to the potential fusion of different units
  - therefore we use the position of a parsed terms as its id
  - unique ids are used by the typechecker which sets a unique id to the type
    of global constants
- type of bound variables
  - the type of bound variables is attached to the lam node by the typechecker
- determinacy checker
  - input arguments functionality setting
  - body premise inference and check
spilling is performend in Check.check
this allows determinacy check to be performed on spilled terms
It is not known a priori the functionality of a fresh unification variable,
for example:
the variable `X` in
`t1 :- pi x\ u (y\ X x y), std.assert! (X 1 2 = 2) "bug".`
cannot be deduced from `u` without typechecking.
We reuse the type assignment given by the typechecker
to the term `X x y` to deduce the functionality of `X`

New:
- typeassignment translation to functionality
- get_functionality_of_term instead returning none if a variable is not
  in the env, returns the conversion of its type assignment to functionality
-
- add get_name api to MutableOnce module
- check if Uvar is set before calling get
- if the Uvar is unset return a Functionality.BoundVar
@gares gares changed the title [determinacy] big refactor [determinacy] static analysis Apr 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants