Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Re-work the way we handle the fresh magicals flag, moving it into an …
…int in the StaticLexPad. Saves several thousand lines of generated PIR in the fixups in CORE.setting, and probably around a thousand PCC method calls (yeah, the slow ones...) on startup.
  • Loading branch information
jnthn committed Mar 1, 2012
1 parent 2d91ccc commit fb6bc7d
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 15 deletions.
4 changes: 1 addition & 3 deletions src/Perl6/Actions.pm
Expand Up @@ -244,9 +244,7 @@ class Perl6::Actions is HLL::Actions {
));

# Mainline should have fresh lexicals.
$unit.loadinit().push(PAST::Op.new(
:pasttype('callmethod'), :name('set_fresh_magicals'),
PAST::Val.new( :value($unit), :returns('LexInfo'))));
$*W.get_static_lexpad($unit).set_fresh_magicals();

# Get the block for the entire compilation unit.
my $outer := $*UNIT_OUTER;
Expand Down
9 changes: 9 additions & 0 deletions src/Perl6/Metamodel/StaticLexPad.pm
Expand Up @@ -10,6 +10,9 @@ class Perl6::Metamodel::StaticLexPad {
# Has anything changed since the guts last memoized it?
has int $!changed;

# Does this block get fresh magicals?
has int $!fresh_magicals;

# Adds a static value (which may actually be a container) to the static
# lexpad.
method add_static_value($name, $value, $is_cloned, $is_state) {
Expand All @@ -21,4 +24,10 @@ class Perl6::Metamodel::StaticLexPad {
$!changed := 1;
$value
}

# Flag that the block gets fresh magicals.
method set_fresh_magicals() {
$!fresh_magicals := 1;
$!changed := 1;
}
}
13 changes: 5 additions & 8 deletions src/Perl6/World.pm
Expand Up @@ -80,9 +80,10 @@ class Perl6::World is HLL::World {
}

# Create it a static lexpad object.
my $slp_type_obj := self.find_symbol(['StaticLexPad']);
my $slp_type_obj_ref := self.get_ref($slp_type_obj);
my $slp := nqp::create($slp_type_obj);
my $slp_type_obj := self.find_symbol(['StaticLexPad']);
my $slp := nqp::create($slp_type_obj);
nqp::bindattr($slp, $slp_type_obj, '%!static_values', nqp::hash());
nqp::bindattr($slp, $slp_type_obj, '%!flags', nqp::hash());

# Deserialization and fixup need to associate static lex pad with the
# low-level LexInfo.
Expand Down Expand Up @@ -691,11 +692,7 @@ class Perl6::World is HLL::World {

# If it's a routine, flag that it needs fresh magicals.
if pir::type_check__IPP($code, self.find_symbol(['Routine'])) {
my $set := PAST::Op.new(
:pasttype('callmethod'), :name('set_fresh_magicals'),
PAST::Val.new( :value($code_past), :returns('LexInfo')));
$des.push($set);
$fixups.push($set);
self.get_static_lexpad($code_past).set_fresh_magicals();
}

self.add_fixup_task(:deserialize_past($des), :fixup_past($fixups));
Expand Down
4 changes: 0 additions & 4 deletions src/pmc/perl6lexinfo.pmc
Expand Up @@ -135,10 +135,6 @@ compiler calls this method in response to a ".lex STRING, PREG" directive.
SET_ATTR_static_lexpad(INTERP, SELF, slp);
}

METHOD set_fresh_magicals() {
SET_ATTR_fresh_magicals(INTERP, SELF, 1);
}

METHOD get_static_code() {
PMC *static_code;
GET_ATTR_static_code(INTERP, SELF, static_code);
Expand Down
3 changes: 3 additions & 0 deletions src/pmc/perl6lexpad.pmc
Expand Up @@ -11,6 +11,7 @@ typedef struct {
PMC *static_values; /* The set of static values (hash names => values). */
PMC *flags; /* Flags for how we handle those (hash names => flags). */
INTVAL changed; /* Has anything in here changed since we last saw it? */
INTVAL fresh_magicals; /* Does this block get fresh magicals? */
} Rakudo_StaticLexPad;

/* Some useful types/container descriptors we like to have to hand. */
Expand Down Expand Up @@ -191,6 +192,7 @@ Return the LexInfo PMC, if any or a Null PMC.
/* Compute the caches if needed. */
if (static_lexpad->changed || PMC_IS_NULL(static_slots_cache)) {
/* (Re-)build caches. */
INTVAL fresh_magicals = static_lexpad->fresh_magicals;
PMC *slots = Parrot_pmc_new(interp, enum_class_ResizableIntegerArray);
PMC *values = Parrot_pmc_new(interp, enum_class_ResizablePMCArray);
PMC *clone_flags = Parrot_pmc_new(interp, enum_class_ResizableIntegerArray);
Expand All @@ -212,6 +214,7 @@ Return the LexInfo PMC, if any or a Null PMC.
SETATTR_Perl6LexInfo_static_values_cache(INTERP, info, values);
SETATTR_Perl6LexInfo_static_clone_flags_cache(INTERP, info, clone_flags);
SETATTR_Perl6LexInfo_state_flags_cache(INTERP, info, state_flags);
SETATTR_Perl6LexInfo_fresh_magicals(INTERP, info, fresh_magicals);
static_slots_cache = slots;

/* Clear changed flag. */
Expand Down

0 comments on commit fb6bc7d

Please sign in to comment.