-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fold nameof string into QueryM in array key pos
Summary: There's special logic in HackC to fold array index keys into the QueryM op ``` // $c["C"] BaseL $c Warn Any QueryM 0 CGet ET:"C" Any // $c[C::class] RaiseClassStringConversionNotice BaseL $c Warn Any QueryM 0 CGet ET:"C" Any ``` but for `nameof` we were falling back to the generic expression path. ``` // $c[nameof C]; String "C" BaseL $c Warn Any QueryM 1 CGet EC:0 Any ``` This factors out the special `MemberKey::ET` logic for `::class` expressions and makes `nameof` use it + emit the empty instruction sequence (like ::class) so it doesn't push a string onto the stack. Updated the HackIR printer to disambiguate indices that are cells of immediates vs. folded literals. Differential Revision: D63041705 fbshipit-source-id: c164c15bd5b387b4285edd66146592183a113611
- Loading branch information
1 parent
61d8ffc
commit b6fc704
Showing
5 changed files
with
132 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?hh | ||
|
||
namespace N { | ||
function f(): void { | ||
$d = dict["N\\C" => "N\\f -- N\\C", "C" => "N\\f -- C"]; | ||
|
||
\var_dump($d["N\\C"]); | ||
\var_dump($d[C::class]); | ||
\var_dump($d[nameof C]); | ||
\var_dump($d[\N\C::class]); | ||
\var_dump($d[nameof \N\C]); | ||
|
||
\var_dump($d["C"]); | ||
\var_dump($d[\C::class]); | ||
\var_dump($d[nameof \C]); | ||
} | ||
} | ||
namespace { | ||
class B { | ||
public static function foo(): void { | ||
$d = dict["B" => "foo -- B", "C" => "foo -- C"]; | ||
|
||
var_dump($d[self::class]); | ||
var_dump($d[nameof self]); | ||
var_dump($d[static::class]); // not folded | ||
var_dump($d[nameof static]); // not folded | ||
} | ||
} | ||
class C extends B { | ||
public static function bar(): void { | ||
$d = dict["B" => "bar -- B", "C" => "bar -- C"]; | ||
|
||
var_dump($d[self::class]); | ||
var_dump($d[nameof self]); | ||
var_dump($d[parent::class]); // not folded | ||
var_dump($d[nameof parent]); // not folded | ||
} | ||
} | ||
|
||
function f(): void { | ||
$c = dict["C" => "f -- C"]; | ||
|
||
var_dump($c["C"]); | ||
var_dump($c[C::class]); | ||
var_dump($c[nameof C]); | ||
} | ||
|
||
<<__EntryPoint>> | ||
function main(): void { | ||
f(); | ||
echo "--------------------\n"; | ||
N\f(); | ||
echo "--------------------\n"; | ||
B::foo(); | ||
echo "--------------------\n"; | ||
C::foo(); | ||
echo "--------------------\n"; | ||
C::bar(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
string(6) "f -- C" | ||
string(6) "f -- C" | ||
string(6) "f -- C" | ||
-------------------- | ||
string(10) "N\f -- N\C" | ||
string(10) "N\f -- N\C" | ||
string(10) "N\f -- N\C" | ||
string(10) "N\f -- N\C" | ||
string(10) "N\f -- N\C" | ||
string(8) "N\f -- C" | ||
string(8) "N\f -- C" | ||
string(8) "N\f -- C" | ||
-------------------- | ||
string(8) "foo -- B" | ||
string(8) "foo -- B" | ||
string(8) "foo -- B" | ||
string(8) "foo -- B" | ||
-------------------- | ||
string(8) "foo -- B" | ||
string(8) "foo -- B" | ||
string(8) "foo -- C" | ||
string(8) "foo -- C" | ||
-------------------- | ||
string(8) "bar -- C" | ||
string(8) "bar -- C" | ||
string(8) "bar -- B" | ||
string(8) "bar -- B" |