Skip to content

Commit

Permalink
Set more sensible defaults to helper methods
Browse files Browse the repository at this point in the history
Further reduces bytecode footprint at the callsites
  • Loading branch information
lizmat committed Apr 1, 2021
1 parent ac9f40d commit 71960b1
Show file tree
Hide file tree
Showing 20 changed files with 61 additions and 61 deletions.
8 changes: 4 additions & 4 deletions src/core.c/Any-iterable-methods.pm6
Expand Up @@ -17,7 +17,7 @@ augment class Any {
# to help reduce bytecode size in hot code paths, making it more likely
# that the (conditional) caller of this method, can be inlined.
method throw-iterator-cannot-be-lazy(
str $action, str $what = ""
str $action, str $what = self.^name
) is hidden-from-backtrace is implementation-detail {
X::Cannot::Lazy.new(:$action, :$what).throw
}
Expand All @@ -26,7 +26,7 @@ augment class Any {
# to help reduce bytecode size in hot code paths, making it more likely
# that the (conditional) caller of this method, can be inlined.
method fail-iterator-cannot-be-lazy(
str $action, str $what = ""
str $action, str $what = self.^name
) is hidden-from-backtrace is implementation-detail {
Failure.new(X::Cannot::Lazy.new(:$action, :$what))
}
Expand All @@ -35,7 +35,7 @@ augment class Any {
# empty, to help reduce bytecode size in hot code paths, making it more
# likely that the (conditional) caller of this method, can be inlined.
method throw-cannot-be-empty(
str $action, str $what = ""
str $action, str $what = self.^name
) is hidden-from-backtrace is implementation-detail {
X::Cannot::Empty.new(:$action, :$what).throw
}
Expand All @@ -44,7 +44,7 @@ augment class Any {
# to help reduce bytecode size in hot code paths, making it more likely
# that the (conditional) caller of this method, can be inlined.
method fail-cannot-be-empty(
str $action, str $what = ""
str $action, str $what = self.^name
) is hidden-from-backtrace is implementation-detail {
Failure.new(X::Cannot::Empty.new(:$action, :$what))
}
Expand Down
2 changes: 1 addition & 1 deletion src/core.c/Array.pm6
Expand Up @@ -710,7 +710,7 @@ my class Array { # declared in BOOTSTRAP
IterationEnd
),
self,
self.throw-iterator-cannot-be-lazy('push', self.^name)
self.throw-iterator-cannot-be-lazy('push')
)
}

Expand Down
2 changes: 1 addition & 1 deletion src/core.c/Bag.pm6
Expand Up @@ -38,7 +38,7 @@ my class Bag does Baggy {
#--- interface methods
multi method STORE(Bag:D: Iterable:D \iterable, :INITIALIZE($)! --> Bag:D) {
(my \iterator := iterable.iterator).is-lazy
?? self.fail-iterator-cannot-be-lazy('initialize', self.^name)
?? self.fail-iterator-cannot-be-lazy('initialize')
!! self.SET-SELF(Rakudo::QuantHash.ADD-PAIRS-TO-BAG(
nqp::create(Rakudo::Internals::IterationSet),iterator,self.keyof
))
Expand Down
2 changes: 1 addition & 1 deletion src/core.c/BagHash.pm6
Expand Up @@ -7,7 +7,7 @@ my class BagHash does Baggy {
#--- interface methods
multi method STORE(BagHash:D: Iterable:D \iterable --> BagHash:D) {
(my \iterator := iterable.iterator).is-lazy
?? self.fail-iterator-cannot-be-lazy('initialize', self.^name)
?? self.fail-iterator-cannot-be-lazy('initialize')
!! self.SET-SELF(
Rakudo::QuantHash.ADD-PAIRS-TO-BAG(
nqp::create(Rakudo::Internals::IterationSet),
Expand Down
4 changes: 2 additions & 2 deletions src/core.c/Baggy.pm6
Expand Up @@ -59,7 +59,7 @@ my role Baggy does QuantHash {
# helper method to create Bag from iterator, check for laziness
method !create-from-iterator(\type, \iterator --> Baggy:D) {
iterator.is-lazy
?? self.fail-iterator-cannot-be-lazy('coerce', type.^name)
?? type.fail-iterator-cannot-be-lazy('coerce')
!! nqp::create(type).SET-SELF(
Rakudo::QuantHash.ADD-ITERATOR-TO-BAG(
nqp::create(Rakudo::Internals::IterationSet),
Expand Down Expand Up @@ -90,7 +90,7 @@ my role Baggy does QuantHash {

method new-from-pairs(Baggy:_: *@pairs --> Baggy:D) {
(my \iterator := @pairs.iterator).is-lazy
?? self.fail-iterator-cannot-be-lazy('coerce', self.^name)
?? self.fail-iterator-cannot-be-lazy('coerce')
!! nqp::create(self).SET-SELF(
Rakudo::QuantHash.ADD-PAIRS-TO-BAG(
nqp::create(Rakudo::Internals::IterationSet),
Expand Down
10 changes: 5 additions & 5 deletions src/core.c/Buf.pm6
Expand Up @@ -57,7 +57,7 @@ my role Blob[::T = uint8] does Positional[T] does Stringy is repr('VMArray') is
multi method STORE(Blob:D: Iterable:D \iterable, :$INITIALIZE) {
$INITIALIZE
?? iterable.is-lazy
?? self.throw-iterator-cannot-be-lazy('store', self.^name)
?? self.throw-iterator-cannot-be-lazy('store')
!! self!push-list("initializ",self,iterable)
!! X::Assignment::RO.new(:value(self)).throw
}
Expand Down Expand Up @@ -734,7 +734,7 @@ my role Buf[::T = uint8] does Blob[T] is repr('VMArray') is array_type(T) {
}
multi method STORE(Buf:D: Iterable:D \iterable) {
iterable.is-lazy
?? self.throw-iterator-cannot-be-lazy('store', self.^name)
?? self.throw-iterator-cannot-be-lazy('store')
!! self!push-list("initializ",nqp::setelems(self,0),iterable);
}
multi method STORE(Buf:D: Any:D \non-iterable) {
Expand Down Expand Up @@ -953,13 +953,13 @@ my role Buf[::T = uint8] does Blob[T] is repr('VMArray') is array_type(T) {
multi method pop(Buf:D:) {
nqp::elems(self)
?? nqp::pop_i(self)
!! self.fail-cannot-be-empty('pop', self.^name)
!! self.fail-cannot-be-empty('pop')
}
proto method shift(|) { * }
multi method shift(Buf:D:) {
nqp::elems(self)
?? nqp::shift_i(self)
!! self.fail-cannot-be-empty('shift', self.^name)
!! self.fail-cannot-be-empty('shift')
}

method reallocate(Buf:D: Int:D $elements) { nqp::setelems(self,$elements) }
Expand Down Expand Up @@ -1053,7 +1053,7 @@ my role Buf[::T = uint8] does Blob[T] is repr('VMArray') is array_type(T) {

method !pend(Buf:D: @values, $action) {
@values.is-lazy
?? self.fail-iterator-cannot-be-lazy($action, self.^name)
?? self.fail-iterator-cannot-be-lazy($action)
!! $action eq 'push' || $action eq 'append'
?? self!push-list($action,self,@values)
!! self!unshift-list($action,self,@values)
Expand Down
4 changes: 2 additions & 2 deletions src/core.c/Hash.pm6
Expand Up @@ -218,7 +218,7 @@ my class Hash { # declared in BOOTSTRAP
method dynamic(Hash:D:) { nqp::hllbool($!descriptor.dynamic) }

method push(+values) {
return self.fail-iterator-cannot-be-lazy('.push', self.^name)
return self.fail-iterator-cannot-be-lazy('.push')
if values.is-lazy;

my $previous;
Expand All @@ -245,7 +245,7 @@ my class Hash { # declared in BOOTSTRAP
}

method append(+values) {
return self.fail-iterator-cannot-be-lazy('.append', self.^name)
return self.fail-iterator-cannot-be-lazy('.append')
if values.is-lazy;

my $previous;
Expand Down
10 changes: 5 additions & 5 deletions src/core.c/Iterable.pm6
Expand Up @@ -62,7 +62,7 @@ my role Iterable {

method !MIXIFY(\type) {
(my \iterator := self.flat.iterator).is-lazy
?? self.fail-iterator-cannot-be-lazy('coerce', type.^name)
?? type.fail-iterator-cannot-be-lazy('coerce')
!! nqp::elems(my \elems := Rakudo::QuantHash.ADD-PAIRS-TO-MIX(
nqp::create(Rakudo::Internals::IterationSet),iterator,Mu
))
Expand All @@ -76,7 +76,7 @@ my role Iterable {

method !BAGGIFY(\type) {
(my \iterator := self.flat.iterator).is-lazy
?? self.fail-iterator-cannot-be-lazy('coerce', type.^name)
?? type.fail-iterator-cannot-be-lazy('coerce')
!! nqp::elems(my \elems := Rakudo::QuantHash.ADD-PAIRS-TO-BAG(
nqp::create(Rakudo::Internals::IterationSet),iterator,Mu
))
Expand All @@ -90,7 +90,7 @@ my role Iterable {

method !SETIFY(\type) {
(my \iterator := self.flat.iterator).is-lazy
?? self.fail-iterator-cannot-be-lazy('coerce', type.^name)
?? type.fail-iterator-cannot-be-lazy('coerce')
!! nqp::elems(my $elems := Rakudo::QuantHash.ADD-PAIRS-TO-SET(
nqp::create(Rakudo::Internals::IterationSet),iterator,Mu
))
Expand All @@ -115,7 +115,7 @@ multi sub infix:<eqv>(Iterable:D \a, Iterable:D \b) {
a.is-lazy,
nqp::if( # a lazy
b.is-lazy,
Any.throw-iterator-cannot-be-lazy('eqv') # a && b lazy
Any.throw-iterator-cannot-be-lazy('eqv','') # a && b lazy
),
nqp::if( # a NOT lazy
b.is-lazy,
Expand All @@ -141,7 +141,7 @@ multi sub infix:<eqv>(Iterable:D \a, Iterable:D \b) {
),
nqp::if(
ia.is-lazy,
Any.throw-iterator-cannot-be-lazy('eqv'),
Any.throw-iterator-cannot-be-lazy('eqv',''),
nqp::stmts(
nqp::until(
nqp::stmts(
Expand Down
2 changes: 1 addition & 1 deletion src/core.c/Mix.pm6
Expand Up @@ -10,7 +10,7 @@ my class Mix does Mixy {
#--- interface methods
multi method STORE(Mix:D: Iterable:D \iterable, :INITIALIZE($)! --> Mix:D) {
(my \iterator := iterable.iterator).is-lazy
?? self.fail-iterator-cannot-be-lazy('.initialize', self.^name)
?? self.fail-iterator-cannot-be-lazy('.initialize')
!! self.SET-SELF(Rakudo::QuantHash.ADD-PAIRS-TO-MIX(
nqp::create(Rakudo::Internals::IterationSet),iterator,self.keyof
))
Expand Down
2 changes: 1 addition & 1 deletion src/core.c/MixHash.pm6
Expand Up @@ -10,7 +10,7 @@ my class MixHash does Mixy {

multi method STORE(MixHash:D: Iterable:D \iterable --> MixHash:D) {
(my \iterator := iterable.iterator).is-lazy
?? self.fail-iterator-cannot-be-lazy('initialize', self.^name)
?? self.fail-iterator-cannot-be-lazy('initialize')
!! self.SET-SELF(
Rakudo::QuantHash.ADD-PAIRS-TO-MIX(
nqp::create(Rakudo::Internals::IterationSet),
Expand Down
2 changes: 1 addition & 1 deletion src/core.c/Mixy.pm6
Expand Up @@ -69,7 +69,7 @@ my role Mixy does Baggy {
#--- object creation methods
method new-from-pairs(Mixy:_: *@pairs --> Mixy:D) {
(my \iterator := @pairs.iterator).is-lazy
?? self.fail-iterator-cannot-be-lazy('coerce', self.^name)
?? self.fail-iterator-cannot-be-lazy('coerce')
!! nqp::create(self).SET-SELF(
Rakudo::QuantHash.ADD-PAIRS-TO-MIX(
nqp::create(Rakudo::Internals::IterationSet),
Expand Down
4 changes: 2 additions & 2 deletions src/core.c/Rakudo/Iterator.pm6
Expand Up @@ -2255,7 +2255,7 @@ class Rakudo::Iterator {
method new(\iterator,\n,\action,\f) {
nqp::if(
iterator.is-lazy,
Any.throw-iterator-cannot-be-lazy(action),
Any.throw-iterator-cannot-be-lazy(action,''),
nqp::if(
nqp::istype(n,Whatever),
iterator, # * just give back itself
Expand Down Expand Up @@ -2324,7 +2324,7 @@ class Rakudo::Iterator {
method LastValue(\iterator, $action) is raw {
nqp::if(
iterator.is-lazy,
Any.throw-iterator-cannot-be-lazy($action),
Any.throw-iterator-cannot-be-lazy($action,''),
nqp::stmts(
(my $result := IterationEnd),
nqp::if(
Expand Down
2 changes: 1 addition & 1 deletion src/core.c/Set.pm6
Expand Up @@ -94,7 +94,7 @@ my class Set does Setty {
#--- interface methods
multi method STORE(Set:D: Iterable:D \iterable, :INITIALIZE($)! --> Set:D) {
(my \iterator := iterable.iterator).is-lazy
?? self.fail-iterator-cannot-be-lazy('initialize', self.^name)
?? self.fail-iterator-cannot-be-lazy('initialize')
!! self.SET-SELF(Rakudo::QuantHash.ADD-PAIRS-TO-SET(
nqp::create(Rakudo::Internals::IterationSet),
iterator,
Expand Down
2 changes: 1 addition & 1 deletion src/core.c/SetHash.pm6
Expand Up @@ -194,7 +194,7 @@ my class SetHash does Setty {
#--- interface methods
multi method STORE(SetHash:D: Iterable:D \iterable --> SetHash:D) {
(my \iterator := iterable.iterator).is-lazy
?? self.fail-iterator-cannot-be-lazy('initialize', self.^name)
?? self.fail-iterator-cannot-be-lazy('initialize')
!! self.SET-SELF(
Rakudo::QuantHash.ADD-PAIRS-TO-SET(
nqp::create(Rakudo::Internals::IterationSet),
Expand Down
4 changes: 2 additions & 2 deletions src/core.c/Setty.pm6
Expand Up @@ -6,7 +6,7 @@ my role Setty does QuantHash {
# private method to create Set from iterator, check for laziness
method !create-from-iterator(\type, \iterator --> Setty:D) {
iterator.is-lazy
?? self.fail-iterator-cannot-be-lazy('coerce', type.^name)
?? type.fail-iterator-cannot-be-lazy('coerce')
!! nqp::create(type).SET-SELF(
Rakudo::QuantHash.ADD-ITERATOR-TO-SET(
nqp::create(Rakudo::Internals::IterationSet),
Expand Down Expand Up @@ -37,7 +37,7 @@ my role Setty does QuantHash {

method new-from-pairs(*@pairs --> Setty:D) {
(my \iterator := @pairs.iterator).is-lazy
?? self.fail-iterator-cannot-be-lazy('coerce', self.^name)
?? self.fail-iterator-cannot-be-lazy('coerce')
!! nqp::create(self).SET-SELF(
Rakudo::QuantHash.ADD-PAIRS-TO-SET(
nqp::create(Rakudo::Internals::IterationSet),
Expand Down

0 comments on commit 71960b1

Please sign in to comment.