Skip to content

Instantly share code, notes, and snippets.

@lizmat
Created October 6, 2015 07:59
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 lizmat/2bf702c8c08587c3a231 to your computer and use it in GitHub Desktop.
Save lizmat/2bf702c8c08587c3a231 to your computer and use it in GitHub Desktop.
moving DEPRECATED to Rakudo::Internals makes Optimizer infiniloop
diff --git a/src/Perl6/World.nqp b/src/Perl6/World.nqp
index dfa47dd..bcf77a4 100644
--- a/src/Perl6/World.nqp
+++ b/src/Perl6/World.nqp
@@ -766,7 +766,8 @@ class Perl6::World is HLL::World {
}
method DEPRECATED($/,$alternative,$from,$removed,:$what,:$line,:$file) {
- my $DEPRECATED := self.find_symbol(['&DEPRECATED']);
+ my $DEPRECATED :=
+ self.find_symbol(['Rakudo','Internals','&DEPRECATED']);
unless nqp::isnull($DEPRECATED) {
$DEPRECATED($alternative,$from,$removed,
:$what,
diff --git a/src/core/Deprecations.pm b/src/core/Deprecations.pm
index 7775c31..8f0eada 100644
--- a/src/core/Deprecations.pm
+++ b/src/core/Deprecations.pm
@@ -20,12 +20,13 @@ class Deprecation {
my $message = "Saw {+%DEPRECATIONS} occurrence{ 's' if +%DEPRECATIONS != 1 } of deprecated code.\n";
$message ~= ("=" x 80) ~ "\n";
- for %DEPRECATIONS.sort(*.key)>>.value>>.report -> $r {
+ for %Rakudo::Internals::DEPRECATIONS.sort(*.key)>>.value>>.report -> $r {
$message ~= $r;
$message ~= ("-" x 80) ~ "\n";
}
- %DEPRECATIONS = (); # reset for new batches if applicable
+ # reset for new batches if applicable
+ %Rakudo::Internals::DEPRECATIONS = ();
$message.chop;
}
@@ -48,49 +49,6 @@ class Deprecation {
}
}
-sub DEPRECATED($alternative,$from?,$removed?,:$up = 1,:$what,:$file,:$line) {
-
- # not deprecated yet
- state $version = $*PERL.compiler.version;
- my Version $vfrom;
- my Version $vremoved;
- if $from {
- $vfrom = Version.new($from);
- return if ($version cmp $vfrom) ~~ Less | Same; # can be better?
- }
- $vremoved = Version.new($removed) if $removed;
-
- my $bt = Backtrace.new;
- my $deprecated =
- $bt[ my $index = $bt.next-interesting-index(2, :named, :setting) ];
- $index = $bt.next-interesting-index($index, :noproto, :setting) for ^$up;
- my $callsite = $bt[$index];
-
- # get object, existing or new
- my $dep = $what
- ?? Deprecation.new(
- :name($what),
- :$alternative,
- :from($vfrom),
- :removed($vremoved) )
- !! Deprecation.new(
- file => $deprecated.file,
- type => $deprecated.subtype.tc,
- package => try { $deprecated.package.^name } // 'unknown',
- name => $deprecated.subname,
- :$alternative,
- :from($vfrom),
- :removed($vremoved),
- );
- $dep = %DEPRECATIONS{$dep.WHICH} //= $dep;
-
- state $fatal = %*ENV<RAKUDO_DEPRECATIONS_FATAL>;
- die $dep.report if $fatal;
-
- # update callsite
- $dep.callsites{$file // $callsite.file.IO}{$line // $callsite.line}++;
-}
-
END {
unless %*ENV<RAKUDO_NO_DEPRECATIONS> {
if Deprecation.report -> $message {
diff --git a/src/core/Rakudo/Internals.pm b/src/core/Rakudo/Internals.pm
index c060d59..5144ad7 100644
--- a/src/core/Rakudo/Internals.pm
+++ b/src/core/Rakudo/Internals.pm
@@ -1,5 +1,9 @@
my role Iterator { ... }
+my class Backtrace { ... }
+my class Deprecation { ... }
+my class Version { ... }
+
my module Rakudo::Internals {
our role MapIterator does Iterator {
@@ -81,6 +85,52 @@ my module Rakudo::Internals {
}
0;
}
+
+ our %DEPRECATIONS; # where we keep our deprecation info
+ our sub DEPRECATED(
+ $alternative, $from?, $removed?, :$up = 1, :$what, :$file, :$line
+ ) {
+
+ # not deprecated yet
+ state $version = $*PERL.compiler.version;
+ my Version $vfrom;
+ my Version $vremoved;
+ if $from {
+ $vfrom = Version.new($from);
+ return if ($version cmp $vfrom) ~~ Less | Same; # can be better?
+ }
+ $vremoved = Version.new($removed) if $removed;
+
+ my $bt = Backtrace.new;
+ my $deprecated =
+ $bt[ my $index = $bt.next-interesting-index(2, :named, :setting) ];
+ $index = $bt.next-interesting-index($index, :noproto, :setting) for ^$up;
+ my $callsite = $bt[$index];
+
+ # get object, existing or new
+ my $dep = $what
+ ?? Deprecation.new(
+ :name($what),
+ :$alternative,
+ :from($vfrom),
+ :removed($vremoved) )
+ !! Deprecation.new(
+ file => $deprecated.file,
+ type => $deprecated.subtype.tc,
+ package => try { $deprecated.package.^name } // 'unknown',
+ name => $deprecated.subname,
+ :$alternative,
+ :from($vfrom),
+ :removed($vremoved),
+ );
+ $dep = %DEPRECATIONS{$dep.WHICH} //= $dep;
+
+ state $fatal = %*ENV<RAKUDO_DEPRECATIONS_FATAL>;
+ die $dep.report if $fatal;
+
+ # update callsite
+ $dep.callsites{$file // $callsite.file.IO}{$line // $callsite.line}++;
+ }
}
# vim: ft=perl6 expandtab sw=4
diff --git a/src/core/traits.pm b/src/core/traits.pm
index 718bc6a..4cf807d 100644
--- a/src/core/traits.pm
+++ b/src/core/traits.pm
@@ -125,7 +125,7 @@ multi sub trait_mod:<is>(Routine:D $r, :$DEPRECATED!) {
my $new := nqp::istype($DEPRECATED,Bool)
?? "something else"
!! $DEPRECATED;
- $r.add_phaser( 'ENTER', -> { DEPRECATED($new) } );
+ $r.add_phaser( 'ENTER', -> { Rakudo::Internals::DEPRECATED($new) } );
}
multi sub trait_mod:<is>(Routine:D $r, Mu :$inlinable!) {
$r.set_inline_info(nqp::decont($inlinable));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment