Skip to content

Commit

Permalink
Start initializing most attributes at creation
Browse files Browse the repository at this point in the history
Rather than waiting for their first touch. As well as the expected cases
that we need to exclude (BUILD + default or required), we also need to
for now exclude non-P6opaque cases. This is actually a broad brush for
the storage of arrays and hashes; we rely on the auto-viv there too
(though will address that in future changes).

A handful of spectests are unhappy about this change, and will need a
closer look.
  • Loading branch information
jnthn committed Jul 26, 2019
1 parent 6ed66c2 commit 7f58ed0
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/Perl6/Metamodel/REPRComposeProtocol.nqp
Expand Up @@ -29,6 +29,8 @@ role Perl6::Metamodel::REPRComposeProtocol {
# ...then an array of hashes per attribute...
my @attrs;
nqp::push(@type_info, @attrs);
my $build := $type_obj.HOW.find_method($obj, 'BUILD', :no_fallback(1));
my $has_build := !nqp::isnull($build) && nqp::isconcrete($build) ?? 1 !! 0;
for $type_obj.HOW.attributes(nqp::decont($type_obj), :local) -> $attr {
my %attr_info;
%attr_info<name> := $attr.name;
Expand All @@ -38,7 +40,26 @@ role Perl6::Metamodel::REPRComposeProtocol {
%attr_info<box_target> := 1;
}
if nqp::can($attr, 'auto_viv_container') {
%attr_info<auto_viv_container> := $attr.auto_viv_container;
# We only need lazy auto-viv of the container if we need to do
# attrinited on it. In other cases, we're better off creating
# it at object allocation time. The case we need to do the
# attrinited is when the attribute has a default *and* we
# have a BUILD submethod. Temporarily, we also force this
# to happen when the REPR is not P6opaque.
my $viv_value := $attr.auto_viv_container;
#?if moar
my $not_p6o := nqp::reprname($viv_value) ne 'P6opaque';
if $not_p6o || $has_build &&
(nqp::can($attr, 'build') && $attr.build ||
nqp::can($attr, 'required') && $attr.required) {
#?endif
%attr_info<auto_viv_container> := $viv_value;
#?if moar
}
else {
%attr_info<setup_prototype> := $viv_value;
}
#?endif
}
if $attr.positional_delegate {
%attr_info<positional_delegate> := 1;
Expand Down

0 comments on commit 7f58ed0

Please sign in to comment.