-
Notifications
You must be signed in to change notification settings - Fork 15
Refactor: everything is an object #242
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
base: master
Are you sure you want to change the base?
Conversation
d1baf04 to
885f903
Compare
In eager anticipation of actually having enums in the language at some point.
And introduce Dict in the process!
|
Here's an interesting snag this refactor has run into: So, we want to replace ...Or maybe not. Maybe I can break the circularity by making the But yeah, this is tortuous to think about. Even though in one sense 007 should've had the factoring we're heading to all along, I strongly doubt I would've been able to produce it from the start. |
Now that it's ambient in all of bound-method.
|
I must say this is coming together really nicely. |
So we can fill them with name, type, and (later) whether they're optional, or have an initializer. All this is going to feed back into class declarations later, and make them a lot simpler to set up.
Since it's supposed to be a subtype of Object, it needs to have a $.type. This will only ever start to matter once someone starts subtyping the Type hierarchy... but then it'll matter big time.
An interesting thing with Q::Unquote showed up on the way. Will think about that a bit and handle it more properly later.
Update: ~220 s. Still not sorry. |
07d5ba2 to
a2b153a
Compare
|
This PR has now drifted far from I tried rebasing once already, a few weeks ago, and failed. So here's a new-year's resolution for you: I want to merge all the things in this PR into master, sooner rather than later. I think the way to do it is in topical parts. Namely:
The last step might be possible to re-do both as bigger steps, and in conceptual parts. Now we largely know where we're going. In other words, I want to close this long-running PR, but on a happy note, knowing that all the advances going into this PR have made it in one way or another. |
|
Heads-up: I'm going on a two-week vacation starting today. Expect some 007 activity, especially focusing around picking the good stuff out of this PR. (But I also want to look closely at |
|
In the design specified in this PR, the top I now believe that to be an error. In I don't immediately have a similarly nice solution for replacing I can't quite motivate why I feel it's important for |
This is a work in progress.
The main thrust of this refactor is to finally rid 007 of all the
Val::types and all theQ::types on the Perl 6 level.Having the type structure in the host language mirror the type structure in the guest language has carried us unexpectedly far, but the idea is starting to crack at the seams as we introduce classes in 007, whose corresponding type in Perl 6 can't exist. Trying to uphold the illusion leads to contrived code like this:
MOP
The more direct beneficiary, though, is #144. Here's a quick note of the MOP (with a "not-quite-M") we're aiming for:
Object_007::ObjectNonefor abasetype,propertiesType_007::Typebase,fields,methodsThese two types circularly depend on each other:
Typeis a derived type/subclass of the typeObject.ObjectandTypeare instances of the typeType.The cycles are established in host code, so the apparent chicken-and-egg problem is not a big issue in practice.
Fun fact: the fact that
Typeis an instance of typeTypemeans that 007 is susceptible to Girard's paradox. Unfortunately, all explanations of this paradox that I've found are too abstract for me to realize in what way, if any, we'd end up being sorry for inviting this type-system equivalent of Russell's paradox into our language. Until further notice, I consider the above setup rather elegant.The refactor is the biggest change to 007 since it was created. In order to even remotely manage complexity, I proceed by way of Fowler's asset capture: let the new object model handle one more type, and then remove the old type.
The files
_007/Val.pmand_007/Q.pmwill end up disappearing, because they represent an obsolete subdivision between "value types" and "Qtypes". Instead, we'll probably end up with_007/Type.pmand_007/Object.pm.Wrapped types
The point of wrapped types is to borrow the semantics of types from the host language as an internal implementation detail in the guest language. It means that an instance of a wrapped type is an opaque thing with insufficient data on the 007 level to work the way it does. It'd mean that e.g.
infix:<==>,infix:<+>,infix:<~>andinfix:«<»are "axioms" from the point of view of 007, since they're opaque too and rooted in the host language.So far the wrapped types are
Int,Str, andArray. (Boolis not a wrapped type.)TODO
Things that I need to finish up before merge:
TYPE_TYPEandTYPE_INTinto a hashStrandArrayNoneTypeandBoolExceptionDicttype, as simple as possible and asset-captureObject(note the pre-Introduce a dictionary type #184 confusion here)SubandMacro(this one will be tricky)Regex_007/Q.pmType_007/Val.pmsevenizeintowraponce the latter becomes availableX::TypeCheckerrors which got a meaningless:expectedvalue of_007::Objectduring the refactorStrand maybereprBoolt/features/objects.tthat was removed in the heat of battle because it needed to be rewritten for mostlyDictanywaypropertymethod inRuntime.pmgoes away completely, fully replaced by method definitions on the classes themselvesfieldsthan just string names: field type,requiredoptional, initializer.Typefully appear to subclassObjecttype-chain.reverse.map— finding all the fields, including inherited ones, for example. Find all the uses of this pattern and extract one or more appropriate methods intoTypeType.createfrom taking an array-of-arrays to taking a dictt/features/expr.t(after MoarVM/MoarVM@e86428d45e lands in Rakudo blead)