Skip to content

Commit

Permalink
Revert the original Optimizer behaviour, just fix it
Browse files Browse the repository at this point in the history
The old 'scan for setting' approach is better when handling of
user-defined settings is needed. I just got it adapted for mutiple COREs
and SETTINGs loaded.
  • Loading branch information
vrurg committed Jul 12, 2019
1 parent 6520787 commit 44ba0f2
Showing 1 changed file with 22 additions and 37 deletions.
59 changes: 22 additions & 37 deletions src/Perl6/Optimizer.nqp
Expand Up @@ -27,7 +27,7 @@ my class Symbols {
# Some interesting scopes.
has $!GLOBALish;
has $!UNIT;
# has $!SETTING;
has @!CORES;

# Cached setting lookups.
has %!SETTING_CACHE;
Expand Down Expand Up @@ -56,6 +56,7 @@ my class Symbols {
}
method BUILD($compunit) {
@!block_stack := [$compunit[0]];
@!CORES := [];
$!GLOBALish := $compunit.ann('GLOBALish');
$!UNIT := $compunit.ann('UNIT');
%!SETTING_CACHE := {};
Expand Down Expand Up @@ -267,47 +268,31 @@ my class Symbols {
return 0;
}

# method find_in_setting($symbol) {
# if !nqp::defined($!SETTING) {
# my int $i := +@!block_stack;
# while $i > 0 && !nqp::defined($!SETTING) {
# $i := $i - 1;
# my $block := @!block_stack[$i];
# my %sym := $block.symbol("!CORE_MARKER");
# if +%sym {
# $!SETTING := $block;
# }
# }
# if !nqp::defined($!SETTING) {
# nqp::die("Optimizer couldn't find CORE while looking for $symbol.");
# }
# } else {
# if nqp::existskey(%!SETTING_CACHE, $symbol) {
# return %!SETTING_CACHE{$symbol};
# }
# }
# my %sym := $!SETTING.symbol($symbol);
# if +%sym {
# return %!SETTING_CACHE{$symbol} := self.force_value(%sym, $symbol, 1);
# }
# nqp::die("Optimizer couldn't find $symbol in SETTING.");
# }

method find_in_setting($symbol) {
if nqp::existskey(%!SETTING_CACHE, $symbol) {
return %!SETTING_CACHE{$symbol};
}
my @settings := $*W.context().SETTINGS();
unless +@settings {
nqp::die("Optimizer couldn't find CORE while looking for $symbol.");
if !nqp::elems(@!CORES) {
my int $i := +@!block_stack;
while $i > 0 {
$i := $i - 1;
my $block := @!block_stack[$i];
my %sym := $block.symbol("!CORE_MARKER");
if +%sym {
nqp::push(@!CORES, $block);
}
}
if !nqp::elems(@!CORES) {
nqp::die("Optimizer couldn't find CORE while looking for $symbol.");
}
} else {
if nqp::existskey(%!SETTING_CACHE, $symbol) {
return %!SETTING_CACHE{$symbol};
}
}
my int $i := +@settings;
while $i > 0 {
my $setting := @settings[--$i];
my %sym := $setting.symbol($symbol);
for @!CORES -> $core {
my %sym := $core.symbol($symbol);
if +%sym {
return %!SETTING_CACHE{$symbol} := self.force_value(%sym, $symbol, 1);
}

}
nqp::die("Optimizer couldn't find $symbol in SETTING.");
}
Expand Down

0 comments on commit 44ba0f2

Please sign in to comment.