2021-02-12 19:20:14 +03:00
|
|
|
(* This file is part of the Catala compiler, a specification language for tax
|
|
|
|
and social benefits computation rules. Copyright (C) 2020 Inria, contributor:
|
|
|
|
Nicolas Chataing <nicolas.chataing@ens.fr>
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
|
|
|
use this file except in compliance with the License. You may obtain a copy of
|
|
|
|
the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
License for the specific language governing permissions and limitations under
|
|
|
|
the License. *)
|
|
|
|
|
|
|
|
(** Scope dependencies computations using {{:http://ocamlgraph.lri.fr/}
|
|
|
|
OCamlgraph} *)
|
|
|
|
|
2022-11-21 12:46:17 +03:00
|
|
|
open Catala_utils
|
2022-11-07 15:50:28 +03:00
|
|
|
open Shared_ast
|
2021-02-12 19:20:14 +03:00
|
|
|
|
|
|
|
(** {1 Scope variables dependency graph} *)
|
|
|
|
|
|
|
|
(** {2 Graph declaration} *)
|
|
|
|
|
|
|
|
(** Vertices: scope variables or subscopes.
|
|
|
|
|
|
|
|
The vertices of the scope dependency graph are either :
|
|
|
|
|
|
|
|
- the variables of the scope ;
|
|
|
|
- the subscopes of the scope.
|
|
|
|
|
|
|
|
Indeed, during interpretation, subscopes are executed atomically. *)
|
|
|
|
|
|
|
|
module Vertex : sig
|
2022-02-28 19:19:06 +03:00
|
|
|
type t =
|
2022-08-25 13:09:51 +03:00
|
|
|
| Var of Shared_ast.ScopeVar.t * Shared_ast.StateName.t option
|
2022-08-17 18:14:29 +03:00
|
|
|
| SubScope of Shared_ast.SubScopeName.t
|
2021-02-12 19:20:14 +03:00
|
|
|
|
|
|
|
val format_t : Format.formatter -> t -> unit
|
|
|
|
|
|
|
|
include Graph.Sig.COMPARABLE with type t := t
|
|
|
|
end
|
|
|
|
|
|
|
|
module Edge : Graph.Sig.ORDERED_TYPE_DFT with type t = Pos.t
|
|
|
|
(** On the edges, the label is the position of the expression responsible for
|
|
|
|
the use of the variable. In the graph, [x -> y] if [x] is used in the
|
|
|
|
definition of [y].*)
|
|
|
|
|
|
|
|
(** Module of the graph, provided by OCamlGraph *)
|
|
|
|
module ScopeDependencies :
|
|
|
|
Graph.Sig.P with type V.t = Vertex.t and type E.label = Edge.t
|
|
|
|
|
|
|
|
(** {2 Graph computations} *)
|
|
|
|
|
|
|
|
(** Returns an ordering of the scope variables and subscope compatible with the
|
|
|
|
dependencies of the computation *)
|
|
|
|
|
2021-02-11 20:48:59 +03:00
|
|
|
val correct_computation_ordering : ScopeDependencies.t -> Vertex.t list
|
2021-02-12 19:20:14 +03:00
|
|
|
(** Returns an ordering of the scope variables and subscope compatible with the
|
|
|
|
dependencies of the computation *)
|
|
|
|
|
2021-02-11 20:48:59 +03:00
|
|
|
val check_for_cycle : Ast.scope -> ScopeDependencies.t -> unit
|
2021-02-12 19:20:14 +03:00
|
|
|
(** Outputs an error in case of cycles. *)
|
|
|
|
|
2021-02-11 20:48:59 +03:00
|
|
|
val build_scope_dependencies : Ast.scope -> ScopeDependencies.t
|
2021-02-12 19:20:14 +03:00
|
|
|
(** Builds the dependency graph of a particular scope *)
|
|
|
|
|
|
|
|
(** {1 Exceptions dependency graph} *)
|
|
|
|
|
2022-07-13 16:00:57 +03:00
|
|
|
module EdgeExceptions : Graph.Sig.ORDERED_TYPE_DFT with type t = Pos.t list
|
|
|
|
|
2022-01-05 11:14:43 +03:00
|
|
|
module ExceptionsDependencies :
|
2022-11-21 12:12:45 +03:00
|
|
|
Graph.Sig.P with type V.t = RuleName.Set.t and type E.label = EdgeExceptions.t
|
2021-02-12 19:20:14 +03:00
|
|
|
|
|
|
|
val build_exceptions_graph :
|
2022-11-21 12:12:45 +03:00
|
|
|
Ast.rule RuleName.Map.t -> Ast.ScopeDef.t -> ExceptionsDependencies.t
|
2021-02-12 19:20:14 +03:00
|
|
|
|
2021-02-11 20:48:59 +03:00
|
|
|
val check_for_exception_cycle : ExceptionsDependencies.t -> unit
|