Skip to content
This repository was archived by the owner on Aug 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
tests/ export-ignore
examples/ export-ignore
.hhconfig export-ignore
.hhvmconfig.hdf export-ignore
*.hack linguist-language=Hack
2 changes: 1 addition & 1 deletion .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
matrix:
os: [ ubuntu ]
hhvm:
- '4.102'
- '4.128'
- latest
- nightly
runs-on: ${{matrix.os}}-latest
Expand Down
3 changes: 3 additions & 0 deletions .hhvmconfig.hdf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Autoload {
Query = {"expression": ["allof", ["type", "f"], ["suffix", ["anyof", "hack", "php"]], ["not",["anyof",["dirname",".var"],["dirname",".git"]]]]}
}
10 changes: 7 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
"description": "Hack Codegen is a library for programmatically generating Hack code",
"keywords": ["code generation", "Hack"],
"require": {
"hhvm": "^4.102",
"hhvm/hhvm-autoload": "^2.0|^3.0",
"hhvm/hsl": "^4.0"
"hhvm": "^4.128"
},
"bin": [ "bin/hh-codegen-verify-signatures", "bin/hh-codegen-verify-signatures.hack" ],
"authors": [
Expand Down Expand Up @@ -37,6 +35,12 @@
"hhvm/type-assert": "^3.1|^4.0",
"facebook/fbexpect": "^2.6.1",
"hhvm/hhast": "^4.80",
"hhvm/hhvm-autoload": "^2.0|^3.0",
"facebook/difflib": "^1.0"
},
"config": {
"allow-plugins": {
"hhvm/hhvm-autoload": true
}
}
}
2 changes: 1 addition & 1 deletion examples/dorm/CodegenDorm.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ private function getGetters(): Vector<CodegenMethod> {
}

private function getDatabaseRowShape(): CodegenShape {
$db_fields = varray[];
$db_fields = vec[];
foreach ($this->schema->getFields() as $field) {
$type = $field->getType();
if ($type === \DateTime::class) {
Expand Down
3 changes: 2 additions & 1 deletion hh_autoload.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
"examples/",
"tests/"
],
"devFailureHandler": "Facebook\\AutoloadMap\\HHClientFallbackHandler"
"devFailureHandler": "Facebook\\AutoloadMap\\HHClientFallbackHandler",
"useFactsIfAvailable": true
}
22 changes: 11 additions & 11 deletions src/BaseCodeBuilder.hack
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use namespace Facebook\HackCodegen\_Private\Vec as VecP;
* should be used to generate code. For example, Hack code is generated using
* the `HackBuilder` class.
*/
<<__ConsistentConstruct>>
<<__ConsistentConstruct>>
abstract class BaseCodeBuilder {

const string DELIMITER = "\0";
Expand Down Expand Up @@ -94,15 +94,15 @@ abstract class BaseCodeBuilder {
return $this;
}

/**
* Add the specified code with a %-placeholder format string, but no further
/**
* Add the specified code with a %-placeholder format string, but no further
* processing.
*
* For example, if there is a newline, any following characters will not be
* indented. This is useful for heredocs.
*
* @see addVerbatim
*/
*
* For example, if there is a newline, any following characters will not be
* indented. This is useful for heredocs.
*
* @see addVerbatim
*/
final public function addVerbatimf(
Str\SprintfFormatString $code,
mixed ...$args
Expand All @@ -124,7 +124,7 @@ abstract class BaseCodeBuilder {
*
* This is unsafe. Use `addf` instead if you have a literal format string.
*/
final protected function addvf(string $code, varray<mixed> $args): this {
final protected function addvf(string $code, vec<mixed> $args): this {
if ($code === null) {
return $this;
}
Expand Down Expand Up @@ -190,7 +190,7 @@ abstract class BaseCodeBuilder {
* insert a newline. */
final protected function addLineImplvf(
?string $code,
varray<mixed> $args,
vec<mixed> $args,
): this {
return $this->addvf((string)$code, $args)->newLine();
}
Expand Down
8 changes: 4 additions & 4 deletions src/CodegenFile.hack
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ final class CodegenFile {
private vec<CodegenType> $beforeTypes = vec[];
private vec<CodegenType> $afterTypes = vec[];
private vec<CodegenConstant> $consts = vec[];
private vec<CodegenEnum> $enums = vec [];
private vec<CodegenEnum> $enums = vec[];
private bool $doClobber = false;
protected ?CodegenGeneratedFrom $generatedFrom;
private bool $isSignedFile = true;
Expand Down Expand Up @@ -411,7 +411,7 @@ final class CodegenFile {
if ($header !== null) {
invariant(
$this->fileType !== CodegenFileType::HACK_STRICT,
'Pseudomains (and pseudomain headers) are not supported in strict files'
'Pseudomains (and pseudomain headers) are not supported in strict files',
);
$builder->ensureNewLine()->add($header)->ensureNewLine();
}
Expand Down Expand Up @@ -450,7 +450,7 @@ final class CodegenFile {
if ($footer !== null) {
invariant(
$this->fileType !== CodegenFileType::HACK_STRICT,
'Pseudomains (and pseudomain footers) are not supported in strict files'
'Pseudomains (and pseudomain footers) are not supported in strict files',
);
$builder->ensureEmptyLine()->add($footer)->ensureNewLine();
}
Expand All @@ -460,7 +460,7 @@ final class CodegenFile {
private function loadExistingFiles(): ?string {
$file_names = $this->otherFileNames;
$file_names[] = $this->fileName;
$all_content = varray[];
$all_content = vec[];
foreach ($file_names as $file_name) {
if (\file_exists($file_name)) {
$content = Filesystem::readFile($file_name);
Expand Down
30 changes: 8 additions & 22 deletions src/HackfmtFormatter.hack
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,13 @@ use namespace HH\Lib\{Str, Vec};

final class HackfmtFormatter implements ICodegenFormatter {

public function __construct(
private IHackCodegenConfig $config
) {}
public function __construct(private IHackCodegenConfig $config) {}

public function format(
string $code,
string $_file_name,
): string {
$output = varray[];
public function format(string $code, string $_file_name): string {
$output = vec[];
$exit_code = null;

$tempnam = \tempnam(
\sys_get_temp_dir(),
'hack-codegen-hackfmt',
);
$tempnam = \tempnam(\sys_get_temp_dir(), 'hack-codegen-hackfmt');

$options = $this->getFormattedOptions();

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

invariant(
$exit_code === 0,
'Failed to invoke hackfmt',
);
invariant($exit_code === 0, 'Failed to invoke hackfmt');
return Str\join($output, "\n")."\n";
}

<<__Memoize>>
private function getFormattedOptions(): string {
$options = vec[
'--indent-width',
(string) $this->config->getSpacesPerIndentation(),
(string)$this->config->getSpacesPerIndentation(),
'--line-width',
(string) $this->config->getMaxLineLength(),
(string)$this->config->getMaxLineLength(),
];

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

return Vec\map(
$options,
\escapeshellarg<>,
) |> Str\join($$, ' ');
return Vec\map($options, \escapeshellarg<>) |> Str\join($$, ' ');
}
}
14 changes: 8 additions & 6 deletions src/PartiallyGeneratedCode.hack
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ final class PartiallyGeneratedCode {
string $existing_code,
?KeyedContainer<string, Traversable<string>> $rekeys = null,
): string {
$merged = varray[];
$merged = vec[];
$existing = $this->extractManualCode($existing_code);
$generated = $this->iterateCodeSections($this->code);
foreach ($generated as $section) {
Expand Down Expand Up @@ -110,7 +110,7 @@ final class PartiallyGeneratedCode {
* Extract the generated code and returns it as a string.
*/
public function extractGeneratedCode(): string {
$generated = varray[];
$generated = vec[];
foreach ($this->iterateCodeSections($this->code) as $section) {
list($id, $chunk) = $section;
if ($id === null) {
Expand Down Expand Up @@ -146,18 +146,20 @@ final class PartiallyGeneratedCode {

$seen_ids = keyset[];
$current_id = null;
$chunk = varray[];
$chunk = vec[];
$lines = \explode("\n", $code);
foreach ($lines as $line) {
if (\strpos($line, self::$manualEnd) !== false) {
yield tuple($current_id, Str\join($chunk, "\n"));
$chunk = varray[$line];
$chunk = vec[$line];
$current_id = null;

} else if (\preg_match($begin, $line) === 1) {
if ($current_id !== null) {
throw new PartiallyGeneratedCodeException(
'The manual section '.$current_id.' was open before '.
'The manual section '.
$current_id.
' was open before '.
'the previous one was closed',
);
}
Expand All @@ -168,7 +170,7 @@ final class PartiallyGeneratedCode {

$chunk[] = $line;
yield tuple(null, Str\join($chunk, "\n"));
$chunk = varray[];
$chunk = vec[];
$current_id = \trim(\preg_replace($begin, '\\1', $line));

if (C\contains($seen_ids, $current_id)) {
Expand Down
4 changes: 2 additions & 2 deletions src/key-value-render/HackBuilderValues.hack
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ abstract final class HackBuilderValues {
/** Render a `vec`-like PHP array literal */
public static function valueArray<Tv>(
IHackBuilderValueRenderer<Tv> $vr,
): IHackBuilderValueRenderer<varray<Tv>> {
): IHackBuilderValueRenderer<vec<Tv>> {
return new _Private\HackBuilderNativeValueCollectionRenderer(
ContainerType::PHP_ARRAY,
$vr,
Expand All @@ -60,7 +60,7 @@ abstract final class HackBuilderValues {
public static function keyValueArray<Tk as arraykey, Tv>(
IHackBuilderKeyRenderer<Tk> $kr,
IHackBuilderValueRenderer<Tv> $vr,
): IHackBuilderValueRenderer<darray<Tk, Tv>> {
): IHackBuilderValueRenderer<dict<Tk, Tv>> {
return new _Private\HackBuilderNativeKeyValueCollectionRenderer(
ContainerType::PHP_ARRAY,
$kr,
Expand Down
Loading