summary refs log tree commit diff stats
path: root/compiler
Commit message (Collapse)AuthorAgeFilesLines
* allow having {.noinit.} on a complex type avoid memsets to 0 for its … ↵heterodoxic2024-04-182-1/+4
| | | | | | | | | | | | | | | | | | | | | (#23388) …instantiations (C/C++ backend) AFAIK, #22802 expanded `noinit`'s utility by allowing the pragma to be attached to types (thanks @jmgomez !). I suggest broadening the scope a bit further: try to avoid `nimZeroMem`s on a type level beyond imported C/C++ types[^1], saving us from annotating the type instantiations with `noinit`. If this change is deemed acceptable, I will also adjust the docs, of course. Adding tests for this change seems a bit problematic, as the effect of this type annotation will be to work with uninitialized memory, which *might* match 0 patterns. [^1]: "complex value types" as already defined here: https://github.com/nim-lang/Nim/blob/94c599687796f4ee3872c8aa866827b9ed33f52b/compiler/cgen.nim#L470-L471
* Fix duplicated member declarations in structs for C++ backend (#23512)HexSegfaultCat2024-04-181-1/+1
| | | | | | | | | | | | | | | When forward declaration is used with pragmas `virtual` or `member`, the declaration in struct is added twice. It happens because of missing check for `sfWasForwarded` pragma. Current compiler generates the following C++ code: ```cpp struct tyObject_Foo__fFO9b6HU7kRnKB9aJA1RApKw { N_LIB_PRIVATE N_NOCONV(void, abc)(NI x_p1); N_LIB_PRIVATE N_NOCONV(virtual void, def)(NI y_p1); N_LIB_PRIVATE N_NOCONV(void, abc)(NI x_p1); N_LIB_PRIVATE N_NOCONV(virtual void, def)(NI y_p1); }; ```
* remove php code from jsgen (#23502)ringabout2024-04-181-14/+0
| | | | follow up https://github.com/nim-lang/Nim/pull/7606 https://github.com/nim-lang/Nim/pull/13466
* remove `|| []` from jsgen because string cannot be nil anymore (#23508)ringabout2024-04-181-3/+3
| | | introduced in https://github.com/nim-lang/Nim/pull/9411
* fixes #23492; fixes JS float range causes compiler crash (#23517)ringabout2024-04-181-1/+1
| | | | | | | | | | | | | | | fixes #23492 ```nim proc foo = var x: range[1.0 .. 5.0] = 2.0 case x of 1.0..2.0: echo 1 else: echo 3 foo() ```
* fixes #4695; closure iterators support for JS backend (#23493)ringabout2024-04-183-48/+59
| | | | | | | | | | | | | | | | | | | | | | | fixes #4695 ref https://github.com/nim-lang/Nim/pull/15818 Since `nkState` is only for the main loop state labels and `nkGotoState` is used only for dispatching the `:state` (since https://github.com/nim-lang/Nim/pull/7770), it's feasible to rewrite the loop body into a single case-based dispatcher, which enables support for JS, VM backend. `nkState` Node is replaced by a label and Node pair and `nkGotoState` is only used for intermediary processing. Backends only need to implement `nkBreakState` and `closureIterSetupExc` to support closure iterators. pending https://github.com/nim-lang/Nim/pull/23484 <del> I also observed some performance boost for C backend in the release mode (not in the danger mode though, I suppose the old implementation is optimized into computed goto in the danger mode) </del> allPathsAsgnResult???
* fixes #23505; fixes injectdestructors errors on transformed addr (deref) ↵ringabout2024-04-181-1/+4
| | | | | refs (#23507) fixes #23505
* fixes #23494; Wrong type in object construction error message (#23504)ringabout2024-04-162-1/+7
| | | fixes #23494
* fixes #23499; don't skip `addr` when constructing `bracketExpr` (#23503)ringabout2024-04-151-1/+1
| | | | | | | | | | | fixes #23499 In the https://github.com/nim-lang/Nim/commit/8990626ca9715a3687b28331aee4ccf242997aa2 the effect of `skipAddr` changed to skip `nkAddr` and `nkHiddenAddr`. Some old code was not adapted. In the https://github.com/nim-lang/Nim/pull/23477, the magic `addr` function was handled in the semantic analysis phase, which causes it be skipped incorrectly
* [JS backend] improve `discard` statement; ridding of the awkward special ↵ringabout2024-04-131-1/+1
| | | | | | | | | | variable `_` (#23498) According to https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/Expression_statement, some expression statements need parentheses to make it unambiguous. `_` introduced in the https://github.com/nim-lang/Nim/pull/15789 is unnecessary. We can get rid of it by adding parentheses so that object literals are not ambiguous with block statements.
* fixes #4299 #12492 #10849; lambda lifting for JS backend (#23484)ringabout2024-04-113-63/+52
| | | | | | | | fixes #4299 fixes #12492 fixes #10849 It binds `function` with `env`: `function.bind(:env)` to ease codegen for now
* fixes addr/hiddenAddr in strictdefs (#23477)ringabout2024-04-1026-69/+55
|
* remove unused magics: mIntToStr, mInt64ToStr, mFloatToStr (#23486)ringabout2024-04-096-25/+2
| | | mIntToStr, mInt64ToStr, mFloatToStr,
* stop gensym identifiers hijacking routine decl names in templates (#23392)metagn2024-04-092-2/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | fixes #23326 In a routine declaration node in a template, if the routine is marked as `gensym`, the compiler adds it as a new symbol to a preliminary scope of the template. If it's not marked as gensym, then it searches the preliminary scope of the template for the name of the routine, then when it matches a template parameter or a gensym identifier, the compiler replaces the name node with a symbol node of the found symbol. This makes sense for the template parameter since it has to be replaced later, but not really for the gensym identifier, as it doesn't allow us to inject a routine with the same name as an identifier previously declared as gensym (the problem in #23326 is when this is in another `when` branch). However this is the only channel to reuse a gensym symbol in a declaration, so maybe removing it has side effects. For example if we have: ```nim proc foo(x: int) {.gensym.} = discard proc foo(x: float) {.gensym.} = discard ``` it will not behave the same as ```nim proc foo(x: int) {.gensym.} = discard proc foo(x: float) = discard ``` behaved previously, which maybe allowed overloading over the gensym'd symbols. A note to the "undeclared identifier" error message has also been added for a potential error code that implicitly depended on the old behavior might give, namely ``undeclared identifier: 'abc`gensym123'``, which happens when in a template an identifier is first declared gensym in code that doesn't compile, then as a routine which injects by default, then the identifier is used.
* fixes #23440; fixes destruction for temporary object subclass (#23452)ringabout2024-04-051-3/+13
| | | fixes #23440
* apply the new mangle algorithm to JS backend for parameters and procs (#23476)ringabout2024-04-055-57/+71
| | | | | | | | | | | | | | the function name extension encoded by paths could be useful for debugging where the function is from Before: ```js function newSeq_33556909(len_33556911) ``` After: ```js function newSeq__system_u2477(len_p0) ```
* fixes #16771; lower `swap` for JS backend (#23473)ringabout2024-04-031-13/+4
| | | | | | | | | | | | fixes #16771 follow up https://github.com/nim-lang/Nim/pull/16536 Ideally it should be handled in the IR part in the future I have also checked the double evaluation of `swap` in the JS runtime https://github.com/nim-lang/Nim/issues/16779, that might be solved by a copy flag or something. Well, it should be best solved in the IR so that it doesn't bother backends anymore.
* fixes #9550; Concept related crash only when compiling to JS (#23470)ringabout2024-04-021-1/+1
| | | fixes #9550
* adds ccMember CC fixes #23434 (#23457)Juan M Gómez2024-03-295-4/+7
|
* fixes #23422; card regression (#23437)ringabout2024-03-281-1/+1
| | | | | | | | | fixes #23422 ref https://github.com/nim-lang/Nim/issues/20997 https://github.com/nim-lang/Nim/pull/21165 The function `cardSet` is used for large sets that are stored in the form of arrays. It shouldn't be passed as a pointer
* fixes #23429; rework `--verbosity` with warnings/hints (#23441)ringabout2024-03-281-0/+5
| | | fixes #23429
* Converted the 'invalid kind for firstOrd/lastOrd(XXX)' messages from ↵Nikolay Nikolov2024-03-271-4/+4
| | | | | | | | | | internal errors to fatal errors. (#23443) This fixes a nimsuggest crash when opening: beacon_chain/consensus_object_pools/blockchain_dag.nim from the nimbus-eth2 project and many other .nim files (44 files, to be precise) in the same project. Replaces: https://github.com/nim-lang/Nim/pull/23402
* [Cpp] Fixes an issue when mixing hooks and calls (#23428)Juan M Gómez2024-03-212-1/+5
|
* fix: use `ErrorColor` for hints marked as errors (#23430)Igor Sirotin2024-03-211-1/+2
| | | | | | | | | | | | # Description When using `--hintAsError`, we want some red color to appear in the logs. Same is already done for `warningAsError`. # Cherry-picking to Nim 1.6 Would be nice to cherry-pick this and the `warningAsError` log highlight to 1.6 branch, as it's used in status-desktop.
* Adds support for custom ASTs in the Nim parser (#23417)Andreas Rumpf2024-03-185-244/+448
|
* fixes #23401; prevents nrvo for cdecl procs (#23409)ringabout2024-03-161-1/+4
| | | fixes #23401
* chore: fix some typos (#23412)soonsouth2024-03-164-4/+4
| | | Signed-off-by: soonsouth <cuibuwei@163.com>
* + added nimsuggest support for exception inlay hints (#23202)Nikolay Nikolov2024-03-155-22/+324
| | | | | | | | | | | | | | | | | This adds nimsuggest support for displaying inlay hints for exceptions. An inlay hint is displayed around function calls, that can raise an exception, which isn't handled in the current subroutine (in other words, exceptions that can propagate back to the caller). On mouse hover on top of the hint, a list of exceptions that could propagate is shown. The changes, required to support this are already commited to nimlangserver and the VS code extension. The extension and the server allow configuration for whether these new exception hints are enabled (they can be enabled or disabled independently from the type hints), as well as the inlay strings that are inserted before and after the name of the function, around the function call. Potentially, one of these strings can be empty, for example, the user can choose to add an inlay hint only before the name of the function, or only after the name of the function.
* refactoring: no inheritance for PType/PSym (#23403)Andreas Rumpf2024-03-1414-253/+106
|
* propagate efWantStmt in semWhen (#23400)metagn2024-03-141-3/+4
| | | | | | | | fixes #23399 The new case introduced in #21657 is triggered by `efWantStmt` but the `when` statement doesn't normally propagate this flag, so propagate it when the `semCheck` param in `semWhen` is true which happens when the `when` statement is `efWhenStmt` anyway.
* fixes #23382; gives compiler errors for closure iterators in JS (#23398)ringabout2024-03-141-1/+3
| | | | fixes #23382 follow up https://github.com/nim-lang/Nim/pull/15823
* Fixes an issue where exported types werent being cgen with the `exportc` ↵Juan M Gómez2024-03-111-4/+7
| | | | pragma (#23369)
* [C++] Allow `member` to define static funcs (#23387)Juan M Gómez2024-03-111-4/+9
|
* fixes #22284; fixes #22282; don't override original parameters of inferred ↵ringabout2024-03-091-1/+0
| | | | | | | | | | | | | | | | | lambdas (#23368) fixes #22284 fixes #22282 ``` Error: j(uRef, proc (config: F; sources: auto) {.raises: [].} = discard ) can raise an unlisted exception: Exception ``` The problem is that `n.typ.n` contains the effectList which shouldn't appear in the parameter of a function defintion. We could not simply use `n.typ.n` as `n[paramsPos]`. The effect lists should be stripped away anyway.
* fixes #23378; fixes js abs negative int64 (#23379)ringabout2024-03-091-1/+7
| | | fixes #23378
* fixes #12703; nim cpp rejects valid code would lose const qualifier for ↵ringabout2024-03-051-4/+15
| | | | | | cstring to string via cstrToNimstr (#23371) fixes #12703 ref #19588
* fixes #20945; fixes #18262; provides C API `NimDestroyGlobals` for ↵ringabout2024-03-041-0/+23
| | | | | | | | | static/dynlib libraries (#23357) fixes #20945 fixes #18262 todo - [ ] perhaps export with lib prefix when the option is enabled
* Dont mangle when targeting cpp (#23335)Juan M Gómez2024-03-031-1/+1
| | | | Unfortunately we cant trick the debugger when targeting C++ so this one also needs to wait for our own debugger adapter.
* Fix nimsuggest highlight for import statements (#23263)autumngray2024-03-031-1/+9
| | | | | | | | | | | Currently, I don't have syntax highlighting (+ no/wrong jump-to-definition) for some import statement forms, namely: - `import module/name/with/(slashes)` - `import (mod) as alias` - `import basemod/[ (sub1), (sub2) ]` With this patch, highlight/def will work for the regions indicated by parentheses.
* fixes #23273; forbids methods having importc pragmas (#23324)ringabout2024-03-031-0/+4
| | | fixes #23273
* fixes sink regression for ORC; ref #23354 (#23359)ringabout2024-03-032-2/+3
| | | | | | | | | ref #23354 The new move analyzer requires types that have the tfAsgn flag (otherwise `lastRead` will return true); tfAsgn is included when the destructor is not trival. But it should consider the assignement for objects in this case because objects might have a trival destructors but it's the assignement that matters when it is passed to sink parameters.
* fixes #13481; fixes #22708; disable using union objects in VM (#23362)ringabout2024-03-031-0/+2
| | | | | | fixes #13481; fixes #22708 Otherwise it gives implicit results or bad codegen
* make use of C++11's auto type deduction for temporary variables (#23327)heterodoxic2024-03-031-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is just one of those tiny steps towards the goal of an "optimized" C and C++ codegen I raised elsewhere before - what does me babbling "optimized" mainly entail? (not mutually-exclusive ascertainment proposals following:) - less and simplified resulting code: easier to pick up/grasp for the C/C++ compiler for to do its own optimization heuristics, less parsing effort for us mere humans trying to debug, especially in the case of interop - build time reduction: less code emission I/O, runtime string formatting for output... - easier access for fresh contributors and better maintainability - interop improvements - further runtime optimizations I am eagerly looking forward to the results of the LLVM-based undertakings, but I also think we can do a bit better (as outlined above) with our current C/C++ backends till those come to fruition. **Long story short**: this PR here focuses on the C++ backend, augmenting the current codegen method of establishing "temporary" variables by using C++11's auto type deduction. The reasons for adopting an "Almost Always Auto" style have been collected [here ](https://herbsutter.com/2013/08/12/gotw-94-solution-aaa-style-almost-always-auto/) for the C++ world. For those hopping between C++'s and Nim's realms, this change also results in a bit less code and less work for the codegen part (no redundant `getTypeDesc`s): no need to tell the C++ compiler the type it already knows of (in most cases).
* fixes an issue with string to 'var openArray' at compile-time; [backp… ↵Andreas Rumpf2024-03-032-21/+26
| | | | | (#23363) …ort]
* improve error messages [backport] (#23345)ringabout2024-02-261-34/+79
| | | | | | ref https://forum.nim-lang.org/t/11052 ![image](https://github.com/nim-lang/Nim/assets/43030857/1df87691-32d9-46b5-b61b-6b9f7cc94862)
* fixes #23306 nim cpp -r invalid code generation regression with closure ↵Juan M Gómez2024-02-261-2/+2
| | | | iterators and try/catch-like constructions (#23317)
* * fixed nimsuggest crash with 'Something = concept' put (erroneously) ↵Nikolay Nikolov2024-02-241-1/+1
| | | | outside of a 'type' block (#23331)
* fixes #22723; skips tyUserTypeClasses in injectdestructors (#23341)ringabout2024-02-241-9/+10
| | | fixes #22723
* compiler/ast.nim: fix a typo (#23340)litlighilit2024-02-231-1/+1
| | | | | | | constains -> constrains --------- Co-authored-by: ringabout <43030857+ringabout@users.noreply.github.com>
* Fixes #23337; When NimScript errors prevents NimSuggest from Init (#23338)Juan M Gómez2024-02-221-1/+5
|