@noobject on module decalaration to prevent importing object.d#10188
@noobject on module decalaration to prevent importing object.d#10188marler8997 wants to merge 1 commit intodlang:masterfrom
Conversation
|
Thanks for your pull request and interest in making D better, @marler8997! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please see CONTRIBUTING.md for more information. If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment. Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog. Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub fetch digger
dub run digger -- build "master + dmd#10188" |
b0d0dd7 to
2670d30
Compare
|
What happens if I have multiple files? |
|
Yeah. You add it to the files that you don't want to use Just like you have to add "import" statements for each module you need, this is the inverse where you must add an attribute to exclude the |
|
Despite being a beneficiary of such a feature, I don't think this is the best approach because it is much too specialized. I would prefer we aim for more general-purpose, composable features. If I could have my druthers I would require users to explicitly My suggestion, given the history of previous attempts, is to add the ability to implicity import from the compiler command-line. We already have the Such a feature will resolve the issue at hand (having to create phony source files just to get a build), will remove some hard-coded logic from the compiler (which we should be aiming for anyway), and will be more generally useful to everyone. Also, it makes the compiler more "additive" (for lack of a better word); instead turning things OFF, we only need to turn things ON, which is more in the spirit of "pay-as-you-go". If one wants something ON by default, they can add it to the A couple of other use cases: Implicity importing runtime compiler assets This is somewhat unfortunate because Specialized builds |
|
The The module itself is the sole owner and maintainer of its imports. Whether or not a module imports the All this being said, if you want to implicitly add modules to every module you can do this already. Just create your object |
|
@marler8997 I don't disagree with anything you've said. But the fundamental problem is that the compiler is implicitly importing Since we agree that the module is the sole owner of its imports and the compiler is partially assuming ownership of the module's imports, it would be prudent to return the compiler to a more fundamentally correct state by turning off the implicit import of Correction: Edit: |
|
I can't say for sure but it may have been better for I've read #9814 and I lean towards agreeing with @andralex comment in saying that we should focus us making Let me supplement this by clarifying a bit about how I see the So in my mind, any code that could be referenced by compiler-generated code should always be imported/available in every module, and furthermore, isn't specific to the module but is actually specific to the compiler (so I'm changing what I said about the module owning all imports). This means you can still compile your module with a completely different As I write this out, it makes me think that splitting up Anyway I've gone off on a bit of a tangent. I still think that if you want to disable the |
|
I've given this some thought, but I can't support it. We don't need another specialized, niche feature added to the compiler to workaround fundamental problems. Instead, we should be making fundamental improvements or adding transitional features that help us migrate towards those fundamental improvements. This feature doesn't offer any practical benefit to the user over simply creating an empty |
|
Based on your response it sounds like you think that #10184 will help transition the language to more fundamental improvements? Can you elaborate on that? Also how do you handle intrinsics? We are currently using |
I'm still thinking about it, but I'm completely sure I don't want us to introduce a language feature for this. |
|
This isn't a language feature, it's using a user-defined attribute. It's already part of the language. There's no lexical or grammar changes. See the description for why we would want this to be configured in the module rather than a command-line option. Of course, that's assuming we want the feature in the first place. |
See my comments at #10180 (comment) for some more detail about my perspective. In general, I don't see
All great questions. D is a little different from C/C++ in that it has part of its implementation in the runtime itself, that many would want implicitly imported for convenience. I don't think it's too much to ask to have users explicitly import the language features they intend to use (they can all be aggregated into one As I mentioned in the other PRs and on Slack, I would prefer to have this logic delegated to the toolchain configuration (i.e. |
|
Ok well it sounds like we want the same things, just need to work out the best way to get there. Let's keep thinking on this and hopefully we'll hear back from @WalterBright on #9936 and #9944 soon. If he rejects them then we'll have to rethink the strategy of moving things into |
|
@JinShil you keep bringing up the point that the language shouldn't implicitly import anything. This is something I've kept note of as well. I've been playing around and exploring the zig language which uses this strategy. It only imports what you explicitly import and only links to what you tell it to link to. This means the helloworld example is a bit longer since you always need an import, but it makes bare-metal/alternate runtimes more straightforward. Might be worth looking into if you're interested. I've ported a few of my D projects to it so I could really learn it and I think it's got alot of potential. It is still pretty new though and there's a few big changes coming down the pike soon but still very usable right now. Some other things I like about it.
All that being said it has some different core pholosophies from D. It prioritizes one way of doing things. It doesn't have overloads (which is a big change). It's a much simpler language and I'm surprised with how much I can do with it. So it's pretty interesting. |
|
@marler8997 I'm aware of the Zig language and have been checking in on it periodically. If it had a statically-checked memory safety mechanism and a better way to model object composition, I'd be more interested. I think the |
|
That's funny because I just added a proposal for What kind of statically-checked memory safety are you looking for? Does D have some checking that zig doesn't? |
Yes, |
|
Whoa this is a big proposal/change to the D language! Very cool stuff. Can't wait to see what happens with it. |
|
The need for such a feature is so specialized that the programmer doing it shouldn't have any difficulty creating a dummy object.d with nothing in it to import. I don't think this feature pulls its weight. |
|
@WalterBright fair enough. Do you feel the same way about #10184? |
|
@marler8997 yes. |
|
Closing since proper justification for the feature has not been presented. |
An alternative to #10184
This PR allows modules to specify the
@noobjectattribute on their module declartion to disable importing the implicit object module, i.e.PR #10184 instead added a new command-line switch to disable importing the object module. I created this one as an alternative because it's the source code that knows whether or not the object module should be imported. This solution is less brittle as the one compiling the module doesn't need to know whether or not the command-line switch is needed. It also allows the compiler to compile both kinds of modules in the same invocation since each module configures itself instead of having one global configuration that must apply to every module being compiled in the same invocation.
The use case for this pointed out by @JinShil is to be able to compile modules that don't require the
object.dmodule without having to create a dummy object module. Note that I don't have a good idea of how useful this feature will be, however, I would prefer this implementation over a command-line switch if it is accepted.