Skip to content
This repository was archived by the owner on Aug 25, 2025. It is now read-only.

Commit b01b561

Browse files
committed
Stop depending on namespace fallback for functions and constants
These changes generated by HHAST.
1 parent 0c086f7 commit b01b561

27 files changed

+167
-165
lines changed

.hhconfig

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
assume_php=false
2-
enable_experimental_tc_features = safe_pass_by_ref, safe_array, safe_vector_array, contextual_inference
2+
enable_experimental_tc_features = no_fallback_in_namespaces
3+
safe_array = true
4+
safe_vector_array = true
35

46
# ignore HHAST as:
57
# - otherwise, we get a circular dependency

examples/dorm/CodegenDorm.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ public function generate(): void {
5050
->addMethods($this->getGetters())
5151
->addTypeConst('TData', $this->getDatabaseRowShape()->render());
5252

53-
$rc = new \ReflectionClass(get_class($this->schema));
53+
$rc = new \ReflectionClass(\get_class($this->schema));
5454
$path = $rc->getFileName();
55-
$pos = strrpos($path, '/');
56-
$dir = substr($path, 0, $pos + 1);
55+
$pos = \strrpos($path, '/');
56+
$dir = \substr($path, 0, $pos + 1);
5757
$gen_from = 'codegen.php '.$this->getSchemaName().'Schema';
5858

5959
// This generates a file (we pass the file name) that contains the

examples/dorm/CodegenMutator.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ public function generate(): void {
5454
->addMethod($this->getCheckRequiredFieldsMethod())
5555
->addMethods($this->getSetters());
5656

57-
$rc = new \ReflectionClass(get_class($this->schema));
57+
$rc = new \ReflectionClass(\get_class($this->schema));
5858
$path = $rc->getFileName();
59-
$pos = strrpos($path, '/');
60-
$dir = substr($path, 0, $pos + 1);
59+
$pos = \strrpos($path, '/');
60+
$dir = \substr($path, 0, $pos + 1);
6161
$gen_from = 'codegen.php '.$rc->getShortName();
6262

6363
// This generates a file (we pass the file name) that contains the

src/BaseCodeBuilder.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,24 +66,24 @@ final public function addvf(string $code, array<mixed> $args): this {
6666
if ($code === null) {
6767
return $this;
6868
}
69-
$code = vsprintf($code, $args);
69+
$code = \vsprintf($code, $args);
7070

7171
// break into lines and add one by one to handle indentation
7272
$lines = Str\split($code, "\n");
73-
$last_line = array_pop(&$lines);
73+
$last_line = \array_pop(&$lines);
7474
foreach ($lines as $line) {
7575
$this->addLine($line);
7676
}
7777

78-
if (trim($last_line) === '') {
78+
if (\trim($last_line) === '') {
7979
return $this;
8080
}
8181

8282
// if we're in a new line, insert indentation
8383
if ($this->isNewLine) {
8484
if ($this->indentationLevel !== 0) {
8585
$n = $this->config->getSpacesPerIndentation() * $this->indentationLevel;
86-
$this->code->append(str_repeat(' ', $n));
86+
$this->code->append(\str_repeat(' ', $n));
8787
}
8888
$this->isNewLine = false;
8989
}
@@ -184,7 +184,7 @@ final public function addWithSuggestedLineBreaksf(
184184
SprintfFormatString $code,
185185
mixed ...$args
186186
): this {
187-
return $this->addWithSuggestedLineBreaks(vsprintf($code, $args));
187+
return $this->addWithSuggestedLineBreaks(\vsprintf($code, $args));
188188
}
189189

190190
/**
@@ -206,8 +206,8 @@ final public function addWithSuggestedLineBreaks(?string $code): this {
206206
return $this;
207207
}
208208

209-
if (count(debug_backtrace()) > 30) {
210-
hphpd_break();
209+
if (\count(\debug_backtrace()) > 30) {
210+
\hphpd_break();
211211
}
212212

213213
// If there's more than 1 line, add them 1 by 1
@@ -228,7 +228,7 @@ final public function addWithSuggestedLineBreaks(?string $code): this {
228228
$max_length = $max_length - 2;
229229
}
230230

231-
$lines_with_sugg_breaks = explode(self::DELIMITER, $code);
231+
$lines_with_sugg_breaks = \explode(self::DELIMITER, $code);
232232
$final_lines = vec[];
233233
foreach ($lines_with_sugg_breaks as $line) {
234234
if (!$line) {
@@ -242,7 +242,7 @@ final public function addWithSuggestedLineBreaks(?string $code): this {
242242
$last_line = C\lastx($final_lines);
243243
$final_lines = Vec\take($final_lines, C\count($final_lines) - 1);
244244
$composite_line = $last_line.' '.$line;
245-
if (strlen($composite_line) > $max_length) {
245+
if (\strlen($composite_line) > $max_length) {
246246
$final_lines[] = $last_line;
247247
$final_lines[] = $line;
248248
} else {
@@ -251,7 +251,7 @@ final public function addWithSuggestedLineBreaks(?string $code): this {
251251
}
252252
}
253253
}
254-
return $this->add(implode("\n ", $final_lines));
254+
return $this->add(\implode("\n ", $final_lines));
255255
}
256256

257257
/**
@@ -276,8 +276,8 @@ final protected static function checkIfLineIsTooLong(
276276
int $max_length,
277277
): bool {
278278
$line_too_long = false;
279-
foreach (explode("\n", $code) as $line) {
280-
if (strlen($line) > $max_length) {
279+
foreach (\explode("\n", $code) as $line) {
280+
if (\strlen($line) > $max_length) {
281281
$line_too_long = true;
282282
break;
283283
}

src/CodegenClass.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function setExtends(string $name): this {
4848
}
4949

5050
public function setExtendsf(SprintfFormatString $name, mixed ...$args): this {
51-
$this->extendsClass = vsprintf($name, $args);
51+
$this->extendsClass = \vsprintf($name, $args);
5252
return $this;
5353
}
5454

@@ -101,11 +101,11 @@ public function addConstructorWrapperFunc(
101101
$re = '/\$[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/';
102102
foreach ($param_full as $str) {
103103
$matches = array();
104-
if (preg_match_all($re, $str, &$matches)) {
104+
if (\preg_match_all($re, $str, &$matches)) {
105105
$param_names = Vec\concat($param_names, $matches[0]);
106106
}
107107
}
108-
$params_str = implode(', ', $param_names);
108+
$params_str = \implode(', ', $param_names);
109109
$body = 'return new '.$this->getName().'('.$params_str.');';
110110

111111
$this->wrapperFunc = (

src/CodegenClassBase.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function addGenericf(
6969
SprintfFormatString $format,
7070
mixed ...$args
7171
): this {
72-
$this->addGenerics(vsprintf($format, $args));
72+
$this->addGenerics(\vsprintf($format, $args));
7373
return $this;
7474
}
7575

@@ -109,7 +109,7 @@ protected function getTraits(): vec<string> {
109109
$this->traits,
110110
$trait ==> {
111111
$name = $trait->getName();
112-
return strstr($name, '<', true) ?: $name;
112+
return \strstr($name, '<', true) ?: $name;
113113
},
114114
);
115115
}
@@ -146,7 +146,7 @@ public function addPartiallyAbstractTypeConst(
146146
?string $comment = null,
147147
): this {
148148
return $this->addConst(
149-
sprintf('type %s as %s', $name, $constraint),
149+
\sprintf('type %s as %s', $name, $constraint),
150150
$type,
151151
$comment,
152152
HackBuilderValues::literal(),
@@ -159,7 +159,7 @@ public function addAbstractTypeConst(
159159
?string $comment = null,
160160
): this {
161161
return $this->addAbstractConst(
162-
sprintf('type %s as%s%s', $name, HackBuilder::DELIMITER, $type),
162+
\sprintf('type %s as%s%s', $name, HackBuilder::DELIMITER, $type),
163163
$comment,
164164
);
165165
}
@@ -170,8 +170,8 @@ public function addClassNameConst(
170170
?string $comment = null,
171171
): this {
172172
return $this->addConst(
173-
sprintf('classname<%s> %s', $type, $name),
174-
sprintf('%s::class', $type),
173+
\sprintf('classname<%s> %s', $type, $name),
174+
\sprintf('%s::class', $type),
175175
$comment,
176176
HackBuilderValues::literal(),
177177
);
@@ -183,7 +183,7 @@ public function addAbstractClassNameConst(
183183
?string $comment = null,
184184
): this {
185185
return $this->addAbstractConst(
186-
sprintf('classname<%s> %s', $type, $name),
186+
\sprintf('classname<%s> %s', $type, $name),
187187
$comment,
188188
);
189189
}
@@ -278,7 +278,7 @@ protected function buildGenericsDeclaration(): string {
278278
$$,
279279
$decl ==> ' '.$decl.",\n",
280280
)
281-
|> implode("", $$)
281+
|> \implode("", $$)
282282
|> Str\strip_suffix($$, ",\n")
283283
|> "\n <\n".$$."\n >";
284284
}
@@ -375,10 +375,10 @@ public function appendToBuilder(HackBuilder $builder): HackBuilder {
375375
$generated_from =
376376
$this->generatedFrom ? $this->generatedFrom->render() : null;
377377

378-
$doc_block_parts = array_filter(array($this->docBlock, $generated_from));
378+
$doc_block_parts = \array_filter(array($this->docBlock, $generated_from));
379379

380380
if ($doc_block_parts) {
381-
$builder->addDocBlock(implode("\n\n", $doc_block_parts));
381+
$builder->addDocBlock(\implode("\n\n", $doc_block_parts));
382382
}
383383

384384
$wrapper_func = $this->wrapperFunc;
@@ -433,7 +433,7 @@ public function getImplements(): vec<string> {
433433
$this->interfaces,
434434
$interface ==> {
435435
$name = $interface->getName();
436-
return strstr($name, '<', true) ?: $name;
436+
return \strstr($name, '<', true) ?: $name;
437437
},
438438
);
439439
}

src/CodegenFactoryTrait.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ final public function codegenFilef(
2727
SprintfFormatString $format,
2828
mixed ...$args
2929
): CodegenFile {
30-
return $this->codegenFile(vsprintf($format, $args));
30+
return $this->codegenFile(\vsprintf($format, $args));
3131
}
3232

3333
final public function codegenFunction(string $name): CodegenFunction {
@@ -38,7 +38,7 @@ final public function codegenFunctionf(
3838
SprintfFormatString $format,
3939
mixed ...$args
4040
): CodegenFunction {
41-
return $this->codegenFunction(vsprintf($format, $args));
41+
return $this->codegenFunction(\vsprintf($format, $args));
4242
}
4343

4444
final public function codegenClass(string $name): CodegenClass {
@@ -49,7 +49,7 @@ final public function codegenClassf(
4949
SprintfFormatString $format,
5050
mixed ...$args
5151
): CodegenClass {
52-
return $this->codegenClass(vsprintf($format, $args));
52+
return $this->codegenClass(\vsprintf($format, $args));
5353
}
5454

5555
final public function codegenEnum(
@@ -75,7 +75,7 @@ final public function codegenMethodf(
7575
SprintfFormatString $format,
7676
mixed ...$args
7777
): CodegenMethod {
78-
return $this->codegenMethod(vsprintf($format, $args));
78+
return $this->codegenMethod(\vsprintf($format, $args));
7979
}
8080

8181
final public function codegenHackBuilder(): HackBuilder {
@@ -102,7 +102,7 @@ final public function codegenPropertyf(
102102
SprintfFormatString $format,
103103
mixed ...$args
104104
): CodegenProperty {
105-
return $this->codegenProperty(vsprintf($format, $args));
105+
return $this->codegenProperty(\vsprintf($format, $args));
106106
}
107107

108108
final public function codegenUsesTrait(string $name): CodegenUsesTrait {
@@ -147,7 +147,7 @@ final public function codegenGeneratedFromScript(
147147
?string $script = null,
148148
): CodegenGeneratedFrom {
149149
if ($script === null) {
150-
$trace = debug_backtrace();
150+
$trace = \debug_backtrace();
151151
$last = C\lastx($trace);
152152
invariant(
153153
$last !== false,

src/CodegenFile.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ public function getRelativeFileName(): string {
177177
}
178178

179179
public function exists(): bool {
180-
return file_exists($this->fileName);
180+
return \file_exists($this->fileName);
181181
}
182182

183183
/**
@@ -235,7 +235,7 @@ private function getFileTypeDeclaration(): string {
235235
* setShebangLine('#!/usr/bin/env hhvm')
236236
*/
237237
public function setShebangLine(string $shebang): this {
238-
invariant(!strpbrk($shebang, "\n"), "Expected single line");
238+
invariant(!\strpbrk($shebang, "\n"), "Expected single line");
239239
invariant(Str\starts_with($shebang, '#!'), 'Shebang lines start with #!');
240240
$this->shebang = $shebang;
241241
return $this;
@@ -245,7 +245,7 @@ public function setShebangLinef(
245245
SprintfFormatString $format,
246246
mixed ...$args
247247
): this {
248-
return $this->setShebangLine(vsprintf($format, $args));
248+
return $this->setShebangLine(\vsprintf($format, $args));
249249
}
250250

251251
/**
@@ -263,7 +263,7 @@ public function setPseudoMainHeaderf(
263263
SprintfFormatString $format,
264264
mixed ...$args
265265
): this {
266-
return $this->setPseudoMainHeader(vsprintf($format, $args));
266+
return $this->setPseudoMainHeader(\vsprintf($format, $args));
267267
}
268268

269269
/**
@@ -281,7 +281,7 @@ public function setPseudoMainFooterf(
281281
SprintfFormatString $format,
282282
mixed ...$args
283283
): this {
284-
return $this->setPseudoMainFooter(vsprintf($format, $args));
284+
return $this->setPseudoMainFooter(\vsprintf($format, $args));
285285
}
286286

287287
private function assertNotHackStrictForExecutable(): void {
@@ -378,7 +378,7 @@ private function getContent(): string {
378378
$this->fileNamespace,
379379
);
380380

381-
$get_use_statement = ($type, $ns, $as) ==> sprintf(
381+
$get_use_statement = ($type, $ns, $as) ==> \sprintf(
382382
'use %s %s%s;',
383383
$type,
384384
$ns,
@@ -452,7 +452,7 @@ private function loadExistingFiles(): ?string {
452452
$file_names[] = $this->fileName;
453453
$all_content = array();
454454
foreach ($file_names as $file_name) {
455-
if (file_exists($file_name)) {
455+
if (\file_exists($file_name)) {
456456
$content = Filesystem::readFile($file_name);
457457
if ($content) {
458458
$root_dir = $this->config->getRootDir();
@@ -472,7 +472,7 @@ private function loadExistingFiles(): ?string {
472472
$all_content[] = $content;
473473
}
474474
}
475-
return implode('', $all_content);
475+
return \implode('', $all_content);
476476
}
477477

478478
public function setGeneratedFrom(CodegenGeneratedFrom $from): this {
@@ -544,10 +544,10 @@ public function createOnly(): this {
544544
*/
545545
public function save(): CodegenFileResult {
546546
Filesystem::createDirectory(
547-
substr($this->fileName, 0, strrpos($this->fileName, '/')),
547+
\substr($this->fileName, 0, \strrpos($this->fileName, '/')),
548548
0777,
549549
);
550-
$is_creating = !file_exists($this->fileName);
550+
$is_creating = !\file_exists($this->fileName);
551551
if (!$is_creating && $this->createOnly) {
552552
return CodegenFileResult::NONE;
553553
}
@@ -573,7 +573,7 @@ final class CodegenFileBadSignatureException
573573
extends CodegenFileSignatureException {
574574

575575
public function __construct(string $file_name) {
576-
$message = sprintf(
576+
$message = \sprintf(
577577
'The signature of the existing generated file \'%s\' is invalid',
578578
$file_name,
579579
);
@@ -585,7 +585,7 @@ final class CodegenFileNoSignatureException
585585
extends CodegenFileSignatureException {
586586

587587
public function __construct(string $file_name) {
588-
$message = sprintf(
588+
$message = \sprintf(
589589
'The existing generated file \'%s\' does not have a signature',
590590
$file_name,
591591
);

0 commit comments

Comments
 (0)