Skip to content

Instantly share code, notes, and snippets.

@MasterDuke17
Created August 19, 2021 12:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MasterDuke17/9d8c3cf0fbe3c929f7801076eb918947 to your computer and use it in GitHub Desktop.
Save MasterDuke17/9d8c3cf0fbe3c929f7801076eb918947 to your computer and use it in GitHub Desktop.
diff --git src/Perl6/Metamodel/Concretization.nqp src/Perl6/Metamodel/Concretization.nqp
index a9751eb0a..18287e984 100644
--- src/Perl6/Metamodel/Concretization.nqp
+++ src/Perl6/Metamodel/Concretization.nqp
@@ -3,6 +3,8 @@ role Perl6::Metamodel::Concretization {
has @!concretizations;
has %!conc_table;
+ my $lock := NQPLock.new;
+
method add_concretization($obj, $role, $concrete) {
@!concretizations[+@!concretizations] := [$role, $concrete];
nqp::scwbdisable();
@@ -38,21 +40,31 @@ role Perl6::Metamodel::Concretization {
method !rebuild_table() {
for @!concretizations {
nqp::scwbdisable();
- %!conc_table{~nqp::objectid(nqp::decont($_[0]))} := nqp::decont($_[1]);
+ $lock.protect: {
+ %!conc_table{~nqp::objectid(nqp::decont($_[0]))} := nqp::decont($_[1]);
+ };
nqp::scwbenable();
}
}
# Returns a list where the first element is the number of roles found and the rest are actual type objects.
method concretization_lookup($obj, $ptype, :$local = 0, :$transitive = 1, :$relaxed = 0) {
- self.'!rebuild_table'() if nqp::elems(%!conc_table) < nqp::elems(@!concretizations);
- return [0] unless !$local || $transitive || nqp::elems(%!conc_table);
+ my int $conc_table_elems;
+ $lock.protect: {
+ $conc_table_elems := nqp::elems(%!conc_table);
+ };
+ self.'!rebuild_table'() if $conc_table_elems < nqp::elems(@!concretizations);
+ return [0] unless !$local || $transitive || $conc_table_elems;
$ptype := nqp::decont($ptype);
my $id := ~nqp::objectid($ptype);
my @result;
- if nqp::existskey(%!conc_table, $id) {
- return [1, %!conc_table{$id}];
- }
+ my $return_id;
+ $lock.protect: {
+ if nqp::existskey(%!conc_table, $id) {
+ $return_id := %!conc_table{$id};
+ }
+ };
+ return [1, $return_id] if $return_id;
if $relaxed {
# Try search by role group for curryings. The first match is ok. Used by FQN method calls.
@result[0] := 0;
[dan@alexandria rakudo]$ ./rakudo-m -I lib/ t/spec/S12-class/mro-6e.t
1..1
# Subtest: Rolified MRO
1..10
not ok 1 - basic mro with roles
# Failed test 'basic mro with roles'
# at t/spec/S12-class/mro-6e.t line 48
# at position 2:
# expected: Nil of Perl6::Metamodel::ClassHOW
# got: R2a of Perl6::Metamodel::ConcreteRoleHOW
not ok 2 - basic mro with parameterized roles
# Failed test 'basic mro with parameterized roles'
# at t/spec/S12-class/mro-6e.t line 57
# at position 2:
# expected: Nil of Perl6::Metamodel::ClassHOW
# got: R2a of Perl6::Metamodel::ConcreteRoleHOW
not ok 3 - mro with roles: parent on a role
# Failed test 'mro with roles: parent on a role'
# at t/spec/S12-class/mro-6e.t line 65
# at position 2:
# expected: Nil of Perl6::Metamodel::ClassHOW
# got: R2a of Perl6::Metamodel::ConcreteRoleHOW
ok 4 - mro with roles: hiding a class hides its roles
not ok 5 - mro with roles: .^mro method ignores hiding
# Failed test 'mro with roles: .^mro method ignores hiding'
# at t/spec/S12-class/mro-6e.t line 74
# at position 2:
# expected: Nil of Perl6::Metamodel::ClassHOW
# got: R2a of Perl6::Metamodel::ConcreteRoleHOW
ok 6 - mro with roles: puned 'is hidden' role hides its roles too
ok 7 - mro with roles: puned parameterized 'is hidden' role hides its roles too
ok 8 - mro with roles: 'hides' on a role hides its roles too
ok 9 - mro with roles: 'hides' on a parameterized role hides its roles too
not ok 10 - mro with roles: 'hides' used with a role is preserved
# Failed test 'mro with roles: 'hides' used with a role is preserved'
# at t/spec/S12-class/mro-6e.t line 121
# at position 1:
# expected: Nil of Perl6::Metamodel::ClassHOW
# got: R3a of Perl6::Metamodel::ConcreteRoleHOW
# You failed 5 tests of 10
not ok 1 - Rolified MRO
# Failed test 'Rolified MRO'
# at t/spec/S12-class/mro-6e.t line 40
# You failed 1 test of 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment