-
Notifications
You must be signed in to change notification settings - Fork 213
Why do we need to import an augmentation if the augmentation refers to the augmented library? #1958
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
Comments
In general you should be able to understand how these files are linked together whenever you are looking at just one of them, so they both need to point at each other. Beyond that there are some more pragmatic concerns as well with either of the suggested approaches:
We don't want any arbitrary library to be able to augment any other library. This would break modular compilation and also generally enable a lot of "action at a distance".
All files required for a program should be reachable through the import graph, you shouldn't have to arbitrarily search the file system for all Dart files just to check if they augment any library in your program. |
IMO, this is not always the case. Considering macros, that is what I think is the most common case for augmentation libraries, I think referring to the augmentation library is not what most users would expect. Instead, they would expect that simply by having an annotation in the class, function or whatever declaration it is, would be enough to make things happen. Indeed, in current meta programming system ( That being said, I think in terms of user experience, it is must more expected that the macro's augmentation library will refer to the main library and the user won't have to do nothing more.
I though that this would be one possible limitation, but is this an arbitrary choice? Couldn't we simply search through the files? And probably there is even better solutions that we didn't think of that would make this search less arbitrary... Also, is this a valid trade-off to make user experience worse in this specific case to avoid searching the filesystem? |
Opening and parsing every
The speed with which IDEs and some other tools can respond is a huge part of the UX, so ensuring that they can be performant is actually ensuring that we don't make the UX worse. |
Note that macros are intended to use this system generally but users might not be required to explicitly point at an augmentation file - in fact I would likely push for there being an implicit augmentation library for any file that uses any macros. |
Yes, this is why I think we could search for a middle-ground, maybe...
If this is the case, most of my worries in this question are solved. When we go to hand-written augmentation libraries, importing them manually is not that bad. |
Yup, this is my intention. Augmentation libraries are a general purpose Dart feature. And when augmentations are hand-authored or created by separate code generation tools, users will be required to explicitly import them and apply them to the main library. Then macros are a separate feature layered on top. One of the special powers of that feature is that the library augmentation that macros are compiled to gets automatically applied to the main library. Users won't have to author an augmentation import just to hook up macros. |
Thanks, @munificent @jakemac53. |
In the Augmentation Libraries specification, we have the following:
library augment <main library url>
;import <augmentation library url>
;This structure is similar with what we have today (
part
andpart of
).However, isn't it redundant to have to import an augmentation if the augmentation can only refer to a single library? In the current proposal, it is possible that an augmentation library exist but the main library does not import it. Does it makes sense? Considering that an augmentation library refer to specifically a single main library, this augmentation library would be completely useless.
For me, the following makes sense:
I am in favor of the seconds, as the first one would be considerably confusing and it would be fairly rare the cases where an augmentation library would be applicable from more than one main library.
The text was updated successfully, but these errors were encountered: