Skip to content

Commit

Permalink
Add docstring for `source/interprocedural_analyses/type_inference/typ…
Browse files Browse the repository at this point in the history
…eInferenceLocal.ml`

Reviewed By: jasontatton

Differential Revision: D48416805

fbshipit-source-id: 90f5868ef0a8926382d7b18284b7282987b51384
  • Loading branch information
Pradeep Kumar Srinivasan authored and facebook-github-bot committed Aug 17, 2023
1 parent 6f75abc commit 4e21ec3
Showing 1 changed file with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,28 @@
* LICENSE file in the root directory of this source tree.
*)

(* TODO(T132410158) Add a module-level doc comment. *)
(* This module sets up the code needed to infer type annotations for unannotated function
parameters, return type, attributes, and globals.
General idea: Use annotations that are present to infer annotations that are absent.
* The forward pass of the fixpoint propagates types forward in the function: from parameters and
local variables to return types, variables that are assigned to, etc.
For example, if we see `return my_argument` and we know `my_argument` has type `int`, then we can
infer that `int` must be compatible with the type of `x`. If there are no other considerations
(such as other return statements), we can annotate the function as returning `-> int:`. We deal
similarly with `x = my_argument`.
* The backward pass propagates types backward in the function: from return statements, assignment
statements, function calls, etc. to variables and parameters.
For example, if we see `expect_int(my_argument)`, then we can infer that the type of
`my_argument` must be compatible with `int`. If there are no other considerations, we can
annotate the parameter as `my_argument: int`.
* The fixpoint runs the forward and backward passes till there are no more changes to any
variables (or we reach a threshold). *)

open Core
open Ast
Expand Down

0 comments on commit 4e21ec3

Please sign in to comment.