summary refs log tree commit diff stats
path: root/compiler
Commit message (Collapse)AuthorAgeFilesLines
* fixes #22673; Cannot prove that result is initialized for a placehold… ↵ringabout2023-11-062-2/+3
| | | | | | | | (#22915) …er base method returning a lent fixes #22673
* NIR: C codegen additions (#22914)Andreas Rumpf2023-11-063-58/+121
|
* NIR: C codegen, WIP (#22903)Andreas Rumpf2023-11-0510-92/+1072
|
* Add missing std prefix (#22910)Solitude2023-11-041-1/+1
| | | without it, devels fails to build with `-d:useLinenoise`
* Inlay hints support (#22896)Nikolay Nikolov2023-11-045-42/+96
| | | | | | | | | | | | | | | | | | | | | | | | | | | This adds inlay hints support to nimsuggest. It adds a new command to nimsuggest, called 'inlayHints'. Currently, it provides type information to 'var' and 'let' variables. In the future, inlay hints can also be added for 'const' and for function parameters. The protocol also reserves space for a tooltip field, which is not used, yet, but support for it can be added in the future, without further changing the protocol. The change includes refactoring to allow the 'inlayHints' command to return a completely different structure, compared to the other nimsuggest commands. This will allow other future commands to have custom return types as well. All the previous commands return the same structure as before, so perfect backwards compatibility is maintained. To use this feature, an update to the nim language server, as well as the VS code extension is needed. Related PRs: nimlangserver: https://github.com/nim-lang/langserver/pull/53 VS code extension: https://github.com/saem/vscode-nim/pull/134 --------- Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* fixes #22902; borrow from proc return type mismatch (#22908)ringabout2023-11-042-2/+3
| | | fixes #22902
* fixes #22866; fixes #19998; ensure destruction for Object construction with ↵ringabout2023-11-021-1/+3
| | | | | | custom destructors (#22901) fixes #22866; fixes #19998
* so close... (#22885)Andreas Rumpf2023-10-317-159/+255
|
* fixes nightlies; fixes incompatible types with csource_v2 (#22889)ringabout2023-10-301-3/+3
| | | | | | | | | | ref https://github.com/nim-lang/nightlies/actions/runs/6686795512/job/18166625042#logs > /home/runner/work/nightlies/nightlies/nim/compiler/nir/nirvm.nim(163, 35) Error: type mismatch: got 'BiggestInt' for 'b.m.lit.numbers[litId(b.m.types.nodes[int(y)])]' but expected 'int' Or unifies the type in one way or another
* NIR: progress (#22884)Andreas Rumpf2023-10-293-19/+96
|
* prepare for the enforcement of `std` prefix (#22873)ringabout2023-10-2988-149/+244
| | | follow up https://github.com/nim-lang/Nim/pull/22851
* NIR: VM + refactorings (#22835)Andreas Rumpf2023-10-2910-647/+1536
|
* C++: ptr fields now pulls the whole type if it's a member in nkDotExpr (#22855)Juan M Gómez2023-10-231-0/+6
|
* Fix #22826: Don't skip generic instances in type comparison (#22828)SirOlaf2023-10-211-4/+4
| | | | | | | | | | | | | | Close #22826 I am not sure why this code skips generic insts, so letting CI tell me. Update: It has told me nothing. Maybe someone knows during review. Issue itself seems to be that the generic instance is skipped thus it ends up being just `float` which makes it use the wrong generic instance of the proc because it matches the one in cache --------- Co-authored-by: SirOlaf <>
* NIR: temporary ID generation bugfix (#22830)Andreas Rumpf2023-10-165-44/+61
|
* NIR: store sizes, alignments and offsets in the type graph; beginning… ↵Andreas Rumpf2023-10-1620-386/+1385
| | | | | (#22822) …s of a patent-pending new VM
* fixes #19250; fixes #22259; ORC AssertionDefect not ↵ringabout2023-10-131-0/+2
| | | | | | | | | | | containsManagedMemory(n.typ) (#22823) fixes #19250 fixes #22259 The strings, seqs, refs types all have this flag, why should closures be treated differently? follow up https://github.com/nim-lang/Nim/pull/14336
* fixes #22354; Wrong C++ codegen for default parameter values in ORC (#22819)ringabout2023-10-131-2/+2
| | | | | | fixes #22354 It skips `nkHiddenAddr`. No need to hoist `var parameters` without side effects. Besides, it saves lots of temporary variables in ORC.
* NIR: progress (#22817)Andreas Rumpf2023-10-1215-101/+278
| | | | | | Done: - [x] Implement conversions to openArray/varargs. - [x] Implement index/range checking.
* Import std/stackframes in ast2ir.nim (#22815)SirOlaf2023-10-111-0/+3
| | | | | Ref https://github.com/nim-lang/Nim/pull/22777#issuecomment-1758090410 Co-authored-by: SirOlaf <>
* NIR: Nim intermediate representation (#22777)Andreas Rumpf2023-10-1128-92/+3968
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Theoretical Benefits / Plans: - Typed assembler-like language. - Allows for a CPS transformation. - Can replace the existing C backend by a new C backend. - Can replace the VM. - Can do more effective "not nil" checking and static array bounds checking. - Can be used instead of the DFA. - Easily translatable to LLVM. - Reasonably easy to produce native code from. - Tiny memory consumption. No pointers, no cry. **In very early stages of development.** Todo: - [x] Map Nim types to IR types. - [ ] Map Nim AST to IR instructions: - [x] Map bitsets to bitops. - [ ] Implement string cases. - [ ] Implement range and index checks. - [x] Implement `default(T)` builtin. - [x] Implement multi string concat. - [ ] Write some analysis passes. - [ ] Write a backend. - [x] Integrate into the compilation pipeline.
* fixes #22790; use cast suppress AnyEnumConv warnings for enums withou… ↵ringabout2023-10-111-0/+2
| | | | | | | (#22813) …t holes fixes #22790
* suppress incorrect var T destructor warnings for newFinalizer in stdlib (#22810)ringabout2023-10-112-3/+5
| | | | | | | | | | | | in `std/nre` ```nim proc initRegex(pattern: string, flags: int, study = true): Regex = new(result, destroyRegex) ``` gives incorrect warnings like ``` C:\Users\blue\Documents\Nim\lib\impure\nre.nim(252, 6) Error: A custom '=destroy' hook which takes a 'var T' parameter is deprecated; it should take a 'T' parameter [Deprecated ```
* allows cast int to bool/enum in VM (#22809)ringabout2023-10-111-2/+2
| | | | | Since they are integer types, by mean of allowing cast integer to enums in VM, we can suppress some enum warnings in the stdlib in the unified form, namely using a cast expression.
* adds support for noDecl in constructor (#22811)Juan M Gómez2023-10-111-0/+1
| | | Notice the test wouldnt link before
* fixes #8893; guard against array access in renderer (#22807)ringabout2023-10-091-1/+1
| | | fixes #8893
* marking a field with noInit allows to skip constructor initialiser (#22802)Juan M Gómez2023-10-082-3/+4
| | | Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* fixes nimsuggest false error on lifetime tracking hook fixes #22794 (#22805)Juan M Gómez2023-10-081-0/+1
| | | | | fixes #22794 Not sure if it's too much.
* fixes #22787; marks `var section` in the loop as reassign preventing cursor ↵ringabout2023-10-071-0/+4
| | | | | | | | | (#22800) fixes #22787 --------- Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* fixes #22753; Nimsuggest segfault with invalid assignment to table (#22781)ringabout2023-10-022-2/+2
| | | | | | | | fixes #22753 ## Future work We should turn all the error nodes into nodes of a nkError kind, which could be a industrious task. But perhaps we can add a special treatment for error nodes to make the transition smooth.
* Make `typeRel` behave to spec (#22261)Ryan McConnell2023-09-301-15/+60
| | | | | | | | | | | | | | | | | | | | | | | | The goal of this PR is to make `typeRel` accurate to it's definition for generics: ``` # 3) When used with two type classes, it will check whether the types # matching the first type class (aOrig) are a strict subset of the types matching # the other (f). This allows us to compare the signatures of generic procs in # order to give preferrence to the most specific one: ``` I don't want this PR to break any code, and I want to preserve all of Nims current behaviors. I think that making this more accurate will help serve as ground work for the future. It may not be possible to not break anything but this is my attempt. So that it is understood, this code was part of another PR (#22143) but that problem statement only needed this change by extension. It's more organized to split two problems into two PRs and this issue, being non-breaking, should be a more immediate improvement. --------- Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* case macro now can be used inside generic. Fixes #20435 (#22752)Juan M Gómez2023-09-301-1/+15
| | | | | | | | | fixes #20435 --------- Co-authored-by: ringabout <43030857+ringabout@users.noreply.github.com> Co-authored-by: Jake Leahy <jake@leahy.dev> Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* fixes #22763; nimcache in nim.cfg uses the relative path to the config file ↵ringabout2023-09-284-3/+15
| | | | | (#22764) fixes #22763
* C++ Adds support for default arg using object construction syntax. Fixes a ↵Juan M Gómez2023-09-281-1/+6
| | | | | | | | | | compiler crash (#22768) `Foo()` below makes the compiler crash. ```nim proc makeBoo(a:cint = 10, b:cstring = "hello", foo: Foo = Foo()): Boo {.importcpp, constructor.} ```
* fixes #10542; suppresses varargs conversion warnings (#22757)ringabout2023-09-262-2/+3
| | | | fixes #10542 revives and close #20169
* fixes #22706; turn "unknown hint" into a hint (#22755)ringabout2023-09-252-1/+7
| | | fixes #22706
* fixes #22246; generate __builtin_unreachable hints for case defaults (#22737)ringabout2023-09-212-4/+8
| | | | fixes #22246 resurrects #22350
* moves `addUnique` to `std/sequtils` (#22734)Juan M Gómez2023-09-211-5/+1
| | | Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* fixes compiler crash by preventing exportc on generics (#22731)Juan M Gómez2023-09-201-3/+6
| | | Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* `constructor` now uses `result` instead of `this` (#22724)Juan M Gómez2023-09-192-33/+9
|
* fixes #22692; ships `ci/funs.sh` (#22721)ringabout2023-09-181-0/+1
| | | fixes #22692
* fixes `result` requires explicit initialization on noReturn code (#22717)ringabout2023-09-181-1/+1
| | | | | | 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-181-2/+7
| | | Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* make expressions opt in to symchoices (#22716)metagn2023-09-186-57/+52
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-171-4/+3
| | | | | | | Close #22713 --------- Co-authored-by: SirOlaf <>
* implement semgnrc for tuple and object type nodes (#22709)metagn2023-09-161-2/+41
| | | fixes #22699
* implements RFC: [C++] Constructors as default initializers (#22694)Juan M Gómez2023-09-145-41/+86
| | | 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.
* produce better code for object constructions and 'result' [backport] (#22668)Andreas Rumpf2023-09-112-8/+22
|
* fixes #22680 Nim zero clear an object inherits C++ imported class when a ↵Juan M Gómez2023-09-111-3/+10
| | | | proc return it (#22684)