-
-
Notifications
You must be signed in to change notification settings - Fork 1.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
Experimental typeImports #8660
Experimental typeImports #8660
Conversation
compiler/importer.nim
Outdated
## | ||
case s.kind | ||
of skProcKinds: | ||
for tt in s.typ.sons.items: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question: shall I avoid using iterators in the compiler code? maybe they are not as efficient as countup
loops?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to avoid them, they are zero-cost.
doc/manual.rst
Outdated
from colors import Color | ||
|
||
# to string and proc imported | ||
let pink = rgb(255, 192, 203) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this example shows that it's not enough the type is the return type of rgb
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry, I don't understand, could you rephrase?
Maybe it should demonstrate what's going on more explicitly let pink: Color = rgb(255, 192, 203)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean that rgb
should not be imported implicitly as the connection to Color
is invisible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh, yeah, you're right. I implemented it initially without taking into account the return type but it forced to include the factory function from m import T, initT
which I found a pity... and then it occurred to me that one very simple way to teach this is:
Automatically include any symbol that references the imported type on its signature
I think it balances for the implicity on factories, specially since many times it's kind of obvious that they are creating the type.
compiler/importer.nim
Outdated
## | ||
## - Proc refers to the type on any of its input or output values. | ||
## | ||
## TODO: generics are not matched currently. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this should be done though. Requires a bit more code, will show you how to do that later.
IMO the feature should not work with regular import syntax: instead, should be explicit (that way, doens't even have to be "experimental": |
This feature exists to bring Nim closer to Python and I don't think we should introduce more syntax. And even if we did, the |
Implemented support for generics by using |
Otherwise every proc in e.g. |
gotcha, so long, and thanks for all the fish |
Changes the behaviour of
from m import T
following the discussion at https://github.com/nim-lang/Nim/issues/8013To be clear, since it's not exactly the same as discussed on the other issue, the behaviour implemented is:
That doesn't include generic types, basically because they are a tad more difficult to implement and I'm not knowledgeable enough to assert if it's something that should be allowed or not regardless of me being able to do the implementation. Comments about this more than welcome :)