Skip to content
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

Clarify use of import via pseudo dir... #18569

Merged
merged 12 commits into from
Jul 27, 2021
Merged

Clarify use of import via pseudo dir... #18569

merged 12 commits into from
Jul 27, 2021

Conversation

GordonBGood
Copy link
Contributor

This is recommended but not currently enforced due to legacy code not using pseudo directories.

Added clause to make the point that the search path to the desired module is not guaranteed without the use of a pseudo directory qualification.

GordonBGood and others added 9 commits July 10, 2021 13:24
The thamming_orc.nim code now counts all created objects being tested, not just the ones following the "first 20" test, and the position of the `destroyed += 1` counter has been adjusted so it counts all the calls that are as a result of `=trace` tracing and not just the original destruction calls.
The following nuances weren't previously fully explained:

1. That `=trace` is only used by `--gc:orc`.
2. That `=trace` is almost certainly used along with `=destroy` when manual resource allocation has been used, but it is only required if there is a possibility of cyclic references in the wrapped types (ie. generic types).
3. That, currently, a forward definition is required for the second of the pair to avoid an auto compiler generation conflict.

The pattern of the use of `=trace` has also been made more extensive, showing how both a custom `=destroy` and `=trace` are used for manual allocation of resources when there is any possibility of a cyclic reference in the resource-wrapped values.
Two changes, as follows:

1. There is no mention of the newish `std/` library location and how it relates to the pseudo `std/` import search location, so this change tries to rectify that.
2. Add a link to the new `std/channels` library intended to work with Arc/Orc.
This is recommended but not currently enforced due to legacy code not using pseudo directories.

Make the point that the search path to the desired module is not guaranteed without the use of a pseudo directory qualification.
doc/manual.rst Outdated
@@ -6190,6 +6190,7 @@ There are two pseudo directories:
its semantics are: *Use the search path to look for module name but ignore the standard
library locations*. In other words, it is the opposite of `std`.

It is recommended and preferred but not currently enforced that all imports include a "pseudo directorY" to qualify the search path in order to guaranty the correct search path to the desired module.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well no, std is recommended, the other pseudo directories (you have a typo in "directorY" btw) are not recommended and hurt code evolution (code moves from Nimble package to somewhere else).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understood that there were only two "pseudo directories" std/ and pkg/ and an import should choose one or the other. The manual says here that std/ is the whole standard library and pkg/ is everything except the standard library`. What you say here seems to mean there are other "pseudo directories". Do you mean core/pure/impure/js/wrappers/windows/posix, etc.? I understood that these are just physical directories within the standard library code, and it would seem to be very bad form to use any of them, which I have never seen done.

It would seem to just be a coincidence that there is actually a std/ real sub directory in the standard library and that there is also this std/ "pseudo directory" as they aren't directly related to each other (other than not using the std/ pseudo directory doesn't search the real std/ sub directory, which was my problem before.

How about if, along with correcting the typo, I change the above to make it clear there is a choice between just the two "pseudo directories", either std/ or pkg/ as in the following:

"""
It is recommended and preferred but not currently enforced that all imports include either the std/ or pkg/ "pseudo directory" as part of the import name to qualify the search path in order to guarantee the correct search path to the desired module.
"""

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I understand, std/ should be used for all stdlib imports, but pkg/ should only be used if a module name from a 3rd party package clashes with a local module name.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, it that is what is intended, I can do a further change little change to doc/manual.rst. Can someone confirm?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is what is intended indeed, I can confirm.

Copy link
Member

@timotheecour timotheecour Jul 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but pkg/ should only be used if a module name from a 3rd party package clashes with a local module name.

this is a bad rule; it requires knowing about context (path, packages installed, file listing etc) to tell whether an import is local or from a 3rd party package (or from stdlib since std/ isn't always used).

Also, you're contradicting what you said here: nim-lang/RFCs#267 (comment)

Things work better when you don't need context to disambiguate, just like precedence rules work better without having to use a symbol table.

pkg/ should be recommended (and later, required with deprecation period) for external package imports

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, you're contradicting what you said here: nim-lang/RFCs#267 (comment)

What I said there is a proposal and potential solution for RFC 267. There is currently no guideline that says to prefer pkg/. We currently all agree on using std; we can recommend in the manual to use pkg later.

Copy link
Member

@timotheecour timotheecour Jul 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can recommend in the manual to use pkg later.

or we can do it now; the longer we wait, the more work there'll be to change imports to pkg. Adding pkg is forward and backward compatible so doesn't create complications.
We should recommend => deprecate => error

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I cannot "recommend" what is unused by any codebase that I'm aware of.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mandating std/ I understand, but I think pkg/ should only be used for disambiguation.

@konsumlamm
Copy link
Contributor

Most of my suggestions from #18523 still apply (it's called modules, not libraries, channels is not automatically imported, etc.).

@GordonBGood
Copy link
Contributor Author

Most of my suggestions from #18523 still apply (it's called modules, not libraries, channels is not automatically imported, etc.).

I listened to your suggestions in the previous PR and only used the word "library" when referring to the entire Standard Library, using the word(s) "module(s)" when referring to what is being imported. In this PR, I am not talking about channels at all and only adding the preferred and correct way to import any module, whether it be from the Standard Library or otherwise, understanding there there is a choice of just two "pseudo directories".

Implied but not mentioned is that using the correct pseudo directory of std/ then includes all search paths in all of the Standard Library, which then includes the std/ real sub directory: that is what "guarantees the library search path" means without having to get into the details of what modules are or are not included if the "pseudo directory" is not included.

I can add one more word "module" to the suggested change if you prefer as follows:

"""
It is recommended and preferred but not currently enforced that all module imports include either the std/ or pkg/ "pseudo directory" as part of the import name to qualify the search path in order to guarantee the correct search path to the desired module.
"""

Make it clear there are only two "pseudo directories".
@konsumlamm
Copy link
Contributor

I listened to your suggestions in the previous PR and only used the word "library" when referring to the entire Standard Library, using the word(s) "module(s)" when referring to what is being imported. In this PR, I am not talking about channels at all and only adding the preferred and correct way to import any module, whether it be from the Standard Library or otherwise, understanding there there is a choice of just two "pseudo directories".

No you didn't, almost every mention of "library" in your changes to doc/lib.rst should say "module" instead. Furthermore, it's still "ARC/ORC" instead of "Arc/Orc". The new std/channels module is still not automatically imported... Maybe you didn't intend to include the changes to doc/lib.rst in this PR?

@GordonBGood
Copy link
Contributor Author

GordonBGood commented Jul 24, 2021

Maybe you didn't intend to include the changes to doc/lib.rst in this PR?

No, I didn't intend that, I guess I missed a "rebase"? to only include this single tiny addition to doc/manual.rst and make no changes whatsoever to doc/lib.rst as @Araq closed that PR.

I'm new at the more advanced GitHub stuff, as other times I have just contributed a whole file at a time to my own testing suites. Can you remove all commits except for this tiny one to doc/manual.rst?

Commit was part of a PR #18523 that was rejected and closed...
doc/manual.rst Outdated Show resolved Hide resolved
@Araq Araq merged commit 37f5f0d into nim-lang:devel Jul 27, 2021
@GordonBGood GordonBGood deleted the GordonBGood-manual_pseudo_dir branch July 27, 2021 08:29
PMunch pushed a commit to PMunch/Nim that referenced this pull request Mar 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants