[ { "psig_desc": [ "Psig_attribute", { "attr_name": { "loc2": { "loc_start": { "pos_fname": "_none_", "pos_lnum": 0, "pos_bol": 0, "pos_cnum": -1 }, "loc_end": { "pos_fname": "_none_", "pos_lnum": 0, "pos_bol": 0, "pos_cnum": -1 }, "loc_ghost": true }, "txt2": "ocaml.text" }, "attr_payload": [ "PStr", [ { "pstr_desc": [ "Pstr_eval", { "pexp_desc": [ "Pexp_constant", [ "Pconst_string", " Tail-modulo-cons optimization.\n\n {b Warning:} this module is unstable and part of\n {{!Compiler_libs}compiler-libs}.\n", { "loc_start": { "pos_fname": "./lambda/tmc.mli", "pos_lnum": 18, "pos_bol": 1236, "pos_cnum": 1236 }, "loc_end": { "pos_fname": "./lambda/tmc.mli", "pos_lnum": 22, "pos_bol": 1358, "pos_cnum": 1360 }, "loc_ghost": false }, null ] ], "pexp_loc": { "loc_start": { "pos_fname": "./lambda/tmc.mli", "pos_lnum": 18, "pos_bol": 1236, "pos_cnum": 1236 }, "loc_end": { "pos_fname": "./lambda/tmc.mli", "pos_lnum": 22, "pos_bol": 1358, "pos_cnum": 1360 }, "loc_ghost": false }, "pexp_loc_stack": [], "pexp_attributes": [] }, [] ], "pstr_loc": { "loc_start": { "pos_fname": "./lambda/tmc.mli", "pos_lnum": 18, "pos_bol": 1236, "pos_cnum": 1236 }, "loc_end": { "pos_fname": "./lambda/tmc.mli", "pos_lnum": 22, "pos_bol": 1358, "pos_cnum": 1360 }, "loc_ghost": false } } ] ], "attr_loc": { "loc_start": { "pos_fname": "./lambda/tmc.mli", "pos_lnum": 18, "pos_bol": 1236, "pos_cnum": 1236 }, "loc_end": { "pos_fname": "./lambda/tmc.mli", "pos_lnum": 22, "pos_bol": 1358, "pos_cnum": 1360 }, "loc_ghost": false } } ], "psig_loc": { "loc_start": { "pos_fname": "./lambda/tmc.mli", "pos_lnum": 18, "pos_bol": 1236, "pos_cnum": 1236 }, "loc_end": { "pos_fname": "./lambda/tmc.mli", "pos_lnum": 22, "pos_bol": 1358, "pos_cnum": 1360 }, "loc_ghost": false } }, { "psig_desc": [ "Psig_attribute", { "attr_name": { "loc2": { "loc_start": { "pos_fname": "_none_", "pos_lnum": 0, "pos_bol": 0, "pos_cnum": -1 }, "loc_end": { "pos_fname": "_none_", "pos_lnum": 0, "pos_bol": 0, "pos_cnum": -1 }, "loc_ghost": true }, "txt2": "ocaml.text" }, "attr_payload": [ "PStr", [ { "pstr_desc": [ "Pstr_eval", { "pexp_desc": [ "Pexp_constant", [ "Pconst_string", " TMC (Tail Modulo Cons) is a code transformation that\n rewrites transformed functions in destination-passing-style, in\n such a way that certain calls that were not in tail position in the\n original program become tail-calls in the transformed program.\n\n As a classic example, the following program\n {|\n let[@tail_mod_cons] rec map f = function\n | [] -> []\n | x :: xs ->\n let y = f x in\n y :: map f xs\n |}\n becomes (expressed in almost-source-form; the translation is in\n fact at the Lambda-level)\n {|\n let rec map f = function\n | [] -> []\n | x :: xs ->\n let y = f x in\n let dst = y :: Placeholder in\n map_dps dst 1 f xs; dst\n and map_dps dst offset f = function\n | [] ->\n dst.offset <- []\n | x :: xs ->\n let y = f x in\n let dst' = y :: Placeholder in\n dst.offset <- dst';\n map_dps dst 1 f fx\n |}\n\n In this example, the expression (y :: map f xs) had a call in\n non-tail-position, and it gets rewritten into tail-calls. TMC\n handles all such cases where the continuation of the call\n (what needs to be done after the return) is a \"construction\", the\n creation of a (possibly nested) data block.\n\n The code transformation generates two versions of the\n input function, the \"direct\" version with the same type and\n behavior as the original one (here just [map]), and\n the \"destination-passing-style\" version (here [map_dps]).\n\n Any call to the original function from outside the let..rec\n declaration gets transformed into a call into the direct version,\n which will itself call the destination-passing-style versions on\n recursive calls that may benefit from it (they are in tail-position\n modulo constructors).\n\n Because of this inherent code duplication, the transformation may\n not always improve performance. In this implementation, TMC is\n opt-in, we only transform functions that the user has annotated\n with an attribute to request the transformation.\n", { "loc_start": { "pos_fname": "./lambda/tmc.mli", "pos_lnum": 24, "pos_bol": 1362, "pos_cnum": 1362 }, "loc_end": { "pos_fname": "./lambda/tmc.mli", "pos_lnum": 77, "pos_bol": 3402, "pos_cnum": 3404 }, "loc_ghost": false }, null ] ], "pexp_loc": { "loc_start": { "pos_fname": "./lambda/tmc.mli", "pos_lnum": 24, "pos_bol": 1362, "pos_cnum": 1362 }, "loc_end": { "pos_fname": "./lambda/tmc.mli", "pos_lnum": 77, "pos_bol": 3402, "pos_cnum": 3404 }, "loc_ghost": false }, "pexp_loc_stack": [], "pexp_attributes": [] }, [] ], "pstr_loc": { "loc_start": { "pos_fname": "./lambda/tmc.mli", "pos_lnum": 24, "pos_bol": 1362, "pos_cnum": 1362 }, "loc_end": { "pos_fname": "./lambda/tmc.mli", "pos_lnum": 77, "pos_bol": 3402, "pos_cnum": 3404 }, "loc_ghost": false } } ] ], "attr_loc": { "loc_start": { "pos_fname": "./lambda/tmc.mli", "pos_lnum": 24, "pos_bol": 1362, "pos_cnum": 1362 }, "loc_end": { "pos_fname": "./lambda/tmc.mli", "pos_lnum": 77, "pos_bol": 3402, "pos_cnum": 3404 }, "loc_ghost": false } } ], "psig_loc": { "loc_start": { "pos_fname": "./lambda/tmc.mli", "pos_lnum": 24, "pos_bol": 1362, "pos_cnum": 1362 }, "loc_end": { "pos_fname": "./lambda/tmc.mli", "pos_lnum": 77, "pos_bol": 3402, "pos_cnum": 3404 }, "loc_ghost": false } }, { "psig_desc": [ "Psig_open", { "popen_expr": "Lambda", "popen_override": "Fresh", "popen_loc": { "loc_start": { "pos_fname": "./lambda/tmc.mli", "pos_lnum": 79, "pos_bol": 3406, "pos_cnum": 3406 }, "loc_end": { "pos_fname": "./lambda/tmc.mli", "pos_lnum": 79, "pos_bol": 3406, "pos_cnum": 3417 }, "loc_ghost": false }, "popen_attributes": [] } ], "psig_loc": { "loc_start": { "pos_fname": "./lambda/tmc.mli", "pos_lnum": 79, "pos_bol": 3406, "pos_cnum": 3406 }, "loc_end": { "pos_fname": "./lambda/tmc.mli", "pos_lnum": 79, "pos_bol": 3406, "pos_cnum": 3417 }, "loc_ghost": false } }, { "psig_desc": [ "Psig_value", { "pval_name": { "loc2": { "loc_start": { "pos_fname": "./lambda/tmc.mli", "pos_lnum": 81, "pos_bol": 3419, "pos_cnum": 3423 }, "loc_end": { "pos_fname": "./lambda/tmc.mli", "pos_lnum": 81, "pos_bol": 3419, "pos_cnum": 3430 }, "loc_ghost": false }, "txt2": "rewrite" }, "pval_type": { "ptyp_desc": [ "Ptyp_arrow", [ "Nolabel" ], { "ptyp_desc": [ "Ptyp_constr", "lambda", [] ], "ptyp_loc": { "loc_start": { "pos_fname": "./lambda/tmc.mli", "pos_lnum": 81, "pos_bol": 3419, "pos_cnum": 3433 }, "loc_end": { "pos_fname": "./lambda/tmc.mli", "pos_lnum": 81, "pos_bol": 3419, "pos_cnum": 3439 }, "loc_ghost": false }, "ptyp_loc_stack": [], "ptyp_attributes": [] }, { "ptyp_desc": [ "Ptyp_constr", "lambda", [] ], "ptyp_loc": { "loc_start": { "pos_fname": "./lambda/tmc.mli", "pos_lnum": 81, "pos_bol": 3419, "pos_cnum": 3443 }, "loc_end": { "pos_fname": "./lambda/tmc.mli", "pos_lnum": 81, "pos_bol": 3419, "pos_cnum": 3449 }, "loc_ghost": false }, "ptyp_loc_stack": [], "ptyp_attributes": [] } ], "ptyp_loc": { "loc_start": { "pos_fname": "./lambda/tmc.mli", "pos_lnum": 81, "pos_bol": 3419, "pos_cnum": 3433 }, "loc_end": { "pos_fname": "./lambda/tmc.mli", "pos_lnum": 81, "pos_bol": 3419, "pos_cnum": 3449 }, "loc_ghost": false }, "ptyp_loc_stack": [], "ptyp_attributes": [] }, "pval_prim": [], "pval_attributes": [], "pval_loc": { "loc_start": { "pos_fname": "./lambda/tmc.mli", "pos_lnum": 81, "pos_bol": 3419, "pos_cnum": 3419 }, "loc_end": { "pos_fname": "./lambda/tmc.mli", "pos_lnum": 81, "pos_bol": 3419, "pos_cnum": 3449 }, "loc_ghost": false } } ], "psig_loc": { "loc_start": { "pos_fname": "./lambda/tmc.mli", "pos_lnum": 81, "pos_bol": 3419, "pos_cnum": 3419 }, "loc_end": { "pos_fname": "./lambda/tmc.mli", "pos_lnum": 81, "pos_bol": 3419, "pos_cnum": 3449 }, "loc_ghost": false } } ]