Skip to content

Commit e5ea0e4

Browse files
lexidorAtry
andauthored
Require hhvm 4.128 and support autoloading with ext_watchman (#144)
* Require hhvm 4.128 and support autoloading with ext_watchman The hsl is always built-in. ext_watchman and HH\Facts are always available. varray eq vec and darray eq dict is always true. All legacy arrays have been replaced with Hack arrays. * Format the changed files * Fix lint * Allow hhvm-autoload plugin Co-authored-by: Yang, Bo <[email protected]>
1 parent 6e72b74 commit e5ea0e4

12 files changed

+117
-103
lines changed

.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
tests/ export-ignore
22
examples/ export-ignore
33
.hhconfig export-ignore
4+
.hhvmconfig.hdf export-ignore
45
*.hack linguist-language=Hack

.github/workflows/build-and-test.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
matrix:
1414
os: [ ubuntu ]
1515
hhvm:
16-
- '4.102'
16+
- '4.128'
1717
- latest
1818
- nightly
1919
runs-on: ${{matrix.os}}-latest

.hhvmconfig.hdf

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Autoload {
2+
Query = {"expression": ["allof", ["type", "f"], ["suffix", ["anyof", "hack", "php"]], ["not",["anyof",["dirname",".var"],["dirname",".git"]]]]}
3+
}

composer.json

+7-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
"description": "Hack Codegen is a library for programmatically generating Hack code",
44
"keywords": ["code generation", "Hack"],
55
"require": {
6-
"hhvm": "^4.102",
7-
"hhvm/hhvm-autoload": "^2.0|^3.0",
8-
"hhvm/hsl": "^4.0"
6+
"hhvm": "^4.128"
97
},
108
"bin": [ "bin/hh-codegen-verify-signatures", "bin/hh-codegen-verify-signatures.hack" ],
119
"authors": [
@@ -37,6 +35,12 @@
3735
"hhvm/type-assert": "^3.1|^4.0",
3836
"facebook/fbexpect": "^2.6.1",
3937
"hhvm/hhast": "^4.80",
38+
"hhvm/hhvm-autoload": "^2.0|^3.0",
4039
"facebook/difflib": "^1.0"
40+
},
41+
"config": {
42+
"allow-plugins": {
43+
"hhvm/hhvm-autoload": true
44+
}
4145
}
4246
}

examples/dorm/CodegenDorm.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ private function getGetters(): Vector<CodegenMethod> {
184184
}
185185

186186
private function getDatabaseRowShape(): CodegenShape {
187-
$db_fields = varray[];
187+
$db_fields = vec[];
188188
foreach ($this->schema->getFields() as $field) {
189189
$type = $field->getType();
190190
if ($type === \DateTime::class) {

hh_autoload.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@
66
"examples/",
77
"tests/"
88
],
9-
"devFailureHandler": "Facebook\\AutoloadMap\\HHClientFallbackHandler"
9+
"devFailureHandler": "Facebook\\AutoloadMap\\HHClientFallbackHandler",
10+
"useFactsIfAvailable": true
1011
}

src/BaseCodeBuilder.hack

+11-11
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use namespace Facebook\HackCodegen\_Private\Vec as VecP;
1818
* should be used to generate code. For example, Hack code is generated using
1919
* the `HackBuilder` class.
2020
*/
21-
<<__ConsistentConstruct>>
21+
<<__ConsistentConstruct>>
2222
abstract class BaseCodeBuilder {
2323

2424
const string DELIMITER = "\0";
@@ -94,15 +94,15 @@ abstract class BaseCodeBuilder {
9494
return $this;
9595
}
9696

97-
/**
98-
* Add the specified code with a %-placeholder format string, but no further
97+
/**
98+
* Add the specified code with a %-placeholder format string, but no further
9999
* processing.
100-
*
101-
* For example, if there is a newline, any following characters will not be
102-
* indented. This is useful for heredocs.
103-
*
104-
* @see addVerbatim
105-
*/
100+
*
101+
* For example, if there is a newline, any following characters will not be
102+
* indented. This is useful for heredocs.
103+
*
104+
* @see addVerbatim
105+
*/
106106
final public function addVerbatimf(
107107
Str\SprintfFormatString $code,
108108
mixed ...$args
@@ -124,7 +124,7 @@ abstract class BaseCodeBuilder {
124124
*
125125
* This is unsafe. Use `addf` instead if you have a literal format string.
126126
*/
127-
final protected function addvf(string $code, varray<mixed> $args): this {
127+
final protected function addvf(string $code, vec<mixed> $args): this {
128128
if ($code === null) {
129129
return $this;
130130
}
@@ -190,7 +190,7 @@ abstract class BaseCodeBuilder {
190190
* insert a newline. */
191191
final protected function addLineImplvf(
192192
?string $code,
193-
varray<mixed> $args,
193+
vec<mixed> $args,
194194
): this {
195195
return $this->addvf((string)$code, $args)->newLine();
196196
}

src/CodegenFile.hack

+4-4
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ final class CodegenFile {
4545
private vec<CodegenType> $beforeTypes = vec[];
4646
private vec<CodegenType> $afterTypes = vec[];
4747
private vec<CodegenConstant> $consts = vec[];
48-
private vec<CodegenEnum> $enums = vec [];
48+
private vec<CodegenEnum> $enums = vec[];
4949
private bool $doClobber = false;
5050
protected ?CodegenGeneratedFrom $generatedFrom;
5151
private bool $isSignedFile = true;
@@ -411,7 +411,7 @@ final class CodegenFile {
411411
if ($header !== null) {
412412
invariant(
413413
$this->fileType !== CodegenFileType::HACK_STRICT,
414-
'Pseudomains (and pseudomain headers) are not supported in strict files'
414+
'Pseudomains (and pseudomain headers) are not supported in strict files',
415415
);
416416
$builder->ensureNewLine()->add($header)->ensureNewLine();
417417
}
@@ -450,7 +450,7 @@ final class CodegenFile {
450450
if ($footer !== null) {
451451
invariant(
452452
$this->fileType !== CodegenFileType::HACK_STRICT,
453-
'Pseudomains (and pseudomain footers) are not supported in strict files'
453+
'Pseudomains (and pseudomain footers) are not supported in strict files',
454454
);
455455
$builder->ensureEmptyLine()->add($footer)->ensureNewLine();
456456
}
@@ -460,7 +460,7 @@ final class CodegenFile {
460460
private function loadExistingFiles(): ?string {
461461
$file_names = $this->otherFileNames;
462462
$file_names[] = $this->fileName;
463-
$all_content = varray[];
463+
$all_content = vec[];
464464
foreach ($file_names as $file_name) {
465465
if (\file_exists($file_name)) {
466466
$content = Filesystem::readFile($file_name);

src/HackfmtFormatter.hack

+8-22
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,13 @@ use namespace HH\Lib\{Str, Vec};
1313

1414
final class HackfmtFormatter implements ICodegenFormatter {
1515

16-
public function __construct(
17-
private IHackCodegenConfig $config
18-
) {}
16+
public function __construct(private IHackCodegenConfig $config) {}
1917

20-
public function format(
21-
string $code,
22-
string $_file_name,
23-
): string {
24-
$output = varray[];
18+
public function format(string $code, string $_file_name): string {
19+
$output = vec[];
2520
$exit_code = null;
2621

27-
$tempnam = \tempnam(
28-
\sys_get_temp_dir(),
29-
'hack-codegen-hackfmt',
30-
);
22+
$tempnam = \tempnam(\sys_get_temp_dir(), 'hack-codegen-hackfmt');
3123

3224
$options = $this->getFormattedOptions();
3325

@@ -42,20 +34,17 @@ final class HackfmtFormatter implements ICodegenFormatter {
4234
\unlink($tempnam);
4335
}
4436

45-
invariant(
46-
$exit_code === 0,
47-
'Failed to invoke hackfmt',
48-
);
37+
invariant($exit_code === 0, 'Failed to invoke hackfmt');
4938
return Str\join($output, "\n")."\n";
5039
}
5140

5241
<<__Memoize>>
5342
private function getFormattedOptions(): string {
5443
$options = vec[
5544
'--indent-width',
56-
(string) $this->config->getSpacesPerIndentation(),
45+
(string)$this->config->getSpacesPerIndentation(),
5746
'--line-width',
58-
(string) $this->config->getMaxLineLength(),
47+
(string)$this->config->getMaxLineLength(),
5948
];
6049

6150
if ($this->config->shouldUseTabs()) {
@@ -69,9 +58,6 @@ final class HackfmtFormatter implements ICodegenFormatter {
6958
$options[] = '--format-generated-code';
7059
}
7160

72-
return Vec\map(
73-
$options,
74-
\escapeshellarg<>,
75-
) |> Str\join($$, ' ');
61+
return Vec\map($options, \escapeshellarg<>) |> Str\join($$, ' ');
7662
}
7763
}

src/PartiallyGeneratedCode.hack

+8-6
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ final class PartiallyGeneratedCode {
5555
string $existing_code,
5656
?KeyedContainer<string, Traversable<string>> $rekeys = null,
5757
): string {
58-
$merged = varray[];
58+
$merged = vec[];
5959
$existing = $this->extractManualCode($existing_code);
6060
$generated = $this->iterateCodeSections($this->code);
6161
foreach ($generated as $section) {
@@ -110,7 +110,7 @@ final class PartiallyGeneratedCode {
110110
* Extract the generated code and returns it as a string.
111111
*/
112112
public function extractGeneratedCode(): string {
113-
$generated = varray[];
113+
$generated = vec[];
114114
foreach ($this->iterateCodeSections($this->code) as $section) {
115115
list($id, $chunk) = $section;
116116
if ($id === null) {
@@ -146,18 +146,20 @@ final class PartiallyGeneratedCode {
146146

147147
$seen_ids = keyset[];
148148
$current_id = null;
149-
$chunk = varray[];
149+
$chunk = vec[];
150150
$lines = \explode("\n", $code);
151151
foreach ($lines as $line) {
152152
if (\strpos($line, self::$manualEnd) !== false) {
153153
yield tuple($current_id, Str\join($chunk, "\n"));
154-
$chunk = varray[$line];
154+
$chunk = vec[$line];
155155
$current_id = null;
156156

157157
} else if (\preg_match($begin, $line) === 1) {
158158
if ($current_id !== null) {
159159
throw new PartiallyGeneratedCodeException(
160-
'The manual section '.$current_id.' was open before '.
160+
'The manual section '.
161+
$current_id.
162+
' was open before '.
161163
'the previous one was closed',
162164
);
163165
}
@@ -168,7 +170,7 @@ final class PartiallyGeneratedCode {
168170

169171
$chunk[] = $line;
170172
yield tuple(null, Str\join($chunk, "\n"));
171-
$chunk = varray[];
173+
$chunk = vec[];
172174
$current_id = \trim(\preg_replace($begin, '\\1', $line));
173175

174176
if (C\contains($seen_ids, $current_id)) {

src/key-value-render/HackBuilderValues.hack

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ abstract final class HackBuilderValues {
4949
/** Render a `vec`-like PHP array literal */
5050
public static function valueArray<Tv>(
5151
IHackBuilderValueRenderer<Tv> $vr,
52-
): IHackBuilderValueRenderer<varray<Tv>> {
52+
): IHackBuilderValueRenderer<vec<Tv>> {
5353
return new _Private\HackBuilderNativeValueCollectionRenderer(
5454
ContainerType::PHP_ARRAY,
5555
$vr,
@@ -60,7 +60,7 @@ abstract final class HackBuilderValues {
6060
public static function keyValueArray<Tk as arraykey, Tv>(
6161
IHackBuilderKeyRenderer<Tk> $kr,
6262
IHackBuilderValueRenderer<Tv> $vr,
63-
): IHackBuilderValueRenderer<darray<Tk, Tv>> {
63+
): IHackBuilderValueRenderer<dict<Tk, Tv>> {
6464
return new _Private\HackBuilderNativeKeyValueCollectionRenderer(
6565
ContainerType::PHP_ARRAY,
6666
$kr,

0 commit comments

Comments
 (0)