-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
allow generic compileTime proc folding (#22022)
fixes #10753, fixes #22021, refs #19365 (was fixed by #22029, but more faithful test added) For whatever reason `compileTime` proc calls did not fold if the proc was generic ([since this folding was introduced](c25ffbf#diff-539da3a63df08fa987f1b0c67d26cdc690753843d110b6bf0805a685eeaffd40)). I'm guessing the intention was for *unresolved* generic procs to not fold, which is now the logic. Non-magic `compileTime` procs also now don't fold at compile time in `typeof` contexts to avoid possible runtime errors (only the important) and prevent double/needless evaluation.
- Loading branch information
Showing
5 changed files
with
40 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
block: # issue #10753 | ||
proc foo(x: int): int {.compileTime.} = x | ||
const a = foo(123) | ||
doAssert foo(123) == a | ||
|
||
proc bar[T](x: T): T {.compileTime.} = x | ||
const b = bar(123) | ||
doAssert bar(123) == b | ||
const c = bar("abc") | ||
doAssert bar("abc") == c | ||
|
||
block: # issue #22021 | ||
proc foo(x: static int): int {.compileTime.} = x + 1 | ||
doAssert foo(123) == 124 | ||
|
||
block: # issue #19365 | ||
proc f[T](x: static T): T {.compileTime.} = x + x | ||
doAssert f(123) == 246 | ||
doAssert f(1.0) == 2.0 | ||
|
||
block: | ||
# don't fold compile time procs in typeof | ||
proc fail[T](x: T): T {.compileTime.} = | ||
doAssert false | ||
x | ||
doAssert typeof(fail(123)) is typeof(123) | ||
proc p(x: int): int = x | ||
|
||
type Foo = typeof(p(fail(123))) |