Commit Graph

118 Commits

Author SHA1 Message Date
metagn
a27542195c only merge valid implicit pragmas to routine AST, include templates (#24171)
fixes #19277, refs #24169, refs #18124

When pragmas are pushed to a routine, if the routine symbol AST isn't
nil by the time the pushed pragmas are being processed, the pragmas are
implicitly added to the symbol AST. However this is done without
restriction on the pragma, if the pushed pragma isn't supposed to apply
to the routine, it's still added to the routine. This is why the symbol
AST for templates wasn't set before the pushed pragma processing in
#18124. Now, the pragmas added to the AST are restricted to ones that
apply to the given routine. This means we can set the template symbol
AST earlier so that the pragmas get added to the template AST.
2024-09-26 06:34:50 +02:00
ringabout
3b85c1a2e9 fixes #24167; {.push deprecated.} for templates (#24170)
fixes #24167
2024-09-25 13:00:06 +02:00
metagn
7da2ffb751 fix custom pragma with backticks not working [backport] (#24151)
refs https://forum.nim-lang.org/t/12522
2024-09-22 13:56:40 +02:00
ringabout
4bf323d6c4 fixes push warnings for sempass2 (#23603)
ref https://forum.nim-lang.org/t/11590
2024-09-03 09:19:52 +02:00
metagn
6320b0cd5b allow qualifying macro pragmas (#23985)
fixes #12696
2024-08-20 21:27:55 +02:00
ringabout
646bd99d46 [backport] fixes #23711; C code contains backtick`gensym (#23716)
fixes #23711
2024-06-19 08:33:38 +02: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
Jake Leahy
4fdc6c49bd Don't process a user pragma if its invalid (#23041)
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
2023-12-07 08:14:23 +01:00
ringabout
d20b4d5168 fixes #23019; Regression from 2.0 to devel with raise an unlisted exc… (#23034)
…eption: Exception

fixes #23019

I suppose `implicitPragmas` is called somewhere which converts
`otherPragmas`.
2023-12-05 21:04:41 +01:00
ringabout
5dafcf4957 fixes #22913; fixes #12985 differently push-ing pragma exportc genera… (#22941)
…tes invalid C identifiers

fixes #22913
fixes #12985 differently


`{.push.} now does not apply to generic instantiations`
2023-11-19 17:52:42 +01:00
SirOlaf
fcf4c1ae17 Fix #22713: Make size unknown for tyForward (#22714)
Close #22713

---------

Co-authored-by: SirOlaf <>
2023-09-17 20:03:43 +02:00
metagn
602f537eb2 allow non-pragma special words as user pragmas (#22526)
allow non-pragma special words as macro pragmas

fixes #22525
2023-08-21 20:08:57 +02:00
ringabout
825a0e7df4 fixes #22362; Compiler crashes with staticBoundsCheck on (#22363) 2023-08-02 11:00:34 +02:00
metagn
b97d603cd0 some test cleanups & category reorganization (#22010)
* clean up some test categories

* mention exact slice issue

* magics into system

* move trangechecks into overflow

* move tmemory to system

* try fix CI

* try fix CI

* final CI fix
2023-06-06 06:54:07 +02:00
metagn
44736d26cd error on user pragma args (#21776)
closes #20978
2023-05-03 14:18:55 +02:00
metagn
c694d8e4fd custom pragmas: correct error condition, remove outdated symkind whitelist (#21653)
* test not restricting custom pragma applied symbols

fixes #21652

* fix other test

* different patch

* fix tests

* actually test #18212 and other routines
2023-04-13 12:50:43 +02:00
ringabout
fd4e3ae3e4 add a prepass for codeReordering (#21513)
* add a prepass for codeReordering

* simplify

* fixes
2023-03-17 08:02:48 +01:00
ringabout
38f876dd48 fixes #19795; fixes #11852; fixes #19974; remove parsing pipeline, Nim now parses the whole module at one time (#21379)
* fixes #19795; remove parse pipeline

* isScript

* fixes nimscriptapi

* don't touch reorder

* check script

* fixes tests

* it seems implicit imports of system cause troubles

* access the first child of `nkStmtList`

* ignore comments

* minor messages

* perhaps increases hloLoopDetector

* the module is a stmtList, which changes the errors

* fixes nimdoc

* fixes tlinter

* fixes nim  secret tests

* fixes arc_misc

* fixes nim secret tests again

* safe; fixes one more test

* GlobalError is the root cause too

* fixes parsing errors

* put emit types to the cfsForwardTypes section

* fixes #11852; `{.push checks:off}` now works in procs

* disable navigator

* fixes nimdoc

* add tests for JS

* fixes nimsuggest
2023-02-22 20:34:20 +01:00
ringabout
5b20f0685c fixes pragmas reorder (#21205) 2023-01-01 10:25:04 +01:00
Jake Leahy
d00477dffb Check file exists in {.compile.} pragma (#21105)
* Add test

* Check file exists before adding it into compilation

* Make error message look like other error messages

i.e. following the format `error msg: file`
2022-12-15 19:22:45 +01:00
ringabout
5602183234 'lock levels' are deprecated, now a noop (#20539)
* 'lock levels' are deprecated, now a noop

* fixes tests
2022-10-11 09:17:09 +02:00
ringabout
852a7c4919 close #11415; add testcase (#20486) 2022-10-03 10:37:27 +02: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
Tanguy
3a5e38ab9d Allow custom pragma on iterators [backport] (#20344)
Allow custom pragma on iterators
2022-09-17 02:10:47 +08:00
quantimnot
6289b002b6 [Testament] Extend and document message testing aids (#19996)
* [Testament] Extend and document message testing aids

* Enable inline msgs when not reject action.
Eliminates the pain of changing the line and column numbers in `nimout`
or `output` while making changes to the test.
* Enable using inline msgs and nimout together.
Allows ease of inline msgs for the test as well as testing msgs from
other modules.
* Add path separator and test filename variable interpolation in
msgs.
Eases handling path separators in the msgs.
* Add some documentation.

* Fixed lots of broken tests

* Fixed more broken tests

* Support multiple inline messages per a line

* Fix a broken test

* Revert variable substitution in `output`

* Remove uneeded params

* Update doc/testament.md

Co-authored-by: Clay Sweetser <Varriount@users.noreply.github.com>

* Update testament/specs.nim

Co-authored-by: Clay Sweetser <Varriount@users.noreply.github.com>

* Update testament/specs.nim

Co-authored-by: Clay Sweetser <Varriount@users.noreply.github.com>

* Fix indentation

Co-authored-by: quantimnot <quantimnot@users.noreply.github.com>
Co-authored-by: Clay Sweetser <Varriount@users.noreply.github.com>
2022-09-01 17:52:13 +02:00
flywind
8bfc396a4d fixes #18612; apply cache and memcmp for methods in arc/orc (#19749)
* try using endsWith

* use memcmp

* add cache

* cleanup

* better

* minor

* fix

* improve test coverage for methods with ARC
2022-04-26 20:14:39 +02:00
Regis Caillaud
486cb09ec2 Clonkk fix2 11923 (#19451)
* fix nnkBracketExpr not compiling for getImpl on customPragmaNode

* fix test import

* fix alias not working with hasCustomPragmas
2022-02-02 09:44:51 +01:00
metagn
2bd1aa186e New/better macro pragmas, mark some as experimental (#19406)
* New/better macro pragmas, make some experimental

fix #15920, close #18212, close #14781, close #6696,
close https://github.com/nim-lang/RFCs/issues/220

Variable macro pragmas have been changed to
only take a unary section node.
They can now also be applied in sections with multiple variables,
as well as `const` sections. They also accept arguments.

Templates now support macro pragmas, mirroring other routine types.

Type and variable macro pragmas have been made experimental.
Symbols without parentheses instatiating nullary macros or templates
has also been documented in the experimental manual.

A check for a redefinition error based on the left hand side of variable
definitions when using variable macro pragmas was disabled.
This nerfs `byaddr` specifically, however this has been documented as
a consequence of the experimental features `byaddr` uses.

Given how simple these changes are I'm worried if I'm missing something.

* accomodate compiler boot

* allow weird pragmas

* add test for #10994

* remove some control flow, try remove some logic
2022-01-20 20:57:50 +01:00
Regis Caillaud
1563cb2f6e Fix #11923 (#19427)
* Apply commit 5da931fe81 that was never merged (was part of a bigger PR). Should fix issue #11932

* add a generic object for custom pragma
2022-01-20 20:50:36 +01:00
hlaaftana
1b143f5e79 Accept nnkTypeSection from typedef macro pragmas (#19168) 2021-11-22 10:41:35 +01:00
Andreas Rumpf
fce89cb60a fixes another effect inference bug [backport:1.6] (#19100)
* fixes another effect inference bug [backport:1.6]
2021-11-07 16:38:02 +01:00
Dominik Picheta
2aa97a228a Removes deprecated {.injectStmt.}. Fixes #18666 (#18984) 2021-10-13 11:09:45 +02:00
Andreas Rumpf
e0ef859130 strict effects (#18777)
* fixes #17369
* megatest is green for --cpu:arm64
* docgen output includes more tags/raises
* implemented 'effectsOf' 
* algorithm.nim: uses new effectsOf annotation
* closes #18376
* closes #17475
* closes #13905
* allow effectsOf: [a, b]
* added a test case
* parameters that are not ours cannot be declared as .effectsOf
* documentation
* manual: added the 'sort' example
* bootstrap with the new better options
2021-09-02 12:10:14 +02:00
Timothee Cour
394f4ac7bb improvements to addInt and $ for integer types (#18592)
* improvements to $(SomeInteger) and addInt
* remove mIntToStr, mInt64ToStr
* improvements
* fix tests/pragmas/tinjectstmt.nim; the diff is harmless, cgen code is identical with -d:danger or debug mode
* rm tests/system/tstrmantle.nim
* revert compiler/jsgen.nim for -d:nimVersion140
2021-08-19 11:33:52 +02:00
Timothee Cour
6c1bd4bb1c fix: var a{.foo.} = expr inside templates (refs #15920) (except when foo is overloaded) (#13869)
* fix: `var a{.foo.} = expr` inside templates
* add test
* improve tdecls test
* improve tests
* add failing test
* PRTEMP
* fixup
2021-08-11 12:17:17 +02:00
Andreas Rumpf
4920b06973 fixes #18543 (#18601)
* fixes #18543

* make tests green again
2021-07-27 19:04:55 +02:00
Timothee Cour
0b7361e938 followup #18362: make UnusedImport work robustly (#18366)
* warnDuplicateModuleImport => hintDuplicateModuleImport
* improve DuplicateModuleImport msg, add test
2021-06-27 20:39:16 +02:00
Timothee Cour
b8f761b7e2 even lighter version of #17938: fix most issues with UnusedImport, XDeclaredButNotUsed, etc; fix #17511, #17510, #14246 (without realModule) (#18362)
* {.used: symbol}

* add tests

* fix tests with --import

* --import works without giving spurious unused warnings

* new warning warnDuplicateModuleImport for `import foo; import foo`

* fix test, add resolveModuleAlias, use proper line info for module aliases

* fix spurious warnings

* fix deprecation msg for deprecated modules even with `import foo as bar`

* disable a test for i386 pending sorting XDeclaredButNotUsed errors

* UnusedImport now works with re-exported symbols

* fix typo [skip ci]

* ic support

* add genPNode to allow writing PNode-based compiler code similarly to `genAst`

* fix DuplicateModuleImport warning

* adjust test

* fixup

* fixup

* fixup

* fix after rebase

* fix for IC

* keep the proc inline, move the const out

* [skip ci] fix changelog

* experiment: remove calls to resolveModuleAlias

* followup

* fixup

* fix tests/modules/tselfimport.nim

* workaround tests/deprecated/tmodule1.nim

* fix properly

* simplify
2021-06-26 15:21:46 +02:00
Timothee Cour
6030e139b5 move {.injectStmt.} to experimental; add a test (#18300)
* move {.injectStmt.} to experimental; add a test

* undocument and deprecat `.injectStmt` but keep its implementation until we have a replacement
2021-06-20 09:51:07 +02:00
Timothee Cour
3b1aabdcff change --hint[X] => --hint:X in nim repo (avoids shell quoting issues) (#18085) 2021-05-26 09:51:48 +02:00
Clyybber
7c64e49d45 getCustomPragmaVal priority/override fixes (#17725)
* Adhere left-to-right rule for custom pragma priority

* Improve error message for no custom pragmas

* custom pragmas on var/let sym take priority over its type ones

* Workaround & bug
2021-04-21 15:28:42 +02:00
Clyybber
51a40c1f38 Fix getCustomPragmaVal for some multi arg pragmas (#17723)
* Fix getCustomPragmaVal for some multi arg pragmas

* Bootstrap fix
2021-04-15 13:55:50 +02:00
Timothee Cour
d6242d7fe1 simplify asyncfutures, asyncmacro (#17633) 2021-04-14 21:22:22 +02:00
Arne Döring
56c37759d6 getCustomPragma is split up in more usable chunks (#11526)
* getCustomPragma is split up in more usable chunks
* changelog entry
* fix for style checks
* shitty typedesc special casing
* Add since annotation and remove typedesc comments
* Fix typo
* Revert since annotation because it breaks bootstrapping
* Export getCustomPragmaNode conditionally
* Reduce code duplication
* Update since
* Update lib/core/macros.nim
* Apply suggestions from code review

Co-authored-by: Clyybber <darkmine956@gmail.com>
Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
2021-04-14 20:42:09 +02:00
flywind
70a30317f7 fix #16693: testament spec nimout too lax (#16698)
Co-authored-by: Timothee Cour <timothee.cour2@gmail.com>
2021-04-04 13:47:28 -07:00
Timothee Cour
287dec06ae disable hint:processing in tests (#16713)
* disable hint:processing in tests

* fix test
2021-01-14 10:19:20 +01:00
flywind
6d442a40a6 use doAssert in tests (#16486) 2020-12-28 14:13:21 +01:00
flywind
673c5990c6 fix #12558 (#15864)
* fix #12558
* Update compiler/pragmas.nim
2020-11-09 11:46:25 +01:00
flywind
fdd25ed19c close #8457 (#15844) 2020-11-05 18:31:44 +08:00