summary refs log tree commit diff stats
path: root/compiler
Commit message (Collapse)AuthorAgeFilesLines
* fixes #22852; fixes #23435; fixes #23645; SIGSEGV when slicing string or ↵ringabout2024-05-271-1/+9
| | | | | | | | | | | | | | | | | | seq[T] with index out of range (#23279) follow up https://github.com/nim-lang/Nim/pull/23013 fixes #22852 fixes #23435 fixes #23645 reports rangeDefect correctly ```nim /workspaces/Nim/test9.nim(1) test9 /workspaces/Nim/lib/system/indices.nim(116) [] /workspaces/Nim/lib/system/fatal.nim(53) sysFatal Error: unhandled exception: value out of range: -2 notin 0 .. 9223372036854775807 [RangeDefect] ```
* Skip tyAlias inside semTypeTraits in case a concept accidently emits one ↵Jason Beetham2024-05-231-1/+1
| | | | (#23640)
* Minor refactoring (#23637)Andreas Rumpf2024-05-231-17/+15
|
* fixes `reifiedOpenArray`; `nkHiddenStdConv` is PathKinds1 not PathKinds0 ↵ringabout2024-05-221-2/+8
| | | | (#23633)
* fixes #23627; Simple destructor code gives invalid C (#23631)ringabout2024-05-211-3/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | fixes #23627 ```nim type TestObj = object of RootObj TestTestObj = object of RootObj testo: TestObj proc `=destroy`(x: TestTestObj) = echo "Destructor for TestTestObj" proc testCaseT() = echo "\nTest Case T" let tt1 {.used.} = TestTestObj(testo: TestObj()) ``` When generating const object fields, it's likely that we need to generate type infos for the object, which may be an object with custom hooks. We need to generate potential consts in the hooks first. https://github.com/nim-lang/Nim/pull/20433 changed the semantics of initialization. It should evaluate`BracedInit` first.
* fixes #16671; openarray conversion for object construction (#23618)ringabout2024-05-161-3/+7
| | | | | fixes #16671 related to https://github.com/nim-lang/Nim/pull/18911
* Support NetBSD/aarch64 (#23616)PHO2024-05-161-1/+1
| | | | | I could trivially port Nim to NetBSD/aarch64 because it already supported NetBSD and aarch64. I only needed to generate `c_code` for this combination.
* fixes lifting subtype calling parent's hooks (#23612)ringabout2024-05-151-1/+4
| | | | | ref https://forum.nim-lang.org/t/11587 Tested with `gcc version 14.0.1 20240412` locally
* fixes openarray views default values in JS (#23607)ringabout2024-05-141-2/+2
|
* ignore modules when looking up symbol with expected type (#23597)metagn2024-05-141-1/+1
| | | | | | | | | | | | | | | | fixes #23596 When importing a module and declaring an overloadable symbol with the same name as the module in the same scope, the module symbol can take over and make the declared overload impossible to access. Previously enum overloading had a quirk that bypassed this in a context where a specific enum type was expected but this was removed in #23588. Now this is bypassed in every place where a specific type is expected since module symbols don't have a type and so wouldn't be compatible anyway. But the issue still exists in places where no type is expected like `let x = modulename`. I don't see a way of fixing this without nerfing module symbols to the point where they're not accessible by default, which might break some macro code.
* Allow to `exportc` params. (#23396)Juan M Gómez2024-05-101-1/+1
| | | | By allowing `exportc` in params one can decide the name of a param or to dont mangle them.
* unordered enum for better interoperability with C (#23585)ringabout2024-05-102-5/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ref https://forum.nim-lang.org/t/11564 ```nim block: # unordered enum block: type unordered_enum = enum a = 1 b = 0 doAssert (ord(a), ord(b)) == (1, 0) block: type unordered_enum = enum a = 1 b = 0 c doAssert (ord(a), ord(b), ord(c)) == (1, 0, 2) block: type unordered_enum = enum a = 100 b c = 50 d doAssert (ord(a), ord(b), ord(c), ord(d)) == (100, 101, 50, 51) block: type unordered_enum = enum a = 7 b = 6 c = 5 d doAssert (ord(a), ord(b), ord(c), ord(d)) == (7, 6, 5, 8) ```
* remove bad type inference behavior for enum identifiers (#23588)metagn2024-05-101-7/+0
| | | | | | | | | | | | | | | refs https://github.com/nim-lang/Nim/issues/23586#issuecomment-2102113750 In #20091 a bad kind of type inference was mistakenly left in where if an identifier `abc` had an expected type of an enum type `Enum`, and `Enum` had a member called `abc`, the identifier would change to be that enum member. This causes bugs where a local symbol can have the same name as an enum member but have a different value. I had assumed this behavior was removed since but it wasn't, and CI seems to pass having it removed. A separate PR needs to be made for the 2.0 branch because these lines were moved around during a refactoring in #23123 which is not in 2.0.
* fixes #23552; Invalid codegen when trying to mannualy delete distinct seq ↵ringabout2024-05-081-6/+8
| | | | | (#23558) fixes #23552
* fix semFinishOperands for bracket expressions [backport:2.0] (#23571)metagn2024-05-081-7/+8
| | | | | | | | | | | | | | | | fixes #23568, fixes #23310 In #23091 `semFinishOperands` was changed to not be called for `mArrGet` and `mArrPut`, presumably in preparation for #23188 (not sure why it was needed in #23091, maybe they got mixed together), since the compiler handles these later and needs the first argument to not be completely "typed" since brackets can serve as explicit generic instantiations in which case the first argument would have to be an unresolved generic proc (not accepted by `finishOperand`). In this PR we just make it so `mArrGet` and `mArrPut` specifically skip calling `finishOperand` on the first argument. This way the generic arguments in the explicit instantiation get typed, but not the unresolved generic proc.
* rework `wasMoved`, `move` on the JS backend (#23577)ringabout2024-05-087-27/+12
| | | | | `reset`, `wasMoved` and `move` doesn't support primitive types, which generate `null` for these types. It is now produce `x = default(...)` in the backend. Ideally it should be done by ast2ir in the future
* fixes #22409; don't check style for enumFieldSymChoice in the function (#23580)ringabout2024-05-083-6/+7
| | | fixes #22409
* Skips generic owner when mangling instances (#23563)Juan M Gómez2024-05-071-1/+1
|
* fixes #23419; internal error with void in generic array instantiation (#23550)ringabout2024-05-011-3/+6
| | | | | | | | | fixes #23419 `void` is only supported as fields of objects/tuples. It shouldn't allow void in the array. I didn't merge it with taField because that flag is also used for tyLent, which is allowed in the fields of other types.
* fixes #23321; Error: internal error: openArrayLoc: ref array[0..0, int] (#23548)ringabout2024-04-291-1/+4
| | | | | | | | fixes #23321 In the function `mapType`, ptrs (tyPtr, tyVar, tyLent, tyRef) are mapped into ctPtrToArray, the dereference of which is skipped in the `genref`. We need to skip these ptrs in the function `genOpenArraySlice`.
* fixes #23531; fixes invalid meta type accepted in the object fields (#23532)ringabout2024-04-261-9/+17
| | | | | fixes #23531 fixes #19546 fixes #6982
* fixes #23536; Stack trace with wrong line number when the proc called inside ↵ringabout2024-04-261-6/+8
| | | | | for loop (#23540) fixes #23536
* fixes #23522; fixes pre-existing wrong type for iter in `liftIterSym` (#23538)ringabout2024-04-261-2/+1
| | | fixes #23522
* fixes #23525; an 'emit' pragma cannot be pushed (#23537)ringabout2024-04-241-0/+13
| | | fixes #23525
* adds another fix for concept in JS (#23535)ringabout2024-04-241-1/+1
| | | ref https://github.com/nim-lang/Nim/issues/9550
* fixes #23524; global variables cannot be analysed when injecting `move` (#23529)ringabout2024-04-241-3/+3
| | | | | | | | | | | | fixes #23524 ```nim proc isAnalysableFieldAccess*(orig: PNode; owner: PSym): bool = ... result = n.kind == nkSym and n.sym.owner == owner and {sfGlobal, sfThread, sfCursor} * n.sym.flags == {} and (n.sym.kind != skParam or isSinkParam(n.sym)) ``` In `isAnalysableFieldAccess`, globals, cursors are already rejected
* * fix for the debug line info code generation (#23488)Nikolay Nikolov2024-04-222-23/+73
| | | | Previously, in certain cases, the compiler would generate debug info for the correct line number, but for the wrong .nim source file.
* updated compiler DFA docs (#23527)Andreas Rumpf2024-04-221-13/+3
|
* fix #23518 - `<expr> is` crashes nimsuggest (#23523)José Paulo2024-04-211-1/+2
| | | | | | This solution should resolve the nimsuggest crash issue. However, perhaps the problem is in the parser? fix #23518
* 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