summary refs log tree commit diff stats
path: root/compiler/vm.nim
Commit message (Collapse)AuthorAgeFilesLines
* Fixes #23624 "nim check crash" (#23625)Juan M Gómez2024-09-161-28/+39
|
* fixes #21353; fixes default closure in the VM (#24070)ringabout2024-09-091-6/+6
| | | | | | | | | | | | | fixes #21353 ```nim result = newNodeIT(nkTupleConstr, info, t) result.add(newNodeIT(nkNilLit, info, t)) result.add(newNodeIT(nkNilLit, info, t)) ``` The old implementation uses `t` which is the type of the closure function as its type. It is not correct and generates ((nil, nil), (nil, nil)) for `default(closures)`. This PR creates `(tyPointer, tyPointer)` for fake closure types just like what cctypes do.
* adapt generic default parameters to recent generics changes (#24065)metagn2024-09-061-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | fixes #16700, fixes #20916, refs #24010 Fixes the instantiation issues for proc param default values encountered in #24010 by: 1. semchecking generic default param values with `inGenericContext` for #22029 and followups to apply (the bigger change in semtypes), 2. rejecting explicit generic instantiations with unresolved generic types inside `inGenericContext` (sigmatch change), 3. instantiating the default param values using `prepareNode` rather than an insufficient manual method (the bigger change in seminst). This had an important side effect of references to other parameters not working since they would be resolved as a symbol belonging to the uninstantiated original generic proc rather than the later instantiated proc. There is a more radical way to fix this which is generating ident nodes with `tyFromExpr` in specifically this context, but instead we just count them as belonging to the same proc in `hoistParamsUsedInDefault`. Other minor bugfixes: * To make the error message in t20883 make sense, we now give a "cannot instantiate" error when trying to instantiate a proc generic param with `tyFromExpr`. * Object constructors as default param values generated default values of private fields going through `evalConstExpr` more than once, but the VM doesn't mark the object fields as `nfSkipFieldChecking` which gives a "cannot access field" error. So the VM now marks object fields it generates as `nfSkipFieldChecking`. Not sure if this affects VM performance, don't see why it would. * The nkRecWhen changes in #24042 didn't cover the case where all conditions are constantly false correctly, this is fixed with a minor change. This isn't needed for this PR now but I encountered it after forgetting to `dec c.inGenericContext`.
* proper error for calling nil closure in VM (#24059)metagn2024-09-041-0/+4
| | | | | | fixes #24057 Instead of crashing the compiler, the VM now gives a stacktrace if a nil closure is attempted to be called.
* fixes #23936; opcParseFloat accepts the wrong register as the first param ↵ringabout2024-08-121-1/+1
| | | | | | [backport] (#23941) fixes #23936 follow up https://github.com/nim-lang/Nim/pull/20527
* fixes #13391; VM: Can't get address of object (#23903)ringabout2024-07-291-0/+2
| | | fixes #13391
* fixes an issue with string to 'var openArray' at compile-time; [backp… ↵Andreas Rumpf2024-03-031-1/+6
| | | | | (#23363) …ort]
* Don't crash for invalid toplevel parseStmt/Expr calls (#23089)Jake Leahy2023-12-191-0/+3
| | | | | | | | | | | | | | | This code will crash `check`/`nimsuggest` since the `ra` register is uninitialised ```nim import macros static: discard parseExpr("'") ``` Now it assigns an empty node so that it has something Testament changes were so I could properly write a test. It would pass even with a segfault since it could find the error
* types refactoring; WIP (#23086)Andreas Rumpf2023-12-171-3/+3
|
* type refactor: part 4 (#23077)Andreas Rumpf2023-12-151-8/+9
|
* type refactoring: part 2 (#23059)Andreas Rumpf2023-12-131-1/+1
|
* Types: Refactorings; step 1 (#23055)Andreas Rumpf2023-12-121-8/+8
|
* IC: progress and refactorings (#22961)Andreas Rumpf2023-11-201-2/+2
|
* NIR: progress (#22817)Andreas Rumpf2023-10-121-1/+1
| | | | | | Done: - [x] Implement conversions to openArray/varargs. - [x] Implement index/range checking.
* NIR: Nim intermediate representation (#22777)Andreas Rumpf2023-10-111-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* Instantiates generics in the module that uses it (#22513)Juan M Gómez2023-09-091-1/+1
| | | | | | | | | | Attempts to move the generic instantiation to the module that uses it. This should decrease re-compilation times as the source module where the generic lives doesnt need to be recompiled --------- Co-authored-by: ringabout <43030857+ringabout@users.noreply.github.com> Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* minor style changes in the compiler (#22584)ringabout2023-08-291-3/+2
| | | | | * minor style changes in the compiler * use raiseAssert
* fix getNullValue for cstring in VM, make other VM code aware of nil cstring ↵metagn2023-08-211-2/+17
| | | | | | | | | | | | | (#22527) * fix getNullValue for cstring in VM fixes #22524 * very ugly fixes, but fix #15730 * nil cstring len works, more test lines * fix high
* use strictdefs for compiler (#22365)ringabout2023-08-061-4/+9
| | | | | | | | | | | | | | | * wip; use strictdefs for compiler * checkpoint * complete the chores * more fixes * first phase cleanup * Update compiler/bitsets.nim * cleanup
* fix VM uint conversion size bug, stricter int gen on JS (#22150)metagn2023-06-251-3/+7
| | | | | | | | | | | * fix VM uint conversion bug, stricter int gen on JS fixes #19929 * fix float -> uint64 conversion too * no need to mask to source type * simpler diff with explanation, add test for described issue
* allow addressing elements of openArray[char] in VM (#22045)ringabout2023-06-081-0/+2
| | | allow addressing elements of openArray[char]
* adds `rkInt` to the `opcCastPtrToInt` op (#22039)Juan M Gómez2023-06-081-0/+2
| | | adds rkInt to the opcCastPtrToInt op
* Remove unused astago import warning from vm.nim (#22003)Miguel Madrid-Mencía2023-06-041-1/+0
|
* fixes #21708; skip colons for tuples in VM (#21850)ringabout2023-05-171-1/+7
| | | | | | | * fixes #21708; skip colon for tuples in VM * skip nimnodes * fixes types
* adds an experimental `mm:atomicArc` switch (#21798)ringabout2023-05-081-2/+2
|
* refactoring in preparation for better, simpler name mangling that wor… ↵Andreas Rumpf2023-04-241-1/+1
| | | | | | | | | | | (#21667) * refactoring in preparation for better, simpler name mangling that works with IC flawlessly * use new disamb field * see if this makes tests green * make tests green again
* remove nosinks hacks from compiler (#21469)ringabout2023-03-041-3/+3
|
* replaces implicit passes array registed at runtime with explicit function ↵ringabout2023-03-031-8/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | calls; simplify compilation pipeline (#21444) * abolish using passes in the compiler; simplify compilation pipeline * duplicate code * Really cool to have the same signature... * haul * unify other backends * refactor process * introduce PipelinePhase * refactor compiler * fixes passes * fixes nimsuggest * add a sentinel * enable docs checkj * activate doc testing * clean up * complete cleanups
* fixes #20139; hash types based on its path relative to its package path ↵ringabout2023-03-021-1/+1
| | | | | | | | | | | | | | | (#21274) [backport:1.6] * fixes #20139; hash types based on its path relative its project * add a test case * fixes procs * better implementation and test case --------- Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* fixes #21326; fixes #7375; fixes #11986; fixes #9607; rework quote do; ↵ringabout2023-03-021-1/+4
| | | | | | | | | | | | | `getAst` uses type info to annotate the type of quoted variables; no more type erasures for quoted variables (#21433) * fixes #21326; getAst uses type info to annotateType quoted variables * simplify logics; sem types first * fixes important packages * add testcases * tiny
* fixes #19396; Nimdoc hide nonexported fields (#21305)ringabout2023-02-011-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * suppresses non-exported fields of types and adds command-line option to re-enable this if desired * corrected the doctest that produced a CI error * an embarrassingly bad error in reasoning * modified a nimdoc test to reflect updated behavior * needed another change to bring utils.html doctest in sync with update * add info * fix nimdoc * lint * render postfix * fixes a problem * fixes nimdoc * fix nimdoc --------- Co-authored-by: johnperry-math <john.perry@usm.edu> Co-authored-by: johnperry-math <devotus@yahoo.com>
* Implemented basic macro expand functionality (#20579)Ivan Yonchovski2023-01-271-0/+3
| | | | | | | | | | | | | | | | | | * Implemented level based macro expand functionality - it can handle single macro call or expand whole function/proc/etc and it - In addition, I have altered the parser to provide the endInfo for the node. The usefulness of the `endInfo` is not limited to the `expandMacro` functionality but also it is useful for `ideOutline` functionality and I have altered the ideOutline functionality to use `endInfo`. Note `endInfo` most of the time is lost during the AST transformation thus in `nimsuggest.nim` I am using freshly parsed tree to get the location information. * Make sure we stop expanding correctly * Test CI * Fix tv3_outline.nim
* fixes #14409; fixes #10674 VM callbacks switch to table-index seqs (#21297)ringabout2023-01-261-2/+2
| | | | | | | * fixes #14409; fixes#10674 VM callbacks switch to table-index seqs * fixes package name * reduce runtime cost
* remove dead code in VM (#21296)ringabout2023-01-251-6/+0
| | | remove deadcode in VM
* Force lambda lifting for getImplTransformed. Hacky. Fixes #19818 (#21031)Yuriy Glukhov2023-01-191-1/+1
|
* remove legacy code (#21134)ringabout2022-12-261-5/+0
| | | | | * remove legacy code * fixes
* Implement setLineInfo (#21153)Peter Munch-Ellingsen2022-12-221-2/+12
| | | | | * Implement setLineInfo * Add tests
* add more `{.cursor.}` to vm (#20796)ringabout2022-11-091-13/+13
|
* fixes regression #20746; remove string copies for ORC booted compiler (#20776)ringabout2022-11-071-1/+3
| | | | | | | | | | | | | * fixes #20746; remove string copies for ORC booted compiler * add a test case * use `cursor` thanks to @beef331 * for old compilers * change file extension * change test cases
* fix #20148 implicit compile time conversion int to ranged float cause… ↵Bung2022-10-291-1/+4
| | | | | (#20698) fix #20148 implicit compile time conversion int to ranged float causes compiler fatal error
* Added 'openArray[char]' overloads to 'std/parseutils' (#20527)Jason Beetham2022-10-241-5/+22
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Added 'openarray[char]' overloads to 'std/parseutils' * Removed redundant `start` and `last` params from slice using procs * Fixed type for parseIdent overload * fixed one by off with 'substr' * removed missed start parameters for procedures * Added 'openarray[char]' overloads to 'std/parseutils' * Removed redundant `start` and `last` params from slice using procs * Fixed type for parseIdent overload * fixed one by off with 'substr' * removed missed start parameters for procedures * Fixed VM op to work with new 'opcSlice' * Corrected captureBetween's logic to work with openarray * js sys's parsefloat logic now uses openarray Co-authored-by: Clay Sweetser <Varriount@users.noreply.github.com>
* Implemented `mSlice` on the VM allowing `toOpenArray` to work at compile ↵Jason Beetham2022-10-201-16/+119
| | | | | | | | | | | | | | | | | | | | | | | | | time. (#20586) * Implemented opcSlice to make 'toOpenArray' work on the VM * Added nkOpenArray for VM to reduce bodgeness * Fixed range issues and erraneous comments * Range check correctly for openArrays in opcLdArr * Inverted logic for ldArr checking * vm now supports slicing strings * Added string tests * Removed usage of 'nkOpenArray' and redundant operations * Refactored vmSlice implementation, removing redundant and incorrect code * Made tuples go throw opcWrObj for field assignment * All strkinds should be considered for openarrays
* refactorings (#20536)Andreas Rumpf2022-10-101-1/+1
| | | | | | | * refactoring * refactoring: removed unused macroUsagesSection * enum instead of bool for better readability
* pragma for sfCallsite instead of name check + better semantics, test (#20464)metagn2022-10-031-1/+4
| | | | | | | | | | | * pragma for sfCallsite instead of name check at every template definition Not documented because it seems to be for internal use? Should also make it possible to make comparisons and setops imports, but this doesn't have to be done. I can reuse a name like `cursor` for the pragma as well, added a new name just to be safe. * make sfCallsite recursive, add tests
* move formatfloat out of system (#20195)ringabout2022-08-241-0/+3
| | | | | | | | | | | | | | | * move formatfloat out of system * fixes doc * Update changelog.md * careless * fixes * deprecate system/formatfloat * better handling
* remove shallowCopy for ARC/ORC (#20070)ringabout2022-07-261-2/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | * remove shallowCopy for ARC/ORC * use move * fix * more fixes * typo * Update lib/system.nim * follow * add nodestroy * move * copy string * add a changelog entry Co-authored-by: xflywind <43030857+xflywind@users.noreply.github.com> Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* Change `styleCheck` to ignore foreign packages (#19822)quantimnot2022-07-141-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Change `styleCheck` to ignore foreign packages * Symbols from foreign packages are now ignored. * Fixed `styleCheck` violations in `compiler` package. * Added symbol ownership to custom annotation pragmas. * Minor refactors to cleanup style check callsites. * Minor internal documentation of reasons why a symbol isn't checked. Style violations were fixed in the compiler after thet were exposed by the changes. The compiler wouldn't compile otherwise. Symbol ownership for custom pragma annotations is needed for checking the annotation's style. A NPE was raised otherwise. Fixes #10201 See also nim-lang/RFCs#456 * Fix a misunderstanding about excluding field style checks I had refactored the callsites of `styleCheckUse` to apply the DRY principle, but I misunderstood the field access handling in a template as a general case. This corrects it. * Fix some `styleCheck` violations in `compiler/evalffi` The violations were exposed in CI when the compiler was built with libffi. * Removed some uneeded transitionary code * Add changelog entry Co-authored-by: quantimnot <quantimnot@users.noreply.github.com>
* [vm]fixes #15974 #12551 #19464 #16020 #16780 #16613 #14553 #19909 #18641 ↵flywind2022-06-221-10/+18
| | | | | | | | | | | | | | | (#19902) [backport] * revert #12217 since the root problem seems to have been fixed; fix #15974;fix #12551; fix #19464 * fix #16020; fix #16780 * fix tests and #16613 * fix #14553 * fix #19909; skip skipRegisterAddr * fix #18641
* [Tiny] correct comment opcDeref => opcLdDeref (#19908)flywind2022-06-211-1/+1
| | | correct comment opcDeref => opcLdDeref
* [cleanup] remove unnecessary procs in vm (#19888)flywind2022-06-131-1/+0
| | | remove unused procs