Skip to content
Permalink
Browse files

Add an immediate to ReifiedName to indicate whether it is function or…

… class name

Summary:
On the following diffs, I'll be adding some reduction optimizations to HHBBC and in order to prevent it from being brittle
 some verifier code to detect that `ReifiedName` flows into `FPushFunc` and `FPushCtor` as correctly, i.e. we dont give one belonging to a function to `FPushCtor` and vice versa.
This diff adds the infra to be able to accomplish that.

Reviewed By: markw65

Differential Revision: D13811104

fbshipit-source-id: 7d34602e383fd1f3246b43ed841fdc3ac418b466
  • Loading branch information...
oulgen authored and hhvm-bot committed Jan 27, 2019
1 parent c03fa7b commit d0cfc37a70c4b2aedfe77eaa4321cb0579896924
@@ -3901,12 +3901,14 @@ RecordReifiedGeneric <num args> [C..C] -> [C:Arr|Vec]
to the global reified generics table. Returns the resulting static list
of type structures.

ReifiedName <num args> [C:Str C..C] -> [C:Str]
ReifiedName <num args> <op> [C:Str C..C] -> [C:Str]

Takes a name and (%1 - 1) amount of type structures from the stack and
mangles the type structures into the name. Returns this mangled name.
Takes a name and (%1 - 1) type structures from the stack and
mangles the type structures into the name. Returns the mangled name.
This instruction also performs RecordReifiedGeneric instruction's recording
duty but it can be implemented more efficiently subsumed in this instruction.
Op is used to denote whether this name is for a class or a function. This
information is used for optimizations only.

ReifiedGeneric <op> <id> [] -> [C:Arr|Dict]

@@ -957,7 +957,6 @@ let makeunaryinst s arg = match s with
| "AsTypeStructC" -> IOp (AsTypeStructC (typestructresolveofiarg arg))
| "CombineAndResolveTypeStruct" ->
IOp (CombineAndResolveTypeStruct (intofiarg arg))
| "ReifiedName" -> IMisc (ReifiedName (intofiarg arg))
| "RecordReifiedGeneric" -> IMisc (RecordReifiedGeneric (intofiarg arg))
| "ConcatN" -> IOp (ConcatN (intofiarg arg))

@@ -1152,6 +1151,8 @@ match s with

| "ReifiedGeneric" ->
IMisc (ReifiedGeneric (reifiedgenericopofiarg arg1, intofiarg arg2))
| "ReifiedName" ->
IMisc (ReifiedName (intofiarg arg1, reifiedgenericopofiarg arg2))

| _ -> failwith ("NYI binary: " ^ s)

@@ -828,7 +828,7 @@ and emit_new env pos expr targs args uargs =
gather [
gather reified_targs;
name;
instr_reified_name (List.length reified_targs + 1);
instr_reified_name (List.length reified_targs + 1) H.ClsGeneric;
]
in
let instrs = match cexpr with
@@ -3250,7 +3250,7 @@ and emit_call_lhs
gather [
gather reified_targs;
instr_string name;
instr_reified_name (List.length reified_targs + 1);
instr_reified_name (List.length reified_targs + 1) H.FunGeneric;
] in
let reified_fun_name_call name =
gather [
@@ -515,7 +515,7 @@ type instruct_misc =
| Parent of classref_id
| LateBoundCls of classref_id
| ClsRefName of classref_id
| ReifiedName of int
| ReifiedName of int * reified_generic_op
| ReifiedGeneric of reified_generic_op * int
| RecordReifiedGeneric of int
| CheckReifiedGenericMismatch
@@ -550,7 +550,8 @@ let string_of_misc instruction =
| Parent id -> sep ["Parent"; string_of_classref id]
| LateBoundCls id -> sep ["LateBoundCls"; string_of_classref id]
| ClsRefName id -> sep ["ClsRefName"; string_of_classref id]
| ReifiedName n -> sep ["ReifiedName"; string_of_int n]
| ReifiedName (n, op) ->
sep ["ReifiedName"; string_of_int n; string_of_reifiedgeneric_op op]
| ReifiedGeneric (op, n) ->
sep ["ReifiedGeneric"; string_of_reifiedgeneric_op op; string_of_int n]
| RecordReifiedGeneric n -> sep ["RecordReifiedGeneric"; string_of_int n]
@@ -103,7 +103,7 @@ let instr_istypestructc mode = instr (IOp (IsTypeStructC mode))
let instr_astypestructc mode = instr (IOp (AsTypeStructC mode))
let instr_combine_and_resolve_type_struct i =
instr (IOp (CombineAndResolveTypeStruct i))
let instr_reified_name i = instr (IMisc (ReifiedName i))
let instr_reified_name i op = instr (IMisc (ReifiedName (i, op)))
let instr_reified_generic op i = instr (IMisc (ReifiedGeneric (op, i)))
let instr_record_reified_generic i = instr (IMisc (RecordReifiedGeneric i))
let instr_check_reified_generic_mismatch =
@@ -801,7 +801,7 @@ let get_input_output_count i =
| MemoGet _ -> (0, 1) | MemoGetEager _ -> (0, 1)
| MemoSet _ -> (0, 0) | MemoSetEager _ -> (0, 0)
| Idx | ArrayIdx -> (3, 1)
| ReifiedName n | RecordReifiedGeneric n -> (n, 1)
| ReifiedName (n, _) | RecordReifiedGeneric n -> (n, 1)
end
| IGet i ->
begin match i with
@@ -2800,7 +2800,7 @@ OPTBLD_INLINE void iopRecordReifiedGeneric(uint32_t n) {
}
}

OPTBLD_INLINE void iopReifiedName(uint32_t n) {
OPTBLD_INLINE void iopReifiedName(uint32_t n, ReifiedGenericOp op) {
assertx(n != 0);
auto const name = vmStack().topC();
if (!tvIsString(name)) raise_error("Reified name must be a string");
@@ -718,7 +718,8 @@ constexpr uint32_t kMaxConcatN = 4;
O(LateBoundCls, ONE(CAW), NOV, NOV, NF) \
O(RecordReifiedGeneric, \
ONE(IVA), CMANY, ONE(CV), NF) \
O(ReifiedName, ONE(IVA), CMANY, ONE(CV), NF) \
O(ReifiedName, TWO(IVA,OA(ReifiedGenericOp)), \
CMANY, ONE(CV), NF) \
O(ReifiedGeneric, TWO(OA(ReifiedGenericOp),IVA), \
NOV, ONE(CV), NF) \
O(CheckReifiedGenericMismatch, NA, ONE(CV), NOV, NF) \
@@ -482,7 +482,8 @@ void emitCombineAndResolveTypeStruct(IRGS& env, uint32_t)
{ INTERP }
void emitRecordReifiedGeneric(IRGS& env, uint32_t)
{ INTERP }
void emitReifiedName(IRGS& env, uint32_t) { INTERP }
void emitReifiedName(IRGS& env, uint32_t, ReifiedGenericOp)
{ INTERP }
void emitReifiedGeneric(IRGS& env, ReifiedGenericOp, uint32_t)
{ INTERP }
void emitClsRefGetTS(IRGS& env, uint32_t) { INTERP }
@@ -198,7 +198,7 @@ let stk_data : instruct -> stack_sig = function
| ILitConst ColFromArray _ -> ["C"], ["C"]
| IOp CombineAndResolveTypeStruct n -> produce "C" n, ["C"]
| IMisc RecordReifiedGeneric n -> produce "C" n, ["C"]
| IMisc ReifiedName n -> produce "C" n, ["C"]
| IMisc ReifiedName (n, _) -> produce "C" n, ["C"]
| ILitConst NewPair
| IOp _
| ILitConst AddNewElemC -> ["C"; "C"], ["C"]
@@ -21,7 +21,7 @@
FCall <> 1 1 - "" ""
JmpZ L0
String "C"
ReifiedName 1
ReifiedName 1 ClsGeneric
ClsRefGetC 0
Jmp L1
L0:
@@ -17,7 +17,7 @@
.function <"" N > f() {
.numclsrefslots 1;
String "C"
ReifiedName 1
ReifiedName 1 ClsGeneric
ClsRefGetC 0
NewObj 0 MaybeGenerics
Dup

0 comments on commit d0cfc37

Please sign in to comment.
You can’t perform that action at this time.