Commit Graph

21779 Commits

Author SHA1 Message Date
ringabout
c7d742e484 fixes #23148; restricts infix path concatenation to what starts with / (#23150)
fixes #23148
2024-01-02 07:49:16 +01:00
metagn
b280100499 ambiguous identifier resolution (#23123)
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`
2024-01-01 12:21:19 +01:00
Ryan McConnell
ccc7c45d71 typRel and sumGeneric adjustments (#23137)
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.
2023-12-31 17:52:52 +01:00
ringabout
9659da903f fixes wrong indentation (#23145)
4 spaces => 2 spaces
2023-12-31 17:25:14 +01:00
ringabout
9483b11267 Update copyright year 2024 (#23144) 2023-12-31 22:56:48 +08:00
Ikko Eltociear Ashimine
b92163180d Fix typo in pegs.nim (#23143)
wether -> whether
2023-12-30 17:05:55 +08:00
Juan M Gómez
fd253a08b1 Adds info:capabilities to NimSuggest (#23134) 2023-12-29 13:47:08 +01:00
ringabout
d8a5cf4227 fixes a typo in the test (#23140) 2023-12-29 13:36:03 +08:00
Gianmarco
15c7b76c66 Fix cmpRunesIgnoreCase on system where sizeof(int) < 4. Fixes #23125. (#23138)
Fixes an issue where importing the `strutils` module, or any other
importing the `strutils` module, ends up with a compile time error on
platforms where ints are less then 32-bit wide.

The fix follows the suggestions made in #23125.
2023-12-28 23:41:58 +01:00
ASVIEST
1324d2e04c Asm syntax pragma (#23119)
(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>
2023-12-25 07:12:54 +01:00
Ryan McConnell
6f3d3fdf9f CI entry may be reset to default (#23127) 2023-12-25 11:25:05 +08:00
ringabout
53855a9fa3 make -d:debugHeapLinks compile again (#23126)
I have made `realloc` absorb unused adjacent memory, which improves the
performance. I'm investigating whether `deallocOsPages` can be used to
improve memory comsumption.
2023-12-24 15:30:35 +01:00
metagn
fc49c6e3ba fix spurious indent and newlines in rendering of nkRecList (#23121)
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
```
2023-12-24 15:22:10 +01:00
Eric N. Vander Weele
6fee2240cd Add toSinglyLinkedRing and toDoublyLinkedRing to std/lists (#22952)
Allow for conversion from `openArray`s, similar to `toSinglyLinkedList`
and `toDoublyLinkedList`.
2023-12-24 15:21:22 +01:00
metagn
c0acf3ce28 retain postfix node in type section typed AST, with docgen fix (#23101)
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
2023-12-23 09:22:49 +01:00
metagn
4b1a841707 add switch, warning, and bind support for new generic injection behavior (#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>
2023-12-22 08:49:51 +01:00
Juan M Gómez
df3c95d8af makes nimsuggest con work under v3 (#23113)
Co-authored-by: Jake Leahy <jake@leahy.dev>
2023-12-22 05:38:40 +01:00
ringabout
b15463948c document --experimental:vtables (#23111) 2023-12-21 08:56:02 +01:00
ringabout
4321ce2635 fixes nimdoc warnings (#23110) 2023-12-21 14:58:17 +08:00
ringabout
02a1a083ed update action versions (#23109) 2023-12-21 11:15:44 +08:00
metagn
12d847550a update mac CI to macos 12 (#23108)
closes #23107

Could also change to `macos-latest` but nothing else in CI uses `latest`
OS versions.
2023-12-21 02:12:05 +03:00
Jake Leahy
db9d8003b0 Don't crash for invalid toplevel parseStmt/Expr calls (#23089)
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
2023-12-19 17:27:24 +01:00
ringabout
6618448ced fixes strictnotnil for func, method, converter (#23083) 2023-12-19 10:24:36 +01:00
ringabout
434e062e82 fixes #18073; fixes #14730; document notnil is only applied to local … (#23084)
…symbols

fixes #18073
fixes #14730
2023-12-19 10:24:22 +01:00
ringabout
0f54554213 allow non var deinit for locks and conds: alternative way (#23099)
alternative to https://github.com/nim-lang/Nim/pull/23092
2023-12-19 09:47:39 +01:00
metagn
8614f35dc2 Revert "retain postfix node in type section typed AST" (#23098)
Reverts nim-lang/Nim#23096
2023-12-19 00:07:20 +01:00
metagn
d3b9711c5e retain postfix node in type section typed AST (#23096)
fixes #22933
2023-12-18 20:38:34 +01:00
metagn
0613537ca0 add tuple unpacking changes to changelog (#23093)
closes #23042

Adds changes from #22537 and #22611 to changelog (I believe both are set
for 2.2).
2023-12-18 20:34:21 +01:00
metagn
941659581a allow replacing captured syms in macro calls in generics (#23091)
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.
2023-12-18 17:40:30 +01:00
Stephen
080a072336 Fix grammar (#23090) 2023-12-18 13:25:49 +08:00
Andreas Rumpf
fe18ec5dc0 types refactoring; WIP (#23086) 2023-12-17 18:43:52 +01:00
Jake Leahy
9b08abaa05 Show the name of the unexpected exception that was thrown in std/unittest (#23087)
Show name of error that wasn't expected in an `expect` block
2023-12-17 12:30:11 +01:00
Jake Leahy
b3b87f0f8a Mark macros.error as .noreturn. (#23081)
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
```
2023-12-17 12:29:46 +01:00
Jake Leahy
0bd4d80238 Allow parseAll to parse statements separated by semicolons (#23088)
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() = 
  # ...
```
2023-12-17 09:01:00 +01:00
ringabout
9648d97a8d fixes #22637; now --experimental:strictNotNil can be enabled globally (#23079)
fixes #22637
2023-12-16 07:05:57 +01:00
ringabout
0c3e703960 fixes not nil examples (#23080) 2023-12-15 21:12:28 +08:00
Jacek Sieka
315b59e824 make treeToYaml print yaml (and not json) (#23082)
less verbose - used in nph
2023-12-15 12:59:56 +01:00
Andreas Rumpf
91ad6a740b type refactor: part 4 (#23077) 2023-12-15 10:20:57 +01:00
ringabout
cca5684a17 fixes yet another strictdefs bug (#23069) 2023-12-15 08:13:25 +01:00
shirleyquirk
a4628532b2 rationals: support Rational[SomeUnsignedInt] (#23046)
fixes #22227
rationale:
    - `3u - 4u` is supported why not`3u.toRational - 4u.toRational`
- all of rationals' api is on SomeInteger, looks like unsigned is
declared as supported
  - math on unsigned rationals is meaningful and useful.
2023-12-15 07:49:07 +01:00
Ryan McConnell
94f7e9683f Param match relax (#23033)
#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>
2023-12-15 07:48:34 +01:00
ringabout
3a5b729034 fixes #23051; don't generate documentation for exported symbols again (#23074)
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)
2023-12-14 17:27:16 +01:00
Jason Beetham
91efa49550 Overloads passed to static proc parameters now convert to the desired… (#23063)
… type mirroring proc params
2023-12-14 17:05:14 +01:00
ringabout
7e4060cb4a fixes #23065; DocLike command defaults to ORC (#23075)
fixes #23065
2023-12-14 17:04:09 +01:00
Andreas Rumpf
6ed33b6d61 type graph refactor; part 3 (#23064) 2023-12-14 16:25:34 +01:00
Pylgos
1b7b0d69db fixes #9381; Fix double evaluation of types in generic objects (#23072)
fixes https://github.com/nim-lang/Nim/issues/9381
2023-12-14 09:55:04 +01:00
Nikolay Nikolov
a3739751a8 Skip trailing asterisk when placing inlay type hints. Fixes #23067 (#23068) 2023-12-13 21:13:36 +01:00
Andreas Rumpf
cd4ecddb30 nimpretty: check the rendered AST for wrong output (#23057) 2023-12-13 10:39:10 +01:00
ringabout
7e1ea50bc3 fixes #23060; editDistance wrongly compare the length of rune strings (#23062)
fixes #23060
2023-12-13 10:34:41 +01:00
Andreas Rumpf
e51e98997b type refactoring: part 2 (#23059) 2023-12-13 10:29:58 +01:00