Skip to content

Commit 146ede2

Browse files
committed
Start explicitly marking out mixin types
MoarVM will start requiring types that are the target type of a rebless (only used for mixins) to up-front declare they will be used that way. This means it can assume anything that is not such a type - the vast majority of cases - will never have extra data attached to them, which can be used to generate simpler attribute access code. While it's only MoarVM that will immediately use this, it's quite possible that other backends will be able to make use of such things, so it is done in a cross-backend way. This also needed a rebootstrap of both the JVM and MoarVM backends.
1 parent c267ae4 commit 146ede2

26 files changed

+15
-7
lines changed

src/how/NQPClassHOW.nqp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,17 @@ knowhow NQPClassHOW {
8383

8484
# Create a new meta-class instance, and then a new type object
8585
# to go with it, and return that.
86-
method new_type(:$name = '<anon>', :$repr = 'P6opaque', :$array_type) {
86+
method new_type(:$name = '<anon>', :$repr = 'P6opaque', :$array_type, :$is_mixin) {
8787
my $metaclass := self.new(:name($name));
88-
nqp::setdebugtypename(
89-
nqp::setwho(nqp::newtype($metaclass, $repr), {}),
90-
$name);
88+
my $new_type;
89+
if $is_mixin {
90+
$new_type := nqp::newmixintype($metaclass, $repr);
91+
$metaclass.set_is_mixin($new_type);
92+
}
93+
else {
94+
$new_type := nqp::newtype($metaclass, $repr);
95+
}
96+
nqp::setdebugtypename(nqp::setwho($new_type, {}), $name)
9197
}
9298

9399
method add_method($obj, $name, $code_obj) {
@@ -751,8 +757,7 @@ knowhow NQPClassHOW {
751757

752758
# Create new type, derive it from ourself and then add
753759
# all the roles we're mixing it.
754-
$new_type := self.new_type(:name($new_name), :repr($obj.REPR));
755-
$new_type.HOW.set_is_mixin($new_type);
760+
$new_type := self.new_type(:name($new_name), :repr($obj.REPR), :is_mixin);
756761
$new_type.HOW.add_parent($new_type, $obj.WHAT);
757762
$new_type.HOW.add_role($new_type, $role);
758763
$new_type.HOW.compose($new_type);

src/vm/js/Operations.nqp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,7 @@ class QAST::OperationsJS {
428428

429429
add_simple_op('reprname', $T_STR, [$T_OBJ], :decont(0));
430430
add_simple_op('newtype', $T_OBJ, [$T_OBJ, $T_STR], :side_effects, :decont(0));
431+
add_simple_op('newmixintype', $T_OBJ, [$T_OBJ, $T_STR], :side_effects, :decont(0));
431432

432433
add_cmp_op('cmp_i', $T_INT);
433434
add_cmp_op('cmp_n', $T_NUM);

src/vm/js/nqp-runtime/core.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ op.reprname = function(obj) {
421421
}
422422
};
423423

424-
op.newtype = function(how, repr) {
424+
op.newtype = op.newmixintype = function(how, repr) {
425425
if (!reprs[repr]) {
426426
throw 'Unknown REPR: ' + repr;
427427
}

src/vm/jvm/QAST/Compiler.nqp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2647,6 +2647,7 @@ QAST::OperationsJAST.map_classlib_core_op('hllboxtype_s', $TYPE_OPS, 'hllboxtype
26472647
QAST::OperationsJAST.map_classlib_core_op('can', $TYPE_OPS, 'can', [$RT_OBJ, $RT_STR], $RT_INT, :tc);
26482648
QAST::OperationsJAST.map_classlib_core_op('reprname', $TYPE_OPS, 'reprname', [$RT_OBJ], $RT_STR, :tc);
26492649
QAST::OperationsJAST.map_classlib_core_op('newtype', $TYPE_OPS, 'newtype', [$RT_OBJ, $RT_STR], $RT_OBJ, :tc);
2650+
QAST::OperationsJAST.map_classlib_core_op('newmixintype', $TYPE_OPS, 'newtype', [$RT_OBJ, $RT_STR], $RT_OBJ, :tc);
26502651
QAST::OperationsJAST.map_classlib_core_op('composetype', $TYPE_OPS, 'composetype', [$RT_OBJ, $RT_OBJ], $RT_OBJ, :tc);
26512652
QAST::OperationsJAST.map_classlib_core_op('setboolspec', $TYPE_OPS, 'setboolspec', [$RT_OBJ, $RT_INT, $RT_OBJ], $RT_OBJ, :tc);
26522653
QAST::OperationsJAST.map_classlib_core_op('setmethcache', $TYPE_OPS, 'setmethcache', [$RT_OBJ, $RT_OBJ], $RT_OBJ, :tc);

src/vm/jvm/stage0/JASTNodes.jar

14 Bytes
Binary file not shown.

src/vm/jvm/stage0/ModuleLoader.jar

1 Byte
Binary file not shown.

src/vm/jvm/stage0/NQPCORE.setting.jar

185 Bytes
Binary file not shown.

src/vm/jvm/stage0/NQPHLL.jar

277 Bytes
Binary file not shown.

src/vm/jvm/stage0/NQPP6QRegex.jar

-11 Bytes
Binary file not shown.

src/vm/jvm/stage0/QAST.jar

521 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)