summary refs log tree commit diff stats
path: root/compiler
Commit message (Collapse)AuthorAgeFilesLines
* 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>
* case macro now can be used inside generic. Fixes #20435 (#22752)Juan M Gómez2023-09-301-1/+15
| | | | | | | | | fixes #20435 --------- Co-authored-by: ringabout <43030857+ringabout@users.noreply.github.com> Co-authored-by: Jake Leahy <jake@leahy.dev> Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* fixes #22763; nimcache in nim.cfg uses the relative path to the config file ↵ringabout2023-09-284-3/+15
| | | | | (#22764) fixes #22763
* C++ Adds support for default arg using object construction syntax. Fixes a ↵Juan M Gómez2023-09-281-1/+6
| | | | | | | | | | compiler crash (#22768) `Foo()` below makes the compiler crash. ```nim proc makeBoo(a:cint = 10, b:cstring = "hello", foo: Foo = Foo()): Boo {.importcpp, constructor.} ```
* fixes #10542; suppresses varargs conversion warnings (#22757)ringabout2023-09-262-2/+3
| | | | fixes #10542 revives and close #20169
* fixes #22706; turn "unknown hint" into a hint (#22755)ringabout2023-09-252-1/+7
| | | fixes #22706
* fixes #22246; generate __builtin_unreachable hints for case defaults (#22737)ringabout2023-09-212-4/+8
| | | | fixes #22246 resurrects #22350
* moves `addUnique` to `std/sequtils` (#22734)Juan M Gómez2023-09-211-5/+1
| | | Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* fixes compiler crash by preventing exportc on generics (#22731)Juan M Gómez2023-09-201-3/+6
| | | Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* `constructor` now uses `result` instead of `this` (#22724)Juan M Gómez2023-09-192-33/+9
|
* fixes #22692; ships `ci/funs.sh` (#22721)ringabout2023-09-181-0/+1
| | | fixes #22692
* fixes `result` requires explicit initialization on noReturn code (#22717)ringabout2023-09-181-1/+1
| | | | | | fixes #21615; fixes #16735 It also partially fixes | #22673, though It still gives 'baseless' warnings.
* prevents declaring a constructor without importcpp fixes #22712 (#22715)Juan M Gómez2023-09-181-2/+7
| | | Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* make expressions opt in to symchoices (#22716)metagn2023-09-186-57/+52
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | refs #22605 Sym choice nodes are now only allowed to pass through semchecking if contexts ask for them to (with `efAllowSymChoice`). Otherwise they are resolved or treated as ambiguous. The contexts that can receive symchoices in this PR are: * Call operands and addresses and emulations of such, which will subject them to overload resolution which will resolve them or fail. * Type conversion operands only for routine symchoices for type disambiguation syntax (like `(proc (x: int): int)(foo)`), which will resolve them or fail. * Proc parameter default values both at the declaration and during generic instantiation, which undergo type narrowing and so will resolve them or fail. This means unless these contexts mess up sym choice nodes should never leave the semchecking stage. This serves as a blueprint for future improvements to intermediate symbol resolution. Some tangential changes are also in this PR: 1. The `AmbiguousEnum` hint is removed, it was always disabled by default and since #22606 it only started getting emitted after the symchoice was soundly resolved. 2. Proc setter syntax (`a.b = c` becoming `` `b=`(a, c) ``) used to fully type check the RHS before passing the transformed call node to proc overloading. Now it just passes the original node directly so proc overloading can deal with its typechecking.
* Fix #22713: Make size unknown for tyForward (#22714)SirOlaf2023-09-171-4/+3
| | | | | | | Close #22713 --------- Co-authored-by: SirOlaf <>
* implement semgnrc for tuple and object type nodes (#22709)metagn2023-09-161-2/+41
| | | fixes #22699
* implements RFC: [C++] Constructors as default initializers (#22694)Juan M Gómez2023-09-145-41/+86
| | | Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* refactor semtempl ident declarations, some special word use (#22693)metagn2023-09-142-64/+44
| | | | | | | | | `semtempl` is refactored to combine the uses of `getIdentNode`, `onlyReplaceParams`, `isTemplParam` and most of `replaceIdentBySym` into a single `getIdentReplaceParams` proc. This might fix possible problems with injections of `nkAccQuoted`. Some special word comparison in `ast` and `semtempl` are also made more efficient.
* produce better code for object constructions and 'result' [backport] (#22668)Andreas Rumpf2023-09-112-8/+22
|
* fixes #22680 Nim zero clear an object inherits C++ imported class when a ↵Juan M Gómez2023-09-111-3/+10
| | | | proc return it (#22684)
* fixes the `discVal` register is used after free in vmgen (#22688)ringabout2023-09-111-1/+1
| | | follow up https://github.com/nim-lang/Nim/pull/11955
* renderIr should print the actual return assign node (#22682)ringabout2023-09-101-2/+2
| | | | | | | | | | | | | | | | | | follow up https://github.com/nim-lang/Nim/pull/10806 Eventually we need a new option to print high level IR. It's confusing when I'm debugging the compiler without showing `return result = 1` using the expandArc option. For ```nim proc foo: int = return 2 ``` It now outputs when expanding ARC IR ```nim proc foo: int = return result = 2 ```
* fixes #22669 constructor pragma doesnt init Nim default fields (#22670)Juan M Gómez2023-09-103-19/+32
| | | | | | | fixes #22669 constructor pragma doesnt init Nim default fields --------- Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* fixes #22679 Nim zero clear an object contains C++ imported class when a ↵Juan M Gómez2023-09-101-3/+4
| | | | proc return it (#22681)
* [minor] merge similar branches in vmgen (#22683)ringabout2023-09-101-3/+1
|
* Make `newSeqOfCap` not initialize memory. (#21842)Amjad Ben Hedhili2023-09-091-1/+1
| | | | | | | It's used in `newSeqUninitialized`. --------- Co-authored-by: ringabout <43030857+ringabout@users.noreply.github.com>
* fixes #22676; remove wMerge which is a noop for more than 8 years (#22678)ringabout2023-09-092-5/+2
| | | | | | | fixes #22676 If csource or CI forbids it, we can always fall back to adding it to the nonPragmaWords list. I doubt it was used outside of the system since it was used to implement & or something for magics.
* Instantiates generics in the module that uses it (#22513)Juan M Gómez2023-09-0912-8/+41
| | | | | | | | | | 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>
* fixes #22664; guard against potential seqs self assignments (#22671)ringabout2023-09-081-0/+11
| | | fixes #22664
* fixes #22662 Procs with constructor pragma doesn't initialize object's ↵Juan M Gómez2023-09-081-1/+8
| | | | | | | | | | fields (#22665) fixes #22662 Procs with constructor pragma doesn't initialize object's fields --------- Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* Fix #21742: Check generic alias depth before skip (#22443)SirOlaf2023-09-082-2/+13
| | | | | | | | | | | | | | | Close #21742 Checking if there's any side-effects and if just changing typeRel is adequate for this issue before trying to look into related ones. `skipBoth` is also not that great, it can lead to code that works sometimes but fails when the proc is instantiated with branching aliases. This is mostly an issue with error clarity though. --------- Co-authored-by: SirOlaf <unknown> Co-authored-by: SirOlaf <>
* Fix #17509: Continue instead of return with unfinished generics (#22563)SirOlaf2023-09-071-1/+2
| | | | | | | | | | | | | | | | | | | Close #17509 Current knowledge: - delaying cache fixes the issue - changing return of `if inst.len < key.len:` in `searchInstTypes` to `continue` fixes the issue. With return the broken types are also cached over and over Related issues are completely unaffected as of now, so there must be something deeper. I am also still trying to find the true cause, so feel free to ignore for now --------- Co-authored-by: SirOlaf <>
* minor refactoring, move some sym/type construction to semdata (#22654)metagn2023-09-074-26/+22
| | | | | | | | | | Move `symFromType` and `symNodeFromType` from `sem`, and `isSelf` and `makeTypeDesc` from `concepts` into `semdata`. `makeTypeDesc` was moved out from semdata [when the `concepts` module was added](https://github.com/nim-lang/Nim/commit/6278b5d89af38e90aa30cfc4c217a2f4b1323339), so its old position might have been intended. If not, `isSelf` can also go in `ast`.
* make getType nodes of generic insts have full inst type (#22655)metagn2023-09-071-0/+4
| | | | | | | | | | | | | fixes #22639 for the third time Nodes generated by `getType` for `tyGenericInst` types, instead of having the original `tyGenericInst` type, will have the type of the last child (due to the `mapTypeToAst` calls which set the type to the given argument). This will cause subsequent `getType` calls to lose information and think it's OK to use the sym of the instantiated type rather than fully expand the generic instantiation. To prevent this, update the type of the node from the `mapTypeToAst` calls to the full generic instantiation type.