Skip to content

Commit

Permalink
Make legacy_arrays imply arraysets
Browse files Browse the repository at this point in the history
Summary:
# What?
Make `legacy_arrays` imply `arraysets`.

# Why?
`legacy_arrays` require `arraysets`. There is no reason for `arraysets` to appear explicitly.

# Fixtures
Generated fixtures must not change.

# Context
`arraysets`, `no_use_hack_collections`, `stricttypes`, `array_migration`, `shape_arraykeys`, `const_collections` are all compiler options that control the generation of container fields. To make code generator simpler and easier to reason about, identify which of these can be removed/merged.

The new options based on the ones that are currently in use:

`legacy_arrays` replaces `no_use_hack_collections`.
`hack_collections`, which was the implicit default in the absence of `arrays` and `no_use_hack_collections`, is now explicit.
`arrays` will eventually become the default and cease to exist as an explicit option.
`const_collections` imply `hack_collections` and `hack_collections` must not appear explicitly in the presence of `const_collections`.
`legacy_arrays` imply `array_sets` and `arraysets` must not appear explicitly in the presence of `legacy_arrays`.

# The steps
The item in bold corresponds to the current diff.
1. Use new compiler options based on the ones that already exist.
1. Make arrays the default option.
1. Use the legacy arrays + hack collections logical equivalent of arrays.
1. Introduce hack collections wherever necessary.
1. Replace no use hack collections with legacy arrays.
1. Remove arraysets if arrays present.
1. Rename `no_use_hack_collections` compiler option to `legacy_arrays`.
1. Add `hack_collections` compiler option.
1. Remove references to the `arrays` compiler option.
1. Delete the `arrays` compiler option.
1. Remove `const_collections` if not `hack_collections`.
1. Make `const_collections` imply `hack_collections`.
1. **Make `legacy_arrays` imply `arraysets`**.

Reviewed By: rmakheja

Differential Revision: D67727031

fbshipit-source-id: 8db213c5ef116af96ee5a648ebb0d0f3b8280eaf
  • Loading branch information
Satish Kumar authored and facebook-github-bot committed Jan 11, 2025
1 parent 8009217 commit 0ce65a8
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class t_hack_generator : public t_concat_generator {
json_ = option_is_specified(options, "json");
phps_ = option_is_specified(options, "server");
strict_types_ = option_is_specified(options, "stricttypes");
arraysets_ = option_is_specified(options, "arraysets");
auto explicit_arraysets = option_is_specified(options, "arraysets");
no_nullables_ = option_is_specified(options, "nonullables");
from_map_construct_ = option_is_specified(options, "frommap_construct");
shapes_ = option_is_specified(options, "shapes");
Expand Down Expand Up @@ -144,16 +144,21 @@ class t_hack_generator : public t_concat_generator {
ns_type_ == HackThriftNamespaceType::PACKAGE;
has_nested_ns = false;

if (legacy_arrays_ && explicit_arraysets) {
throw std::runtime_error(
"Don't use arraysets with legacy_arrays, because legacy_arrays implies arraysets.");
}
arraysets_ = explicit_arraysets || legacy_arrays_;

if (const_collections_ && explicit_hack_collections) {
throw std::runtime_error(
"Don't use hack_collections with const_collections, because const_collections implies hack_collections.");
}
hack_collections_ = explicit_hack_collections || const_collections_;

// legacy_arrays_ is only used to migrate away from php gen
if (legacy_arrays_ && strict_types_) {
throw std::runtime_error("Don't use legacy_arrays with strict_types");
} else if (legacy_arrays_ && !arraysets_) {
throw std::runtime_error("Don't use legacy_arrays without arraysets");
} else if (arraysets_ && !(legacy_arrays_ || hack_collections_)) {
throw std::runtime_error(
"Don't use arraysets without either legacy_arrays or hack_collections");
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
hack: hack:array_migration=1,arraysets=1,frommap_construct=1,legacy_arrays=1,nullable_everything=1,server=1 src/module.thrift
hack: hack:array_migration=1,frommap_construct=1,legacy_arrays=1,nullable_everything=1,server=1 src/module.thrift
Original file line number Diff line number Diff line change
@@ -1 +1 @@
hack: hack:shape_construct=1,arraysets=1,shapes=1,legacy_arrays=1,shapes_use_pipe_structure=1 src/module.thrift
hack: hack:shape_construct=1,shapes=1,legacy_arrays=1,shapes_use_pipe_structure=1 src/module.thrift

0 comments on commit 0ce65a8

Please sign in to comment.