-
-
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
init checks and 'out' parameters #14521
Conversation
Note: Needs an RFC. |
I think a callsite magic to not prevent observable stores is a better idea than introducing out params. |
It is not about observable stores though, it's about "definite assignment" analysis. |
if 99% of the time tyOut is treated like tyVar, why not instead introduce As you mentioned, new type kinds are expensive in terms of code maintenance (and well, i was kind of hoping to use the tyOpt spot for tyAliasSym in #11992, but it's not just about that) |
Fair enough. I thought a type flag makes the language less "introspectable" because you cannot query a type flag as easily from macros.nim. |
the same will hold for macro writers; I am better that consolidating var+out will lead to less bugs even for macro writers because it'll avoid cases like "oh i forgot to handle Whether to expose type flags is a different story (because of minmizing leaks of internal detail) but it's totally find to introduce an api analog to => stable macro API hiding internal details that may change
after all, |
|
this compiles with 1.0 when false:
proc main(a {.out2.}: var int)=
echo a
main() (but in other cases this is a recurring problem: lexer tries to to too much, instead of deferring to semantic; It makes
that's definitely application specific, there are legitimate cases where |
I think you do, read the spec additions please in this PR. |
I had only read changelog + skimmed code, hadn't seen manual.rst diff; now that I've read it I have many questions
that seems to imply that's also the case if it throws; if so, that severely restricts what you can do for initialization. proc divmod(a, b: int; res, remainder: out int) =
res = a div b # if this throws
remainder = a mod b
var res, remainder
divmod(0,0, res,remainder) # this raises, and `remainder` was unassigned even though the routine returned it's even worse in following example:
divmod(0,0, a2, res) # a2 was modified, but not so that implies you can only initialize the out params inside the proc with code that doesn't raise (or only raises defects AND user has that means the only thing you can use in practice is use builtin constructors eg performance
If I'm reading this right it means the proc itself can't read any out params before all the out params were assigned (otherwise it'd be redundant with A typical use case for proc toStr[T](result: var string, b: T) =
result.setLen 0
# etc with breaking changeSeeing as you had to add out =
|
More precise C interop (see Futhermore, |
I think more often than not we got it right, see for example how the parser always allowed for |
for me, that's just 1 of several parameter specfiers, eg: And in many cases it doesn't behave like
semantic of
|
Maybe sure, but for now I consider it an unimportant detail. |
I think out parameters is a different enough concept (from var) that deserve their one language constract and not hidden / confused with var. |
BTW, I would check if this patch breaks the test suite with |
I have no interest whatsoever in covariance. :-/ |
The covariant generic parameters seem like an obscure feature now, but they will become quite important when people start defining smart pointer types in Nim. The feature is essential for preserving the sub-type relationship between |
@zah => timotheecour#285 to avoid hijacking this |
Note: The upcoming RFC for |
Note: I removed |
@Araq @Clyybber I just want to make sure we're not going in circles some of the changes in this PR relating to for examples things like this: and in fact that change gets reverted here: https://github.com/nim-lang/Nim/pull/14777/files?file-filters%5B%5D=#diff-31a643844935ff24fb24f54b472f38cbL110 |
No description provided.