Skip to content

Commit

Permalink
compare user attributes on parameters
Browse files Browse the repository at this point in the history
Summary: After D5896103 and D5895465 lands both HackC and HHVM will be able to emit user attributes on parameters. This diff allows semdiff to compare them

Differential Revision: D5896362

fbshipit-source-id: a4f6c44289af4d8dbc742d1d7765d07d1d04f76f
  • Loading branch information
vladima authored and hhvm-bot committed Sep 28, 2017
1 parent 3424f2f commit 9d2a7db
Show file tree
Hide file tree
Showing 4 changed files with 352 additions and 6 deletions.
22 changes: 16 additions & 6 deletions hphp/hack/src/hhbc/semdiff/diff.ml
Expand Up @@ -386,12 +386,27 @@ let type_info_type_constraint_comparer = wrap Hhas_type_info.type_constraint
let type_info_comparer = join (fun s1 s2 -> "<" ^ s1 ^ " " ^s2 ^ ">")
type_info_user_type_comparer
type_info_type_constraint_comparer

let attribute_comparer =
join (fun s1 s2 -> s1 ^ "(" ^ s2 ^ ")")
(wrap Hhas_attribute.name (fun _a s -> s) string_comparer)
(wrap Hhas_attribute.arguments (fun _l s -> s)
(list_comparer typed_value_comparer " "))

let param_attributes_comparer =
wrap Hhas_param.user_attributes (fun _ s -> s)
(list_comparer attribute_comparer " ")

let param_type_info_comparer = wrap Hhas_param.type_info
(fun _p s -> s)
(option_comparer type_info_comparer)

let param_user_attributes_is_variadic_comparer =
join (^) param_attributes_comparer param_is_variadic_comparer

let param_variadic_type_info_comparer =
join (fun s1 s2 -> s1 ^ s2)
param_is_variadic_comparer
param_user_attributes_is_variadic_comparer
param_type_info_comparer
let param_name_reference_comparer =
join (fun s1 s2 -> s1 ^ s2)
Expand Down Expand Up @@ -439,11 +454,6 @@ let method_return_type_comparer =
wrap Hhas_method.return_type (fun _f s -> s)
(option_comparer type_info_comparer)

let attribute_comparer =
join (fun s1 s2 -> s1 ^ "(" ^ s2 ^ ")")
(wrap Hhas_attribute.name (fun _a s -> s) string_comparer)
(wrap Hhas_attribute.arguments (fun _l s -> s)
(list_comparer typed_value_comparer " "))

let function_attributes_comparer =
wrap Hhas_function.attributes (fun _ s -> s)
Expand Down
158 changes: 158 additions & 0 deletions hphp/hack/test/semdiff/attributes_on_params.1.hhas
@@ -0,0 +1,158 @@
#starts here

.main {
DefCls 0
FPushFuncD 0 "run"
FCall 0
PopR
Int 1
RetC
}

.function <"" N > f(["A1"("""a:0:{}""")]$p1, ["A2"("""a:0:{}""")]$p2) {
Null
RetC
}

.function <"" N > test($caption, $parameters, $i, $attribute) {
.declvars $p;
BaseL $parameters Warn
QueryM 0 CGet EL:$i
FPushObjMethodD 1 "getAttribute" NullThrows
FPassL 0 $attribute Cell
FCall 1
UnboxR
SetL $p
PopC
String ":"
CGetL2 $caption
Concat
IssetL $p
JmpZ L0
String "SET"
Jmp L1
L0:
String "NOTSET"
L1:
Concat
Print
PopC
String "\\n"
Print
PopC
Null
RetC
}

.function <"" N > run() {
.declvars $cls $ctor $func;
FPushCtorD 1 "ReflectionClass"
String "A"
FPassCE 0 Cell
FCall 1
PopR
SetL $cls
PopC
CGetL $cls
FPushObjMethodD 0 "getConstructor" NullThrows
FCall 0
UnboxR
SetL $ctor
PopC
FPushFuncD 4 "test"
String "1. existing attribute"
FPassCE 0 Cell
CGetL $ctor
FPushObjMethodD 0 "getParameters" NullThrows
FCall 0
FPassR 1 Cell
Int 0
FPassCE 2 Cell
String "Annotation"
FPassCE 3 Cell
FCall 4
PopR
FPushFuncD 4 "test"
String "2. missing attribute"
FPassCE 0 Cell
CGetL $ctor
FPushObjMethodD 0 "getParameters" NullThrows
FCall 0
FPassR 1 Cell
Int 0
FPassCE 2 Cell
String "Annotation-missing"
FPassCE 3 Cell
FCall 4
PopR
FPushCtorD 1 "ReflectionFunction"
String "f"
FPassCE 0 Cell
FCall 1
PopR
SetL $func
PopC
FPushFuncD 4 "test"
String "3. existing attribute"
FPassCE 0 Cell
CGetL $func
FPushObjMethodD 0 "getParameters" NullThrows
FCall 0
FPassR 1 Cell
Int 0
FPassCE 2 Cell
String "A1"
FPassCE 3 Cell
FCall 4
PopR
FPushFuncD 4 "test"
String "4. missing attribute"
FPassCE 0 Cell
CGetL $func
FPushObjMethodD 0 "getParameters" NullThrows
FCall 0
FPassR 1 Cell
Int 0
FPassCE 2 Cell
String "A1-missing"
FPassCE 3 Cell
FCall 4
PopR
FPushFuncD 4 "test"
String "5. existing attribute"
FPassCE 0 Cell
CGetL $func
FPushObjMethodD 0 "getParameters" NullThrows
FCall 0
FPassR 1 Cell
Int 1
FPassCE 2 Cell
String "A2"
FPassCE 3 Cell
FCall 4
PopR
FPushFuncD 4 "test"
String "6. missing attribute"
FPassCE 0 Cell
CGetL $func
FPushObjMethodD 0 "getParameters" NullThrows
FCall 0
FPassR 1 Cell
Int 1
FPassCE 2 Cell
String "A2-missing"
FPassCE 3 Cell
FCall 4
PopR
Null
RetC
}

.class A {
.method [public] <"" N > __construct(["Annotation"("""a:0:{}""")]$property) {
Null
RetC
}
}

#ends here
158 changes: 158 additions & 0 deletions hphp/hack/test/semdiff/attributes_on_params.2.hhas
@@ -0,0 +1,158 @@
#starts here

.main {
DefCls 0
FPushFuncD 0 "run"
FCall 0
PopR
Int 1
RetC
}

.function <"" N > f(["A11"("""a:0:{}""")]$p1, ["A2"("""a:0:{}""")]$p2) {
Null
RetC
}

.function <"" N > test($caption, $parameters, $i, $attribute) {
.declvars $p;
BaseL $parameters Warn
QueryM 0 CGet EL:$i
FPushObjMethodD 1 "getAttribute" NullThrows
FPassL 0 $attribute Cell
FCall 1
UnboxR
SetL $p
PopC
String ":"
CGetL2 $caption
Concat
IssetL $p
JmpZ L0
String "SET"
Jmp L1
L0:
String "NOTSET"
L1:
Concat
Print
PopC
String "\\n"
Print
PopC
Null
RetC
}

.function <"" N > run() {
.declvars $cls $ctor $func;
FPushCtorD 1 "ReflectionClass"
String "A"
FPassCE 0 Cell
FCall 1
PopR
SetL $cls
PopC
CGetL $cls
FPushObjMethodD 0 "getConstructor" NullThrows
FCall 0
UnboxR
SetL $ctor
PopC
FPushFuncD 4 "test"
String "1. existing attribute"
FPassCE 0 Cell
CGetL $ctor
FPushObjMethodD 0 "getParameters" NullThrows
FCall 0
FPassR 1 Cell
Int 0
FPassCE 2 Cell
String "Annotation"
FPassCE 3 Cell
FCall 4
PopR
FPushFuncD 4 "test"
String "2. missing attribute"
FPassCE 0 Cell
CGetL $ctor
FPushObjMethodD 0 "getParameters" NullThrows
FCall 0
FPassR 1 Cell
Int 0
FPassCE 2 Cell
String "Annotation-missing"
FPassCE 3 Cell
FCall 4
PopR
FPushCtorD 1 "ReflectionFunction"
String "f"
FPassCE 0 Cell
FCall 1
PopR
SetL $func
PopC
FPushFuncD 4 "test"
String "3. existing attribute"
FPassCE 0 Cell
CGetL $func
FPushObjMethodD 0 "getParameters" NullThrows
FCall 0
FPassR 1 Cell
Int 0
FPassCE 2 Cell
String "A1"
FPassCE 3 Cell
FCall 4
PopR
FPushFuncD 4 "test"
String "4. missing attribute"
FPassCE 0 Cell
CGetL $func
FPushObjMethodD 0 "getParameters" NullThrows
FCall 0
FPassR 1 Cell
Int 0
FPassCE 2 Cell
String "A1-missing"
FPassCE 3 Cell
FCall 4
PopR
FPushFuncD 4 "test"
String "5. existing attribute"
FPassCE 0 Cell
CGetL $func
FPushObjMethodD 0 "getParameters" NullThrows
FCall 0
FPassR 1 Cell
Int 1
FPassCE 2 Cell
String "A2"
FPassCE 3 Cell
FCall 4
PopR
FPushFuncD 4 "test"
String "6. missing attribute"
FPassCE 0 Cell
CGetL $func
FPushObjMethodD 0 "getParameters" NullThrows
FCall 0
FPassR 1 Cell
Int 1
FPassCE 2 Cell
String "A2-missing"
FPassCE 3 Cell
FCall 4
PopR
Null
RetC
}

.class A {
.method [public] <"" N > __construct(["Annotation42"("""a:0:{}""")]$property) {
Null
RetC
}
}

#ends here
20 changes: 20 additions & 0 deletions hphp/hack/test/semdiff/attributes_on_params.semdiff.exp
@@ -0,0 +1,20 @@
Semdiff succeeded
comparing key f
Semdiff succeeded
comparing key test
Semdiff succeeded
comparing key run
Semdiff succeeded
comparing key __construct
Semdiff succeeded
Distance = 2
Size = 214
Similarity = 99.07
Edits =

for f:
- A11
+ A1
for __construct:
- Annotation42
+ Annotation

0 comments on commit 9d2a7db

Please sign in to comment.