summary refs log tree commit diff stats
path: root/compiler
Commit message (Collapse)AuthorAgeFilesLines
* Ast stmt now saves its ast structure in the compiler (#23053)ASVIEST2023-12-122-1/+8
| | | | | | | see https://github.com/nim-lang/Nim/issues/23052 --------- Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* Only suggest symbols that could be pragmas when typing a pragma (#23040)Jake Leahy2023-12-074-3/+45
| | | | | | Currently pragmas just fall through to `suggestSentinel` and show everything which isn't very useful. Now it filters for symbols that could be pragmas (templates with `{.pragma.}`, macros, user pragmas) and only shows them
* Don't process a user pragma if its invalid (#23041)Jake Leahy2023-12-071-1/+4
| | | | | | | | | | | | | | | When running `check`/`suggest` in a file with an invalid user pragma like ```nim {.pragma foo: test.} ``` It will continue to try and process it which leads to the compiler running into a `FieldDefect` ``` fatal.nim(53) sysFatal Error: unhandled exception: field 'sons' is not accessible for type 'TNode' using 'kind = nkIdent' [FieldDefect] ``` This makes it instead bail out trying to process the user pragma if its invalid
* lexer cleanups (#23037)Jacek Sieka2023-12-066-75/+20
| | | | * remove some dead code and leftovers from past features * fix yaml printing of uint64 literals
* fixes #23019; Regression from 2.0 to devel with raise an unlisted exc… ↵ringabout2023-12-051-1/+1
| | | | | | | | | | (#23034) …eption: Exception fixes #23019 I suppose `implicitPragmas` is called somewhere which converts `otherPragmas`.
* forbides adding sons for `PType` (#23030)ringabout2023-12-044-16/+7
| | | I image `add` for `PType` to be used everythere
* Also show the `raises` pragma when converting proc types to string (#23026)Nikolay Nikolov2023-12-041-1/+9
| | | | This affects also nimsuggest hints (e.g. on mouse hover), as well as compiler messages.
* Fix nimsuggest `def` being different on proc definition/use (#23025)Jake Leahy2023-12-041-2/+12
| | | | | | | | | | | | | | | | | | Currently the documentation isn't shown when running `def` on the definition of a proc (Which works for things like variables). `gcsafe`/`noSideEffects` status also isn't showing up when running `def` on the definition Images of current behavior. After PR both look like "Usage" **Definition** ![image](https://github.com/nim-lang/Nim/assets/19339842/bf75ff0b-9a96-49e5-bf8a-d2c503efa784) **Usage** ![image](https://github.com/nim-lang/Nim/assets/19339842/15ea3ebf-64e1-48f5-9233-22605183825f) Issue was the symbol getting passed too early to nimsuggest so it didn't have all that info, now gets passed once proc is fully semmed
* Show proper error message if trying to run a Nim file in a directory that ↵Jake Leahy2023-12-021-1/+4
| | | | | | | | | | | | | | | | | | | | doesn't exist (#23017) For example with the command `nim r foo/bar.nim`, if `foo/` doesn't exist then it shows this message ``` oserrors.nim(92) raiseOSError Error: unhandled exception: No such file or directory Additional info: foo [OSError] ``` After PR it shows ``` Error: cannot open 'foo/bar.nim' ``` Which makes it line up with the error message if `foo/` did exist but `bar.nim` didn't. Does this by using the same logic for [handling if the file doesn't exist](https://github.com/ire4ever1190/Nim/blob/0dc12ec24b7902ef0023a9e694faa11bcf99e257/compiler/options.nim#L785-L788)
* fixes #22552 (#23014)Andreas Rumpf2023-12-025-10/+28
|
* fixes #23001; give a better warning for PtrToCstringConv (#23005)ringabout2023-11-301-1/+1
| | | fixes #23001
* enable vtable implementation for C++ and make it an experimental feature ↵ringabout2023-11-307-15/+26
| | | | | | | | | | | (#23004) follow up https://github.com/nim-lang/Nim/pull/22991 - [x] turning it into an experimental feature --------- Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* 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.