package odoc
OCaml Documentation Generator
Install
Dune Dependency
Authors
Maintainers
Sources
odoc-3.0.0.tbz
sha256=ce84fa7e0cc5f3e8a54e6adeb10826152798b602057b9e46c5ae7e5d5206812b
sha512=9febd413450ca2e3824c9ef7e1c9ae8d8094aa72ed71327a69d8d6b42f6f197b3f3f40d674de0d11fa1242ee0df95c693b5d74467d530704e1339f3a523452f6
doc/src/odoc.xref2/subst.ml.html
Source file subst.ml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969
open Component exception Invalidated type ('a, 'b) or_replaced = Not_replaced of 'a | Replaced of 'b type 'a type_or_replaced = ('a, TypeExpr.t * TypeDecl.Equation.t) or_replaced type 'a module_type_or_replaced = ('a, ModuleType.expr) or_replaced let map_replaced f = function | Not_replaced p -> Not_replaced (f p) | Replaced _ as r -> r open Component open Substitution type nonrec t = t let identity = { module_ = ModuleMap.empty; module_type = ModuleTypeMap.empty; module_type_replacement = ModuleTypeMap.empty; type_ = TypeMap.empty; class_type = TypeMap.empty; type_replacement = TypeMap.empty; path_invalidating_modules = []; unresolve_opaque_paths = false; } let unresolve_opaque_paths s = { s with unresolve_opaque_paths = true } let path_invalidate_module id t = { t with path_invalidating_modules = id :: t.path_invalidating_modules } let add_module id p rp t = { t with module_ = ModuleMap.add id (`Prefixed (p, rp)) t.module_ } let add_module_type id p rp t = { t with module_type = ModuleTypeMap.add id (`Prefixed (p, rp)) t.module_type; } let add_type : Ident.type_ -> Cpath.type_ -> Cpath.Resolved.type_ -> t -> t = fun id p rp t -> { t with type_ = TypeMap.add (id :> Ident.type_) (`Prefixed (p, rp)) t.type_ } let add_class : Ident.type_ -> Cpath.class_type -> Cpath.Resolved.class_type -> t -> t = fun id p rp t -> { t with type_ = TypeMap.add (id :> Ident.type_) (`Prefixed ((p :> Cpath.type_), (rp :> Cpath.Resolved.type_))) t.type_; class_type = TypeMap.add (id :> Ident.type_) (`Prefixed (p, rp)) t.class_type; } let add_class_type : Ident.type_ -> Cpath.class_type -> Cpath.Resolved.class_type -> t -> t = fun id p rp t -> { t with type_ = TypeMap.add (id :> Ident.type_) (`Prefixed ((p :> Cpath.type_), (rp :> Cpath.Resolved.type_))) t.type_; class_type = TypeMap.add (id :> Ident.type_) (`Prefixed (p, rp)) t.class_type; } let add_type_replacement id texp equation t = { t with type_replacement = TypeMap.add id (texp, equation) t.type_replacement; } let add_module_type_replacement path mty t = { t with module_type_replacement = ModuleTypeMap.add path mty t.module_type_replacement; } let add_module_substitution : Ident.module_ -> t -> t = fun id t -> { t with path_invalidating_modules = id :: t.path_invalidating_modules; module_ = ModuleMap.add id `Substituted t.module_; } let rename_module : Ident.module_ -> Ident.module_ -> t -> t = fun id id' t -> { t with module_ = ModuleMap.add id (`Renamed id') t.module_ } let rename_module_type : Ident.module_type -> Ident.module_type -> t -> t = fun id id' t -> { t with module_type = ModuleTypeMap.add id (`Renamed id') t.module_type } let rename_type : Ident.type_ -> Ident.type_ -> t -> t = fun id id' t -> { t with type_ = TypeMap.add id (`Renamed id') t.type_ } let rename_class_type : Ident.type_ -> Ident.type_ -> t -> t = fun id id' t -> { t with class_type = TypeMap.add id (`Renamed id') t.class_type; type_ = TypeMap.add (id :> Ident.type_) (`Renamed (id' :> Ident.type_)) t.type_; } let rec substitute_vars vars t = let open TypeExpr in match t with | Var s -> ( try List.assoc s vars with Not_found -> t) | Any -> Any | Alias (t, str) -> Alias (substitute_vars vars t, str) | Arrow (lbl, t1, t2) -> Arrow (lbl, substitute_vars vars t1, substitute_vars vars t2) | Tuple ts -> Tuple (List.map (substitute_vars vars) ts) | Constr (p, ts) -> Constr (p, List.map (substitute_vars vars) ts) | Polymorphic_variant v -> Polymorphic_variant (substitute_vars_poly_variant vars v) | Object o -> Object (substitute_vars_type_object vars o) | Class (p, ts) -> Class (p, List.map (substitute_vars vars) ts) | Poly (strs, ts) -> Poly (strs, substitute_vars vars ts) | Package p -> Package (substitute_vars_package vars p) and substitute_vars_package vars p = let open TypeExpr.Package in let subst_subst (p, t) = (p, substitute_vars vars t) in { p with substitutions = List.map subst_subst p.substitutions } and substitute_vars_type_object vars o = let open TypeExpr.Object in let subst_field = function | Method m -> Method { m with type_ = substitute_vars vars m.type_ } | Inherit t -> Inherit (substitute_vars vars t) in { o with fields = List.map subst_field o.fields } and substitute_vars_poly_variant vars v = let open TypeExpr.Polymorphic_variant in let subst_element = function | Type t -> Type (substitute_vars vars t) | Constructor c -> let arguments = List.map (substitute_vars vars) c.Constructor.arguments in Constructor { c with arguments } in { v with elements = List.map subst_element v.elements } let rec resolved_module_path : t -> Cpath.Resolved.module_ -> Cpath.Resolved.module_ = fun s p -> match p with | `Local id -> ( if List.mem id s.path_invalidating_modules then raise Invalidated; match try Some (ModuleMap.find (id :> Ident.module_) s.module_) with _ -> None with | Some (`Renamed x) -> `Local x | Some (`Prefixed (_p, rp)) -> rp | Some `Substituted -> `Substituted p | None -> p) | `Gpath _ -> p | `Apply (p1, p2) -> `Apply (resolved_module_path s p1, resolved_module_path s p2) | `Substituted p -> `Substituted (resolved_module_path s p) | `Module (p, n) -> `Module (resolved_parent_path s p, n) | `Alias (p1, p2, p3opt) -> let p2' = module_path s p2 in let up2' = try Cpath.unresolve_module_path p2' with _ -> p2' in let p3opt' = match p3opt with | Some p3 -> Some (resolved_module_path s p3) | None -> None in `Alias (resolved_module_path s p1, up2', p3opt') | `Subst (p1, p2) -> let p1 = match resolved_module_type_path s p1 with | Replaced _ -> (* the left hand side of Subst is a named module type inside a module, it cannot be substituted away *) assert false | Not_replaced p1 -> p1 in `Subst (p1, resolved_module_path s p2) | `Hidden p1 -> `Hidden (resolved_module_path s p1) | `Canonical (p1, p2) -> `Canonical (resolved_module_path s p1, p2) | `OpaqueModule m -> if s.unresolve_opaque_paths then raise Invalidated else `OpaqueModule (resolved_module_path s m) and resolved_parent_path s = function | `Module m -> `Module (resolved_module_path s m) | `ModuleType m -> let p = match resolved_module_type_path s m with | Replaced _ -> assert false | Not_replaced p1 -> p1 in `ModuleType p | `FragmentRoot as x -> x and module_path : t -> Cpath.module_ -> Cpath.module_ = fun s p -> match p with | `Resolved p' -> ( try `Resolved (resolved_module_path s p') with Invalidated -> let path' = Cpath.unresolve_resolved_module_path p' in module_path s path') | `Dot (p', str) -> `Dot (module_path s p', str) | `Module (p', str) -> `Module (resolved_parent_path s p', str) | `Apply (p1, p2) -> `Apply (module_path s p1, module_path s p2) | `Local (id, b) -> ( match try Some (ModuleMap.find (id :> Ident.module_) s.module_) with _ -> None with | Some (`Prefixed (p, _rp)) -> p | Some (`Renamed x) -> `Local (x, b) | Some `Substituted -> `Substituted p | None -> `Local (id, b)) | `Identifier _ -> p | `Substituted p -> `Substituted (module_path s p) | `Forward _ -> p | `Root _ -> p and resolved_module_type_path : t -> Cpath.Resolved.module_type -> (Cpath.Resolved.module_type, ModuleType.expr) or_replaced = fun s p -> match p with | `Local id -> ( if ModuleTypeMap.mem id s.module_type_replacement then Replaced (ModuleTypeMap.find id s.module_type_replacement) else match ModuleTypeMap.find id s.module_type with | `Prefixed (_p, rp) -> Not_replaced rp | `Renamed x -> Not_replaced (`Local x) | exception Not_found -> Not_replaced (`Local id)) | `Gpath _ -> Not_replaced p | `Substituted p -> resolved_module_type_path s p |> map_replaced (fun p -> `Substituted p) | `ModuleType (p, n) -> Not_replaced (`ModuleType (resolved_parent_path s p, n)) | `CanonicalModuleType (mt1, mt2) -> ( match resolved_module_type_path s mt1 with | Not_replaced mt1' -> Not_replaced (`CanonicalModuleType (mt1', mt2)) | x -> x) | `OpaqueModuleType m -> if s.unresolve_opaque_paths then raise Invalidated else resolved_module_type_path s m |> map_replaced (fun x -> `OpaqueModuleType x) | `SubstT (p1, p2) -> ( match (resolved_module_type_path s p1, resolved_module_type_path s p2) with | Not_replaced p1, Not_replaced p2 -> Not_replaced (`SubstT (p1, p2)) | Replaced mt, _ | _, Replaced mt -> Replaced mt) | `AliasModuleType (p1, p2) -> ( match (resolved_module_type_path s p1, resolved_module_type_path s p2) with | Not_replaced p1, Not_replaced p2 -> Not_replaced (`AliasModuleType (p1, p2)) | Replaced mt, _ | _, Replaced mt -> Replaced mt) and module_type_path : t -> Cpath.module_type -> Cpath.module_type module_type_or_replaced = fun s p -> match p with | `Resolved r -> ( try resolved_module_type_path s r |> map_replaced (fun r -> `Resolved r) with Invalidated -> let path' = Cpath.unresolve_resolved_module_type_path r in module_type_path s path') | `Substituted p -> module_type_path s p |> map_replaced (fun r -> `Substituted r) | `Local (id, b) -> if ModuleTypeMap.mem id s.module_type_replacement then Replaced (ModuleTypeMap.find id s.module_type_replacement) else let r = match try Some (ModuleTypeMap.find id s.module_type) with _ -> None with | Some (`Prefixed (p, _rp)) -> p | Some (`Renamed x) -> `Local (x, b) | None -> `Local (id, b) in Not_replaced r | `Identifier _ -> Not_replaced p | `DotMT (p, n) -> Not_replaced (`DotMT (module_path s p, n)) | `ModuleType (p', str) -> Not_replaced (`ModuleType (resolved_parent_path s p', str)) and resolved_type_path : t -> Cpath.Resolved.type_ -> (Cpath.Resolved.type_, TypeExpr.t * TypeDecl.Equation.t) or_replaced = fun s p -> match p with | `CoreType _ as c -> Not_replaced c | `Local id -> ( if TypeMap.mem id s.type_replacement then Replaced (TypeMap.find id s.type_replacement) else match try Some (TypeMap.find id s.type_) with Not_found -> None with | Some (`Prefixed (_p, rp)) -> Not_replaced rp | Some (`Renamed x) -> Not_replaced (`Local x) | None -> Not_replaced (`Local id)) | `CanonicalType (t1, t2) -> ( match resolved_type_path s t1 with | Not_replaced t1' -> Not_replaced (`CanonicalType (t1', t2)) | x -> x) | `Gpath _ -> Not_replaced p | `Substituted p -> resolved_type_path s p |> map_replaced (fun p -> `Substituted p) | `Type (p, n) -> Not_replaced (`Type (resolved_parent_path s p, n)) | `ClassType (p, n) -> Not_replaced (`ClassType (resolved_parent_path s p, n)) | `Class (p, n) -> Not_replaced (`Class (resolved_parent_path s p, n)) and type_path : t -> Cpath.type_ -> Cpath.type_ type_or_replaced = fun s p -> match p with | `Resolved r -> ( try resolved_type_path s r |> map_replaced (fun r -> `Resolved r) with Invalidated -> let path' = Cpath.unresolve_resolved_type_path r in type_path s path') | `Substituted p -> type_path s p |> map_replaced (fun r -> `Substituted r) | `Local (id, b) -> ( if TypeMap.mem id s.type_replacement then Replaced (TypeMap.find id s.type_replacement) else match try Some (TypeMap.find id s.type_) with Not_found -> None with | Some (`Prefixed (p, _rp)) -> Not_replaced p | Some (`Renamed x) -> Not_replaced (`Local (x, b)) | None -> Not_replaced (`Local (id, b))) | `Identifier _ -> Not_replaced p | `DotT (p, n) -> Not_replaced (`DotT (module_path s p, n)) | `Type (p, n) -> Not_replaced (`Type (resolved_parent_path s p, n)) | `Class (p, n) -> Not_replaced (`Class (resolved_parent_path s p, n)) | `ClassType (p, n) -> Not_replaced (`ClassType (resolved_parent_path s p, n)) and resolved_class_type_path : t -> Cpath.Resolved.class_type -> Cpath.Resolved.class_type = fun s p -> match p with | `Local id -> ( match try Some (TypeMap.find id s.class_type) with _ -> None with | Some (`Prefixed (_p, rp)) -> rp | Some (`Renamed x) -> `Local x | None -> `Local id) | `Gpath _ -> p | `Substituted p -> `Substituted (resolved_class_type_path s p) | `ClassType (p, n) -> `ClassType (resolved_parent_path s p, n) | `Class (p, n) -> `Class (resolved_parent_path s p, n) and class_type_path : t -> Cpath.class_type -> Cpath.class_type = fun s p -> match p with | `Resolved r -> ( try `Resolved (resolved_class_type_path s r) with Invalidated -> let path' = Cpath.unresolve_resolved_class_type_path r in class_type_path s path') | `Local (id, b) -> ( match try Some (TypeMap.find id s.class_type) with _ -> None with | Some (`Prefixed (p, _rp)) -> p | Some (`Renamed x) -> `Local (x, b) | None -> `Local (id, b)) | `Identifier _ -> p | `Substituted p -> `Substituted (class_type_path s p) | `DotT (p, n) -> `DotT (module_path s p, n) | `Class (p, n) -> `Class (resolved_parent_path s p, n) | `ClassType (p, n) -> `ClassType (resolved_parent_path s p, n) let rec resolved_signature_fragment : t -> Cfrag.resolved_signature -> Cfrag.resolved_signature = fun t r -> match r with | `Root (`ModuleType p) -> let p = match resolved_module_type_path t p with | Not_replaced p -> p | Replaced _ -> assert false in `Root (`ModuleType p) | `Root (`Module p) -> `Root (`Module (resolved_module_path t p)) | (`Subst _ | `Alias _ | `OpaqueModule _ | `Module _) as x -> (resolved_module_fragment t x :> Cfrag.resolved_signature) and resolved_module_fragment : t -> Cfrag.resolved_module -> Cfrag.resolved_module = fun t r -> match r with | `Subst (mty, f) -> let p = match resolved_module_type_path t mty with | Not_replaced p -> p | Replaced _ -> (* the left hand side of subst is a named module type inside a module, it cannot be substituted *) assert false in `Subst (p, resolved_module_fragment t f) | `Alias (m, f) -> `Alias (resolved_module_path t m, resolved_module_fragment t f) | `Module (sg, n) -> `Module (resolved_signature_fragment t sg, n) | `OpaqueModule m -> `OpaqueModule (resolved_module_fragment t m) and resolved_module_type_fragment : t -> Cfrag.resolved_module_type -> Cfrag.resolved_module_type = fun t r -> match r with | `ModuleType (s, n) -> `ModuleType (resolved_signature_fragment t s, n) and resolved_type_fragment : t -> Cfrag.resolved_type -> Cfrag.resolved_type = fun t r -> match r with | `Type (s, n) -> `Type (resolved_signature_fragment t s, n) | `ClassType (s, n) -> `ClassType (resolved_signature_fragment t s, n) | `Class (s, n) -> `Class (resolved_signature_fragment t s, n) let rec signature_fragment : t -> Cfrag.signature -> Cfrag.signature = fun t r -> match r with | `Resolved f -> `Resolved (resolved_signature_fragment t f) | `Dot (sg, n) -> `Dot (signature_fragment t sg, n) | `Root -> `Root let rec module_fragment : t -> Cfrag.module_ -> Cfrag.module_ = fun t r -> match r with | `Resolved r -> ( try `Resolved (resolved_module_fragment t r) with Invalidated -> let frag' = Cfrag.unresolve_module r in module_fragment t frag') | `Dot (sg, n) -> `Dot (signature_fragment t sg, n) let rec module_type_fragment : t -> Cfrag.module_type -> Cfrag.module_type = fun t r -> match r with | `Resolved r -> ( try `Resolved (resolved_module_type_fragment t r) with Invalidated -> let frag' = Cfrag.unresolve_module_type r in module_type_fragment t frag') | `Dot (sg, n) -> `Dot (signature_fragment t sg, n) let rec type_fragment : t -> Cfrag.type_ -> Cfrag.type_ = fun t r -> match r with | `Resolved r -> ( try `Resolved (resolved_type_fragment t r) with Invalidated -> let frag' = Cfrag.unresolve_type r in type_fragment t frag') | `Dot (sg, n) -> `Dot (signature_fragment t sg, n) let option_ conv s x = match x with Some x -> Some (conv s x) | None -> None let list conv s xs = List.map (conv s) xs let rec type_ s t = let open Component.TypeDecl in let representation = option_ type_decl_representation s t.representation in { t with equation = type_decl_equation s t.equation; representation } and type_decl_representation s t = let open Component.TypeDecl.Representation in match t with | Variant cs -> Variant (List.map (type_decl_constructor s) cs) | Record fs -> Record (List.map (type_decl_field s) fs) | Extensible -> t and type_decl_constructor s t = let open Component.TypeDecl.Constructor in let args = type_decl_constructor_arg s t.args in let res = option_ type_expr s t.res in { t with args; res } and type_poly_var s v = let open Component.TypeExpr.Polymorphic_variant in let map_constr c = let open Constructor in { name = c.name; constant = c.constant; arguments = List.map (type_expr s) c.arguments; doc = c.doc; } in let map_element = function | Type t -> ( match type_expr s t with | Polymorphic_variant v -> v.elements | x -> [ Type x ]) | Constructor c -> [ Constructor (map_constr c) ] in { kind = v.kind; elements = List.flatten (List.map map_element v.elements) } and type_object s o = let open Component.TypeExpr.Object in let map_field = function | Method m -> Method { m with type_ = type_expr s m.type_ } | Inherit t -> Inherit (type_expr s t) in { fields = List.map map_field o.fields; open_ = o.open_ } and type_package s p = let open Component.TypeExpr.Package in let sub (x, y) = (type_fragment s x, type_expr s y) in { path = (match module_type_path s p.path with | Not_replaced p -> p | Replaced (Path p) -> p.p_path | Replaced _ -> (* substituting away a packed module type by a non-path module type is a type error *) assert false); substitutions = List.map sub p.substitutions; } and type_expr s t = let open Component.TypeExpr in match t with | Var s -> Var s | Any -> Any | Alias (t, str) -> Alias (type_expr s t, str) | Arrow (lbl, t1, t2) -> Arrow (lbl, type_expr s t1, type_expr s t2) | Tuple ts -> Tuple (List.map (type_expr s) ts) | Constr (p, ts) -> ( match type_path s p with | Replaced (t, eq) -> let mk_var acc pexpr param = match param.Odoc_model.Lang.TypeDecl.desc with | Any -> acc | Var n -> (n, type_expr s pexpr) :: acc in let vars = List.fold_left2 mk_var [] ts eq.params in substitute_vars vars t | Not_replaced p -> Constr (p, List.map (type_expr s) ts)) | Polymorphic_variant v -> Polymorphic_variant (type_poly_var s v) | Object o -> Object (type_object s o) | Class (p, ts) -> Class (class_type_path s p, List.map (type_expr s) ts) | Poly (strs, ts) -> Poly (strs, type_expr s ts) | Package p -> Package (type_package s p) and simple_expansion : t -> Component.ModuleType.simple_expansion -> Component.ModuleType.simple_expansion = fun s t -> let open Component.ModuleType in match t with | Signature sg -> Signature (signature s sg) | Functor (arg, sg) -> Functor (functor_parameter s arg, simple_expansion s sg) and module_type s t = let open Component.ModuleType in let expr = match t.expr with Some m -> Some (module_type_expr s m) | None -> None in { expr; source_loc = t.source_loc; doc = t.doc; canonical = t.canonical } and module_type_substitution s t = let open Component.ModuleTypeSubstitution in let manifest = module_type_expr s t.manifest in { manifest; doc = t.doc } and functor_parameter s t = let open Component.FunctorParameter in match t with | Named arg -> Named { arg with expr = module_type_expr s arg.expr } | Unit -> Unit and module_type_type_of_desc s t = let open Component.ModuleType in match t with | ModPath p -> ModPath (module_path s p) | StructInclude p -> StructInclude (module_path s p) and u_module_type_expr s t = let open Component.ModuleType.U in match t with | Path p -> ( match module_type_path s p with | Not_replaced p -> Path p | Replaced eqn -> ( match eqn with | Path p -> Path p.p_path | Signature s -> Signature s | TypeOf t -> TypeOf (t.t_desc, t.t_original_path) | With w -> With (w.w_substitutions, w.w_expr) | Functor _ -> (* non functor cannot be substituted away to a functor *) assert false)) | Signature sg -> Signature (signature s sg) | With (subs, e) -> With (List.map (with_module_type_substitution s) subs, u_module_type_expr s e) | TypeOf (t_desc, t_original_path) -> TypeOf (module_type_type_of_desc s t_desc, t_original_path) and module_type_expr s t = let open Component.ModuleType in match t with | Path { p_path; p_expansion } -> ( match module_type_path s p_path with | Not_replaced p_path -> Path { p_path; p_expansion = option_ simple_expansion s p_expansion } | Replaced s -> s) | Signature sg -> Signature (signature s sg) | Functor (arg, expr) -> Functor (functor_parameter s arg, module_type_expr s expr) | With { w_substitutions; w_expansion; w_expr } -> With { w_substitutions = List.map (with_module_type_substitution s) w_substitutions; w_expansion = option_ simple_expansion s w_expansion; w_expr = u_module_type_expr s w_expr; } | TypeOf t -> TypeOf { t with t_desc = module_type_type_of_desc s t.t_desc; t_expansion = option_ simple_expansion s t.t_expansion; } and with_module_type_substitution s sub = let open Component.ModuleType in match sub with | ModuleEq (f, m) -> ModuleEq (module_fragment s f, module_decl s m) | ModuleSubst (f, p) -> ModuleSubst (module_fragment s f, module_path s p) | TypeEq (f, eq) -> TypeEq (type_fragment s f, type_decl_equation s eq) | TypeSubst (f, eq) -> TypeSubst (type_fragment s f, type_decl_equation s eq) | ModuleTypeEq (f, eq) -> ModuleTypeEq (module_type_fragment s f, module_type_expr s eq) | ModuleTypeSubst (f, eq) -> ModuleTypeSubst (module_type_fragment s f, module_type_expr s eq) and module_decl s t = match t with | Alias (p, e) -> Alias (module_path s p, option_ simple_expansion s e) | ModuleType t -> ModuleType (module_type_expr s t) and include_decl s t = match t with | Include.Alias p -> Include.Alias (module_path s p) | ModuleType t -> ModuleType (u_module_type_expr s t) and module_ s t = let open Component.Module in let type_ = module_decl s t.type_ in let canonical = t.canonical in { t with type_; canonical } and module_substitution s m = let open Component.ModuleSubstitution in let manifest = module_path s m.manifest in { manifest; doc = m.doc } and type_decl_field s f = let open Component.TypeDecl.Field in { f with type_ = type_expr s f.type_ } and type_decl_constructor_arg s a = let open Component.TypeDecl.Constructor in match a with | Tuple ts -> Tuple (list type_expr s ts) | Record fs -> Record (list type_decl_field s fs) and type_decl_equation s t = let open Component.TypeDecl.Equation in { t with manifest = option_ type_expr s t.manifest; constraints = List.map (fun (x, y) -> (type_expr s x, type_expr s y)) t.constraints; } and exception_ s e = let open Component.Exception in let res = option_ type_expr s e.res in let args = type_decl_constructor_arg s e.args in { e with args; res } and extension_constructor s c = let open Component.Extension.Constructor in { c with args = type_decl_constructor_arg s c.args; res = option_ type_expr s c.res; } and extension s e = let open Component.Extension in let type_path = match type_path s e.type_path with | Not_replaced p -> p | Replaced (TypeExpr.Constr (p, _), _) -> p | Replaced _ -> (* What else is possible ? *) assert false and constructors = List.map (extension_constructor s) e.constructors in { e with type_path; constructors } and include_ s i = let open Component.Include in { i with decl = include_decl s i.decl; strengthened = option_ module_path s i.strengthened; expansion_ = apply_sig_map_sg s i.expansion_; } and open_ s o = let open Component.Open in { expansion = apply_sig_map_sg s o.expansion; doc = o.doc } and value s v = let open Component.Value in { v with type_ = type_expr s v.type_ } and class_ s c = let open Component.Class in let expansion = option_ class_signature s c.expansion in { c with type_ = class_decl s c.type_; expansion } and class_decl s = let open Component.Class in function | ClassType e -> ClassType (class_type_expr s e) | Arrow (lbl, t, d) -> Arrow (lbl, type_expr s t, class_decl s d) and class_type_expr s = let open Component.ClassType in function | Constr (p, ts) -> Constr (class_type_path s p, List.map (type_expr s) ts) | Signature sg -> Signature (class_signature s sg) and class_type s c = let open Component.ClassType in let expansion = option_ class_signature s c.expansion in { c with expr = class_type_expr s c.expr; expansion } and class_signature_item s = let open Component.ClassSignature in function | Method (id, m) -> Method (id, method_ s m) | InstanceVariable (id, i) -> InstanceVariable (id, instance_variable s i) | Constraint cst -> Constraint (class_constraint s cst) | Inherit e -> Inherit (inherit_ s e) | Comment _ as y -> y and class_signature s sg = let open Component.ClassSignature in { sg with self = option_ type_expr s sg.self; items = List.map (class_signature_item s) sg.items; } and method_ s m = let open Component.Method in { m with type_ = type_expr s m.type_ } and instance_variable s i = let open Component.InstanceVariable in { i with type_ = type_expr s i.type_ } and class_constraint s cst = let open Component.ClassSignature.Constraint in { cst with left = type_expr s cst.left; right = type_expr s cst.right } and inherit_ s ih = let open Component.ClassSignature.Inherit in { ih with expr = class_type_expr s ih.expr } and rename_bound_idents s sg = let open Component.Signature in let new_module_id id = try match ModuleMap.find (id :> Ident.module_) s.module_ with | `Renamed (`LModule _ as x) -> x | `Prefixed (_, _) -> (* This is unusual but can happen when we have TypeOf expressions. It means we're already prefixing this module path, hence we can essentially rename it to whatever we like because it's never going to be referred to. *) Ident.Rename.module_ id | _ -> failwith "Error" with Not_found -> Ident.Rename.module_ id in let new_module_type_id id = try match ModuleTypeMap.find id s.module_type with | `Renamed x -> x | `Prefixed (_, _) -> Ident.Rename.module_type id with Not_found -> Ident.Rename.module_type id in let new_type_id id = try match TypeMap.find (id :> Ident.type_) s.type_ with | `Renamed (`LType _ as x) -> x | `Prefixed (_, _) -> Ident.Rename.type_ id with Not_found -> Ident.Rename.type_ id in let new_class_id id = try match TypeMap.find (id :> Ident.type_) s.class_type with | `Renamed (`LType _ as x) -> x | `Prefixed (_, _) -> Ident.Rename.type_ id with Not_found -> Ident.Rename.type_ id in let new_class_type_id id = try match TypeMap.find (id :> Ident.type_) s.class_type with | `Renamed (`LType _ as x) -> x | `Prefixed (_, _) -> Ident.Rename.type_ id with Not_found -> Ident.Rename.type_ id in function | [] -> (s, List.rev sg) | Module (id, r, m) :: rest -> let id' = new_module_id id in rename_bound_idents (rename_module (id :> Ident.module_) (id' :> Ident.module_) s) (Module (id', r, m) :: sg) rest | ModuleSubstitution (id, m) :: rest -> let id' = new_module_id id in rename_bound_idents (rename_module (id :> Ident.module_) (id' :> Ident.module_) s) (ModuleSubstitution (id', m) :: sg) rest | ModuleType (id, mt) :: rest -> let id' = new_module_type_id id in rename_bound_idents (rename_module_type id id' s) (ModuleType (id', mt) :: sg) rest | ModuleTypeSubstitution (id, mt) :: rest -> let id' = new_module_type_id id in rename_bound_idents (rename_module_type id id' s) (ModuleTypeSubstitution (id', mt) :: sg) rest | Type (id, r, t) :: rest -> let id' = new_type_id id in rename_bound_idents (rename_type (id :> Ident.type_) (id' :> Ident.type_) s) (Type (id', r, t) :: sg) rest | TypeSubstitution (id, t) :: rest -> let id' = new_type_id id in rename_bound_idents (rename_type (id :> Ident.type_) (id' :> Ident.type_) s) (TypeSubstitution (id', t) :: sg) rest | Exception (id, e) :: rest -> let id' = Ident.Rename.exception_ id in rename_bound_idents s (Exception (id', e) :: sg) rest | TypExt e :: rest -> rename_bound_idents s (TypExt e :: sg) rest | Value (id, v) :: rest -> let id' = Ident.Rename.value id in rename_bound_idents s (Value (id', v) :: sg) rest | Class (id, r, c) :: rest -> let id' = new_class_id id in rename_bound_idents (rename_class_type (id :> Ident.type_) (id' :> Ident.type_) s) (Class (id', r, c) :: sg) rest | ClassType (id, r, c) :: rest -> let id' = new_class_type_id id in rename_bound_idents (rename_class_type (id :> Ident.type_) (id' :> Ident.type_) s) (ClassType (id', r, c) :: sg) rest | Include ({ expansion_; _ } as i) :: rest -> let s, items = rename_bound_idents s [] expansion_.items in rename_bound_idents s (Include { i with expansion_ = { expansion_ with items; removed = [] } } :: sg) rest | Open { expansion; doc } :: rest -> let s, items = rename_bound_idents s [] expansion.items in rename_bound_idents s (Open { expansion = { expansion with items; removed = [] }; doc } :: sg) rest | (Comment _ as item) :: rest -> rename_bound_idents s (item :: sg) rest and removed_items s items = let open Component.Signature in List.map (function | RModule (id, p) -> RModule (id, module_path s p) | RType (id, exp, eqn) -> RType (id, type_expr s exp, type_decl_equation s eqn) | RModuleType (id, mty) -> RModuleType (id, module_type_expr s mty)) items and signature s sg = let s, items = rename_bound_idents s [] sg.items in let items, removed, dont_recompile = apply_sig_map s items sg.removed in { sg with items; removed; compiled = sg.compiled && dont_recompile } and apply_sig_map_sg s (sg : Component.Signature.t) = let items, removed, dont_recompile = apply_sig_map s sg.items sg.removed in { sg with items; removed; compiled = sg.compiled && dont_recompile } and apply_sig_map_item s item = let open Component.Signature in match item with | Module (id, r, m) -> Module ( id, r, Component.Delayed.put (fun () -> module_ s (Component.Delayed.get m)) ) | ModuleSubstitution (id, m) -> ModuleSubstitution (id, module_substitution s m) | ModuleType (id, mt) -> ModuleType ( id, Component.Delayed.put (fun () -> module_type s (Component.Delayed.get mt)) ) | ModuleTypeSubstitution (id, mt) -> ModuleTypeSubstitution (id, module_type_substitution s mt) | Type (id, r, t) -> Type ( id, r, Component.Delayed.put (fun () -> type_ s (Component.Delayed.get t)) ) | TypeSubstitution (id, t) -> TypeSubstitution (id, type_ s t) | Exception (id, e) -> Exception (id, exception_ s e) | TypExt e -> TypExt (extension s e) | Value (id, v) -> Value (id, Component.Delayed.put (fun () -> value s (Component.Delayed.get v))) | Class (id, r, c) -> Class (id, r, class_ s c) | ClassType (id, r, c) -> ClassType (id, r, class_type s c) | Include i -> Include (include_ s i) | Open o -> Open (open_ s o) | Comment c -> Comment c and apply_sig_map_items s items = List.rev_map (apply_sig_map_item s) items |> List.rev and apply_sig_map s items removed = let dont_recompile = List.length s.path_invalidating_modules = 0 in (apply_sig_map_items s items, removed_items s removed, dont_recompile)
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>