Skip to content

Commit

Permalink
Add/move some documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
goldfirere committed Nov 21, 2022
1 parent 9891a36 commit 8788ff6
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 19 deletions.
17 changes: 17 additions & 0 deletions parsing/location.mli
Expand Up @@ -22,6 +22,23 @@

open Format

(* loc_ghost: Ghost expressions and patterns:
expressions and patterns that do not appear explicitly in the
source file they have the loc_ghost flag set to true.
Then the profiler will not try to instrument them and the
-annot option will not try to display their type.
Every grammar rule that generates an element with a location must
make at most one non-ghost element, the topmost one.
How to tell whether your location must be ghost:
A location corresponds to a range of characters in the source file.
If the location contains a piece of code that is syntactically
valid (according to the documentation), and corresponds to the
AST node, then the location must be real; in all other cases,
it must be ghost.
*)

type t = Warnings.loc = {
loc_start: Lexing.position;
loc_end: Lexing.position;
Expand Down
18 changes: 1 addition & 17 deletions parsing/parser.mly
Expand Up @@ -115,23 +115,7 @@ let mkoperator =
let mkpatvar ~loc name =
mkpat ~loc (Ppat_var (mkrhs name loc))

(*
Ghost expressions and patterns:
expressions and patterns that do not appear explicitly in the
source file they have the loc_ghost flag set to true.
Then the profiler will not try to instrument them and the
-annot option will not try to display their type.
Every grammar rule that generates an element with a location must
make at most one non-ghost element, the topmost one.
How to tell whether your location must be ghost:
A location corresponds to a range of characters in the source file.
If the location contains a piece of code that is syntactically
valid (according to the documentation), and corresponds to the
AST node, then the location must be real; in all other cases,
it must be ghost.
*)
(* See commentary about ghost locations at the declaration of Location.t *)
let ghexp ~loc d = Exp.mk ~loc:(ghost_loc loc) d
let ghpat ~loc d = Pat.mk ~loc:(ghost_loc loc) d
let ghtyp ~loc d = Typ.mk ~loc:(ghost_loc loc) d
Expand Down
10 changes: 8 additions & 2 deletions typing/typeopt.ml
Expand Up @@ -21,6 +21,9 @@ open Asttypes
open Typedtree
open Lambda

(* Expand a type, looking through ordinary synonyms, private synonyms,
links, and [@@unboxed] types. The returned type will be therefore be none
of these cases. *)
let scrape_ty env ty =
match get_desc ty with
| Tconstr _ ->
Expand All @@ -42,6 +45,7 @@ let scrape_ty env ty =
end
| _ -> ty

(* See [scrape_ty]; this returns the [type_desc] of a scraped [type_expr]. *)
let scrape env ty =
get_desc (scrape_ty env ty)

Expand Down Expand Up @@ -77,13 +81,15 @@ let maybe_pointer_type env ty =
let maybe_pointer exp = maybe_pointer_type exp.exp_env exp.exp_type

type classification =
| Int
| Int (* any immediate type *)
| Float
| Lazy
| Addr (* anything except a float or a lazy *)
| Any

let classify env ty =
(* Classify a ty into a [classification]. Looks through synonyms, using [scrape_ty].
Returning [Any] is safe, though may skip some optimizations. *)
let classify env ty : classification =
let ty = scrape_ty env ty in
if maybe_pointer_type env ty = Immediate then Int
else match get_desc ty with
Expand Down

0 comments on commit 8788ff6

Please sign in to comment.