summary refs log tree commit diff stats
path: root/compiler
Commit message (Collapse)AuthorAgeFilesLines
* fixes #22664; guard against potential seqs self assignments (#22671)ringabout2023-09-081-0/+11
| | | fixes #22664
* fixes #22662 Procs with constructor pragma doesn't initialize object's ↵Juan M Gómez2023-09-081-1/+8
| | | | | | | | | | 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-082-2/+13
| | | | | | | | | | | | | | | 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-071-1/+2
| | | | | | | | | | | | | | | | | | | 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 <>
* 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`.
* make getType nodes of generic insts have full inst type (#22655)metagn2023-09-071-0/+4
| | | | | | | | | | | | | 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.
* fully revert generic inst sym change, test #22646 (#22653)metagn2023-09-062-21/+2
| | | | | | | 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-051-2/+1
| | | | | | | | | | | | | | | | | | | | | | | 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-053-6/+24
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-041-0/+2
| | | Needed for #21842.
* fixes branches interacting with break, raise etc. in strictdefs (#22627)ringabout2023-09-042-20/+69
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ```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
* resolve unambiguous enum symchoices from local scope, error on rest (#22606)metagn2023-09-032-1/+39
| | | | | | | | | | | | | | | | 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-021-1/+1
| | | Co-authored-by: SirOlaf <>
* fix isNil folding for compile time closures (#22574)metagn2023-09-021-1/+7
| | | fixes #20543
* Fix the problem where instances of generic objects with `sendable` pragmas ↵Pylgos2023-09-021-1/+1
| | | | | are not being cached (#22622) remove `tfSendable` from `eqTypeFlags`
* use dummy dest for void branches to fix noreturn in VM (#22617)metagn2023-09-011-9/+30
| | | fixes #22216
* unify explicit generic param semchecking in calls (#22618)metagn2023-09-012-6/+6
| | | fixes #9040
* fixes internal error: no generic body fixes #1500 (#22580)Juan M Gómez2023-09-012-1/+11
| | | | | | | | | | | * fixes internal error: no generic body fixes #1500 * adds guard * adds guard * removes unnecessary test * refactor: extracts containsGenericInvocationWithForward
* resolve local symbols in generic type call RHS (#22610)metagn2023-09-011-0/+1
| | | | | resolve local symbols in generic type call fixes #14509
* don't update const symbol on const section re-sems (#22609)metagn2023-09-011-5/+10
| | | fixes #19849
* fixes #22613; Default value does not work with object's discriminator (#22614)ringabout2023-09-011-23/+43
| | | | | | | | | | | | | | | * 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
* Fix #22604: Make endsInNoReturn traverse the tree (#22612)SirOlaf2023-09-014-12/+55
| | | | | | | | | | | | | | | | | * 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 <>
* type annotations for variable tuple unpacking, better error messages (#22611)metagn2023-09-013-6/+19
| | | | | | | | | * type annotations for variable tuple unpacking, better error messages closes #17989, closes https://github.com/nim-lang/RFCs/issues/339 * update grammar * fix test
* fixes #17197; fixes #22560; fixes the dest of newSeqOfCap in refc (#22594)ringabout2023-08-311-0/+1
|
* handle typedesc params in VM (#22581)metagn2023-08-301-1/+7
| | | | | | | | | * handle typedesc params in VM fixes #15760 * add test * fix getType(typedesc) test
* fixes an issue where sometimes wasMoved produced bad codegen for cpp (#22587)Juan M Gómez2023-08-301-1/+4
|
* clearer error for different size int/float cast in VM (#22582)metagn2023-08-291-3/+11
| | | refs #16547
* minor style changes in the compiler (#22584)ringabout2023-08-291-3/+2
| | | | | * minor style changes in the compiler * use raiseAssert
* properly fold constants for dynlib pragma (#22575)metagn2023-08-281-1/+1
| | | fixes #12929
* correct logic for qualified symbol in templates (#22577)metagn2023-08-281-1/+4
| | | | | | | * correct logic for qualified symbol in templates fixes #19865 * add test
* `initCandidate` and friends now return values (#22570)ringabout2023-08-283-42/+32
| | | | | | | | | * `initCandidate` and friends now return values * fixes semexprs.nim * fixes semcall.nim * Update compiler/semcall.nim
* fix #22548;environment misses for type reference in iterator access n… ↵Bung2023-08-271-5/+19
| | | | | | | | | | | | | (#22559) * fix #22548;environment misses for type reference in iterator access nested in closure * fix #21737 * Update lambdalifting.nim * remove containsCallKinds * simplify
* Improve compiler cli args (#22509)Juan Carlos2023-08-251-4/+10
| | | | | | | * . * Fix cli args out of range with descriptive error instead of crash * https://github.com/nim-lang/Nim/pull/22509#issuecomment-1692259451
* fix generic param substitution in templates (#22535)metagn2023-08-252-2/+13
| | | | | | | * 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
* follow up #22549 (#22551)ringabout2023-08-254-4/+7
|
* fixes a strictdef ten years long vintage bug, which counts the same thing ↵ringabout2023-08-243-10/+23
| | | | | twice (#22549) fixes a strictdef ten years long vintage bug
* round out tuple unpacking assignment, support underscores (#22537)metagn2023-08-243-27/+42
| | | | | | | | | | | | | | | * round out tuple unpacking assignment, support underscores fixes #18710 * fix test messages * use discard instead of continue Co-authored-by: Andreas Rumpf <rumpf_a@web.de> --------- Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* don't render underscore identifiers with id (#22538)metagn2023-08-231-3/+5
|
* Fix #21532: Check if template return is untyped (#22517)SirOlaf2023-08-231-0/+3
| | | | | | | | | * Don't ignore return in semTemplateDef * Add test --------- Co-authored-by: SirOlaf <>
* allow non-pragma special words as user pragmas (#22526)metagn2023-08-212-11/+24
| | | | | allow non-pragma special words as macro pragmas fixes #22525
* fix getNullValue for cstring in VM, make other VM code aware of nil cstring ↵metagn2023-08-213-6/+22
| | | | | | | | | | | | | (#22527) * fix getNullValue for cstring in VM fixes #22524 * very ugly fixes, but fix #15730 * nil cstring len works, more test lines * fix high
* use old typeinfo generation for hot code reloading (#22518)metagn2023-08-201-1/+1
| | | | | * use old typeinfo generation for hot code reloading * at least test hello world compilation on orc
* Fix #21722 (#22512)SirOlaf2023-08-191-6/+8
| | | | | | | | | | | * Keep return in mind for sink * Keep track of return using bool instead of mode * Update compiler/injectdestructors.nim * Add back IsReturn --------- Co-authored-by: SirOlaf <> Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* Markdown code blocks migration part 9 (#22506)Amjad Ben Hedhili2023-08-192-2/+2
| | | | | * Markdown code blocks migration part 9 * fix [skip ci]
* Remove Deprecated Babel (#22507)Juan Carlos2023-08-191-4/+2
|
* Fix #22366 by making nimlf_/nimln_ part of the same line (#22503)Alberto Torres2023-08-181-2/+2
| | | Fix #22366 by making nimlf_/nimln_ part of the same line so the debugger doesn't advance to the next line before executing it
* Add staticFileExists and staticDirExists (#22278)Tomohiro2023-08-181-0/+4
|
* make float32 literals stringifying behave in JS the same as in C (#22500)ringabout2023-08-171-2/+7
|
* cascade tyFromExpr in type conversions in generic bodies (#22499)metagn2023-08-171-5/+7
| | | fixes #22490, fixes #22491, adapts #22029 to type conversions
* fixes #22357; don't sink elements of var tuple cursors (#22486)ringabout2023-08-161-1/+3
|