-
Notifications
You must be signed in to change notification settings - Fork 15
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
Refactor: everything is an object #242
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::Object
None
for abase
type
,properties
Type
_007::Type
base
,fields
,methods
These two types circularly depend on each other:
Type
is a derived type/subclass of the typeObject
.Object
andType
are 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
Type
is an instance of typeType
means 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.pm
and_007/Q.pm
will end up disappearing, because they represent an obsolete subdivision between "value types" and "Qtypes". Instead, we'll probably end up with_007/Type.pm
and_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
. (Bool
is not a wrapped type.)TODO
Things that I need to finish up before merge:
TYPE_TYPE
andTYPE_INT
into a hashStr
andArray
NoneType
andBool
Exception
Dict
type, as simple as possible and asset-captureObject
(note the pre-Introduce a dictionary type #184 confusion here)Sub
andMacro
(this one will be tricky)Regex
_007/Q.pm
Type
_007/Val.pm
sevenize
intowrap
once the latter becomes availableX::TypeCheck
errors which got a meaningless:expected
value of_007::Object
during the refactorStr
and mayberepr
Bool
t/features/objects.t
that was removed in the heat of battle because it needed to be rewritten for mostlyDict
anywayproperty
method inRuntime.pm
goes away completely, fully replaced by method definitions on the classes themselvesfields
than just string names: field type,requiredoptional, initializer.Type
fully appear to subclassObject
type-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 intoType
Type.create
from taking an array-of-arrays to taking a dictt/features/expr.t
(after MoarVM/MoarVM@e86428d45e lands in Rakudo blead)