diff options
author | Don-Duong Quach <geekrelief@gmail.com> | 2024-08-12 06:18:56 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-12 15:18:56 +0200 |
commit | 20043ea09ef44f413308158a74ba2ba1fe3379bb (patch) | |
tree | f4228a59c4507ee2e458878ec9cba9346bed1350 | |
parent | b215ec3735b7df9d1d34c0b93013eac8dfeff89f (diff) | |
download | Nim-20043ea09ef44f413308158a74ba2ba1fe3379bb.tar.gz |
Implemented `compileOption` for `experimental` to test if a feature i… (#23933)
…s enabled at compile time. #8644 This doesn't handle the case if `{.push experimental.}` is used, but at least we can test if a feature was enabled globally.
-rw-r--r-- | compiler/commands.nim | 9 | ||||
-rw-r--r-- | tests/compileoption/texperimental.nim | 20 | ||||
-rw-r--r-- | tests/compileoption/texperimental.nims | 19 |
3 files changed, 47 insertions, 1 deletions
diff --git a/compiler/commands.nim b/compiler/commands.nim index 5b261b3e8..cbf915ca6 100644 --- a/compiler/commands.nim +++ b/compiler/commands.nim @@ -24,7 +24,7 @@ bootSwitch(usedMarkAndSweep, defined(gcmarkandsweep), "--gc:markAndSweep") bootSwitch(usedGoGC, defined(gogc), "--gc:go") bootSwitch(usedNoGC, defined(nogc), "--gc:none") -import std/[setutils, os, strutils, parseutils, parseopt, sequtils, strtabs] +import std/[setutils, os, strutils, parseutils, parseopt, sequtils, strtabs, enumutils] import msgs, options, nversion, condsyms, extccomp, platform, wordrecg, nimblecmd, lineinfos, pathutils @@ -248,6 +248,7 @@ const errNoneSpeedOrSizeExpectedButXFound = "'none', 'speed' or 'size' expected, but '$1' found" errGuiConsoleOrLibExpectedButXFound = "'gui', 'console', 'lib' or 'staticlib' expected, but '$1' found" errInvalidExceptionSystem = "'goto', 'setjmp', 'cpp' or 'quirky' expected, but '$1' found" + errInvalidFeatureButXFound = Feature.toSeq.map(proc(val:Feature): string = "'$1'" % $val).join(", ") & " expected, but '$1' found" template warningOptionNoop(switch: string) = warningDeprecated(conf, info, "'$#' is deprecated, now a noop" % switch) @@ -303,6 +304,12 @@ proc testCompileOptionArg*(conf: ConfigRef; switch, arg: string, info: TLineInfo else: result = false localError(conf, info, errInvalidExceptionSystem % arg) + of "experimental": + try: + result = conf.features.contains parseEnum[Feature](arg) + except ValueError: + result = false + localError(conf, info, errInvalidFeatureButXFound % arg) else: result = false invalidCmdLineOption(conf, passCmd1, switch, info) diff --git a/tests/compileoption/texperimental.nim b/tests/compileoption/texperimental.nim new file mode 100644 index 000000000..e31b0481d --- /dev/null +++ b/tests/compileoption/texperimental.nim @@ -0,0 +1,20 @@ +static: + doAssert compileOption("experimental", "dotOperators") + doAssert compileOption("experimental", "callOperator") + doAssert compileOption("experimental", "parallel") + doAssert compileOption("experimental", "destructor") + doAssert compileOption("experimental", "notnil") + doAssert compileOption("experimental", "dynamicBindSym") + doAssert compileOption("experimental", "codeReordering") + doAssert compileOption("experimental", "compiletimeFFI") + doAssert compileOption("experimental", "vmopsDanger") + doAssert compileOption("experimental", "strictFuncs") + doAssert compileOption("experimental", "views") + doAssert compileOption("experimental", "strictNotNil") + doAssert compileOption("experimental", "strictEffects") + doAssert compileOption("experimental", "flexibleOptionalParams") + doAssert compileOption("experimental", "strictDefs") + doAssert compileOption("experimental", "strictCaseObjects") + doAssert compileOption("experimental", "inferGenericTypes") + doAssert compileOption("experimental", "genericsOpenSym") + doAssert compileOption("experimental", "vtables") \ No newline at end of file diff --git a/tests/compileoption/texperimental.nims b/tests/compileoption/texperimental.nims new file mode 100644 index 000000000..a2094eb4a --- /dev/null +++ b/tests/compileoption/texperimental.nims @@ -0,0 +1,19 @@ +switch("experimental", "dotOperators") +switch("experimental", "callOperator") +switch("experimental", "parallel") +switch("experimental", "destructor") +switch("experimental", "notnil") +switch("experimental", "dynamicBindSym") +switch("experimental", "codeReordering") +switch("experimental", "compiletimeFFI") +switch("experimental", "vmopsDanger") +switch("experimental", "strictFuncs") +switch("experimental", "views") +switch("experimental", "strictNotNil") +switch("experimental", "strictEffects") +switch("experimental", "flexibleOptionalParams") +switch("experimental", "strictDefs") +switch("experimental", "strictCaseObjects") +switch("experimental", "inferGenericTypes") +switch("experimental", "genericsOpenSym") +switch("experimental", "vtables") \ No newline at end of file |