-
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
DRY forward declarations #163
Comments
Well the bugs that are left in the "pragma unification" logic would need to be fixed anyway and this solution cannot work with overloaded procs. -1 from me, simply yet another thing others have to learn. |
yes it can, that's the whole point of the proc fun*(a: A, b: string, c = myInit(32)): tuple[int, string] {.gcsafe, noSideEffect.} as fun1
proc fun*(a: B): string as fun2
# some lines below...
define(foo1) = (12, "bar")
define(foo2) = discard it's simpler (for humans but also for compiler) to find matching declaration via a non-overloadable identifier ( proc fun(z: tuple[a: int, b: float], u = 12, v = 13): cint
proc bar() = echo fun((23, 3.3))
type T = tuple[a: int, b: float]
# definition matching declaration but with very different looking signature:
# v doesn't specify its optional value here; return type is int32 instead of cint, tuple is represented as T
proc fun(z: T, u = 12, v: int): int32 = 23
bar() this is especially true when definition/declaration are split in different files (eg |
Ok, my bad, I skimmed too much. :-) |
This may be DRY, but code written with this approach is going to be a lot harder to understand IMO, since it's really inconvinient to have a proc without a signature (have to constantly scroll to check args) and the approach taken for overloads requires one to remember all those aliases. |
This'd be really unpleasant for tooling. 👎 |
After IC, we will finally tackle the problem wrt forward declarations and cyclic imports. |
before RFC
after RFC
allow this:
foo
must be be unique in a given scope (overloads must use different identifiers, eg:as foo1
,as foo2
) using the usual symbol lookup rules; it shall resolve to an identifier pointing to aPSym
that must be a forward declarationNote that current rules are buggy: nim incorrectly accepts this code despite
exportc
mismatch; there are similar issues.note: yes we can improve
--experimental:codeReordering
to avoid need for forward declarations but the fact is that forward declarations are still needed, and quite often so.benefits
avoid common pitfalls due to lack of DRY-ness of forward declarations, eg pragmas, default params, types; especially when these change and we have to remember to change both fwd declaration and definition
difficulty to implement:
low
The text was updated successfully, but these errors were encountered: