Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avm2: Various Object / ClassObject cleanups #5325

Merged
merged 15 commits into from
Sep 21, 2021

Conversation

adrian17
Copy link
Collaborator

@adrian17 adrian17 commented Sep 18, 2021

This changes aren't intended to have major observable impact, unless my fundamental assumptions or understanding of old implementation turn out to be completely wrong.

This is also a prelude to future PR, to make ScriptObject's instance traits not per-instance. Also prelude to the SomeClass as Class fix.

In particular:

  • I might have accidentally introduced reliance on the assumption that superclass_object, instance_of, SystemClasses etc are always ClassObjects. I am willing to introduce this assumption in future PRs (unless someone proves me wrong), but not here.
  • avm2: Replace all uses of as_class_object by instance_of is a change in logic, in theoretical fringe cases where someone somehow passes a class object to specific instance initializer (but I don't even know if it's possible and it still shouldn't change observable behavior, I think). One place I am worried about is op_call_property/op_call_prop_void, but for all I know this might actually be a change for the better.
  • I'm also assuming that get_own_class_definition() (old as_class()) in 99% of cases shouldn't be used; you either want an object as class (as_class_object()) or an object's class (instance_of()), not a mix of these. I'm delaying cleaning these up until future PR, as these changes will definitely increase strictness. nvm doing this now in the last commit; it'll probably require extra scrutiny.

@kmeisthax
Copy link
Member

I filed this PR adrian17#57 which should correctly make all classes instances of Class.

I won't be able to review the rest of this PR until later but what I saw of it looked good. Hopefully it doesn't conflict with #5317 too much.

Copy link
Member

@kmeisthax kmeisthax left a comment

Choose a reason for hiding this comment

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

Your PR looks good as is.

If you decide to merge in adrian17#57, I'll re-approve that immediately.

adrian17 and others added 15 commits September 22, 2021 00:04
* avm2: Properly make all classes an instance of `Class`.

Also, does this technically mean that `Class` is a metaclass?

* avm2: Remove `Function::from_method_and_proto` as it will no longer be needed

* avm2: Ensure builtin classes are also instances of `Class`.

This requires tying a veritable gordian knot of classes; everything needs to be allocated up-front, linked together, and then properly initialized later on. This necessitated splitting the whole class construction process up into three steps:

1. Allocation via `from_class_partial`, which does everything that can be done without any other classes
2. Weaving via `link_prototype` and `link_type`, which links all of the allocated parts together correctly. This also includes initializing `SystemClasses` and `SystemPrototypes`.
3. Initialization via `into_finished_class`, which must be done *after* the weave has finished.

Once complete you have core classes that are all instances of `Class`, along with prototypes that have their usual legacy quirks.

Note that this does *not* make prototypes instances of their class. We do need to do that, but doing so breaks ES3 legacy support. This is because we currently only work with bound methods, but need to be able to call unbound methods in `callproperty`.

* tests: Add a test for all core classes' instance-of relationships
@adrian17 adrian17 merged commit 42275f4 into ruffle-rs:master Sep 21, 2021
@adrian17 adrian17 deleted the avm2-classobject-cleanups branch September 21, 2021 22:33
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.

None yet

2 participants