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

[determinacy] big refactor #290

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

Conversation

FissoreD
Copy link
Collaborator

No description provided.

@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
…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
… relational

- fold_left_partial loops over its arguments and modes,
  if the former is shorter than the latter: partial application
  if the two lists have same length: full application
  NEW:
    if the former is longer than then second: we deal with
    variadic function -> all exceeding arguments are considered in output
- comparison between two functionality `f1` and `f2` when `f1` = Any
  and `f2` <> Any, is ok if `f1` does not contain Functional or AssumedFunctional
  subterm
- Modes are wrong if the pred is variadic.
  New: In fold_left_partial if there are more args than modes,
       we suppose the exceeding args are in output mode
- Change unify_func algo:
  New: instead of looking on functionalities, we look on terms
       if one of them is flex we unify their functionalities
- Correct pattern match in infer
New: cmp f1 f2 compares two functionalities. raise an error
     if f1 and f2 are not comparable, i.e.
     when f1 <<= f2 = false and f1 <<= f2 = false

Bug correction:
  the min and max of two functionalities was wrong if the functionalities
  were not comparable: now the use of cmp raises the error if a
  wrong comparison is performed.

Bug in sintax:
  corrected the syntax of some functionality/test files:
  `:functional pred` becomes `func`


Refactor:
  change functionality_leq with the infix operator (<<=)
FissoreD and others added 12 commits December 16, 2024 09:42
…m ScopedTypeExpression

- The typechecker assigns types to terms, this types have modes:
  the node arrow has carries the mode
- To simplify translation from ScopeTypeExpression to TypeAssignement,
  the node Pred has disappeard in favour of a combination of Arrow with mode
  and Prop
- The type mode_arg and all the related auxiliary functions
  have been replaced with Mode.t where Mode is a global
  module in Utils used by Ast, Compiler, Runtime etc...
  the goal is to have a easier way to work with modes
- The DeterminacyChecker benefits from modes attached to types since it has
  no more to find them into the mode map: they are already referenced in the type
  of terms taken into account
- TODO: check if variable representing partial application of predicates
  have correct mode: e.g. in `X = map []`, the variable `X` has the type
  of `X` ha good associated mode?
- remove modes from program
- modes are deduced from types
- modes are added to the symbol map during the creation of the indexing

- add clone function for terms, this is needed since terms contains
  pointers: memory sharing cannot be performed

- macro are cloned before doing beta reduction
  this avoids type assignments to be wrongly assigned by side effects
  (add test for this: see macro_type.elpi)

- typechecker does not perform typechecking if the ty projection of a
  ScopedTerm has been already set (this means that the term has already
  been typechecked)

- pretty printer of scoped term takes a function printing values
  carried by Uvar (Uvar carries a polymorphic object)
- add pretty_raw allowing to print raw types, i.e. types with modes
  and functionality
@FissoreD FissoreD force-pushed the scoped-term-wip branch 5 times, most recently from dcba75e to 6630341 Compare December 19, 2024 09:25
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