Commit Graph

21539 Commits

Author SHA1 Message Date
SirOlaf
ee4a219012 Fix #17509: Continue instead of return with unfinished generics (#22563)
Close #17509

Current knowledge:
- delaying cache fixes the issue
- changing return of `if inst.len < key.len:` in `searchInstTypes` to
`continue` fixes the issue. With return the broken types are also cached
over and over

Related issues are completely unaffected as of now, so there must be
something deeper.

I am also still trying to find the true cause, so feel free to ignore
for now

---------

Co-authored-by: SirOlaf <>
2023-09-07 05:46:45 +02:00
Amjad Ben Hedhili
a4df44d9fb Remove some unnecessary initialization in string operations (#22579)
* `prepareAdd`
* `toNimStr`
* `setLengthStrV2`
* `NimAsgnStrV2`
* `prepareMutation`
* Some cleanups
2023-09-07 05:45:54 +02:00
metagn
e5106d1ef3 minor refactoring, move some sym/type construction to semdata (#22654)
Move `symFromType` and `symNodeFromType` from `sem`, and `isSelf` and
`makeTypeDesc` from `concepts` into `semdata`.

`makeTypeDesc` was moved out from semdata [when the `concepts` module
was
added](6278b5d89a),
so its old position might have been intended. If not, `isSelf` can also
go in `ast`.
2023-09-07 05:33:01 +02:00
metagn
ad7c1c38ff run docs CI on compiler changes (#22656)
refs #22650

Docs CI cover standard library runnable examples that aren't covered by
the test suite and can be affected by compiler changes without knowing
2023-09-07 05:31:15 +02:00
metagn
ed9e3cba07 make getType nodes of generic insts have full inst type (#22655)
fixes #22639 for the third time

Nodes generated by `getType` for `tyGenericInst` types, instead of
having the original `tyGenericInst` type, will have the type of the last
child (due to the `mapTypeToAst` calls which set the type to the given
argument). This will cause subsequent `getType` calls to lose
information and think it's OK to use the sym of the instantiated type
rather than fully expand the generic instantiation.

To prevent this, update the type of the node from the `mapTypeToAst`
calls to the full generic instantiation type.
2023-09-07 05:30:37 +02:00
metagn
b9f039e0c3 switch back to main neo in CI (#22660)
refs https://github.com/andreaferretti/neo/pull/53
2023-09-06 12:37:51 +03:00
ringabout
009ce1e17e add union to packages (#22658) 2023-09-06 09:05:01 +02:00
metagn
90f87bcab7 fully revert generic inst sym change, test #22646 (#22653)
reverts #22642, reopens #22639, closes #22646, refs #22650, refs
https://github.com/alaviss/union/issues/51, refs #22652

The fallout is too much from #22642, we can come back to it if we can
account for all the affected code.
2023-09-06 05:45:07 +03:00
ringabout
eb91cf991a fixes #22619; don't lift cursor fields in the hook calls (#22638)
fixes https://github.com/nim-lang/Nim/issues/22619

It causes double free for closure iterators because cursor fields are
destroyed in the lifted destructors of `Env`.

Besides, according to the Nim manual

> In fact, cursor more generally prevents object
construction/destruction pairs and so can also be useful in other
contexts.

At least, destruction of cursor fields might cause troubles.


todo
- [x] tests
- [x] revert a certain old PR

---------

Co-authored-by: zerbina <100542850+zerbina@users.noreply.github.com>
2023-09-05 10:31:28 +02:00
metagn
6000cc8c0f fix sym of created generic instantiation type (#22642)
fixes #22639

A `tyGenericInst` has its last son as the instantiated body of the
original generic type. However this type keeps its original `sym` field
from the original generic types, which means the sym's type is
uninstantiated. This causes problems in the implementation of `getType`,
where it uses the `sym` fields of types to represent them in AST, the
relevant example for the issue being
[here](d13aab50cf/compiler/vmdeps.nim (L191))
called from
[here](d13aab50cf/compiler/vmdeps.nim (L143)).

To fix this, create a new symbol from the original symbol for the
instantiated body during the creation of `tyGenericInst`s with the
appropriate type. Normally `replaceTypeVarsS` would be used for this,
but here it seems to cause some recursion issue (immediately gives an
error like "cannot instantiate HSlice[T, U]"), so we directly set the
symbol's type to the instantiated type.

Avoiding recursion means we also cannot use `replaceTypeVarsN` for the
symbol AST, and the symbol not having any AST crashes the implementation
of `getType` again
[here](d13aab50cf/compiler/vmdeps.nim (L167)),
so the symbol AST is set to the original generic type AST for now which
is what it was before anyway.

Not sure about this because not sure why the recursion issue is
happening, putting it at the end of the proc doesn't help either. Also
not sure if the `cl.owner != nil and s.owner != cl.owner` condition from
`replaceTypeVarsS` is relevant here. This might also break some code if
it depended on the original generic type symbol being given.
2023-09-05 10:30:13 +02:00
Amjad Ben Hedhili
8f7aedb3d1 Add hasDefaultValue type trait (#22636)
Needed for #21842.
2023-09-04 23:18:58 +02:00
ringabout
3fbb078a3c update checkout to v4 (#22640)
ref https://github.com/actions/checkout/issues/1448

probably nodejs needs to be updated to 20.x
2023-09-04 23:09:27 +02:00
ringabout
d13aab50cf fixes branches interacting with break, raise etc. in strictdefs (#22627)
```nim
{.experimental: "strictdefs".}

type Test = object
  id: int

proc test(): Test =
  if true:
    return Test()
  else:
    return
echo test()
```

I will tackle https://github.com/nim-lang/Nim/issues/16735 and #21615 in
the following PR.


The old code just premises that in branches ended with returns, raise
statements etc. , all variables including the result variable are
initialized for that branch. It's true for noreturn statements. But it
is false for the result variable in a branch tailing with a return
statement, in which the result variable is not initialized. The solution
is not perfect for usages below branch statements with the result
variable uninitialized, but it should suffice for now, which gives a
proper warning.

It also fixes

```nim

{.experimental: "strictdefs".}

type Test = object
  id: int

proc foo {.noreturn.} = discard

proc test9(x: bool): Test =
  if x:
    foo()
  else:
    foo()
```
which gives a warning, but shouldn't
2023-09-04 14:36:45 +02:00
Andrey Makarov
c5495f40d5 docgen: add Pandoc footnotes (fixes #21080) (#22591)
This implements Pandoc Markdown-style footnotes,
that are compatible with Pandoc referencing syntax:

    Ref. [^ftn].

    [^ftn]: Block.

See https://pandoc.org/MANUAL.html#footnotes for more examples.
2023-09-03 16:09:36 +02:00
metagn
480e98c479 resolve unambiguous enum symchoices from local scope, error on rest (#22606)
fixes #22598, properly fixes #21887 and fixes test case issue number

When an enum field sym choice has to choose a type, check if its name is
ambiguous in the local scope, then check if the first symbol found in
the local scope is the first symbol in the sym choice. If so, choose
that symbol. Otherwise, give an ambiguous identifier error.

The dependence on the local scope implies this will always give
ambiguity errors for unpicked enum symchoices from generics and
templates and macros from other scopes. We can change `not
isAmbiguous(...) and foundSym == first` to `not (isAmbiguous(...) and
foundSym == first)` to make it so they never give ambiguity errors, and
always pick the first symbol in the symchoice. I can do this if this is
preferred, but no code from CI seems affected.
2023-09-03 13:59:03 +02:00
SirOlaf
d2f36c071b Exclude block from endsInNoReturn, fix regression (#22632)
Co-authored-by: SirOlaf <>
2023-09-02 20:42:40 +02:00
metagn
bd6adbcc9d fix isNil folding for compile time closures (#22574)
fixes #20543
2023-09-02 10:32:46 +02:00
Pylgos
9f1fe8a2da Fix the problem where instances of generic objects with sendable pragmas are not being cached (#22622)
remove `tfSendable` from `eqTypeFlags`
2023-09-02 06:00:26 +02:00
metagn
2542dc09c8 use dummy dest for void branches to fix noreturn in VM (#22617)
fixes #22216
2023-09-01 15:38:25 +02:00
metagn
6738f44af3 unify explicit generic param semchecking in calls (#22618)
fixes #9040
2023-09-01 15:37:16 +02:00
Juan M Gómez
0c6e13806d fixes internal error: no generic body fixes #1500 (#22580)
* fixes internal error: no generic body fixes #1500

* adds guard

* adds guard

* removes unnecessary test

* refactor: extracts containsGenericInvocationWithForward
2023-09-01 13:42:47 +02:00
metagn
f1789cc465 resolve local symbols in generic type call RHS (#22610)
resolve local symbols in generic type call

fixes #14509
2023-09-01 09:00:15 +02:00
metagn
53d9fb259f don't update const symbol on const section re-sems (#22609)
fixes #19849
2023-09-01 08:59:48 +02:00
ringabout
affd3f7858 fixes #22613; Default value does not work with object's discriminator (#22614)
* fixes #22613; Default value does not work with object's discriminator

fixes #22613

* merge branches

* add a test case

* fixes status

* remove outdated comments

* move collectBranchFields into the global scope
2023-09-01 08:55:19 +02:00
SirOlaf
3b206ed988 Fix #22604: Make endsInNoReturn traverse the tree (#22612)
* Rewrite endsInNoReturn

* Handle `try` stmt again and add tests

* Fix unreachable code warning

* Remove unreachable code in semexprs again

* Check `it.len` before skip

* Move import of assertions

---------

Co-authored-by: SirOlaf <>
2023-09-01 06:41:39 +02:00
metagn
ba158d73dc type annotations for variable tuple unpacking, better error messages (#22611)
* type annotations for variable tuple unpacking, better error messages

closes #17989, closes https://github.com/nim-lang/RFCs/issues/339

* update grammar

* fix test
2023-09-01 06:26:53 +02:00
ringabout
b3912c25d3 remove outdated config (#22603) 2023-08-31 18:01:29 +02:00
ringabout
5387b30211 closes #22600; adds a test case (#22602)
closes #22600
2023-08-31 22:30:19 +08:00
ringabout
5bd1afc3f9 fixes #17197; fixes #22560; fixes the dest of newSeqOfCap in refc (#22594) 2023-08-31 19:04:32 +08:00
ringabout
dfb3a88cc3 fixes yaml tests (#22595) 2023-08-31 15:26:09 +08:00
metagn
2e4e2f8f50 handle typedesc params in VM (#22581)
* handle typedesc params in VM

fixes #15760

* add test

* fix getType(typedesc) test
2023-08-30 07:23:14 +02:00
Juan M Gómez
d7634c1bd4 fixes an issue where sometimes wasMoved produced bad codegen for cpp (#22587) 2023-08-30 07:22:36 +02:00
ringabout
a7a0105d8c deprecate std/threadpool; use malebolgia, weave, nim-taskpool instead (#22576)
* deprecate `std/threadpool`; use `malebolgia` instead

* Apply suggestions from code review

* Apply suggestions from code review

* change the URL of inim
2023-08-29 15:00:13 +02:00
metagn
b6cea7b599 clearer error for different size int/float cast in VM (#22582)
refs #16547
2023-08-29 14:59:49 +02:00
ringabout
e53c66ef39 fixes #22555; implements newStringUninit (#22572)
* fixes newStringUninitialized; implement `newStringUninitialized`

* add a simple test case

* adds a changelog

* Update lib/system.nim

* Apply suggestions from code review

rename to newStringUninit
2023-08-29 13:29:42 +02:00
ringabout
1fcb53cded fixes broken nightlies; follow up #22544 (#22585)
ref https://github.com/nim-lang/nightlies/actions/runs/5970369118/job/16197865657

> /home/runner/work/nightlies/nightlies/nim/lib/pure/os.nim(678, 30) Error: getApplOpenBsd() can raise an unlisted exception: ref OSError
2023-08-29 10:40:19 +02:00
ringabout
d8ffc6a75e minor style changes in the compiler (#22584)
* minor style changes in the compiler

* use raiseAssert
2023-08-29 13:59:51 +08:00
metagn
6b955ac4af properly fold constants for dynlib pragma (#22575)
fixes #12929
2023-08-28 21:41:18 +02:00
metagn
3de8d75513 correct logic for qualified symbol in templates (#22577)
* correct logic for qualified symbol in templates

fixes #19865

* add test
2023-08-28 21:40:46 +02:00
metagn
94454addb2 define toList procs after add for lists [backport] (#22573)
fixes #22543
2023-08-28 15:09:43 +02:00
ringabout
2e7c8a339f newStringOfCap now won't initialize all elements anymore (#22568)
newStringOfCap nows won't initialize all elements anymore
2023-08-28 10:43:58 +02:00
ringabout
306b9aca48 initCandidate and friends now return values (#22570)
* `initCandidate` and friends now return values

* fixes semexprs.nim

* fixes semcall.nim

* Update compiler/semcall.nim
2023-08-28 15:57:24 +08:00
Bung
094a29eb31 add test case for #19095 (#22566) 2023-08-28 12:31:16 +08:00
Bung
100eb6820c close #9334 (#22565) 2023-08-27 22:56:50 +08:00
Bung
0b78b7f595 fix #22548;environment misses for type reference in iterator access n… (#22559)
* fix #22548;environment misses for type reference in iterator access nested in closure

* fix #21737

* Update lambdalifting.nim

* remove containsCallKinds

* simplify
2023-08-27 14:29:24 +02:00
metagn
c19fd69b69 test case haul for old generic/template/macro issues (#22564)
* test case haul for old generic/template/macro issues

closes #12582, closes #19552, closes #2465, closes #4596, closes #15246,
closes #12683, closes #7889, closes #4547, closes #12415, closes #2002,
closes #1771, closes #5121

The test for #5648 is also moved into its own test
from `types/tissues_types` due to not being joinable.

* fix template gensym test
2023-08-27 11:27:47 +02:00
Juan Carlos
a108a451c5 Improve compiler cli args (#22509)
* .

* Fix cli args out of range with descriptive error instead of crash

* https://github.com/nim-lang/Nim/pull/22509#issuecomment-1692259451
2023-08-25 22:55:17 +02:00
metagn
1cc4d3f622 fix generic param substitution in templates (#22535)
* fix generic param substitution in templates

fixes #13527, fixes #17240, fixes #6340, fixes #20033, fixes #19576, fixes #19076

* fix bare except in test, test updated packages in CI
2023-08-25 21:08:47 +02:00
ringabout
d677ed31e5 follow up #22549 (#22551) 2023-08-25 06:48:08 +02:00
Amjad Ben Hedhili
fc6a388780 Add cursor to lists iterator variables (#22531)
* followup #21507
2023-08-24 20:57:49 +02:00