summary refs log tree commit diff stats
path: root/compiler
Commit message (Collapse)AuthorAgeFilesLines
...
* Fix endsInNoReturn for case statements (#23009)SirOlaf2023-11-302-10/+23
| | | | | | | | | While looking at the CI I noticed that there's a couple false positives for `case` statements that cannot be checked for exhaustiveness since my changes, this should resolve them. --------- Co-authored-by: SirOlaf <>
* fixes #22926; Different type inferred when setting a default value for an ↵ringabout2023-11-291-0/+6
| | | | | array field (#22999) fixes #22926
* fixes #22996; `typeAllowedCheck` for default fields (#22998)ringabout2023-11-292-2/+8
| | | fixes #22996
* rework the vtable implementation embedding the vtable array directly with ↵ringabout2023-11-2815-51/+350
| | | | | | | | | | | | | | | | | | | | | | | | new strictions on methods (#22991) **TODO** - [x] fixes changelog With the new option `nimPreviewVtables`, `methods` are confined in the same module where the type of the first parameter is defined - [x] make it opt in after CI checks its feasibility ## In the following-up PRs - [ ] in the following PRs, refactor code into a more efficient one - [ ] cpp needs special treatments since it cannot embed array in light of the preceding limits: ref https://github.com/nim-lang/Nim/pull/20977#discussion_r1035528927; we can support cpp backends with vtable implementations later on the comprise that uses indirect vtable access --------- Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* Don't try and get enum value if its invalid (#22997)Jake Leahy2023-11-281-3/+4
| | | | | | | | | | | | | | | | | | Currently running `nimsuggest`/`check` on this code causes the compiler to raise an exception ```nim type Test = enum A = 9.0 ``` ``` assertions.nim(34) raiseAssert Error: unhandled exception: int128.nim(69, 11) `arg.sdata(3) == 0` out of range [AssertionDefect] ``` Issue was the compiler still trying to get the ordinal value even if it wasn't an ordinal
* Register declaration of enum field has a use (#22990)Jake Leahy2023-11-271-0/+1
| | | | | | | Currently when using `use` with nimsuggest on an enum field, it doesn't return the definition of the field. Breaks renaming in IDEs since it will replace all the usages, but not the declaration
* fixes #22286; enforce Non-var T destructors by `nimPreviewNonVarDestructor` ↵ringabout2023-11-252-3/+6
| | | | | | | | | | | | | | | | | | (#22975) fixes #22286 ref https://forum.nim-lang.org/t/10642 For backwards compatibilities, we might need to keep the changes under a preview compiler flag. Let's see how many packags it break. **TODO** in the following PRs - [ ] Turn the `var T` destructors warning into an error with `nimPreviewNonVarDestructor` --------- Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* nimsuggest: Added optional command line option '--clientProcessId:XXX' (#22969)Nikolay Nikolov2023-11-241-0/+1
| | | | | | | | | | When it is specified, the nimsuggest instance monitors whether this process is still alive. In case it's found to be dead, nimsuggest shuts itself down. Currently only implemented on POSIX and Windows platforms. The switch is silently ignored on other platforms. Note that the Nim language server should still try to shut down its child nimsuggest processes. This switch just adds extra protection against crashing Nim language server and gets rid of the remaining nimsuggest processes, which consume memory and system resources.
* progress: 'm' command line switch (#22976)Andreas Rumpf2023-11-223-2/+9
|
* fixes #22971; `inferGenericTypes` does not work with method call syntax (#22972)Pylgos2023-11-221-2/+2
| | | fixes #22971
* Don't provide suggestions for enum fields (#22959)Jake Leahy2023-11-201-0/+3
| | | | | | | | | Currently the suggestions create a lot of noise when creating enum fields. I don't see any way of a macro creating fields (when called inside an enum) so it should be safe to not show suggestions --------- Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* IC: progress and refactorings (#22961)Andreas Rumpf2023-11-2045-360/+456
|
* fixes #22939; fixes #16890; push should but doesn't apply to importc … ↵ringabout2023-11-191-0/+6
| | | | | | | | | | | | | | | | | | | | | | (#22944) …var/let symbols fixes #22939 fixes #16890 Besides, it was applied to let/const/var with pragmas, now it is universally applied. ```nim {.push exportc.} proc foo = let bar = 12 echo bar {.pop.} ``` For example, the `bar` variable will be affected by `exportc`.
* fixes #22913; fixes #12985 differently push-ing pragma exportc genera… ↵ringabout2023-11-192-1/+7
| | | | | | | | | | | (#22941) …tes invalid C identifiers fixes #22913 fixes #12985 differently `{.push.} now does not apply to generic instantiations`
* fixes #22947; static integers in quote do [backport] (#22948)ringabout2023-11-181-1/+1
| | | fixes #22947
* nimsuggest: Instead of checking for protocol version 3 exactly, check for ↵Nikolay Nikolov2023-11-151-2/+2
| | | | | | | | | version 3 or later. (#22945) Refactored the way nimsuggest checks for protocol version 3. Instead of checking for version 3 exactly, it now checks for version 3 or later. This way, once a version 4 is introduced, it will use version 3 as a base line, and then extra changes to the protocol can be added on top. No functional changes are introduced in this commit.
* Fix using `--stdout` with `jsondoc` (#22925)Jake Leahy2023-11-092-1/+3
| | | | | | | | | | | Fixes the assertion defect that happens when using `jsondoc --stdout` (There is no outfile since its just stdout) ``` Error: unhandled exception: options.nim(732, 3) `not conf.outFile.isEmpty` [AssertionDefect] ``` Also makes the output easier to parse by ending each module output with a new line.
* IC: use better packed line information format (#22917)Andreas Rumpf2023-11-077-147/+135
|
* Inlay hints for types of consts (#22916)Nikolay Nikolov2023-11-073-5/+19
| | | This adds inlay hint support for the types of consts.
* 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>