Implement parsing for optional shape fields
commitea3abab5c21c724a9da5dea688cd85bbca0dc646
authorMichael Tingley <tingley@fb.com>
Mon, 27 Feb 2017 19:44:25 +0000 (27 11:44 -0800)
committerHhvm Bot <hhvm-bot@users.noreply.github.com>
Mon, 27 Feb 2017 19:48:07 +0000 (27 11:48 -0800)
treeb0c3cc74e260e002282dd8bc1c742b30070175aa
parentda0523f6c2a4404e29cea80d1ccd266e8e6837a6
Implement parsing for optional shape fields

Summary:
Introduces parsing for optional `shape` fields. An optional shape field is a field whose name is annotated as nullable:

  type ShapeWithOptionalField = shape(
    ?'a' => int
  );

As discussed with dlreeves, we want the entire field, and //not// just the name, to be considered optional in this case. As a result, the type for `shape_field` has been changed as follows:

```lang=diff
  shape_field =
  -  shape_field_name * hint
  +  {
  +    sf_optional : bool;
  +    sf_name : shape_field_name;
  +    sf_hint : hint;
  +  }
```

See comments for discussion on why this design was chosen.

Note that this diff does not update the changes needed for naming, which will prevent optional shape fields from being valid Hack, until we're ready to roll this feature to a wider audience. The main change that will be needed for this to work is in `naming.ml`. `astConstructor.ml` will also need to be updated, although I'm less sure about what this is used for.

Reviewed By: dlreeves

Differential Revision: D4534386

fbshipit-source-id: 501323601b2c1ce840bfdc2f781e07889e42671d
20 files changed:
hphp/hack/src/full_fidelity/classic_ast/classic_ast_mapper.ml
hphp/hack/src/h2tp/mapper/detect_collections.ml
hphp/hack/src/h2tp/mapper/map_ast.ml
hphp/hack/src/h2tp/unparser/unparser.ml
hphp/hack/src/hh_matcher/astConstructor.ml
hphp/hack/src/hh_matcher/matcher.ml
hphp/hack/src/naming/naming.ml
hphp/hack/src/parsing/ast.ml
hphp/hack/src/parsing/parser_hack.ml
hphp/hack/src/utils/errors.ml
hphp/hack/src/utils/errors_sig.ml
hphp/hack/test/typecheck/shape/shape_typedef_with_multiple_optional_tokens.php [new file with mode: 0644]
hphp/hack/test/typecheck/shape/shape_typedef_with_multiple_optional_tokens.php.exp [new file with mode: 0644]
hphp/hack/test/typecheck/shape/shape_typedef_with_multiple_optional_tokens.php.no_format [new file with mode: 0644]
hphp/hack/test/typecheck/shape/shape_typedef_with_optional_field.php [new file with mode: 0644]
hphp/hack/test/typecheck/shape/shape_typedef_with_optional_field.php.exp [new file with mode: 0644]
hphp/hack/test/typecheck/shape/shape_typedef_with_optional_field.php.no_format [new file with mode: 0644]
hphp/hack/test/typecheck/shape/shape_usage_with_optional_field.php [new file with mode: 0644]
hphp/hack/test/typecheck/shape/shape_usage_with_optional_field.php.exp [new file with mode: 0644]
hphp/hack/test/typecheck/shape/shape_usage_with_optional_field.php.no_format [new file with mode: 0644]