Skip to content

Commit

Permalink
Use "self" as shortcut for $target.HOW
Browse files Browse the repository at this point in the history
Although technically it *is* possible to call a method on a
xxxHOW class where the target does not have the invocant as
its HOW, it would really naughty to do so.

So use "self" as a shortcut for $target.HOW where possible.
This should at least reduce the bytecode size.

This also makes naughtiness a DIHWIDT.
  • Loading branch information
lizmat committed Feb 27, 2024
1 parent fd936ef commit 0422989
Show file tree
Hide file tree
Showing 12 changed files with 25 additions and 26 deletions.
17 changes: 8 additions & 9 deletions src/Perl6/Metamodel/BUILDPLAN.nqp
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,13 @@ role Perl6::Metamodel::BUILDPLAN {
method create_BUILDPLAN($target) {
# First, we'll create the build plan for just this class.
my @plan;
my @attrs := $target.HOW.attributes($target, :local(1));
my @attrs := self.attributes($target, :local(1));
# When adding role's BUILD/TWEAK into the buildplan for pre-6.e classes only roles of 6.e+ origin must be
# considered.
my $ohow := $target.HOW;
my $only_6e_roles := nqp::can($ohow, 'language_revision')
?? $ohow.language_revision < 3
!! nqp::can($ohow, 'lang-rev-before')
?? $ohow.lang-rev-before($target, 'e') # Support legacy approach where implemented
my $only_6e_roles := nqp::can(self, 'language_revision')
?? self.language_revision < 3
!! nqp::can(self, 'lang-rev-before')
?? self.lang-rev-before($target, 'e') # Support legacy approach where implemented
!! 1; # Assume the HOW being compiled against an older Raku language version

# Emit any container initializers. Also build hash of attrs we
Expand All @@ -71,7 +70,7 @@ role Perl6::Metamodel::BUILDPLAN {
"Defaults on compound attribute types",
workaround =>
"Create/Adapt TWEAK method in class "
~ $target.HOW.name($target)
~ self.name($target)
~ ", e.g:\n\n method TWEAK() \{\n "
~ $_.name
~ " := (initial values) unless "
Expand Down Expand Up @@ -107,7 +106,7 @@ role Perl6::Metamodel::BUILDPLAN {
add_from_roles('BUILD');

# Does it have its own BUILD?
my $build := $target.HOW.find_method($target, 'BUILD', :no_fallback(1));
my $build := self.find_method($target, 'BUILD', :no_fallback(1));
if !nqp::isnull($build) && $build {
# We'll call the custom one.
nqp::push(@plan,$build);
Expand Down Expand Up @@ -246,7 +245,7 @@ role Perl6::Metamodel::BUILDPLAN {
add_from_roles('TWEAK');

# Does it have a TWEAK?
my $TWEAK := $target.HOW.find_method($target, 'TWEAK', :no_fallback(1));
my $TWEAK := self.find_method($target, 'TWEAK', :no_fallback(1));
if !nqp::isnull($TWEAK) && $TWEAK {
nqp::push(@plan,$TWEAK);
}
Expand Down
6 changes: 3 additions & 3 deletions src/Perl6/Metamodel/ClassHOW.nqp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class Perl6::Metamodel::ClassHOW
return 1;
}
}
return 0;
0
}

method compose($target, :$compiler_services) {
Expand Down Expand Up @@ -235,8 +235,8 @@ class Perl6::Metamodel::ClassHOW
if nqp::isconcrete($compiler_services) {

# Class does not appear to have a BUILDALL yet
unless nqp::existskey(nqp::hllize($target.HOW.submethod_table($target)),'BUILDALL')
|| nqp::existskey(nqp::hllize($target.HOW.method_table($target)),'BUILDALL') {
unless nqp::existskey(nqp::hllize(self.submethod_table($target)),'BUILDALL')
|| nqp::existskey(nqp::hllize(self.method_table($target)),'BUILDALL') {
my $builder := nqp::findmethod(
$compiler_services,'generate_buildplan_executor');
my $method :=
Expand Down
2 changes: 1 addition & 1 deletion src/Perl6/Metamodel/Concretization.nqp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ role Perl6::Metamodel::Concretization {
}
return @result if @result[0];
}
return [0] if !$relaxed && $target.HOW.is_composed($target) && !nqp::istype(nqp::decont($target), $ptype);
return [0] if !$relaxed && self.is_composed($target) && !nqp::istype(nqp::decont($target), $ptype);
if $transitive {
for @!concretizations {
if nqp::istype($_[1], $ptype) {
Expand Down
2 changes: 1 addition & 1 deletion src/Perl6/Metamodel/CurriedRoleHOW.nqp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class Perl6::Metamodel::CurriedRoleHOW
$role := $role.HOW.instantiate_generic($role, $type_env);
}
unless $role.HOW.archetypes.generic || $role.HOW.archetypes.parametric {
my $target-name := $target.HOW.name($target);
my $target-name := self.name($target);
my $role-name := $role.HOW.name($role);
Perl6::Metamodel::Configuration.throw_or_die(
'X::Composition::NotComposable',
Expand Down
2 changes: 1 addition & 1 deletion src/Perl6/Metamodel/DefiniteHOW.nqp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class Perl6::Metamodel::DefiniteHOW
}

method nominalize($target) {
my $base_type := $target.HOW.base_type($target);
my $base_type := self.base_type($target);
$base_type.HOW.archetypes($base_type).nominalizable
?? $base_type.HOW.nominalize($base_type)
!! $base_type
Expand Down
2 changes: 1 addition & 1 deletion src/Perl6/Metamodel/InvocationProtocol.nqp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ role Perl6::Metamodel::InvocationProtocol {
# Check if we have a invoke, and if so install
# the default invocation forwarder. Otherwise, see if we or
# a parent has an invocation attr.
if $target.HOW.archetypes.composable {
if self.archetypes.composable {
# We special case roles by using only default handler
nqp::setinvokespec($target, nqp::null(), nqp::null_s(),
$default_invoke_handler);
Expand Down
2 changes: 1 addition & 1 deletion src/Perl6/Metamodel/LanguageRevision.nqp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ role Perl6::Metamodel::LanguageRevision
my $comp := nqp::getcomp('Raku');
Perl6::Metamodel::Configuration.throw_or_die(
'X::Language::IncompatRevisions',
"Type object " ~ $target.HOW.name($target) ~ " of v" ~ $comp.lvs.as-public-repr($!lang_rev, :as-str)
"Type object " ~ self.name($target) ~ " of v" ~ $comp.lvs.as-public-repr($!lang_rev, :as-str)
~ " is not compatible with " ~ $type.HOW.name($type)
~ " of v" ~ $comp.lvs.as-public-repr($type.HOW.language_revision, :as-str),
:type-a($target),
Expand Down
4 changes: 2 additions & 2 deletions src/Perl6/Metamodel/MROBasedMethodDispatch.nqp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ role Perl6::Metamodel::MROBasedMethodDispatch {

# uncomment line below for verbose information about uncached
# method lookups
#nqp::say( "looking for " ~ $name ~ " in " ~ $target.HOW.name($target));
#nqp::say( "looking for " ~ $name ~ " in " ~ self.name($target));

my $HOW := nqp::how_nd($target);
if nqp::can($HOW, 'submethod_table') {
Expand Down Expand Up @@ -104,7 +104,7 @@ role Perl6::Metamodel::MROBasedMethodDispatch {
}

# Also add submethods.
for nqp::hllize($target.HOW.submethod_table($target)) {
for nqp::hllize(self.submethod_table($target)) {
%cache{$_.key} := nqp::decont($_.value);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Perl6/Metamodel/MethodContainer.nqp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ role Perl6::Metamodel::MethodContainer {
# installed earlier. This step is here until Method::Also incorporates support for :!handles argument.
if $handles
&& nqp::can($code_obj, 'apply_handles')
&& nqp::can($target.HOW, 'find_method_fallback')
&& nqp::can(self, 'find_method_fallback')
{
my $do_apply := 1;
for @!method_order {
Expand Down
2 changes: 1 addition & 1 deletion src/Perl6/Metamodel/MultiMethodContainer.nqp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ role Perl6::Metamodel::MultiMethodContainer {
nqp::push(@new_protos, $proto);
}
}
if nqp::can($code, 'apply_handles') && nqp::can($target.HOW, 'find_method_fallback') {
if nqp::can($code, 'apply_handles') && nqp::can(self, 'find_method_fallback') {
$code.apply_handles($target);
}
$i := $i + 1;
Expand Down
2 changes: 1 addition & 1 deletion src/Perl6/Metamodel/ParametricRoleGroupHOW.nqp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class Perl6::Metamodel::ParametricRoleGroupHOW
Perl6::Metamodel::Configuration.throw_or_die(
'X::Role::Parametric::NoSuchCandidate',
"Could not find an appropriate parametric role variant for '"
~ $target.HOW.name($target) ~ "' using the arguments supplied:\n "
~ self.name($target) ~ "' using the arguments supplied:\n "
~ $hint
,
:role($target), :$hint
Expand Down
8 changes: 4 additions & 4 deletions src/Perl6/Metamodel/ParametricRoleHOW.nqp
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ class Perl6::Metamodel::ParametricRoleHOW
# to initialize $?CONCRETIZATION by role's body block.
my $*MOP-ROLE-CONCRETIZATION := $conc :=
$concrete.new_type(:roles([$target]), :name(self.name($target)));
$conc.HOW.set_language_revision($conc, $target.HOW.language_revision);
$conc.HOW.set_hidden($conc) if $target.HOW.hidden($target);
$conc.HOW.set_language_revision($conc, self.language_revision);
$conc.HOW.set_hidden($conc) if self.hidden($target);

# Run the body block to get the type environment (we know
# the role in this case).
Expand All @@ -164,7 +164,7 @@ class Perl6::Metamodel::ParametricRoleHOW
else {
Perl6::Metamodel::Configuration.throw_or_die(
'X::Role::BodyReturn',
"Role '" ~ $target.HOW.name($target) ~ "' body block is expected to return a list, got '"
"Role '" ~ self.name($target) ~ "' body block is expected to return a list, got '"
~ $original-result.HOW.name($original-result) ~ "' instead",
:role($target),
:expected("a list of two elements"),
Expand Down Expand Up @@ -237,7 +237,7 @@ class Perl6::Metamodel::ParametricRoleHOW
if $_.HOW.archetypes($_).generic {
$ins := $ins.HOW.instantiate_generic($ins, $type_env);
unless $ins.HOW.archetypes.parametric {
my $target-name := $target.HOW.name($target);
my $target-name := self.name($target);
my $role-name := $ins.HOW.name($ins);
Perl6::Metamodel::Configuration.throw_or_die(
'X::Composition::NotComposable',
Expand Down

0 comments on commit 0422989

Please sign in to comment.