Skip to content

Commit

Permalink
Rename no_use_hack_collections to legacy_arrays
Browse files Browse the repository at this point in the history
Summary:
# What?
Rename `no_use_hack_collections` to `legacy_arrays`.

# Why?
The thrift compiler options help describes this compiler option as follows:
```
DEPRECATED WARNING - Cannot be used with arrays, or stricttypes, must
be used with arraysets. Generate array types in a clowny way, some
may be legacy hack arrays while others normal hack arrays.
```
Based on the above description, `legacy_arrays` describe this option better.

# 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.

# 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.

Reviewed By: rmakheja

Differential Revision: D67602754

fbshipit-source-id: 22cc9ae784f699847463e3d807091de13270ec42
  • Loading branch information
Satish Kumar authored and facebook-github-bot committed Jan 7, 2025
1 parent ef2b40a commit 7749516
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 17 deletions.
22 changes: 7 additions & 15 deletions thrift/compiler/generate/t_hack_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,10 @@ class t_hack_generator : public t_concat_generator {
option_is_specified(options, "shapes_allow_unknown_fields");
array_migration_ = option_is_specified(options, "array_migration");
arrays_ = option_is_specified(options, "arrays");
no_use_hack_collections_ =
option_is_specified(options, "no_use_hack_collections");
legacy_arrays_ = option_is_specified(options, "legacy_arrays");
// Set the future state of compiler options based on the current state.
// A subsequent change will remove the current compiler options.
hack_collections_ = !arrays_ && !no_use_hack_collections_;
legacy_arrays_ = no_use_hack_collections_;
hack_collections_ = !arrays_ && !legacy_arrays_;

nullable_everything_ = option_is_specified(options, "nullable_everything");
const_collections_ = option_is_specified(options, "const_collections");
Expand All @@ -147,16 +145,11 @@ class t_hack_generator : public t_concat_generator {
has_hack_namespace = ns_type_ == HackThriftNamespaceType::HACK ||
ns_type_ == HackThriftNamespaceType::PACKAGE;
has_nested_ns = false;
// no_use_hack_collections_ is only used to migrate away from php gen
if (no_use_hack_collections_ && strict_types_) {
throw std::runtime_error(
"Don't use no_use_hack_collections with strict_types");
} else if (no_use_hack_collections_ && !arraysets_) {
throw std::runtime_error(
"Don't use no_use_hack_collections without arraysets");
} else if (no_use_hack_collections_ && arrays_) {
throw std::runtime_error(
"Don't use no_use_hack_collections with arrays. Just use arrays");
// 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 Expand Up @@ -1203,7 +1196,6 @@ class t_hack_generator : public t_concat_generator {
* True to never use hack collection objects. Only used for migrations
*/
bool legacy_arrays_;
bool no_use_hack_collections_;

/**
* True to use hack collection objects.
Expand Down
2 changes: 1 addition & 1 deletion thrift/compiler/test/fixtures/php-migration/cmd
Original file line number Diff line number Diff line change
@@ -1 +1 @@
hack: hack:array_migration=1,arraysets=1,frommap_construct=1,no_use_hack_collections=1,nullable_everything=1,server=1 src/module.thrift
hack: hack:array_migration=1,arraysets=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,no_use_hack_collections=1,shapes_use_pipe_structure=1 src/module.thrift
hack: hack:shape_construct=1,arraysets=1,shapes=1,legacy_arrays=1,shapes_use_pipe_structure=1 src/module.thrift

0 comments on commit 7749516

Please sign in to comment.