Skip to content

Commit

Permalink
Do all coercion type makeup within parametrization
Browse files Browse the repository at this point in the history
Don't use compose. This would also serve as a bit of optimization by
reducing number of calls needed to create a coercion type.

Alongside got rid of accessing attributes via accessors and replaced
with direct references. This would also remove extra method invocations.

Should fix Net::BGP, as bisected in #4108
  • Loading branch information
vrurg committed Dec 15, 2020
1 parent 79b55ac commit b5465b1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 26 deletions.
36 changes: 11 additions & 25 deletions src/Perl6/Metamodel/CoercionHOW.nqp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ class Perl6::Metamodel::CoercionHOW
does Perl6::Metamodel::LanguageRevision
does Perl6::Metamodel::Nominalizable
{
has $!composed;
has $!target_type;
has $!nominal_target;
has $!constraint_type;
Expand Down Expand Up @@ -36,16 +35,6 @@ class Perl6::Metamodel::CoercionHOW
$coercion_type
}

method compose($coercion_type) {
if $!composed {
return $coercion_type;
}
self.set_language_version($coercion_type, :force);
nqp::settypecheckmode($coercion_type, 2);
$!composed := 1;
$coercion_type
}

method set_target_type($target_type) {
$!target_type := $target_type;
$!nominal_target := $!target_type.HOW.archetypes.nominalizable
Expand Down Expand Up @@ -78,10 +67,9 @@ class Perl6::Metamodel::CoercionHOW
}

method nominalize($coercion_type) {
my $target_type := $coercion_type.HOW.target_type($coercion_type);
$target_type.HOW.archetypes.nominalizable
?? $target_type.HOW.nominalize($target_type)
!! $target_type
$!target_type.HOW.archetypes.nominalizable
?? $!target_type.HOW.nominalize($!target_type)
!! $!target_type
}

method instantiate_generic($coercion_type, $type_env) {
Expand All @@ -99,13 +87,11 @@ class Perl6::Metamodel::CoercionHOW
}

method find_method($coercion_type, $name, *%c) {
my $target_type := $coercion_type.HOW.target_type($coercion_type);
$target_type.HOW.find_method($target_type, $name, |%c)
$!target_type.HOW.find_method($!target_type, $name, |%c)
}

method find_method_qualified($coercion_type, $qtype, $name) {
my $target_type := $coercion_type.HOW.target_type($coercion_type);
$target_type.HOW.find_method_qualified($target_type, $qtype, $name)
$!target_type.HOW.find_method_qualified($!target_type, $qtype, $name)
}

method isa($obj, $type) {
Expand All @@ -120,15 +106,12 @@ class Perl6::Metamodel::CoercionHOW
if $coercion_type =:= $checkee {
return 1;
}
my $target_type := $coercion_type.HOW.target_type($coercion_type);
my $rc := $target_type.HOW.type_check($target_type, $checkee);
my $rc := $!target_type.HOW.type_check($!target_type, $checkee);
$rc
}

method accepts_type($coercion_type, $checkee) {
my $target_type := $coercion_type.HOW.target_type($coercion_type);
my $constraint_type := $coercion_type.HOW.constraint_type($coercion_type);
my $rc := nqp::istype($checkee, $target_type) || nqp::istype($checkee, $constraint_type);
my $rc := nqp::istype($checkee, $!target_type) || nqp::istype($checkee, $!constraint_type);
$rc
}

Expand Down Expand Up @@ -249,7 +232,10 @@ BEGIN {
my $metaclass := $type.HOW.new();
$metaclass.set_target_type($params[0]);
$metaclass.set_constraint_type($params[1]);
nqp::settypehll(nqp::newtype($metaclass, 'Uninstantiable'), 'Raku');
my $coercion_type := nqp::settypehll(nqp::newtype($metaclass, 'Uninstantiable'), 'Raku');
$metaclass.set_language_version($coercion_type, :force);
nqp::settypecheckmode($coercion_type, 2);
$coercion_type
});
(Perl6::Metamodel::CoercionHOW.WHO)<root> := $root;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Perl6/World.nqp
Original file line number Diff line number Diff line change
Expand Up @@ -4169,7 +4169,7 @@ class Perl6::World is HLL::World {
self.ex-handle($/, {
my $type := $/.how('coercion').new_type($target, $constraint);
if nqp::isnull(nqp::getobjsc($type)) { self.add_object_if_no_sc($type); }
$type.HOW.compose($type)
$type
})
}

Expand Down

0 comments on commit b5465b1

Please sign in to comment.