Refactoring of the Objective-C integration#5766
Refactoring of the Objective-C integration#5766jacob-carlborg wants to merge 2 commits intodlang:masterfrom
Conversation
|
@yebblies Refactoring of the Objective-C integration |
|
Can you give a brief description of the purpose of the refactoring? My cursory look at it is it appears to move ObjC logic out of objc modules and dispersing it into the rest of the front end. Why? |
I talked with Daniel and Iain during dconf about this and they both think that this is the right decision. I'm pretty sure that David agrees as well. |
0fa2a8f to
1845ead
Compare
|
Hmm, seems I need to give this refactoring some more thought. |
9bb6cc8 to
c495956
Compare
c495956 to
c820a37
Compare
No, it's not. Header generation, json generation, ddoc, array ops, etc., are all factored out into separate modules. I would like to increase this sort of encapsulation, not decrease it. The main modules are already far too large and convoluted. Distributing the objc support among them will make things more convoluted and harder to understand. Your other goals with this are good, but I do not believe they require distributing their contents around the rest of the code to achieve them. |
|
Those other features are not adding new types, semantic processing, etc. We do not have a nice system for factoring out extern language support in dmd, and rather than making it clearer this layout just makes a mess. An entire function for two lines of code? It's a joke, and it doesn't work. Either this is a first-class feature that deserves being integrated with the rest of dmd, or we should delete it. |
|
Objective-C implementation is pretty dumb, I couldn't find a way to integrate it into GDC without #4813 |
|
Everything should have been put into an |
This. |
|
I am interested in proper encapsulation in order to reduce bugs and complexity. I am not interested in status symbols of where code is located. If objc is support is lacking (and I don't know if it is or is not) we can address that.
We have lots of functions in dmd that are a couple lines. They serve encapsulation purposes. As I recall you asked for a one-liner in root/outbuffer yesterday (a The front end, in my not-so-humble opinion, has major problems with lack of encapsulation. The lack of encapsulation is not a justification for even less encapsulation. |
|
The frontend definitely suffers from a lot of encapsulation problems. The question is just whether "Objective-C support" is an useful unit of encapsulation. |
That's what I intend to work on. After the huge 12k+ lines of code PR which was the initial one, we decided to split it up in more manageable pieces. The rest of the Objective-C support has not been integrated yet. I talked with Daniel at dconf and we agreed that we should do this refactoring first (assuming this is what he had in mind). |
The full integration will touch many (most) parts of the compiler. |
| TypeInfoClassDeclaration *vclassinfo; // the ClassInfo object for this ClassDeclaration | ||
| bool com; // true if this is a COM class (meaning it derives from IUnknown) | ||
| bool cpp; // true if this is a C++ interface | ||
| bool objc; // true if this is an Objective-C class/interface |
There was a problem hiding this comment.
Classes can only be com, cpp, or objc, but never two at once, right? These bool flags could be squashed into an enum later, perhaps.
There was a problem hiding this comment.
Yes, as far as I know. If it's objc it cannot be anything else at least. I guess a new PR would be a better fit for that.
There was a problem hiding this comment.
IIRC there is at least one other way to mark a class as c++, it could do with some cleaning up.
My point is that unless we're planning to delete it (and therefore want it nicely isolated and easy to delete) then we should put the parts where they logically make sense - next to the handling of other extern types in dmd.
These functions do not serve encapsulation purposes. They are simply manually outlined chunks of code, that only have one caller. If your concern is that it might not be immediately obvious what they're for, then adding comments would be a less disruptive solution.
Because it give a name to a common pattern... there is a difference here.
I would agree with you if I thought that outlining objective-C support into another file improved encapsulation. Instead it just hides the code from people editing the related functions, and adds more false dependencies between modules. Just look at how the line count changes... |
|
BTW, I added documentation for most of the remaining functions. Any reason why the Windows builds are still pending? It looks like it already has built twice on the other platforms. |
|
I assume the Windows failures are not related: |
|
@Hackerpilot thanks. Can we rerun the Windows tests? |
|
Awesome, all tests are passing now. |
| void accept(Visitor *v) { v->visit(this); } | ||
| }; | ||
|
|
||
| struct ObjcSelector |
There was a problem hiding this comment.
This should go in objc.d, there's no reason to make the fields and methods available throughout the compiler.
| Symbol *sfunc = toSymbol(fd); | ||
|
|
||
| if (esel) | ||
| if (global.params.hasObjectiveC && esel) |
There was a problem hiding this comment.
I don't see how this is an improvement.
|
I object to moving the code into func.d. I don't see how that improves anything. It reduces encapsulation by making the objc structs and members visible everywhere. I don't see how it makes anything easier to understand. |
c820a37 to
ee5fe1f
Compare
|
Could we please come to some form of agreement here. I would like to continue with the Objective-C integration but we need to decide how to structure the code. |
Removing files has no correlation with simplifying the design. But I see no reason why the ObjC logic cannot all be contained in objc.d, objc.h, and objc_glue.c. Then, one only has 3 files to look at to follow the ObjC design and figure out how it works. |
I would say that all data structures and functions prefixed with Other routines that hide the internals implementation should be in an |
I'd rather have global state in globals where possible. |
|
Yet another PR that is stalled. @WalterBright you seem to be the only one against this change. |
|
Yes, I am against it, for reasons stated. |
|
You want encapsulation, but way the current Objective-C integration is written doesn't increase encapsulation. You mentioned that header generation, json generation and ddoc all have separate files. But the (I assume) do not need to modify the AST in anyway, they just read the AST and generate the output. |
|
@WalterBright @yebblies what if we do a compromise. If I inline calls like |
|
I don't understand what the proposed compromise does. |
@WalterBright I have not changed any code yet in the PR. Currently the definition of if (sc.linkage == LINKobjc)
{
if (global.params.hasObjectiveC)
objc = true;
else
error("Objective-C classes are not supported for this target");
}Other symbols like [1] https://github.com/dlang/dmd/blob/master/src/objc.d#L143 |
|
Thanks for the explanation. I honestly don't see the point of making this change. How does it improve things? |
@WalterBright it would remove the awkward functions like |
@jacob-carlborg did you ever come to an agreement or is this still stalled? |
|
This is still stalled as far as I know. Which is a shame I think it's in the interest of everyone to fix this interface. |
|
@wilzbach it's still stalled. Therefore the rest of Objective-C integration is stalled. |
I'm not sure if there's a better place for the functions in
objc_glue.c.