-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Disallow access to internals (unless overridden) #52314
Comments
I agree that preventing access to private internals must be opt in at first for the package whose internals are being accessed because this is not a viable option for packages that have public unexported functionality and have not yet adopted the public keyword. I think that we should disallow (in the general registry) packages that both declare dependence on internals and declare compatibility with an infinite set of minor versions (an infinite set of patch versions is okay IMO) This would pair well with normalizing retroactively changing compat entries on a package when new versions of their dependants are released.
It already is :) Lines 589 to 602 in 5b2fcb6
|
I think we might not need a new language feature for this--you can overload |
For internal fields, I would want |
This seems like the type of thing where it would be really nice to have the |
How would that help? |
IIUC, we're just trying to inject the call context somewhere between lowering |
It would be nice if this feature was something you could turn on for a code block/on the REPL, and not just be for an entire package. Force the developer to document which specific internals they are accessing, either as a parallel to |
This makes more sense to me than fully supporting |
A. Maybe that's the wrong word, but I'm thinking all old (registered) packages are allowed the old rules. Packages registered from now on conform to the new default rules. Or since they've been in development for a while maybe allow registering under the old rules for a while, 1 or 2 months. From publishing this policy. Then nobody needs to change their Project file or wherever this is marked. The marking will be added to the registry for old packages for you. Possibly you would also be able to add it explicitly (or not) for packages registered from now on. There's a question, what to do about upgrading old packages? They probably need the old rules, forever..., at least until next major version upgrade only? B. |
@StefanKarpinski, does "Without override" mean there is no override option or that there is no access unless the user overrides it? |
I just wanted to make it clear that it's not a "there's no way to access internals" proposal, but rather that we want accessing internals to require a project-level declaration of the need to do so. I've edited the title again to hopefully make that clearer. |
I think it would be useful to discuss this on triage and try to lay out a roadmap. |
Preventing field access by modifying
|
Ian suggested a three phase approach
Maybe we do 3 (this issue) eventually, maybe not. Jeff is not optimistic about doing 3, I am, but I don't know the internals as well. Let's table this (3) until 2 is done well. |
Originally posted by @StefanKarpinski in #49973 (comment)
Not breaking existing code limits what we can do. However, there's a decent argument to be made that since what's breaking is not a public API, blocking access to package internals is not actually technically breaking according to semver. Of course, we still have to be cautious to prevent massive ecosystem breakage. It would not go well to just flip the "no private access" switch for the whole ecosystem at once. Here's a possible transition strategy:
I'm not sure about the implementation side. If we can control module internals access per depender that would be ideal. That suggests that private/public needs to be metadata associated with the binding itself, which is kind of gnarly. Maybe we can do something with auto-wrapping each package in a public-only wrapper that rebinds only the public bindings of the internal package. That's the simplest to implement, but feels kind of icky.
Having public/private annotations on fields in structs would also be good, but I'm not quite ready to tackle that.
The text was updated successfully, but these errors were encountered: