Skip to content

Commit

Permalink
Hhvm 4 102 (#68)
Browse files Browse the repository at this point in the history
* add dictRowsTyped

* test on 4.102, and autofix linters

* drop 4.80 support in this branch since dictRowsTyped doesn't exist there

* disable this test for now

* linty mclintface
  • Loading branch information
ssandler committed Aug 19, 2021
1 parent 7f33860 commit bc67d24
Show file tree
Hide file tree
Showing 23 changed files with 17 additions and 69 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
matrix:
os: [ ubuntu ]
hhvm:
- '4.80'
- '4.102'
runs-on: ${{matrix.os}}-latest
steps:
- uses: actions/checkout@v2
Expand Down
5 changes: 5 additions & 0 deletions src/AsyncMysql/AsyncMysqlQueryResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ public function mapRows(): Vector<Map<string, ?string>> {
return $out;
}

<<__Override>>
public function dictRowsTyped(): vec<dict<string, mixed>> {
return vec($this->rows);
}

<<__Override>>
public function mapRowsTyped(): Vector<Map<string, mixed>> {
$out = Vector {};
Expand Down
2 changes: 1 addition & 1 deletion src/BuildSchemaCLI.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ protected function getSupportedOptions(): vec<CLIOptions\CLIOption> {
'fields' => HackBuilderValues::vec(HackBuilderValues::shapeWithPerKeyRendering(
shape(
'name' => HackBuilderValues::export(),
'type' => HackBuilderValues::lambda(($cfg, $str) ==> 'DataType::'.$str),
'type' => HackBuilderValues::lambda(($_cfg, $str) ==> 'DataType::'.$str),
'length' => HackBuilderValues::export(),
'null' => HackBuilderValues::export(),
'hack_type' => HackBuilderValues::export(),
Expand Down
3 changes: 0 additions & 3 deletions src/DataIntegrity.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ protected static function getDefaultValueForField(
public static function ensureFieldsPresent(dict<string, mixed> $row, table_schema $schema): dict<string, mixed> {

foreach ($schema['fields'] as $field) {

$field_name = $field['name'];
$field_type = $field['hack_type'];
$field_length = $field['length'];
Expand Down Expand Up @@ -109,7 +108,6 @@ public static function ensureFieldsPresent(dict<string, mixed> $row, table_schem
$row[$field_name] = (int)$row[$field_name];
}
} else {

$signed = !($field_unsigned);
$field_value = (int)$row[$field_name];

Expand Down Expand Up @@ -211,7 +209,6 @@ public static function coerceToSchema(dict<string, mixed> $row, table_schema $sc
$row = self::ensureFieldsPresent($row, $schema);

foreach ($schema['fields'] as $field) {

$field_name = $field['name'];
$field_type = $field['hack_type'];

Expand Down
1 change: 0 additions & 1 deletion src/Expressions/ColumnExpression.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ final class ColumnExpression extends Expression {
private ?string $databaseName;
private bool $allowFallthrough = false;


public function __construct(token $token) {
$this->type = $token['type'];
$this->precedence = 0;
Expand Down
1 change: 0 additions & 1 deletion src/Expressions/Expression.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ public function negate(): void {
*/
public abstract function isWellFormed(): bool;


// This is not the method to override by the concrete Expression subclasses ()
final public function evaluate(
row $row,
Expand Down
1 change: 0 additions & 1 deletion src/Expressions/FunctionExpression.php
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,6 @@ private function sqlFromUnixtime(row $row, AsyncMysqlConnection $conn): string {

$column = $args[0]->evaluate($row, $conn);


//
// This is the default format from MySQL ‘YYYYY-MM-DD HH:MM:SS’
//
Expand Down
1 change: 0 additions & 1 deletion src/Expressions/JSONFunctionExpression.hack
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,6 @@ final class JSONFunctionExpression extends BaseFunctionExpression {
throw new SQLFakeRuntimeException('MySQL JSON_DEPTH() function doc has incorrect type');
}


try {
return (new JSONPath\JSONObject($json))->depth()->value;
} catch (JSONPath\JSONException $e) {
Expand Down
27 changes: 0 additions & 27 deletions src/Parser/CreateTableParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ private function lexImpl(string $sql): vec<(int, int)> {
$source_map = vec[];

while ($pos < $len) {

# <space>
# <newline>

Expand Down Expand Up @@ -136,7 +135,6 @@ private function lexImpl(string $sql): vec<(int, int)> {
continue;
}


# <regular identifier>
# <key word>g
$match = Regex\first_match($sql, re"![[:alpha:]][[:alnum:]_]*!A", $pos);
Expand Down Expand Up @@ -214,10 +212,8 @@ private function lexImpl(string $sql): vec<(int, int)> {
return $source_map;
}
private function walk(vec<string> $tokens, string $sql, vec<(int, int)> $source_map): dict<string, parsed_table> {
#
# split into statements
#
Expand Down Expand Up @@ -265,15 +261,13 @@ private function walk(vec<string> $tokens, string $sql, vec<(int, int)> $source_
$s = $stmt['tuples'];
if (Str\uppercase($s[0]) === 'CREATE TABLE') {
$s = Vec\drop($s, 1);
$table = $this->parseCreateTable($s, $stmt['sql']);
$tables[$table['name']] = $table;
}
if (Str\uppercase($s[0]) === 'CREATE TEMPORARY TABLE') {
$s = Vec\drop($s, 1);
$table = $this->parseCreateTable($s, $stmt['sql']);
Expand All @@ -285,22 +279,19 @@ private function walk(vec<string> $tokens, string $sql, vec<(int, int)> $source_
return $tables;
}
private function parseCreateTable(vec<string> $tokens, string $sql): parsed_table {
if ($tokens[0] === 'IF NOT EXISTS') {
$tokens = Vec\drop($tokens, 1);
}
#
# name
#
$t = $this->vecUnshift(inout $tokens);
$name = $this->decodeIdentifier($t);
#
# CREATE TABLE x LIKE y
#
Expand All @@ -319,7 +310,6 @@ private function parseCreateTable(vec<string> $tokens, string $sql): parsed_tabl
);
}
#
# create_definition
#
Expand Down Expand Up @@ -347,7 +337,6 @@ private function parseCreateTable(vec<string> $tokens, string $sql): parsed_tabl
return $table;
}
private function nextTokenIs(vec<string> $tokens, string $val): bool {
return Str\uppercase($tokens[0]) === $val;
}
Expand All @@ -361,7 +350,6 @@ private function parseCreateDefinition(inout vec<string> $tokens): shape(
$indexes = vec[];
while ($tokens[0] !== ')') {
$these_tokens = $this->sliceUntilNextField(inout $tokens);
$this->parseFieldOrKey(inout $these_tokens, inout $fields, inout $indexes);
Expand All @@ -386,7 +374,6 @@ private function parseFieldOrKey(
#
if ($tokens[0] === 'CONSTRAINT') {
if (
$tokens[1] === 'PRIMARY KEY' ||
$tokens[1] === 'UNIQUE' ||
Expand All @@ -401,7 +388,6 @@ private function parseFieldOrKey(
}
}
switch ($tokens[0]) {
#
Expand Down Expand Up @@ -440,14 +426,12 @@ private function parseFieldOrKey(
$this->parseIndexColumns(inout $tokens, inout $index);
$this->parseIndexOptions(inout $tokens, inout $index);
if (C\count($tokens)) {
$index['more'] = $tokens;
}
$indexes[] = $index;
return;
#
# PRIMARY KEY [index_type] (index_col_name,...) [index_option] ...
#
Expand All @@ -471,7 +455,6 @@ private function parseFieldOrKey(
$indexes[] = $index;
return;
# FULLTEXT [index_name] (index_col_name,...) [index_option] ...
# FULLTEXT INDEX [index_name] (index_col_name,...) [index_option] ...
# FULLTEXT KEY [index_name] (index_col_name,...) [index_option] ...
Expand Down Expand Up @@ -512,7 +495,6 @@ private function parseFieldOrKey(
$indexes[] = $index;
return;
# older stuff
case 'CHECK':
Expand Down Expand Up @@ -602,7 +584,6 @@ private function parseField(vec<string> $tokens): parsed_field {
$this->parseFieldZerofill(inout $tokens, inout $f);
break;
# REAL[(length,decimals)] [UNSIGNED] [ZEROFILL]
case 'REAL':
case 'DOUBLE':
Expand All @@ -613,7 +594,6 @@ private function parseField(vec<string> $tokens): parsed_field {
$this->parseFieldZerofill(inout $tokens, inout $f);
break;
# DECIMAL[(length[,decimals])] [UNSIGNED] [ZEROFILL]
case 'DECIMAL':
case 'NUMERIC':
Expand All @@ -624,7 +604,6 @@ private function parseField(vec<string> $tokens): parsed_field {
$this->parseFieldZerofill(inout $tokens, inout $f);
break;
# BIT[(length)]
# BINARY[(length)]
case 'BIT':
Expand All @@ -633,7 +612,6 @@ private function parseField(vec<string> $tokens): parsed_field {
$this->parseFieldLength(inout $tokens, inout $f);
break;
# VARBINARY(length)
case 'VARBINARY':
Expand Down Expand Up @@ -803,7 +781,6 @@ private function parseTableProps(inout vec<string> $tokens): dict<string, string
return $props;
}
# Given the source map, extract the tokens from the original sql,
# Along the way, simplify parsing by merging certain tokens when
# they occur next to each other. MySQL treats these productions
Expand Down Expand Up @@ -843,7 +820,6 @@ private function extractTokens(string $sql, vec<(int, int)> $source_map): vec<st
'UNIQUE',
];
$maps = dict[];
foreach ($lists as $l) {
$a = Str\split($l, ' ');
Expand Down Expand Up @@ -932,7 +908,6 @@ private function parseIndexColumns(inout vec<string> $tokens, inout parsed_index
$tokens = Vec\drop($tokens, 1);
while (true) {
$t = $this->vecUnshift(inout $tokens);
$col = shape(
'name' => $this->decodeIdentifier($t),
Expand Down Expand Up @@ -991,7 +966,6 @@ private function parseIndexOptions(inout vec<string> $tokens, inout parsed_index
}
}
#
# helper functions for parsing bits of field definitions
#
Expand Down Expand Up @@ -1047,7 +1021,6 @@ private function parseValueList(inout vec<string> $tokens): ?vec<string> {
$values = vec[];
while (C\count($tokens)) {
if ($tokens[0] === ')') {
$tokens = Vec\drop($tokens, 1);
return $values;
Expand Down
17 changes: 8 additions & 9 deletions src/Parser/ExpressionParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ final class ExpressionParser {
];

private ?vec<Expression> $selectExpressions;

private Expression $expression;

/**
* Most of the time, only the first two props are set. List of tokens to iterate on, and column references to index into.
Expand All @@ -80,10 +80,15 @@ final class ExpressionParser {
public function __construct(
private token_list $tokens,
private int $pointer = -1,
private Expression $expression = new PlaceholderExpression(),
?Expression $expression = null,
public int $min_precedence = 0,
private bool $is_child = false,
) {}
) {
if ($expression is null) {
$expression = new PlaceholderExpression();
}
$this->expression = $expression;
}

/** parses an expression that is inside a delimited list, such as function arguments or row expressions
* i.e.: [col1, col2, col3]
Expand All @@ -99,7 +104,6 @@ private function getListExpression(token_list $tokens): (bool, vec<Expression>)
$args = vec[];

while ($pos < $token_count) {

$arg = $tokens[$pos];

if ($arg['value'] === 'DISTINCT' || $arg['value'] === 'DISTINCTROW') {
Expand Down Expand Up @@ -154,7 +158,6 @@ public function tokenToExpression(token $token): Expression {
// this is because the select may define aliases we can use in these clauses
// i.e. SELECT something as foo ... GROUP BY foo
if ($this->selectExpressions is nonnull) {

foreach ($this->selectExpressions as $expr) {
if ($expr->name === $token['value']) {
return $expr;
Expand Down Expand Up @@ -211,7 +214,6 @@ public function build(): Expression {
list($p, $select) = $parser->parse();
$expr = new SubqueryExpression($select, '');
} else if ($this->expression is InOperatorExpression) {

$pointer = -1;
$in_list = vec[];
$token_count = C\count($arg_tokens);
Expand Down Expand Up @@ -256,7 +258,6 @@ public function build(): Expression {
}
}


if ($this->expression is PlaceholderExpression) {
$this->expression = new BinaryOperatorExpression($expr);
} else {
Expand Down Expand Up @@ -363,7 +364,6 @@ public function build(): Expression {
}
$this->expression->negate();
} else {

// If the new operator has higher precedence, we need to recurse so that it can end up inside the current expression (so it gets evaluated first)
// Otherwise, we take the entire current expression and nest it inside a new one, which we assume to be Binary for now

Expand Down Expand Up @@ -441,7 +441,6 @@ public function build(): Expression {

// possibly break out of the loop depending on next token, operator precedence, child status
if ($this->expression->isWellFormed()) {

// alias for the expression?
if ($nextToken['type'] === TokenType::IDENTIFIER) {
break;
Expand Down
3 changes: 0 additions & 3 deletions src/Parser/Lexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ private function groupComments(dict<int, string> $tokens): dict<int, string> {
$quote = null;

for ($i = 0; $i < $count; $i++) {

$token = $tokens[$i];

// are we inside a comment already?
Expand Down Expand Up @@ -121,7 +120,6 @@ private function groupEscapeSequences(dict<int, string> $tokens): dict<int, stri
$i = 0;

while ($i < $tokenCount) {

if (Str\ends_with($tokens[$i], '\\')) {
$i++;
if (C\contains_key($tokens, $i)) {
Expand All @@ -140,7 +138,6 @@ private function groupQuotedTokens(dict<int, string> $tokens): vec<string> {
$i = 0;
$count = C\count($tokens);
while ($i < $count) {

$token = $tokens[$i];

// single quotes, double quotes, or backticks
Expand Down
Loading

0 comments on commit bc67d24

Please sign in to comment.