Created
June 2, 2020 23:41
-
-
Save timo/ae05d4ac8a0727b70c46c51e571cd716 to your computer and use it in GitHub Desktop.
spesh logging the results of dispatch resolutions
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
========== | |
Latest statistics for 'type-name' (cuid: 25, file: t/moar/53-dispatch.t:123) | |
Total hits: 9 | |
Callsite 0x4d8910 (1 args, 1 pos) | |
Positional flags: | |
Callsite hits: 9 | |
Maximum stack depth: 11 | |
Type tuple 0 | |
Type 0: C1 (TypeObj) | |
Hits: 4 | |
Maximum stack depth: 11 | |
Logged at offset: | |
20: | |
1 x type VMNull (TypeObj) | |
16: | |
2 x spesh plugin guard index 0 | |
Type tuple 1 | |
Type 0: C2 (TypeObj) | |
Hits: 3 | |
Maximum stack depth: 11 | |
Logged at offset: | |
20: | |
1 x type VMNull (TypeObj) | |
16: | |
2 x spesh plugin guard index 1 | |
Type tuple 2 | |
Type 0: C3 (TypeObj) | |
Hits: 2 | |
Maximum stack depth: 11 | |
Logged at offset: | |
20: | |
1 x type VMNull (TypeObj) | |
16: | |
1 x spesh plugin guard index 2 |
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
{ | |
my class C1 { } | |
my class C2 { } | |
my class C3 { } | |
my $count := 0; | |
nqp::dispatch('boot-syscall', 'dispatcher-register', 'type-name', -> $capture { | |
$count++; | |
my $arg := nqp::dispatch('boot-syscall', 'dispatcher-track-arg', $capture, 0); | |
my $arg-val := nqp::captureposarg($capture, 0); | |
my str $name := $arg-val.HOW.name($arg-val); | |
nqp::dispatch('boot-syscall', 'dispatcher-guard-type', $arg); | |
nqp::dispatch('boot-syscall', 'dispatcher-delegate', 'boot-constant', | |
nqp::dispatch('boot-syscall', 'dispatcher-insert-arg-literal-str', | |
nqp::dispatch('boot-syscall', 'dispatcher-drop-arg', $capture, 0), | |
0, $name)); | |
}); | |
sub type-name($obj) { | |
nqp::dispatch('type-name', $obj) | |
} | |
ok(type-name(C1) eq 'C1', 'Dispatcher setting guard works'); | |
ok($count == 1, 'Dispatch callback ran once'); | |
ok(type-name(C1) eq 'C1', 'Can use it another time with the same type'); | |
ok($count == 1, 'Dispatch callback was not run again'); | |
ok(type-name(C2) eq 'C2', 'Can handle polymorphic sites when guard fails'); | |
ok($count == 2, 'Dispatch callback ran a second time for new type'); | |
ok(type-name(C2) eq 'C2', 'Second call with new type works'); | |
ok(type-name(C1) eq 'C1', 'Call with original type still works'); | |
ok($count == 2, 'Dispatch callback only ran a total of 2 times'); | |
ok(type-name(C3) eq 'C3', 'Can handle a third level of polymorphism'); | |
ok($count == 3, 'Dispatch callback ran a third time for new type'); | |
ok(type-name(C1) eq 'C1', 'Works with first type'); | |
ok(type-name(C2) eq 'C2', 'Works with second type'); | |
ok(type-name(C3) eq 'C3', 'Works with third type'); | |
ok($count == 3, 'There were no further dispatch callback invocations'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment