Commit bb5e5d6
Build POISON_MARKER and TANY_MARKER
Summary:
We introduce two new type aliases to the `HH\FIXME` namespace such that
| Alias | Current Value | Sound Dynamic Value |
| -- | -- | -- |
| POISON_MARKER<T> | T | ~T |
| TANY_MARKER<T> | Tany | T |
> NOTE: in the examples below, commented out method declarations represent the code before migration.
`POISON_MARKER` will be used for hierarchy poisoning when an unenforceable type overrides an enforced one e.g. a closure
```
class C {
// public function f(): nonnull {}
public function f(): HH\FIXME\POISON_MARKER<nonnull> {}
}
class D extends C {
public function f(): (function (): void) {
/* HH_FIXME[4110] */
return null;
}
}
/**
* POISON_MARKER will retain current behavior -- expression has type nonnull
* but will become ~nonnull under sound dynamic
*/
function get_nonnull(C $c): nonnull {
return $c->f(); // type hint violation, returning null
}
function test(): void {
get_nonnull(new D());
}
```
`TANY_MARKER` will be used for migrating existing uses of Tany to desired types under sound dynamic without affecting current inference. This is why it points to `T` and not `~T` -- we want full manual control here. In some cases we may want a combination of TANY_MARKER and POISON_MARKER.
```
class C {
// public function f(): int {
public function f(): HH\FIXME\POISON_MARKER<arraykey> { // slightly weaken enforcement
return 1;
}
}
class D extends C {
// public function f(): DECL_TANY {
public function f(): HH\FIXME\TANY_MARKER<string> {
return "hello";
}
}
class E extends D {
public function f(): string {
return "hello";
}
}
```
## Implementation
There is some sleight of hand here - despite outward appearance, the implementation of these aliases diverges.
- For `POISON_MARKER`, I've stripped off the alias for both type constraints and type structures, now matches like types in hint positions and almost matches for type structures (see test cases). The upshot is the runtime doesn't know about POISON_MARKER's existence.
- For `TANY_MARKER`, I strip off the type arguments to simulate how we do decl Tanys, but HHVM still needs to have the symbol name in scope to create the OF_GENERIC type structure, so it's declared in systemlib. See the `tany.php` example from D40516837 (9e8c173) for an analogue.
Reviewed By: andrewjkennedy
Differential Revision: D40371013
fbshipit-source-id: d2d9e4f4d57f6f88d1c31201d60d9c9e196561731 parent 8159883 commit bb5e5d6
17 files changed
Lines changed: 198 additions & 0 deletions
File tree
- hphp
- hack
- hhi
- src
- hackc/emitter
- naming
- typing
- test
- sound_dynamic/typing
- typecheck
- runtime/ext/hh
- test/slow/sound_dynamic
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
| |||
287 | 288 | | |
288 | 289 | | |
289 | 290 | | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
290 | 305 | | |
291 | 306 | | |
292 | 307 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
285 | 285 | | |
286 | 286 | | |
287 | 287 | | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
288 | 294 | | |
289 | 295 | | |
290 | 296 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1090 | 1090 | | |
1091 | 1091 | | |
1092 | 1092 | | |
| 1093 | + | |
| 1094 | + | |
| 1095 | + | |
| 1096 | + | |
| 1097 | + | |
| 1098 | + | |
1093 | 1099 | | |
1094 | 1100 | | |
1095 | 1101 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
661 | 661 | | |
662 | 662 | | |
663 | 663 | | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
664 | 667 | | |
665 | 668 | | |
666 | 669 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
227 | 227 | | |
228 | 228 | | |
229 | 229 | | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
230 | 245 | | |
231 | 246 | | |
232 | 247 | | |
| |||
Lines changed: 13 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
Lines changed: 9 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
Lines changed: 9 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
0 commit comments