Skip to content

Commit

Permalink
Add a newmixintype op
Browse files Browse the repository at this point in the history
A form of `newtype` that sets a flag saying that this type can be the
target of a mixin. Added as a new op used at type creation time so that
we can easily reason about a type always having that property for its
lifetime, rather than any timing worries about it being set later. This
alone doesn't do anything useful; the useful part will be when we start
to enforce its usage and then introduce new ops that avoid the whole
"look at real_data" dance in P6opaque attribute access, which it seems
can save us around 4 CPU instructions per attribute read/write. Which,
given we do a lot of those - Perl 6 is full of objects - is potentially
going to be a measurable improvement.
  • Loading branch information
jnthn committed Feb 13, 2019
1 parent 0d2968e commit b51bb13
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 13 deletions.
8 changes: 4 additions & 4 deletions lib/MAST/Ops.nqp
Expand Up @@ -2628,7 +2628,7 @@ BEGIN {
65,
58,
57,
65,
66,
65,
57,
66,
Expand Down Expand Up @@ -4125,7 +4125,7 @@ BEGIN {
'popcompsc', 411,
'scgetdesc', 412,
'loadbytecode', 413,
'DEPRECATED_1', 414,
'newmixintype', 414,
'DEPRECATED_2', 415,
'iscompunit', 416,
'compunitmainline', 417,
Expand Down Expand Up @@ -4944,7 +4944,7 @@ BEGIN {
'popcompsc',
'scgetdesc',
'loadbytecode',
'DEPRECATED_1',
'newmixintype',
'DEPRECATED_2',
'iscompunit',
'compunitmainline',
Expand Down Expand Up @@ -8563,7 +8563,7 @@ BEGIN {
my uint $index0 := nqp::unbox_u($op0); nqp::writeuint($bytecode, nqp::add_i($elems, 2), $index0, 5);
my uint $index1 := nqp::unbox_u($op1); nqp::writeuint($bytecode, nqp::add_i($elems, 4), $index1, 5);
},
'DEPRECATED_1', sub ($op0, $op1, $op2) {
'newmixintype', sub ($op0, $op1, $op2) {
my $bytecode := $*MAST_FRAME.bytecode;
my uint $elems := nqp::elems($bytecode);
nqp::writeuint($bytecode, $elems, 414, 5);
Expand Down
4 changes: 4 additions & 0 deletions src/6model/6model.h
Expand Up @@ -371,6 +371,10 @@ struct MVMSTable {
/* If this STable is currently in the process of being repossessed. Used
* to trigger clearup of memory pre-repossession. */
MVMuint8 being_repossessed;

/* If this STable represents a type that can be the target of a
* change_type - that is to say, it's been mixed in to. */
MVMuint8 is_mixin_type;
};

/* The representation operations table. Note that representations are not
Expand Down
8 changes: 6 additions & 2 deletions src/6model/serialization.c
Expand Up @@ -10,7 +10,7 @@

/* Version of the serialization format that we are currently at and lowest
* version we support. */
#define CURRENT_VERSION 20
#define CURRENT_VERSION 21
#define MIN_VERSION 16

/* Various sizes (in bytes). */
Expand Down Expand Up @@ -1172,6 +1172,7 @@ static void serialize_stable(MVMThreadContext *tc, MVMSerializationWriter *write
}

MVM_serialization_write_cstr(tc, writer, MVM_6model_get_stable_debug_name(tc, st));
MVM_serialization_write_int(tc, writer, st->is_mixin_type);

/* Store offset we save REPR data at. */
write_int32(writer->root.stables_table, offset + 8, writer->stables_data_offset);
Expand Down Expand Up @@ -2713,7 +2714,10 @@ static void deserialize_stable(MVMThreadContext *tc, MVMSerializationReader *rea
if (reader->root.version >= 18) {
st->debug_name = MVM_serialization_read_cstr(tc, reader);
} else {
st->debug_name = 0;
st->debug_name = NULL;
}
if (reader->root.version >= 21) {
st->is_mixin_type = MVM_serialization_read_int(tc, reader);
}

/* If the REPR has a function to deserialize representation data, call it. */
Expand Down
11 changes: 10 additions & 1 deletion src/core/interp.c
Expand Up @@ -3211,6 +3211,16 @@ void MVM_interp_run(MVMThreadContext *tc, void (*initial_invoke)(MVMThreadContex
MVM_load_bytecode(tc, filename);
goto NEXT;
}
OP(newmixintype): {
MVMObject *how = GET_REG(cur_op, 2).o;
MVMString *repr_name = GET_REG(cur_op, 4).s;
const MVMREPROps *repr = MVM_repr_get_by_name(tc, repr_name);
MVMObject *type = repr->type_object_for(tc, how);
STABLE(type)->is_mixin_type = 1;
GET_REG(cur_op, 0).o = type;
cur_op += 6;
goto NEXT;
}
OP(iscompunit): {
MVMObject *maybe_cu = GET_REG(cur_op, 2).o;
GET_REG(cur_op, 0).i64 = REPR(maybe_cu)->ID == MVM_REPR_ID_MVMCompUnit;
Expand Down Expand Up @@ -6342,7 +6352,6 @@ void MVM_interp_run(MVMThreadContext *tc, void (*initial_invoke)(MVMThreadContex
}
/* The compiler compiles faster if all deprecated are together and at the end
* even though the op numbers are technically out of order. */
OP(DEPRECATED_1):
OP(DEPRECATED_2):
MVM_exception_throw_adhoc(tc, "The mastto* ops were removed in MoarVM 2018.01.");
OP(DEPRECATED_4):
Expand Down
2 changes: 1 addition & 1 deletion src/core/oplabels.h
Expand Up @@ -415,7 +415,7 @@ static const void * const LABELS[] = {
&&OP_popcompsc,
&&OP_scgetdesc,
&&OP_loadbytecode,
&&OP_DEPRECATED_1,
&&OP_newmixintype,
&&OP_DEPRECATED_2,
&&OP_iscompunit,
&&OP_compunitmainline,
Expand Down
2 changes: 1 addition & 1 deletion src/core/oplist
Expand Up @@ -471,7 +471,7 @@ pushcompsc r(obj)
popcompsc w(obj)
scgetdesc w(str) r(obj)
loadbytecode w(str) r(str) :invokish :maycausedeopt :noinline
DEPRECATED_1 r(obj) r(obj) r(str)
newmixintype w(obj) r(obj) r(str)
DEPRECATED_2 w(obj) r(obj) r(obj) :invokish :maycausedeopt
iscompunit w(int64) r(obj) :pure
compunitmainline w(obj) r(obj)
Expand Down
6 changes: 3 additions & 3 deletions src/core/ops.c
Expand Up @@ -6208,8 +6208,8 @@ static const MVMOpInfo MVM_op_infos[] = {
{ MVM_operand_write_reg | MVM_operand_str, MVM_operand_read_reg | MVM_operand_str }
},
{
MVM_OP_DEPRECATED_1,
"DEPRECATED_1",
MVM_OP_newmixintype,
"newmixintype",
" ",
3,
0,
Expand All @@ -6220,7 +6220,7 @@ static const MVMOpInfo MVM_op_infos[] = {
0,
0,
0,
{ MVM_operand_read_reg | MVM_operand_obj, MVM_operand_read_reg | MVM_operand_obj, MVM_operand_read_reg | MVM_operand_str }
{ MVM_operand_write_reg | MVM_operand_obj, MVM_operand_read_reg | MVM_operand_obj, MVM_operand_read_reg | MVM_operand_str }
},
{
MVM_OP_DEPRECATED_2,
Expand Down
2 changes: 1 addition & 1 deletion src/core/ops.h
Expand Up @@ -415,7 +415,7 @@
#define MVM_OP_popcompsc 411
#define MVM_OP_scgetdesc 412
#define MVM_OP_loadbytecode 413
#define MVM_OP_DEPRECATED_1 414
#define MVM_OP_newmixintype 414
#define MVM_OP_DEPRECATED_2 415
#define MVM_OP_iscompunit 416
#define MVM_OP_compunitmainline 417
Expand Down

0 comments on commit b51bb13

Please sign in to comment.