Commit Graph

250 Commits

Author SHA1 Message Date
ringabout
d062c4fc70 Merge branch 'devel' into pr_remove_macros 2025-01-08 20:57:04 +08:00
metagn
aeb3fe9505 test case haul to prevent pileup (#24525)
closes #6013, closes #7009, closes #9190, closes #12487, closes #12831,
closes #13184, closes #13252, closes #14860, closes #14877, closes
#14894, closes #14917, closes #16153, closes #16439, closes #17779,
closes #18074, closes #18202, closes #18314, closes #18648, closes
#19063, closes #19446, closes #20065, closes #20367, closes #22126,
closes #22820, closes #22888, closes #23020, closes #23287, closes
#23510
2024-12-09 08:11:47 +01:00
ringabout
02fb0476ce adds a test case (#24515)
closes #17733
2024-12-05 22:19:34 +08:00
metagn
dc3ffb6a71 consider calling convention and iterator in getType for procs (#24181)
fixes #19010

`getType` for proc types generated an `nkProcTy` for iterator types
instead of `nkIteratorTy`, and didn't generate a calling convention
pragma unless it was in the proc AST. Iterator types now generate
`nkIteratorTy`, and a calling convention pragma is added if the calling
convention isn't `closure` or was explicitly provided.
2024-09-27 11:11:21 +02:00
metagn
1bd5a4a99e render float128 literals (#24182)
fixes #23639

Not sure if these are meant to be supported but it's better than
crashing.
2024-09-27 06:11:21 +02:00
metagn
fc853cb726 generic issues test cases (#24028)
closes #1969, closes #7547, closes #7737, closes #11838, closes #12283,
closes #12714, closes #12720, closes #14053, closes #16118, closes
#19670, closes #22645

I was going to wait on these but regression tests even for recent PRs
are turning out to be important in wide reaching PRs like #24010.

The other issues with the working label felt either finnicky (#7385,
#9156, #12732, #15247), excessive to test (#12405, #12424, #17527), or I
just don't know what fixed them/what the issue was (#16128: the PR link
gives a server error by Github, #12457, #12487).
2024-08-30 16:12:38 +02:00
ringabout
e93c5a635c fixes tests 2024-08-14 22:07:51 +08:00
ringabout
04288236f4 Merge branch 'devel' into pr_remove_macros 2024-08-14 15:17:53 +08:00
SirOlaf
f765898a75 Set type of object constructor during annotateType (#23852)
Fix https://github.com/nim-lang/Nim/issues/23547

Tested locally with the included test, the test from constantine and the
original issue.
2024-07-17 23:54:15 +02:00
ringabout
051a536275 fixes #23784; don't allow fold paths containing nkAddr (#23792)
fixes #23784

notes that before https://github.com/nim-lang/Nim/pull/23477, it didn't
fold paths containing `addr`/`unsafeAddr` because it retained the form
of the magic function: `mAddr`.
2024-07-03 22:48:19 +02:00
ringabout
19fd8f5ec1 remove deprecated stuffs since v0.18.1 from macros 2024-05-02 12:33:45 +00:00
ringabout
9b378296f6 fixes addr/hiddenAddr in strictdefs (#23477) 2024-04-10 14:41:16 +02:00
ringabout
a2584c779b closes #15751; adds a test case (#23372)
closes #15751
2024-03-06 16:25:20 +08:00
Ryan McConnell
74fa8ed59a Changing generic weight of tyGenericParam (#22143)
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>
2024-01-05 09:42:21 +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
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
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
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
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
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
Juan M Gómez
0c179db657 case macro now can be used inside generic. Fixes #20435 (#22752)
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>
2023-09-30 06:27:02 +02:00
metagn
c19fd69b69 test case haul for old generic/template/macro issues (#22564)
* test case haul for old generic/template/macro issues

closes #12582, closes #19552, closes #2465, closes #4596, closes #15246,
closes #12683, closes #7889, closes #4547, closes #12415, closes #2002,
closes #1771, closes #5121

The test for #5648 is also moved into its own test
from `types/tissues_types` due to not being joinable.

* fix template gensym test
2023-08-27 11:27:47 +02:00
ringabout
7ee00d86b1 fixes overriden typo (#22044) 2023-06-08 08:02:11 +02:00
metagn
02be212dae clean up SOME pending/xxx/issue link comments (#21826)
* clean up SOME pending/xxx/issue link comments

* great
2023-05-11 10:23:52 +02:00
metagn
be06446ffe fix #15691 (#21623)
`semProcAux` has a check for `checkMinSonsLen(n, bodyPos + 1)`
2023-04-11 09:37:53 +02:00
chmod222
0c6f14af04 macros: Extend treeTraverse intVal range to nnkUInt64Lit (#21597)
* Extend intVal range to nnkUInt64Lit

Fixes #21593

* Properly cast intVal as unsigned

* Add testcase for #21593
2023-04-01 20:29:28 +02:00
metagn
2315b01ae6 tuple unpacking for vars as just sugar, allowing nesting (#21563)
* tuple unpacking for vars as just sugar, allowing nesting

* set temp symbol AST

* hopeful fix some issues, add test for #19364

* always use temp for consts

* document, fix small issue

* fix manual indentation

* actually fix manual

* use helper proc

* don't resem temp tuple assignment
2023-03-28 17:52:23 +02:00
Jake Leahy
900fe8f501 Add contains to std/macrocache (#21304)
* Add test cases

* Implement contains for CacheSeq

* Implement contains for CacheTable

* Fix implementation of hasKey

* Remove contains for CacheSeq

Fix runnable examples

I was accidently using --doccmd:skip so I didn't spot the failure locally

* Implement hasKey as a VM callback instead of magic

* Implement suggestions from PR

Co-Authored-By: ringabout <ringabout@users.noreply.github.com>

* Update lib/core/macrocache.nim

---------

Co-authored-by: ringabout <ringabout@users.noreply.github.com>
Co-authored-by: ringabout <43030857+ringabout@users.noreply.github.com>
2023-02-01 10:00:10 +01:00
Peter Munch-Ellingsen
613829f7a4 Implement setLineInfo (#21153)
* Implement setLineInfo

* Add tests
2022-12-22 04:34:36 +01:00
Bung
1585bfec3b fix #16758 Nim crashes in fixAbstractType (#20855)
* fix #16758 Nim crashes in fixAbstractType

* Update compiler/semexprs.nim

Co-authored-by: Andreas Rumpf <rumpf_a@web.de>

Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
2022-12-11 06:58:29 +01:00
metagn
de4b0346bd store full definition AST for consts, fix noRewrite (#20115)
* continue #9582 for consts, close #9331, fix #20114

also move extractPragma to ast to pave the way for things like {.strdefine: "abc".} etc

* changelog correctly

* fix jsgen

* update tgetimpl

* fix sighashes

* fix #19766, add comment about postfix

* fix noRewrite LOL

refs #16620

* fix changelog

* fix destructors
2022-09-28 15:05:01 +02:00
ringabout
7739e23420 defaults to ORC (#19972)
* defaults to Orc

* bootstrap using refc

* use gc

* init orc defines

* unregister orc

* fix gc

* fix commands

* add prepareMutation for orc

* enable deepcopy for orc

* prepareMutation

* more fixes

* some cases

* bug #20081

* partial fixes

* partial fixes

* fixes command line

* more fixes

* build Nim with refc

* use gc

* more fixes

* rstore

* orc doesn't support threadpool

* more shallowCopy

* more fixes

* fixes unsafeNew

* workarounds

* small

* more fixes

* fixes some megatest

* tcodegenbugs1 refc

* fxies megatest

* build nimble with refc

* workaround tensordsl tests

* replace shallowCopy with move

* fixes action

* workaround

* add todo

* fixes important packages

* unpublic unregisterArcOrc

* fixes cpp

* enable windows

Co-authored-by: xflywind <43030857+xflywind@users.noreply.github.com>
2022-09-23 13:05:05 +02:00
metagn
86f7f4ffa5 remove deprecated type pragma syntax, fix bugs that required it (#20199)
* remove deprecated pragma syntax from 0.20.0

closes #4651, closes #16653 with a cheap fix for now due to
how early `tfFinal` is set

* remove type pragma between name and generics

* undo removal, try removing bind expression (0.8.14)

* fix test, unremove bind expr

* remove again

* Update changelog.md

Co-authored-by: konsumlamm <44230978+konsumlamm@users.noreply.github.com>

* dependencies @ HEAD & weave test dependencies

* try fix package ci

Co-authored-by: konsumlamm <44230978+konsumlamm@users.noreply.github.com>
2022-09-03 09:52:13 +02:00
metagn
d1d141b135 new .redefine pragma for templates, warn on redefinition without it (#20211)
* test CI for template redefinitions

* adapt asyncmacro

* fix quote

* fix again

* try something else

* revert

* fix ioselectors_select, disable packages CI

* adapt more tests & simplify

* more

* more

* more

* rename to redefine, warn on implicit redefinition

* basic documentation [skip ci]

* Update compiler/lineinfos.nim

Co-authored-by: konsumlamm <44230978+konsumlamm@users.noreply.github.com>

Co-authored-by: konsumlamm <44230978+konsumlamm@users.noreply.github.com>
2022-08-23 21:41:30 +02:00
metagn
685bf944aa fix #20067, fix #18976 [backport] (#20069) 2022-07-22 15:04:07 +08:00
flywind
15ae9323e8 fix NimNode comment repr() regression [backport: 1.2] (#19726) 2022-04-25 11:19:21 +02:00
Tanguy
ef3f343ec2 Allow std/macros.params to work with nnkProcTy (#19563)
* Allow std/macros.params to work with nnkProcTy

* Add tests for proc params & pragma
2022-02-25 12:57:58 +01:00
flywind
2ef71c0a46 [testcase] genSym fails to make unique identifier for ref object types (#19506)
close #15118
2022-02-14 14:36:01 +01:00
hlaaftana
f91867aa31 accept object type node from macros (#19179) 2021-11-24 16:34:42 +01:00
hlaaftana
c7c6b13a32 parseExpr/parseStmt accept filename, fixes #13540 (#19182) 2021-11-24 12:22:40 +01:00
hlaaftana
5933aece9b caseStmtMacros no longer experimental, experimental manual refactor (#19173)
* `caseStmtMacros` no longer experimental, experimental manual refactor

* Update doc/manual.rst

* apply review suggestions

* apply review

Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
2021-11-23 16:30:17 +01:00
Dankr4d
c70e4040bd fixes #14511 [backport:1.4] (#18732)
* fixes #14511 [backport:1.4]

Signed-off-by: Dankr4d <dude569@freenet.de>

* Replaced fix with code from alaviss, for better readability, with small
changes.

Signed-off-by: Dankr4d <dude569@freenet.de>

* - Specified output in test.

Signed-off-by: Dankr4d <dude569@freenet.de>

* Replaced case in nnkRecCase with a simpler version, which just adds the
last son.

Signed-off-by: Dankr4d <dude569@freenet.de>

* Update tests/macros/t14511.nim

* Update tests/macros/t14511.nim

Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
2021-08-25 17:27:00 +00:00
Clyybber
13b94c0297 Fix doubly typed forward declarations (#18279)
* Add testcase

* Fix testcase

* Fix doubly typed forward decls

* Better fix
2021-06-16 16:40:22 +02:00
Clyybber
c5cf21c0c4 Don't report unused hints for consumed AST (#18270)
* Fix #18203

* Add testcase

* Fix testcase

* Fix test
2021-06-16 02:45:05 +02:00
Saem Ghani
488acd9d07 fixes #18235 - proc annotation type macro sym leak (#18249)
* fixes #18235 - proc annotation type macro sym leak

- also fixed a typo
- proc annotations guard symbol exports with shadow scopes
- symbol handling is shadow scope aware

* test for exporting an existing unexported sym

this one is for my homie alaviss.

* Special handling not needed in semProcAnnotation

* Testcasing

* [skip ci]  clean-up and add some more comments

* [skip ci] rm trailing whitespace

Co-authored-by: Clyybber <darkmine956@gmail.com>
2021-06-14 09:21:33 +02:00
Timothee Cour
897e50d5fe getType now works with tyInferred (arising from concepts); refs #18220 (#18241)
* getType now works with tyInferred (concepts); refs #18220

* avoid cast

* add more docs
2021-06-12 21:35:12 +02:00
Timothee Cour
3cc547f2df macros.treeRepr + friends: collapse SymChoice (#18072)
* macros.treeRepr + friends: collapse SymChoice

* make repr+friends work with invalid symchoice nodes

* address comment
2021-06-05 06:58:26 +02:00
Dylan Modesitt
06d50bfd4c Fixes #5034 illformed AST from getImpl with proc returning value (#17976)
* Fixes 5034

* address comments
2021-05-31 22:51:32 +02:00