summary refs log tree commit diff stats
Commit message (Collapse)AuthorAgeFilesLines
* fixes compiler crash by preventing exportc on generics (#22731)Juan M Gómez2023-09-202-3/+14
| | | Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* `constructor` now uses `result` instead of `this` (#22724)Juan M Gómez2023-09-193-37/+13
|
* second test case haul for templates and generics (#22728)metagn2023-09-196-6/+62
| | | | closes #8390, closes #11726, closes #8446, closes #21221, closes #7461, closes #7995
* make parseEnum skip type aliases for enum type sym (#22727)metagn2023-09-192-5/+17
| | | fixes #22726
* Fix `capacity` for const and shallow [backport] (#22705)Amjad Ben Hedhili2023-09-184-8/+8
|
* fixes #22692; ships `ci/funs.sh` (#22721)ringabout2023-09-181-0/+1
| | | fixes #22692
* Add descriptions and examples for `rawProc` and `rawEnv` (#22710)sls10052023-09-181-1/+31
| | | | | | | | | | Add descriptions for `rawProc` and `rawEnv`. See <https://forum.nim-lang.org/t/10485> for more informations. --------- Co-authored-by: ringabout <43030857+ringabout@users.noreply.github.com> Co-authored-by: Juan Carlos <juancarlospaco@gmail.com> Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* Update osfiles.nim, make `moveFile` consider permission on *nix (#22719)litlighilit2023-09-181-1/+1
| | | see https://github.com/nim-lang/Nim/issues/22674
* fixes incorrect cint overflow in system (#22718)ringabout2023-09-182-2/+2
| | | fixes #22700
* fixes `result` requires explicit initialization on noReturn code (#22717)ringabout2023-09-182-1/+28
| | | | | | fixes #21615; fixes #16735 It also partially fixes | #22673, though It still gives 'baseless' warnings.
* prevents declaring a constructor without importcpp fixes #22712 (#22715)Juan M Gómez2023-09-182-2/+22
| | | Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* make expressions opt in to symchoices (#22716)metagn2023-09-1811-64/+66
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | refs #22605 Sym choice nodes are now only allowed to pass through semchecking if contexts ask for them to (with `efAllowSymChoice`). Otherwise they are resolved or treated as ambiguous. The contexts that can receive symchoices in this PR are: * Call operands and addresses and emulations of such, which will subject them to overload resolution which will resolve them or fail. * Type conversion operands only for routine symchoices for type disambiguation syntax (like `(proc (x: int): int)(foo)`), which will resolve them or fail. * Proc parameter default values both at the declaration and during generic instantiation, which undergo type narrowing and so will resolve them or fail. This means unless these contexts mess up sym choice nodes should never leave the semchecking stage. This serves as a blueprint for future improvements to intermediate symbol resolution. Some tangential changes are also in this PR: 1. The `AmbiguousEnum` hint is removed, it was always disabled by default and since #22606 it only started getting emitted after the symchoice was soundly resolved. 2. Proc setter syntax (`a.b = c` becoming `` `b=`(a, c) ``) used to fully type check the RHS before passing the transformed call node to proc overloading. Now it just passes the original node directly so proc overloading can deal with its typechecking.
* Fix #22713: Make size unknown for tyForward (#22714)SirOlaf2023-09-172-4/+15
| | | | | | | Close #22713 --------- Co-authored-by: SirOlaf <>
* implement semgnrc for tuple and object type nodes (#22709)metagn2023-09-163-3/+52
| | | fixes #22699
* Document C++ Initializers (#22704)Juan M Gómez2023-09-151-0/+27
| | | Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* Fix Bisect bot (#22703)Juan Carlos2023-09-141-1/+3
| | | | | - https://github.com/nim-lang/Nim/actions/runs/6187256704/job/16796720625#step:4:29 - https://github.com/nim-lang/Nim/issues/22699
* followup of #22568 (#22690)Amjad Ben Hedhili2023-09-141-24/+17
|
* implements RFC: [C++] Constructors as default initializers (#22694)Juan M Gómez2023-09-146-41/+119
| | | Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* refactor semtempl ident declarations, some special word use (#22693)metagn2023-09-142-64/+44
| | | | | | | | | `semtempl` is refactored to combine the uses of `getIdentNode`, `onlyReplaceParams`, `isTemplParam` and most of `replaceIdentBySym` into a single `getIdentReplaceParams` proc. This might fix possible problems with injections of `nkAccQuoted`. Some special word comparison in `ast` and `semtempl` are also made more efficient.
* Make capacity work with refc [backport] (#22697)Amjad Ben Hedhili2023-09-133-11/+26
| | | followup of #19771.
* produce better code for object constructions and 'result' [backport] (#22668)Andreas Rumpf2023-09-113-12/+29
|
* fixes #22680 Nim zero clear an object inherits C++ imported class when a ↵Juan M Gómez2023-09-112-3/+60
| | | | proc return it (#22684)
* fixes the `discVal` register is used after free in vmgen (#22688)ringabout2023-09-111-1/+1
| | | follow up https://github.com/nim-lang/Nim/pull/11955
* Remove some unnecessary initialization in `seq` operations (#22677)Amjad Ben Hedhili2023-09-101-7/+35
| | | | | | | | | | | | * `PrepareSeqAdd` * `add` * `setLen` * `grow` Merge after #21842. --------- Co-authored-by: ringabout <43030857+ringabout@users.noreply.github.com>
* renderIr should print the actual return assign node (#22682)ringabout2023-09-101-2/+2
| | | | | | | | | | | | | | | | | | follow up https://github.com/nim-lang/Nim/pull/10806 Eventually we need a new option to print high level IR. It's confusing when I'm debugging the compiler without showing `return result = 1` using the expandArc option. For ```nim proc foo: int = return 2 ``` It now outputs when expanding ARC IR ```nim proc foo: int = return result = 2 ```
* fixes #22669 constructor pragma doesnt init Nim default fields (#22670)Juan M Gómez2023-09-104-20/+66
| | | | | | | fixes #22669 constructor pragma doesnt init Nim default fields --------- Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* fixes #22679 Nim zero clear an object contains C++ imported class when a ↵Juan M Gómez2023-09-102-3/+54
| | | | proc return it (#22681)
* [minor] merge similar branches in vmgen (#22683)ringabout2023-09-101-3/+1
|
* Make `newSeqOfCap` not initialize memory. (#21842)Amjad Ben Hedhili2023-09-094-4/+13
| | | | | | | It's used in `newSeqUninitialized`. --------- Co-authored-by: ringabout <43030857+ringabout@users.noreply.github.com>
* fixes #22676; remove wMerge which is a noop for more than 8 years (#22678)ringabout2023-09-092-5/+2
| | | | | | | fixes #22676 If csource or CI forbids it, we can always fall back to adding it to the nonPragmaWords list. I doubt it was used outside of the system since it was used to implement & or something for magics.
* Instantiates generics in the module that uses it (#22513)Juan M Gómez2023-09-0913-8/+52
| | | | | | | | | | Attempts to move the generic instantiation to the module that uses it. This should decrease re-compilation times as the source module where the generic lives doesnt need to be recompiled --------- Co-authored-by: ringabout <43030857+ringabout@users.noreply.github.com> Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* fixes #22664; guard against potential seqs self assignments (#22671)ringabout2023-09-083-0/+38
| | | fixes #22664
* fixes #22662 Procs with constructor pragma doesn't initialize object's ↵Juan M Gómez2023-09-082-2/+30
| | | | | | | | | | fields (#22665) fixes #22662 Procs with constructor pragma doesn't initialize object's fields --------- Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* Fix #21742: Check generic alias depth before skip (#22443)SirOlaf2023-09-083-2/+23
| | | | | | | | | | | | | | | Close #21742 Checking if there's any side-effects and if just changing typeRel is adequate for this issue before trying to look into related ones. `skipBoth` is also not that great, it can lead to code that works sometimes but fails when the proc is instantiated with branching aliases. This is mostly an issue with error clarity though. --------- Co-authored-by: SirOlaf <unknown> Co-authored-by: SirOlaf <>
* Fix #17509: Continue instead of return with unfinished generics (#22563)SirOlaf2023-09-072-1/+27
| | | | | | | | | | | | | | | | | | | 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 <>
* Remove some unnecessary initialization in string operations (#22579)Amjad Ben Hedhili2023-09-071-37/+61
| | | | | | | | * `prepareAdd` * `toNimStr` * `setLengthStrV2` * `NimAsgnStrV2` * `prepareMutation` * Some cleanups
* minor refactoring, move some sym/type construction to semdata (#22654)metagn2023-09-074-26/+22
| | | | | | | | | | 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](https://github.com/nim-lang/Nim/commit/6278b5d89af38e90aa30cfc4c217a2f4b1323339), so its old position might have been intended. If not, `isSelf` can also go in `ast`.
* run docs CI on compiler changes (#22656)metagn2023-09-071-4/+2
| | | | | | 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
* make getType nodes of generic insts have full inst type (#22655)metagn2023-09-072-0/+39
| | | | | | | | | | | | | 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.
* switch back to main neo in CI (#22660)metagn2023-09-061-2/+1
| | | refs https://github.com/andreaferretti/neo/pull/53
* add union to packages (#22658)ringabout2023-09-061-0/+1
|
* fully revert generic inst sym change, test #22646 (#22653)metagn2023-09-064-56/+34
| | | | | | | 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.
* fixes #22619; don't lift cursor fields in the hook calls (#22638)ringabout2023-09-052-2/+80
| | | | | | | | | | | | | | | | | | | | | | | 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>
* fix sym of created generic instantiation type (#22642)metagn2023-09-054-10/+59
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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](https://github.com/nim-lang/Nim/blob/d13aab50cf465a7f2edf9c37a4fa30e128892e72/compiler/vmdeps.nim#L191) called from [here](https://github.com/nim-lang/Nim/blob/d13aab50cf465a7f2edf9c37a4fa30e128892e72/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](https://github.com/nim-lang/Nim/blob/d13aab50cf465a7f2edf9c37a4fa30e128892e72/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.
* Add `hasDefaultValue` type trait (#22636)Amjad Ben Hedhili2023-09-043-1/+21
| | | Needed for #21842.
* update checkout to v4 (#22640)ringabout2023-09-045-6/+6
| | | | | ref https://github.com/actions/checkout/issues/1448 probably nodejs needs to be updated to 20.x
* fixes branches interacting with break, raise etc. in strictdefs (#22627)ringabout2023-09-044-20/+226
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ```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
* docgen: add Pandoc footnotes (fixes #21080) (#22591)Andrey Makarov2023-09-036-101/+221
| | | | | | | | | | 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.
* resolve unambiguous enum symchoices from local scope, error on rest (#22606)metagn2023-09-035-14/+67
| | | | | | | | | | | | | | | | 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.
* Exclude block from endsInNoReturn, fix regression (#22632)SirOlaf2023-09-022-14/+1
| | | Co-authored-by: SirOlaf <>