summary refs log tree commit diff stats
path: root/compiler
Commit message (Collapse)AuthorAgeFilesLines
...
* trigger range check with new type inference on nkIntLit [backport:1.6] (#23179)metagn2024-01-081-2/+1
| | | | | | | | | | | | fixes #23177 `changeType` doesn't perform range checks to see if the expression fits the new type [if the old type is the same as the new type](https://github.com/nim-lang/Nim/blob/62d8ca43063197272968b4acf8c7a1ef27874c54/compiler/semexprs.nim#L633). For `nkIntLit`, we previously set the type to the concrete base of the expected type first, then call `changeType`, which works for things like range types but not bare types of smaller bit size like `int8`. Now we don't set the type (so the type is nil), and `changeType` performs the range check when the type is unset (nil).
* don't transform typed bracket exprs to `[]` calls in templates (#23175)metagn2024-01-071-14/+25
| | | | | | | | | | | | | | fixes #22775 It's pre-existing that [`prepareOperand` doesn't typecheck expressions which have types](https://github.com/nim-lang/Nim/blob/a4f3bf374238df96f0982b7106e3702da6b485b1/compiler/sigmatch.nim#L2444). Templates can take typed subscript expressions, transform them into calls to `[]`, and then have this `[]` not be resolved later if the expression is nested inside of a call argument, which leaks an untyped expression past semantic analysis. To prevent this, don't transform any typed subscript expressions into calls to `[]` in templates. Ditto for curly subscripts (with `{}`) and assignments to subscripts and curly subscripts (with `[]=` and `{}=`).
* Fixes #23172 (#23173)Ryan McConnell2024-01-061-1/+1
| | | #23172
* Changing generic weight of `tyGenericParam` (#22143)Ryan McConnell2024-01-051-27/+36
| | | | | | | | | | | | This is in reference to a [feature request](https://github.com/nim-lang/Nim/issues/22142) that I posted. I'm making this PR to demonstrate the suggested change and expect that this should be scrutinized --------- Co-authored-by: Bung <crc32@qq.com> Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* fixes #23167; take `nkOpenSymChoice` into consideration caused by templates ↵ringabout2024-01-051-6/+10
| | | | | [backport] (#23168) fixes #23167
* Deprecate asm stmt for js target (#23149)ASVIEST2024-01-021-3/+9
| | | | | | | | | | | | | | | | | | | | | | | why ? - We already have an emit that does the same thing - The name asm itself is a bit confusing, you might think it's an alias for asm.js or something else. - The asm keyword is used differently on different compiler targets (it makes it inexpressive). - Does anyone (other than some compiler libraries) use asm instead of emit ? If yes, it's a bit strange to use asm somewhere and emit somewhere. By making the asm keyword for js target deprecated, there would be even less use of the asm keyword for js target, reducing the amount of confusion. - New users might accidentally use a non-universal approach via the asm keyword instead of emit, and then when they learn about asm, try to figure out what the differences are. see https://forum.nim-lang.org/t/10821 --------- Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* fixes #23148; restricts infix path concatenation to what starts with `/` ↵ringabout2024-01-021-5/+8
| | | | | (#23150) fixes #23148
* ambiguous identifier resolution (#23123)metagn2024-01-013-63/+114
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | fixes #23002, fixes #22841, refs comments in #23097 When an identifier is ambiguous in scope (i.e. multiple imports contain symbols with the same name), attempt resolving it through type inference (by creating a symchoice). To do this efficiently, `qualifiedLookUp` had to be broken up so that `semExpr` can access the ambiguous candidates directly (now obtained directly via `lookUpCandidates`). This fixes the linked issues, but an example like: ```nim let on = 123 {.warning[ProveInit]: on.} ``` will still fail, since `on` is unambiguously the local `let` symbol here (this is also true for `proc on` but `proc` symbols generate symchoices anyway). Type symbols are not considered to not confuse the type inference. This includes the change in sigmatch, up to this point symchoices with nonoverloadable symbols could be created, they just wouldn't be considered during disambiguation. Now every proper symbol except types are considered in disambiguation, so the correct symbols must be picked during the creation of the symchoice node. I remember there being a violating case of this in the compiler, but this was very likely fixed by excluding type symbols as CI seems to have found no issues. The pure enum ambiguity test was disabled because ambiguous pure enums now behave like overloadable enums with this behavior, so we get a longer error message for `echo amb` like `type mismatch: got <MyEnum | OtherEnum> but expected T`
* `typRel` and `sumGeneric` adjustments (#23137)Ryan McConnell2023-12-311-54/+46
| | | | | | | | | | Filling in some more logic in `typeRel` that I came across when poking the compiler in another PR. Some of the cases where `typeRel` returns an "incorrect" result are actually common, but `sumGeneric` ends up breaking the tie correctly. There isn't anything wrong with that necessarily, but I assume that it's preferred these functions behave just as well in isolation as they do when integrated. I will be following up this description with specific examples.
* Update copyright year 2024 (#23144)ringabout2023-12-311-1/+1
|
* Asm syntax pragma (#23119)ASVIEST2023-12-253-15/+34
| | | | | | | | | | | | | | | | | | | | | | | | | | | | (Inspired by this pragma in nir asm PR) `inlineAsmSyntax` pragma allowing specify target inline assembler syntax in `asm` stmt. It prevents compiling code with different of the target CC inline asm syntax, i.e. it will not allow gcc inline asm code to be compiled with vcc. ```nim proc nothing() = asm {.inlineAsmSyntax: "gcc".} """ nop """ ``` The current C(C++) backend implementation cannot generate code for gcc and for vcc at the same time. For example, `{.inlineAsmSyntax: "vcc".}` with the ICC compiler will not generate code with intel asm syntax, even though ICC can use both gcc-like asm and vcc-like. For implement support for gcc and for vcc at the same time in ICC compiler, we need to refactor extccomp --------- Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* fix spurious indent and newlines in rendering of nkRecList (#23121)metagn2023-12-241-3/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Rendering of `nkRecList` produces an indent and adds a new line at the end. However for things like case object `of`/`else` branches or `when` branches this is already done, so this produces 2 indents and an extra new line. Instead, just add an indent in the place where the indent that `nkRecList` produces is needed, for the rendering of the final node of `nkObjectTy`. There doesn't seem to be a need to add the newline. Before: ```nim case x*: bool of true: y*: int of false: nil ``` After: ```nim case x*: bool of true: y*: int of false: nil ```
* retain postfix node in type section typed AST, with docgen fix (#23101)metagn2023-12-233-23/+55
| | | | | | Continued from #23096 which was reverted due to breaking a package and failing docgen tests. Docgen should now work, but ~~a PR is still pending for the package: https://github.com/SciNim/Unchained/pull/45~~ has been merged
* add switch, warning, and `bind` support for new generic injection behavior ↵metagn2023-12-224-6/+22
| | | | | | | | | | | | | | | | | | | | | (#23102) refs #23091, especially post merge comments Unsure if `experimental` and `bind` are the perfect constructs to use but they seem to get the job done here. Symbol nodes do not get marked `nfOpenSym` if the `bind` statement is used for their symbol, and `nfOpenSym` nodes do not get replaced by new local symbols if the experimental switch is not enabled in the local context (meaning it also works with `push experimental`). However this incurs a warning as the fact that the node is marked `nfOpenSym` means we did not `bind` it, so we might want to do that or turn on the experimental switch if we didn't intend to bind it. The experimental switch name is arbitrary and could be changed. --------- Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* 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
* fixes strictnotnil for func, method, converter (#23083)ringabout2023-12-191-1/+1
|
* Revert "retain postfix node in type section typed AST" (#23098)metagn2023-12-191-19/+3
| | | Reverts nim-lang/Nim#23096
* retain postfix node in type section typed AST (#23096)metagn2023-12-181-3/+19
| | | fixes #22933
* allow replacing captured syms in macro calls in generics (#23091)metagn2023-12-184-7/+40
| | | | | | | | | | | | | | | | | | fixes #22605, separated from #22744 This marks symbol captures in macro calls in generic contexts as `nfOpenSym`, which means if there is a new symbol in the local instantiatied body during instantiation time, this symbol replaces the captured symbol. We have to be careful not to consider symbols outside of the instantiation body during instantiation, because this will leak symbols from the instantiation context scope rather than the original declaration scope. This is done by checking if the local context owner (maybe should be the symbol of the proc currently getting instantiated instead? not sure how to get this) is the same as or a parent owner of the owner of the replacement candidate symbol. This solution is distinct from the symchoice mechanisms which we originally assumed had to be related, if this assumption was wrong it would explain why this solution took so long to arrive at.
* types refactoring; WIP (#23086)Andreas Rumpf2023-12-1711-97/+81
|
* Mark `macros.error` as `.noreturn.` (#23081)Jake Leahy2023-12-172-0/+6
| | | | | | | | | | | | | | | Closes #14329 Marks `macros.error` as `.noreturn` so that it can be used in expressions. This also fixes the issue that occurred in #19659 where a stmt that could be an expression (Due to having `discardable` procs at the end of other branches) would believe a `noreturn` proc is returning the same type e.g. ```nim proc bar(): int {.discardable.} = discard if true: bar() else: quit(0) # Says that quit is of type `int` and needs to be used/discarded except it actually has no return type ```
* Allow `parseAll` to parse statements separated by semicolons (#23088)Jake Leahy2023-12-171-16/+10
| | | | | | | | | | | | | | | | | | Fixes the second issue listed in #9918. Fixed by replacing the logic used in `parseAll` with just a continious loop to `complexOrSimpleStmt` like what the [normal parser does](https://github.com/nim-lang/Nim/blob/devel/compiler/passes.nim#L143-L146). `complexOrSimpleStmt` [guarantees progress](https://github.com/nim-lang/Nim/blob/devel/compiler/parser.nim#L2541) so we don't need to check progress ourselves. Also allows `nimpretty` to parse more valid Nim code such as ```nim proc foo(); # Would complain about indention here # ... proc foo() = # ... ```
* fixes #22637; now `--experimental:strictNotNil` can be enabled globally (#23079)ringabout2023-12-161-2/+2
| | | fixes #22637
* make treeToYaml print yaml (and not json) (#23082)Jacek Sieka2023-12-152-170/+203
| | | less verbose - used in nph
* type refactor: part 4 (#23077)Andreas Rumpf2023-12-1525-194/+197
|
* fixes yet another strictdefs bug (#23069)ringabout2023-12-1528-117/+135
|
* Param match relax (#23033)Ryan McConnell2023-12-153-64/+91
| | | | | | | | | | | #23032 --------- Co-authored-by: Nikolay Nikolov <nickysn@gmail.com> Co-authored-by: Pylgos <43234674+Pylgos@users.noreply.github.com> Co-authored-by: Andreas Rumpf <rumpf_a@web.de> Co-authored-by: ringabout <43030857+ringabout@users.noreply.github.com> Co-authored-by: Jason Beetham <beefers331@gmail.com>
* fixes #23051; don't generate documentation for exported symbols again (#23074)ringabout2023-12-141-1/+2
| | | | | | | | | | | | | fixes #23051 Before ![image](https://github.com/nim-lang/Nim/assets/43030857/d402a837-281e-4035-8302-500f64dccdb5) After ![image](https://github.com/nim-lang/Nim/assets/43030857/de9a23f1-9e50-4551-b3fd-3311e1de378e)
* Overloads passed to static proc parameters now convert to the desired… ↵Jason Beetham2023-12-143-7/+24
| | | | | (#23063) … type mirroring proc params
* fixes #23065; DocLike command defaults to ORC (#23075)ringabout2023-12-141-1/+2
| | | fixes #23065
* type graph refactor; part 3 (#23064)Andreas Rumpf2023-12-1416-254/+257
|
* fixes #9381; Fix double evaluation of types in generic objects (#23072)Pylgos2023-12-141-5/+14
| | | fixes https://github.com/nim-lang/Nim/issues/9381
* Skip trailing asterisk when placing inlay type hints. Fixes #23067 (#23068)Nikolay Nikolov2023-12-131-2/+13
|
* nimpretty: check the rendered AST for wrong output (#23057)Andreas Rumpf2023-12-132-12/+15
|
* type refactoring: part 2 (#23059)Andreas Rumpf2023-12-1335-430/+422
|
* Typrel whitespace (#23061)Ryan McConnell2023-12-131-24/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Just makes the case statements easier to look at when folded ```nim case foo of a: of b: of c: else: case bar: of a: of b: of c: of d: else: ``` to ```nim case foo of a: of b: of c: else: case bar: of a: of b: of c: of d: else: ```
* Types: Refactorings; step 1 (#23055)Andreas Rumpf2023-12-1257-658/+713
|
* Look up generic parameters when found inside semOverloadedCall, fixin… ↵Jason Beetham2023-12-121-0/+13
| | | | | | | | | (#23054) …g static procs --------- Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* 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>