-
Notifications
You must be signed in to change notification settings - Fork 23
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
[RFC] Cyclic imports and symbol dependencies #6
Comments
Is it possible to ease these limitations somehow? Why does body content matter here? I think large portion of Nim procedures are dependent on template evaluation - there are lots of them in stdlib and Nim promotes usage of templates to reduce boilerplate code. |
note: there is a (very) partial support for cyclic imports, see http://nim-lang.github.io/Nim/manual.html#modules
(see corresponding example + limitations) |
I just ran into a similar limitation, where one type refers to another, sort of a child-parent relationship. Can this get fixed soonish? It's been open for several years... |
Any progress on this? It's really a pain when doing game dev, you have to split your modules in weird ways to achieve what you want. |
At the risk of making a post that basically boils down to "+1", this has been probably the biggest pain point for me with Nim so far. To add a little more substance, here's something that's trivial to do in C/C++ and java-like languages (not to even mention scripting languages), but awkward to do in Nim: widget.nim: import processor
type
Widget* = object
processorOption: ProcessorOption processor.nim: import widget
type
ProcessorOption* = enum
ProcessFast
ProcessSlow
proc process*(widget: Widget) =
internalProcess(widget.processorOption) Today, this yields the following error:
What are the refactor options for fixing this error?
Not a solution:
How do other languages solve this problem?
|
you could just export the processorOption |
I was lazy with the export markers ( |
i mean |
First of all, I would really like to improve the usability of Nim for multi module projects. But I don't think we can do a prototype prepass like you describe here, and here is why: The problem I see is, a function signature is not just what is visible at the first line. Nim also has an effect system. Many effects are inferred automatically. These inferred effects are attached automatically, but they are necessary to know, to compute the effects of other procedures. This also applies to forward declarations. A forward declaration should list all effects of that function. If it does not do that, the compiler won't be able to inject them in a later compilation stage. |
@chr-1x The way to deal with the current module system is to sort things by their dependency. This means if you have things that actually depend on each other, it is often a good idea to make it a single module. Put types that depend on each other in a single type section. But in your case, you don't have a cycling dependency, you can fix the cycle dependency by moving |
@Araq keeps claiming that my original attempt to solve the cyclic dependencies problem through the nim-lang/Nim@1d29d24#diff-d86fb8f908ad34638ec054b961e99424R4651 The multi-module support with the |
Having same problem, hard to structure project and I forced to create artificial and unneeded modules like Some may argue that circular module dependencies are bad, like they breaks levelled architecture and have other problems. But here the case is different. Those problems are if you have long distance circular dependencies between different layers etc. And here we are talking about short distance circular dependencies, that are frequently is just a more convenient way to re-arrange code in large module into smaller chunks as separate modules. |
We don't want to implement a solution that accentically prevents incremental compilation from working so the priority was put on IC. Now that IC is slowly beginning to work, we are looking into how to support recursive modules. |
Great new, this has been a constant source of frustration for me (and I'm guessing for many others). |
Has any progress been made on this front now that IC has been in the works for a while? |
I had to drop Nim on many projects due to this. |
Stretch goal for 2023: #503 |
This is a feature request to allow cyclic imports. This allows to define mutually dependent types and procs (templates/macros) in different modules or in the same module regardless their definition order. Example:
The symbol may be subjected to a cyclic lookup only if the following conditions are met:
Forum discussion: http://forum.nim-lang.org/t/2114
The text was updated successfully, but these errors were encountered: