2020-11-25 20:00:34 +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:
|
|
|
|
Denis Merigoux <denis.merigoux@inria.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. *)
|
|
|
|
|
|
|
|
(** Graph representation of the dependencies between scopes in the Catala
|
|
|
|
program. Vertices are functions, x -> y if x is used in the definition of y. *)
|
|
|
|
|
2022-11-21 12:46:17 +03:00
|
|
|
open Catala_utils
|
2022-08-12 23:42:39 +03:00
|
|
|
open Shared_ast
|
2023-01-23 14:19:36 +03:00
|
|
|
|
2023-02-13 17:00:23 +03:00
|
|
|
type vertex = Scope of ScopeName.t | Topdef of TopdefName.t
|
2023-01-23 14:19:36 +03:00
|
|
|
|
|
|
|
module SVertex = struct
|
|
|
|
type t = vertex
|
|
|
|
(* While we enforce that globals don't depend on scopes, and could therefore
|
|
|
|
compute two separate dependency graphs and traverse them one after the
|
|
|
|
other, code-wise it's simpler to have a single graph including both *)
|
|
|
|
|
|
|
|
let compare v1 v2 =
|
|
|
|
match v1, v2 with
|
|
|
|
| Scope s1, Scope s2 -> ScopeName.compare s1 s2
|
2023-02-13 17:00:23 +03:00
|
|
|
| Topdef g1, Topdef g2 -> TopdefName.compare g1 g2
|
2023-01-23 14:19:36 +03:00
|
|
|
| Scope _, _ -> -1
|
|
|
|
| _, Scope _ -> 1
|
2023-02-13 17:00:23 +03:00
|
|
|
| Topdef _, _ | _, Topdef _ -> .
|
2023-01-23 14:19:36 +03:00
|
|
|
|
|
|
|
let equal v1 v2 =
|
|
|
|
match v1, v2 with
|
|
|
|
| Scope s1, Scope s2 -> ScopeName.equal s1 s2
|
2023-02-13 17:00:23 +03:00
|
|
|
| Topdef g1, Topdef g2 -> TopdefName.equal g1 g2
|
|
|
|
| (Scope _ | Topdef _), _ -> false
|
2023-01-23 14:19:36 +03:00
|
|
|
|
|
|
|
let hash = function
|
|
|
|
| Scope s -> ScopeName.hash s
|
2023-02-13 17:00:23 +03:00
|
|
|
| Topdef g -> TopdefName.hash g
|
2023-01-23 14:19:36 +03:00
|
|
|
|
2023-07-12 12:48:46 +03:00
|
|
|
let format ppf = function
|
|
|
|
| Scope s -> ScopeName.format ppf s
|
|
|
|
| Topdef g -> TopdefName.format ppf g
|
2023-03-06 16:42:24 +03:00
|
|
|
|
2023-07-12 12:48:46 +03:00
|
|
|
(* let to_string v = Format.asprintf "%a" format v
|
2023-03-06 16:42:24 +03:00
|
|
|
|
|
|
|
let info = function | Scope s -> ScopeName.get_info s | Topdef g ->
|
|
|
|
TopdefName.get_info g *)
|
2023-01-23 14:19:36 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
module VMap = Map.Make (SVertex)
|
2020-11-25 20:00:34 +03:00
|
|
|
|
|
|
|
(** On the edges, the label is the expression responsible for the use of the
|
|
|
|
function *)
|
2020-12-06 14:32:36 +03:00
|
|
|
module SEdge = struct
|
2020-11-25 20:00:34 +03:00
|
|
|
type t = Pos.t
|
|
|
|
|
|
|
|
let compare = compare
|
|
|
|
let default = Pos.no_pos
|
|
|
|
end
|
|
|
|
|
2020-12-06 14:32:36 +03:00
|
|
|
module SDependencies =
|
|
|
|
Graph.Persistent.Digraph.ConcreteBidirectionalLabeled (SVertex) (SEdge)
|
2022-03-08 17:03:14 +03:00
|
|
|
|
2020-12-06 14:32:36 +03:00
|
|
|
module STopologicalTraversal = Graph.Topological.Make (SDependencies)
|
2020-11-25 20:00:34 +03:00
|
|
|
|
2020-12-06 14:32:36 +03:00
|
|
|
module SSCC = Graph.Components.Make (SDependencies)
|
2020-11-25 20:00:34 +03:00
|
|
|
(** Tarjan's stongly connected components algorithm, provided by OCamlGraph *)
|
|
|
|
|
2023-01-23 14:19:36 +03:00
|
|
|
let rec expr_used_defs e =
|
2022-10-21 16:47:17 +03:00
|
|
|
let recurse_subterms e =
|
|
|
|
Expr.shallow_fold
|
2023-01-23 14:19:36 +03:00
|
|
|
(fun e -> VMap.union (fun _ x _ -> Some x) (expr_used_defs e))
|
|
|
|
e VMap.empty
|
2022-10-21 16:47:17 +03:00
|
|
|
in
|
|
|
|
match e with
|
2023-08-30 18:49:29 +03:00
|
|
|
| ELocation (ToplevelVar { name = v, pos }), _ ->
|
2023-08-31 17:54:45 +03:00
|
|
|
if TopdefName.path v <> [] then VMap.empty
|
|
|
|
else VMap.singleton (Topdef v) pos
|
2023-08-30 18:49:29 +03:00
|
|
|
| (EScopeCall { scope; _ }, m) as e ->
|
2023-10-13 16:09:00 +03:00
|
|
|
if ScopeName.path scope <> [] then recurse_subterms e
|
2023-08-31 17:54:45 +03:00
|
|
|
else VMap.add (Scope scope) (Expr.mark_pos m) (recurse_subterms e)
|
2022-11-17 19:13:35 +03:00
|
|
|
| EAbs { binder; _ }, _ ->
|
2022-10-21 16:47:17 +03:00
|
|
|
let _, body = Bindlib.unmbind binder in
|
2023-01-23 14:19:36 +03:00
|
|
|
expr_used_defs body
|
2022-10-21 16:47:17 +03:00
|
|
|
| e -> recurse_subterms e
|
|
|
|
|
2023-01-23 14:19:36 +03:00
|
|
|
let rule_used_defs = function
|
2024-04-04 11:56:56 +03:00
|
|
|
| Ast.Assertion e
|
|
|
|
| Ast.ScopeVarDefinition { e; _ }
|
|
|
|
| Ast.SubScopeVarDefinition { e; _ } ->
|
2022-10-21 16:47:17 +03:00
|
|
|
(* TODO: maybe this info could be passed on from previous passes without
|
|
|
|
walking through all exprs again *)
|
2023-01-23 14:19:36 +03:00
|
|
|
expr_used_defs e
|
2022-10-21 16:47:17 +03:00
|
|
|
|
2022-09-23 18:43:48 +03:00
|
|
|
let build_program_dep_graph (prgm : 'm Ast.program) : SDependencies.t =
|
2020-12-06 14:32:36 +03:00
|
|
|
let g = SDependencies.empty in
|
2023-01-23 14:19:36 +03:00
|
|
|
let g =
|
|
|
|
TopdefName.Map.fold
|
2023-02-13 17:00:23 +03:00
|
|
|
(fun v _ g -> SDependencies.add_vertex g (Topdef v))
|
|
|
|
prgm.program_topdefs g
|
2023-01-23 14:19:36 +03:00
|
|
|
in
|
2020-12-06 14:32:36 +03:00
|
|
|
let g =
|
2022-11-21 12:12:45 +03:00
|
|
|
ScopeName.Map.fold
|
2023-01-23 14:19:36 +03:00
|
|
|
(fun v _ g -> SDependencies.add_vertex g (Scope v))
|
2020-12-06 14:32:36 +03:00
|
|
|
prgm.program_scopes g
|
|
|
|
in
|
2023-01-23 14:19:36 +03:00
|
|
|
let g =
|
|
|
|
TopdefName.Map.fold
|
|
|
|
(fun glo_name (expr, _) g ->
|
|
|
|
let used_defs = expr_used_defs expr in
|
2023-02-13 17:00:23 +03:00
|
|
|
if VMap.mem (Topdef glo_name) used_defs then
|
2024-04-10 19:39:30 +03:00
|
|
|
Message.error
|
|
|
|
~pos:(Mark.get (TopdefName.get_info glo_name))
|
2024-04-10 18:33:19 +03:00
|
|
|
"The toplevel declaration@ %a@ has@ a@ definition@ that@ refers@ \
|
|
|
|
to@ itself,@ which@ is@ not@ supported@ (Catala does not provide \
|
|
|
|
recursion)"
|
2023-07-12 12:48:46 +03:00
|
|
|
TopdefName.format glo_name;
|
2023-01-23 14:19:36 +03:00
|
|
|
VMap.fold
|
|
|
|
(fun def pos g ->
|
2023-02-13 17:00:23 +03:00
|
|
|
let edge = SDependencies.E.create def pos (Topdef glo_name) in
|
2023-01-23 14:19:36 +03:00
|
|
|
SDependencies.add_edge_e g edge)
|
|
|
|
used_defs g)
|
2023-02-13 17:00:23 +03:00
|
|
|
prgm.program_topdefs g
|
2023-01-23 14:19:36 +03:00
|
|
|
in
|
2022-11-21 12:12:45 +03:00
|
|
|
ScopeName.Map.fold
|
2023-08-10 17:52:39 +03:00
|
|
|
(fun scope_name (scope, _) g ->
|
2022-10-21 16:47:17 +03:00
|
|
|
List.fold_left
|
|
|
|
(fun g rule ->
|
2023-01-23 14:19:36 +03:00
|
|
|
let used_defs = rule_used_defs rule in
|
|
|
|
if VMap.mem (Scope scope_name) used_defs then
|
2024-04-10 19:39:30 +03:00
|
|
|
Message.error
|
|
|
|
~pos:(Mark.get (ScopeName.get_info scope.Ast.scope_decl_name))
|
2024-04-10 18:33:19 +03:00
|
|
|
"The scope@ %a@ is@ calling@ into@ itself@ as@ a@ subscope,@ \
|
|
|
|
which@ is@ not@ supported@ (Catala does not provide recursion)"
|
2023-07-12 12:48:46 +03:00
|
|
|
ScopeName.format scope.Ast.scope_decl_name;
|
2023-01-23 14:19:36 +03:00
|
|
|
VMap.fold
|
|
|
|
(fun used_def pos g ->
|
|
|
|
let edge =
|
|
|
|
SDependencies.E.create used_def pos (Scope scope_name)
|
|
|
|
in
|
2022-10-21 16:47:17 +03:00
|
|
|
SDependencies.add_edge_e g edge)
|
2023-01-23 14:19:36 +03:00
|
|
|
used_defs g)
|
2022-10-21 16:47:17 +03:00
|
|
|
g scope.Ast.scope_decl_rules)
|
2020-12-04 18:40:17 +03:00
|
|
|
prgm.program_scopes g
|
2020-11-25 20:00:34 +03:00
|
|
|
|
2023-02-13 17:00:23 +03:00
|
|
|
let check_for_cycle_in_defs (g : SDependencies.t) : unit =
|
2020-11-25 20:00:34 +03:00
|
|
|
(* if there is a cycle, there will be an strongly connected component of
|
|
|
|
cardinality > 1 *)
|
2020-12-06 14:32:36 +03:00
|
|
|
let sccs = SSCC.scc_list g in
|
2023-03-06 16:42:24 +03:00
|
|
|
match List.find_opt (function [] | [_] -> false | _ -> true) sccs with
|
|
|
|
| None -> ()
|
|
|
|
| Some [] -> assert false
|
|
|
|
| Some (v0 :: _ as scc) ->
|
|
|
|
let module VSet = Set.Make (SVertex) in
|
|
|
|
let scc = VSet.of_list scc in
|
|
|
|
let rec get_cycle cycle cycle_set v =
|
|
|
|
let cycle = v :: cycle in
|
|
|
|
let cycle_set = VSet.add v cycle_set in
|
|
|
|
let succ = SDependencies.succ g v in
|
|
|
|
if List.exists (fun v -> VSet.mem v cycle_set) succ then
|
|
|
|
(* a cycle may be smaller than the scc, in that case we just return the
|
|
|
|
first one found *)
|
|
|
|
let rec cut_after acc = function
|
|
|
|
| [] -> acc
|
|
|
|
| v :: vs ->
|
|
|
|
if List.mem v succ then v :: acc else cut_after (v :: acc) vs
|
|
|
|
in
|
|
|
|
cut_after [] cycle
|
|
|
|
else
|
|
|
|
get_cycle cycle cycle_set
|
|
|
|
(List.find (fun succ -> VSet.mem succ scc) succ)
|
|
|
|
in
|
|
|
|
let cycle = get_cycle [] VSet.empty v0 in
|
2022-03-08 15:04:27 +03:00
|
|
|
let spans =
|
2023-03-06 16:42:24 +03:00
|
|
|
List.map2
|
|
|
|
(fun v1 v2 ->
|
|
|
|
let msg =
|
|
|
|
Format.asprintf "%a is used here in the definition of %a:"
|
2023-07-12 12:48:46 +03:00
|
|
|
SVertex.format v1 SVertex.format v2
|
2023-03-06 16:42:24 +03:00
|
|
|
in
|
|
|
|
let _, edge_pos, _ = SDependencies.find_edge g v1 v2 in
|
2024-04-09 20:08:29 +03:00
|
|
|
msg, edge_pos)
|
2023-03-06 16:42:24 +03:00
|
|
|
cycle
|
|
|
|
(List.tl cycle @ [List.hd cycle])
|
2022-03-08 15:04:27 +03:00
|
|
|
in
|
2024-04-10 19:39:30 +03:00
|
|
|
Message.error ~extra_pos:spans
|
2024-04-10 18:33:19 +03:00
|
|
|
"Cyclic dependency detected between the following scopes:@ @[<hv>%a@]"
|
2023-03-06 16:42:24 +03:00
|
|
|
(Format.pp_print_list
|
|
|
|
~pp_sep:(fun ppf () -> Format.fprintf ppf " →@ ")
|
2023-07-12 12:48:46 +03:00
|
|
|
SVertex.format)
|
2023-03-06 16:42:24 +03:00
|
|
|
(cycle @ [List.hd cycle])
|
2020-11-25 20:00:34 +03:00
|
|
|
|
2023-02-13 17:00:23 +03:00
|
|
|
let get_defs_ordering (g : SDependencies.t) : SVertex.t list =
|
2020-12-06 14:32:36 +03:00
|
|
|
List.rev (STopologicalTraversal.fold (fun sd acc -> sd :: acc) g [])
|
|
|
|
|
|
|
|
module TVertex = struct
|
2022-08-12 23:42:39 +03:00
|
|
|
type t = Struct of StructName.t | Enum of EnumName.t
|
2020-12-06 14:32:36 +03:00
|
|
|
|
|
|
|
let hash x =
|
2022-08-12 23:42:39 +03:00
|
|
|
match x with Struct x -> StructName.hash x | Enum x -> EnumName.hash x
|
2020-12-06 14:32:36 +03:00
|
|
|
|
|
|
|
let compare x y =
|
|
|
|
match x, y with
|
2022-08-12 23:42:39 +03:00
|
|
|
| Struct x, Struct y -> StructName.compare x y
|
|
|
|
| Enum x, Enum y -> EnumName.compare x y
|
2020-12-06 14:32:36 +03:00
|
|
|
| Struct _, Enum _ -> 1
|
|
|
|
| Enum _, Struct _ -> -1
|
|
|
|
|
|
|
|
let equal x y =
|
|
|
|
match x, y with
|
2022-08-12 23:42:39 +03:00
|
|
|
| Struct x, Struct y -> StructName.compare x y = 0
|
|
|
|
| Enum x, Enum y -> EnumName.compare x y = 0
|
2020-12-06 14:32:36 +03:00
|
|
|
| _ -> false
|
|
|
|
|
2023-07-12 12:48:46 +03:00
|
|
|
let format (fmt : Format.formatter) (x : t) : unit =
|
2020-12-06 14:32:36 +03:00
|
|
|
match x with
|
2023-07-12 12:48:46 +03:00
|
|
|
| Struct x -> StructName.format fmt x
|
|
|
|
| Enum x -> EnumName.format fmt x
|
2020-12-06 14:32:36 +03:00
|
|
|
|
|
|
|
let get_info (x : t) =
|
|
|
|
match x with
|
2022-08-12 23:42:39 +03:00
|
|
|
| Struct x -> StructName.get_info x
|
|
|
|
| Enum x -> EnumName.get_info x
|
2020-12-06 14:32:36 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
module TVertexSet = Set.Make (TVertex)
|
|
|
|
|
|
|
|
(** On the edges, the label is the expression responsible for the use of the
|
|
|
|
function *)
|
|
|
|
module TEdge = struct
|
|
|
|
type t = Pos.t
|
|
|
|
|
|
|
|
let compare = compare
|
|
|
|
let default = Pos.no_pos
|
|
|
|
end
|
|
|
|
|
|
|
|
module TDependencies =
|
|
|
|
Graph.Persistent.Digraph.ConcreteBidirectionalLabeled (TVertex) (TEdge)
|
2022-03-08 17:03:14 +03:00
|
|
|
|
2020-12-06 14:32:36 +03:00
|
|
|
module TTopologicalTraversal = Graph.Topological.Make (TDependencies)
|
|
|
|
|
|
|
|
module TSCC = Graph.Components.Make (TDependencies)
|
|
|
|
(** Tarjan's stongly connected components algorithm, provided by OCamlGraph *)
|
|
|
|
|
2022-08-25 18:29:00 +03:00
|
|
|
let rec get_structs_or_enums_in_type (t : typ) : TVertexSet.t =
|
2023-05-17 16:44:57 +03:00
|
|
|
match Mark.remove t with
|
2022-08-25 13:09:51 +03:00
|
|
|
| TStruct s -> TVertexSet.singleton (TVertex.Struct s)
|
|
|
|
| TEnum e -> TVertexSet.singleton (TVertex.Enum e)
|
|
|
|
| TArrow (t1, t2) ->
|
2020-12-06 14:32:36 +03:00
|
|
|
TVertexSet.union
|
2023-02-20 19:21:44 +03:00
|
|
|
(t1
|
|
|
|
|> List.map get_structs_or_enums_in_type
|
|
|
|
|> List.fold_left TVertexSet.union TVertexSet.empty)
|
2020-12-06 14:32:36 +03:00
|
|
|
(get_structs_or_enums_in_type t2)
|
2023-06-15 12:11:56 +03:00
|
|
|
| TClosureEnv | TLit _ | TAny -> TVertexSet.empty
|
2023-11-03 12:29:32 +03:00
|
|
|
| TOption t1 | TArray t1 | TDefault t1 -> get_structs_or_enums_in_type t1
|
2022-08-25 13:09:51 +03:00
|
|
|
| TTuple ts ->
|
|
|
|
List.fold_left
|
|
|
|
(fun acc t -> TVertexSet.union acc (get_structs_or_enums_in_type t))
|
|
|
|
TVertexSet.empty ts
|
|
|
|
|
|
|
|
let build_type_graph (structs : struct_ctx) (enums : enum_ctx) : TDependencies.t
|
|
|
|
=
|
2020-12-06 14:32:36 +03:00
|
|
|
let g = TDependencies.empty in
|
|
|
|
let g =
|
2022-11-21 12:12:45 +03:00
|
|
|
StructName.Map.fold
|
2023-08-30 18:49:29 +03:00
|
|
|
(fun s fields g ->
|
2022-11-21 12:12:45 +03:00
|
|
|
StructField.Map.fold
|
2022-11-17 19:13:35 +03:00
|
|
|
(fun _ typ g ->
|
2020-12-06 14:32:36 +03:00
|
|
|
let def = TVertex.Struct s in
|
|
|
|
let g = TDependencies.add_vertex g def in
|
|
|
|
let used = get_structs_or_enums_in_type typ in
|
|
|
|
TVertexSet.fold
|
|
|
|
(fun used g ->
|
|
|
|
if TVertex.equal used def then
|
2024-04-10 19:39:30 +03:00
|
|
|
Message.error ~pos:(Mark.get typ)
|
2024-04-10 18:33:19 +03:00
|
|
|
"The type@ %a@ is@ defined@ using@ itself,@ which@ is@ \
|
|
|
|
not@ supported@ (Catala does not allow recursive types)"
|
2023-08-30 18:49:29 +03:00
|
|
|
TVertex.format used
|
2020-12-06 14:32:36 +03:00
|
|
|
else
|
2023-05-17 16:44:57 +03:00
|
|
|
let edge = TDependencies.E.create used (Mark.get typ) def in
|
2020-12-06 14:32:36 +03:00
|
|
|
TDependencies.add_edge_e g edge)
|
|
|
|
used g)
|
2022-11-17 19:13:35 +03:00
|
|
|
fields g)
|
2020-12-06 14:32:36 +03:00
|
|
|
structs g
|
|
|
|
in
|
|
|
|
let g =
|
2022-11-21 12:12:45 +03:00
|
|
|
EnumName.Map.fold
|
2023-08-30 18:49:29 +03:00
|
|
|
(fun e cases g ->
|
2022-11-21 12:12:45 +03:00
|
|
|
EnumConstructor.Map.fold
|
2022-11-17 19:13:35 +03:00
|
|
|
(fun _ typ g ->
|
2020-12-06 14:32:36 +03:00
|
|
|
let def = TVertex.Enum e in
|
|
|
|
let g = TDependencies.add_vertex g def in
|
|
|
|
let used = get_structs_or_enums_in_type typ in
|
|
|
|
TVertexSet.fold
|
|
|
|
(fun used g ->
|
|
|
|
if TVertex.equal used def then
|
2024-04-10 19:39:30 +03:00
|
|
|
Message.error ~pos:(Mark.get typ)
|
2024-04-10 18:33:19 +03:00
|
|
|
"The type@ %a@ is@ defined@ using@ itself,@ which@ is@ \
|
|
|
|
not@ supported@ (Catala does not allow recursive types)"
|
2023-08-30 18:49:29 +03:00
|
|
|
TVertex.format used
|
2020-12-06 14:32:36 +03:00
|
|
|
else
|
2023-05-17 16:44:57 +03:00
|
|
|
let edge = TDependencies.E.create used (Mark.get typ) def in
|
2020-12-06 14:32:36 +03:00
|
|
|
TDependencies.add_edge_e g edge)
|
|
|
|
used g)
|
2022-11-17 19:13:35 +03:00
|
|
|
cases g)
|
2020-12-06 14:32:36 +03:00
|
|
|
enums g
|
|
|
|
in
|
|
|
|
g
|
|
|
|
|
2022-08-25 13:09:51 +03:00
|
|
|
let check_type_cycles (structs : struct_ctx) (enums : enum_ctx) : TVertex.t list
|
|
|
|
=
|
2020-12-06 14:32:36 +03:00
|
|
|
let g = build_type_graph structs enums in
|
|
|
|
(* if there is a cycle, there will be an strongly connected component of
|
|
|
|
cardinality > 1 *)
|
|
|
|
let sccs = TSCC.scc_list g in
|
2021-01-29 01:46:39 +03:00
|
|
|
(if List.length sccs < TDependencies.nb_vertex g then
|
2020-12-06 14:32:36 +03:00
|
|
|
let scc = List.find (fun scc -> List.length scc > 1) sccs in
|
2022-03-08 15:04:27 +03:00
|
|
|
let spans =
|
|
|
|
List.flatten
|
|
|
|
(List.map
|
|
|
|
(fun v ->
|
|
|
|
let var_str, var_info =
|
2023-07-12 12:48:46 +03:00
|
|
|
Format.asprintf "%a" TVertex.format v, TVertex.get_info v
|
2022-03-08 15:04:27 +03:00
|
|
|
in
|
|
|
|
let succs = TDependencies.succ_e g v in
|
|
|
|
let _, edge_pos, succ =
|
|
|
|
List.find (fun (_, _, succ) -> List.mem succ scc) succs
|
|
|
|
in
|
2023-07-12 12:48:46 +03:00
|
|
|
let succ_str = Format.asprintf "%a" TVertex.format succ in
|
2022-03-08 15:04:27 +03:00
|
|
|
[
|
2024-04-09 20:08:29 +03:00
|
|
|
"Cycle type " ^ var_str ^ ", declared:", Mark.get var_info;
|
|
|
|
( "Used here in the definition of another cycle type "
|
|
|
|
^ succ_str
|
|
|
|
^ ":",
|
2022-03-08 15:04:27 +03:00
|
|
|
edge_pos );
|
|
|
|
])
|
|
|
|
scc)
|
|
|
|
in
|
2024-04-10 19:39:30 +03:00
|
|
|
Message.error ~extra_pos:spans "Cyclic dependency detected between types!");
|
2021-01-29 01:46:39 +03:00
|
|
|
List.rev (TTopologicalTraversal.fold (fun v acc -> v :: acc) g [])
|