Skip to content

Module#prepend - #2885

Merged
matz merged 29 commits into
mruby:masterfrom
polyfox:module-prepend
Sep 4, 2015
Merged

Module#prepend#2885
matz merged 29 commits into
mruby:masterfrom
polyfox:module-prepend

Conversation

@archseer

Copy link
Copy Markdown
Contributor

Hi, we requested Module#prepend, so about a year later we figured what the heck and went ahead and implemented it.

We've gone and ported over the original ruby commits by ko1 and nobu over to mruby, all tests currently pass. RClass struct size is now bigger, because we needed to add origin, but that seems unavoidable.

/cc @matz @cremno @zzak

Closes #2082.

Blaž Hrastnik and others added 26 commits July 13, 2015 14:04
Currently kind_of fails miserably, still looking for the reason
And of course, some of them fail miserably
Not sure if this apart of the ISO standard, so make sure its not misrepresented
Prepended modules would include their origin ICLASS
Also tried to fix it, however the problem lies with how aliased methods
are done and their internal structure.

mruby simply aliases methods by grabbing the RProc and giving it a new name,
super then determines the original method to call by using the name

so a method called m, aliased as m2, will call the m2 super method instead of m
Comment thread include/mruby/class.h Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think MRB_FLAG_IS_INSTANCE should be renamed to MRB_INSTANCE_TT_MASK since it's a mask for instance type tag.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@take-cheeze Ah, right, okay, I've changed it, can you review again?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@matz

matz commented Jul 16, 2015

Copy link
Copy Markdown
Member

Thank you for the implementation. I will merge this. But I need at least a few days to review the patch, sinch the change is huge.

@archseer

Copy link
Copy Markdown
Contributor Author

@matz Alright, thank you! For reference, here's our fork PR where we discussed the implementation commit-by-commit, if it's of any help: polyfox#1

Comment thread src/class.c

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

static or declare it in a header: mruby.h like mrb_include_module() or maybe even mruby/class.h because it won't be used that often.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, we missed that one, thanks!

Since I can't forsee any reason to use it directly inplace of using
prepend/include
@archseer

Copy link
Copy Markdown
Contributor Author

Hi @matz, sorry for the bother, any updates on this?

@matz

matz commented Sep 3, 2015

Copy link
Copy Markdown
Member

Finally I took time to review this pull request. Sorry for being so late.

The PR seems fine except for on thing. You have added origin member to struct RClass but due to union RVALUE system in gc.c, adding an extra member to the struct would increase 1 word memory space for every mruby object. This is unacceptable for small footprint implementation.

If you are willing to address this issue, I'd love to wait. If you are not, I will take time to fix, but you may have to wait longer in this case.

@archseer

archseer commented Sep 3, 2015

Copy link
Copy Markdown
Contributor Author

Hi @matz, in the original pull request description we pointed out "RClass struct size is now bigger, because we needed to add origin, but that seems unavoidable."

I'd be happy to try and implement an alternative, however I have no idea how that would look like.

@furunkel

furunkel commented Sep 3, 2015

Copy link
Copy Markdown
Contributor

A golden opportunity to remove RVALUE and introduce something like a segregated free list 😉 .

@matz

matz commented Sep 4, 2015

Copy link
Copy Markdown
Member

@furunkel it's trade-off, RVALUE makes GC simpler and sweeping faster.

@archseer I think I can succeeded to remove origin by adding one bit flag. I will commit soon.

@matz
matz merged commit 26bee4a into mruby:master Sep 4, 2015
matz added a commit that referenced this pull request Sep 4, 2015
…2885

instead origin is saved in ICLASS with MRB_FLAG_IS_ORIGIN set.
@archseer

archseer commented Sep 4, 2015

Copy link
Copy Markdown
Contributor Author

🎉 🎈 🎉 thanks matz!

@furunkel

furunkel commented Sep 4, 2015

Copy link
Copy Markdown
Contributor

@matz, sure, but segregating into a small number of object types, say, small, medium, large wouldn't be very complicated and allow to simplify a few other things while not really hurting sweeping performance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants