diff --git a/src/dmd/cli.d b/src/dmd/cli.d index 678cf7266530..b163a1db853b 100644 --- a/src/dmd/cli.d +++ b/src/dmd/cli.d @@ -860,6 +860,8 @@ dmd -cov -unittest myprog.d "'in' contracts of overridden methods must be a superset of parent contract"), Feature("shortenedMethods", "shortenedMethods", "allow use of => for methods and top-level functions in addition to lambdas"), + Feature("complex", "previewComplex", + "remove complex and imaginary types from the language"), // DEPRECATED previews // trigger deprecation message once D repositories don't use this flag anymore Feature("markdown", "markdown", "enable Markdown replacements in Ddoc", false, false), diff --git a/src/dmd/frontend.h b/src/dmd/frontend.h index 69c16727056e..49b2fdb9805a 100644 --- a/src/dmd/frontend.h +++ b/src/dmd/frontend.h @@ -475,6 +475,7 @@ struct Param final bool vgc; bool vfield; bool vcomplex; + bool previewComplex; bool vin; uint8_t symdebug; bool symdebugref; @@ -603,6 +604,7 @@ struct Param final vgc(), vfield(), vcomplex(true), + previewComplex(), vin(), symdebug(), symdebugref(), @@ -710,7 +712,7 @@ struct Param final mapfile() { } - Param(bool obj, bool link = true, bool dll = false, bool lib = false, bool multiobj = false, bool oneobj = false, bool trace = false, bool tracegc = false, bool verbose = false, bool vcg_ast = false, bool showColumns = false, bool vtls = false, bool vtemplates = false, bool vtemplatesListInstances = false, bool vgc = false, bool vfield = false, bool vcomplex = true, bool vin = false, uint8_t symdebug = 0u, bool symdebugref = false, bool optimize = false, DiagnosticReporting useDeprecated = (DiagnosticReporting)1u, bool stackstomp = false, bool useUnitTests = false, bool useInline = false, FeatureState useDIP25 = (FeatureState)-1, FeatureState useDIP1000 = (FeatureState)-1, bool useDIP1021 = false, bool release = false, bool preservePaths = false, DiagnosticReporting warnings = (DiagnosticReporting)2u, PIC pic = (PIC)0u, bool color = false, bool cov = false, uint8_t covPercent = 0u, bool ctfe_cov = false, bool nofloat = false, bool ignoreUnsupportedPragmas = false, bool useModuleInfo = true, bool useTypeInfo = true, bool useExceptions = true, bool noSharedAccess = false, bool previewIn = false, bool shortenedMethods = false, bool betterC = false, bool addMain = false, bool allInst = false, bool fix16997 = true, bool fixAliasThis = false, bool inclusiveInContracts = false, bool ehnogc = false, FeatureState dtorFields = (FeatureState)-1, bool fieldwise = false, bool rvalueRefParam = false, CppStdRevision cplusplus = (CppStdRevision)201103u, bool markdown = true, bool vmarkdown = false, bool showGaggedErrors = false, bool printErrorContext = false, bool manual = false, bool usage = false, bool mcpuUsage = false, bool transitionUsage = false, bool checkUsage = false, bool checkActionUsage = false, bool revertUsage = false, bool previewUsage = false, bool externStdUsage = false, bool hcUsage = false, bool logo = false, CHECKENABLE useInvariants = (CHECKENABLE)0u, CHECKENABLE useIn = (CHECKENABLE)0u, CHECKENABLE useOut = (CHECKENABLE)0u, CHECKENABLE useArrayBounds = (CHECKENABLE)0u, CHECKENABLE useAssert = (CHECKENABLE)0u, CHECKENABLE useSwitchError = (CHECKENABLE)0u, CHECKENABLE boundscheck = (CHECKENABLE)0u, CHECKACTION checkAction = (CHECKACTION)0u, uint32_t errorLimit = 20u, _d_dynamicArray< const char > argv0 = {}, Array modFileAliasStrings = Array(0LLU, {}, arrayliteral), Array* imppath = nullptr, Array* fileImppath = nullptr, _d_dynamicArray< const char > objdir = {}, _d_dynamicArray< const char > objname = {}, _d_dynamicArray< const char > libname = {}, bool doDocComments = false, _d_dynamicArray< const char > docdir = {}, _d_dynamicArray< const char > docname = {}, Array ddocfiles = Array(0LLU, {}, arrayliteral), bool doHdrGeneration = false, _d_dynamicArray< const char > hdrdir = {}, _d_dynamicArray< const char > hdrname = {}, bool hdrStripPlainFunctions = true, CxxHeaderMode doCxxHdrGeneration = (CxxHeaderMode)0u, _d_dynamicArray< const char > cxxhdrdir = {}, _d_dynamicArray< const char > cxxhdrname = {}, bool doJsonGeneration = false, _d_dynamicArray< const char > jsonfilename = {}, JsonFieldFlags jsonFieldFlags = (JsonFieldFlags)0u, OutBuffer* mixinOut = nullptr, const char* mixinFile = nullptr, int32_t mixinLines = 0, uint32_t debuglevel = 0u, Array* debugids = nullptr, uint32_t versionlevel = 0u, Array* versionids = nullptr, _d_dynamicArray< const char > defaultlibname = {}, _d_dynamicArray< const char > debuglibname = {}, _d_dynamicArray< const char > mscrtlib = {}, _d_dynamicArray< const char > moduleDepsFile = {}, OutBuffer* moduleDeps = nullptr, bool emitMakeDeps = false, _d_dynamicArray< const char > makeDepsFile = {}, Array makeDeps = Array(0LLU, {}, arrayliteral), MessageStyle messageStyle = (MessageStyle)0u, bool run = false, Array runargs = Array(0LLU, {}, arrayliteral), Array objfiles = Array(0LLU, {}, arrayliteral), Array linkswitches = Array(0LLU, {}, arrayliteral), Array linkswitchIsForCC = Array(0LLU, {}, arrayliteral), Array libfiles = Array(0LLU, {}, arrayliteral), Array dllfiles = Array(0LLU, {}, arrayliteral), _d_dynamicArray< const char > deffile = {}, _d_dynamicArray< const char > resfile = {}, _d_dynamicArray< const char > exefile = {}, _d_dynamicArray< const char > mapfile = {}) : + Param(bool obj, bool link = true, bool dll = false, bool lib = false, bool multiobj = false, bool oneobj = false, bool trace = false, bool tracegc = false, bool verbose = false, bool vcg_ast = false, bool showColumns = false, bool vtls = false, bool vtemplates = false, bool vtemplatesListInstances = false, bool vgc = false, bool vfield = false, bool vcomplex = true, bool previewComplex = false, bool vin = false, uint8_t symdebug = 0u, bool symdebugref = false, bool optimize = false, DiagnosticReporting useDeprecated = (DiagnosticReporting)1u, bool stackstomp = false, bool useUnitTests = false, bool useInline = false, FeatureState useDIP25 = (FeatureState)-1, FeatureState useDIP1000 = (FeatureState)-1, bool useDIP1021 = false, bool release = false, bool preservePaths = false, DiagnosticReporting warnings = (DiagnosticReporting)2u, PIC pic = (PIC)0u, bool color = false, bool cov = false, uint8_t covPercent = 0u, bool ctfe_cov = false, bool nofloat = false, bool ignoreUnsupportedPragmas = false, bool useModuleInfo = true, bool useTypeInfo = true, bool useExceptions = true, bool noSharedAccess = false, bool previewIn = false, bool shortenedMethods = false, bool betterC = false, bool addMain = false, bool allInst = false, bool fix16997 = true, bool fixAliasThis = false, bool inclusiveInContracts = false, bool ehnogc = false, FeatureState dtorFields = (FeatureState)-1, bool fieldwise = false, bool rvalueRefParam = false, CppStdRevision cplusplus = (CppStdRevision)201103u, bool markdown = true, bool vmarkdown = false, bool showGaggedErrors = false, bool printErrorContext = false, bool manual = false, bool usage = false, bool mcpuUsage = false, bool transitionUsage = false, bool checkUsage = false, bool checkActionUsage = false, bool revertUsage = false, bool previewUsage = false, bool externStdUsage = false, bool hcUsage = false, bool logo = false, CHECKENABLE useInvariants = (CHECKENABLE)0u, CHECKENABLE useIn = (CHECKENABLE)0u, CHECKENABLE useOut = (CHECKENABLE)0u, CHECKENABLE useArrayBounds = (CHECKENABLE)0u, CHECKENABLE useAssert = (CHECKENABLE)0u, CHECKENABLE useSwitchError = (CHECKENABLE)0u, CHECKENABLE boundscheck = (CHECKENABLE)0u, CHECKACTION checkAction = (CHECKACTION)0u, uint32_t errorLimit = 20u, _d_dynamicArray< const char > argv0 = {}, Array modFileAliasStrings = Array(0LLU, {}, arrayliteral), Array* imppath = nullptr, Array* fileImppath = nullptr, _d_dynamicArray< const char > objdir = {}, _d_dynamicArray< const char > objname = {}, _d_dynamicArray< const char > libname = {}, bool doDocComments = false, _d_dynamicArray< const char > docdir = {}, _d_dynamicArray< const char > docname = {}, Array ddocfiles = Array(0LLU, {}, arrayliteral), bool doHdrGeneration = false, _d_dynamicArray< const char > hdrdir = {}, _d_dynamicArray< const char > hdrname = {}, bool hdrStripPlainFunctions = true, CxxHeaderMode doCxxHdrGeneration = (CxxHeaderMode)0u, _d_dynamicArray< const char > cxxhdrdir = {}, _d_dynamicArray< const char > cxxhdrname = {}, bool doJsonGeneration = false, _d_dynamicArray< const char > jsonfilename = {}, JsonFieldFlags jsonFieldFlags = (JsonFieldFlags)0u, OutBuffer* mixinOut = nullptr, const char* mixinFile = nullptr, int32_t mixinLines = 0, uint32_t debuglevel = 0u, Array* debugids = nullptr, uint32_t versionlevel = 0u, Array* versionids = nullptr, _d_dynamicArray< const char > defaultlibname = {}, _d_dynamicArray< const char > debuglibname = {}, _d_dynamicArray< const char > mscrtlib = {}, _d_dynamicArray< const char > moduleDepsFile = {}, OutBuffer* moduleDeps = nullptr, bool emitMakeDeps = false, _d_dynamicArray< const char > makeDepsFile = {}, Array makeDeps = Array(0LLU, {}, arrayliteral), MessageStyle messageStyle = (MessageStyle)0u, bool run = false, Array runargs = Array(0LLU, {}, arrayliteral), Array objfiles = Array(0LLU, {}, arrayliteral), Array linkswitches = Array(0LLU, {}, arrayliteral), Array linkswitchIsForCC = Array(0LLU, {}, arrayliteral), Array libfiles = Array(0LLU, {}, arrayliteral), Array dllfiles = Array(0LLU, {}, arrayliteral), _d_dynamicArray< const char > deffile = {}, _d_dynamicArray< const char > resfile = {}, _d_dynamicArray< const char > exefile = {}, _d_dynamicArray< const char > mapfile = {}) : obj(obj), link(link), dll(dll), @@ -728,6 +730,7 @@ struct Param final vgc(vgc), vfield(vfield), vcomplex(vcomplex), + previewComplex(previewComplex), vin(vin), symdebug(symdebug), symdebugref(symdebugref), @@ -888,7 +891,7 @@ struct Global final varSequenceNumber(1u) { } - Global(_d_dynamicArray< const char > inifilename, _d_dynamicArray< const char > copyright = { 73, "Copyright (C) 1999-2022 by The D Language Foundation, All Rights Reserved" }, _d_dynamicArray< const char > written = { 24, "written by Walter Bright" }, Array* path = nullptr, Array* filePath = nullptr, _d_dynamicArray< const char > vendor = {}, Param params = Param(true, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, false, 0u, false, false, (DiagnosticReporting)1u, false, false, false, (FeatureState)-1, (FeatureState)-1, false, false, false, (DiagnosticReporting)2u, (PIC)0u, false, false, 0u, false, false, false, true, true, true, false, false, false, false, false, false, true, false, false, false, (FeatureState)-1, false, false, (CppStdRevision)201103u, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, (CHECKENABLE)0u, (CHECKENABLE)0u, (CHECKENABLE)0u, (CHECKENABLE)0u, (CHECKENABLE)0u, (CHECKENABLE)0u, (CHECKENABLE)0u, (CHECKACTION)0u, 20u, {}, Array(0LLU, {}, arrayliteral), nullptr, nullptr, {}, {}, {}, false, {}, {}, Array(0LLU, {}, arrayliteral), false, {}, {}, true, (CxxHeaderMode)0u, {}, {}, false, {}, (JsonFieldFlags)0u, nullptr, nullptr, 0, 0u, nullptr, 0u, nullptr, {}, {}, {}, {}, nullptr, false, {}, Array(0LLU, {}, arrayliteral), (MessageStyle)0u, false, Array(0LLU, {}, arrayliteral), Array(0LLU, {}, arrayliteral), Array(0LLU, {}, arrayliteral), Array(0LLU, {}, arrayliteral), Array(0LLU, {}, arrayliteral), Array(0LLU, {}, arrayliteral), {}, {}, {}, {}), uint32_t errors = 0u, uint32_t warnings = 0u, uint32_t gag = 0u, uint32_t gaggedErrors = 0u, uint32_t gaggedWarnings = 0u, void* console = nullptr, Array* versionids = nullptr, Array* debugids = nullptr, bool hasMainFunction = false, uint32_t varSequenceNumber = 1u) : + Global(_d_dynamicArray< const char > inifilename, _d_dynamicArray< const char > copyright = { 73, "Copyright (C) 1999-2022 by The D Language Foundation, All Rights Reserved" }, _d_dynamicArray< const char > written = { 24, "written by Walter Bright" }, Array* path = nullptr, Array* filePath = nullptr, _d_dynamicArray< const char > vendor = {}, Param params = Param(true, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, 0u, false, false, (DiagnosticReporting)1u, false, false, false, (FeatureState)-1, (FeatureState)-1, false, false, false, (DiagnosticReporting)2u, (PIC)0u, false, false, 0u, false, false, false, true, true, true, false, false, false, false, false, false, true, false, false, false, (FeatureState)-1, false, false, (CppStdRevision)201103u, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, (CHECKENABLE)0u, (CHECKENABLE)0u, (CHECKENABLE)0u, (CHECKENABLE)0u, (CHECKENABLE)0u, (CHECKENABLE)0u, (CHECKENABLE)0u, (CHECKACTION)0u, 20u, {}, Array(0LLU, {}, arrayliteral), nullptr, nullptr, {}, {}, {}, false, {}, {}, Array(0LLU, {}, arrayliteral), false, {}, {}, true, (CxxHeaderMode)0u, {}, {}, false, {}, (JsonFieldFlags)0u, nullptr, nullptr, 0, 0u, nullptr, 0u, nullptr, {}, {}, {}, {}, nullptr, false, {}, Array(0LLU, {}, arrayliteral), (MessageStyle)0u, false, Array(0LLU, {}, arrayliteral), Array(0LLU, {}, arrayliteral), Array(0LLU, {}, arrayliteral), Array(0LLU, {}, arrayliteral), Array(0LLU, {}, arrayliteral), Array(0LLU, {}, arrayliteral), {}, {}, {}, {}), uint32_t errors = 0u, uint32_t warnings = 0u, uint32_t gag = 0u, uint32_t gaggedErrors = 0u, uint32_t gaggedWarnings = 0u, void* console = nullptr, Array* versionids = nullptr, Array* debugids = nullptr, bool hasMainFunction = false, uint32_t varSequenceNumber = 1u) : inifilename(inifilename), copyright(copyright), written(written), diff --git a/src/dmd/globals.d b/src/dmd/globals.d index eccd1ee183df..7d3fd572b2c3 100644 --- a/src/dmd/globals.d +++ b/src/dmd/globals.d @@ -117,7 +117,8 @@ extern (C++) struct Param bool vtemplatesListInstances; // collect and list statistics on template instantiations origins. TODO: make this an enum when we want to list other kinds of instances bool vgc; // identify gc usage bool vfield; // identify non-mutable field variables - bool vcomplex = true; // identify complex/imaginary type usage + bool vcomplex = true; // deprecate complex and imaginary types + bool previewComplex; // remove complex and imaginary types bool vin; // identify 'in' parameters ubyte symdebug; // insert debug symbolic information bool symdebugref; // insert debug information for all referenced types, too diff --git a/src/dmd/globals.h b/src/dmd/globals.h index 49fa5b98e954..a55bcf037064 100644 --- a/src/dmd/globals.h +++ b/src/dmd/globals.h @@ -106,7 +106,8 @@ struct Param bool vtemplatesListInstances; // collect and list statistics on template instantiations origins bool vgc; // identify gc usage bool vfield; // identify non-mutable field variables - bool vcomplex; // identify complex/imaginary type usage + bool vcomplex; // deprecate complex and imaginary types + bool previewComplex; // remove complex and imaginary types bool vin; // identify 'in' parameters unsigned char symdebug; // insert debug symbolic information bool symdebugref; // insert debug information for all referenced types, too diff --git a/src/dmd/lexer.d b/src/dmd/lexer.d index 7c8b504f4197..520cb9fd40b0 100644 --- a/src/dmd/lexer.d +++ b/src/dmd/lexer.d @@ -478,6 +478,22 @@ class Lexer p++; } } + if (global.params.previewComplex) + { + switch (t.value) + { + case TOK.imaginary32: + case TOK.imaginary64: + case TOK.imaginary80: + case TOK.complex32: + case TOK.complex64: + case TOK.complex80: + t.value = TOK.identifier; + break; + default: + break; + } + } //printf("t.value = %d\n",t.value); return; } @@ -2519,7 +2535,7 @@ class Lexer result = TOK.float80Literal; break; } - if ((*p == 'i' || *p == 'I') && !Ccompile) + if ((*p == 'i' || *p == 'I') && !Ccompile && !global.params.previewComplex) { if (*p == 'I') error("use 'i' suffix instead of 'I'"); diff --git a/test/compilable/preview_complex.d b/test/compilable/preview_complex.d new file mode 100644 index 000000000000..b351051e15eb --- /dev/null +++ b/test/compilable/preview_complex.d @@ -0,0 +1,22 @@ +// REQUIRED_ARGS: -preview=complex + +struct cfloat +{ + float re; + ifloat im; +} +alias ifloat = float; + +struct cdouble +{ + double re; + idouble im; +} +alias idouble = double; + +struct creal +{ + real re; + ireal im; +} +alias ireal = real; diff --git a/test/compilable/previewhelp.d b/test/compilable/previewhelp.d index cccdf0b166d2..8977d99df820 100644 --- a/test/compilable/previewhelp.d +++ b/test/compilable/previewhelp.d @@ -16,5 +16,6 @@ Upcoming language changes listed by -preview=name: =in `in` on parameters means `scope const [ref]` and accepts rvalues =inclusiveincontracts 'in' contracts of overridden methods must be a superset of parent contract =shortenedMethods allow use of => for methods and top-level functions in addition to lambdas + =complex remove complex and imaginary types from the language ---- */ diff --git a/test/fail_compilation/preview_complex.d b/test/fail_compilation/preview_complex.d new file mode 100644 index 000000000000..0fe5ed3693d6 --- /dev/null +++ b/test/fail_compilation/preview_complex.d @@ -0,0 +1,23 @@ +/* +REQUIRED_ARGS: -preview=complex +TEST_OUTPUT: +--- +fail_compilation/preview_complex.d(3): Error: undefined identifier `ifloat` +fail_compilation/preview_complex.d(4): Error: undefined identifier `cfloat` +fail_compilation/preview_complex.d(5): Error: undefined identifier `idouble` +fail_compilation/preview_complex.d(6): Error: undefined identifier `cdouble` +fail_compilation/preview_complex.d(7): Error: undefined identifier `ireal` +fail_compilation/preview_complex.d(8): Error: undefined identifier `creal` +--- + */ + +#line 1 +void main() +{ + ifloat fi; + cfloat fc; + idouble di; + cdouble dc; + ireal ri; + creal rc; +} diff --git a/test/fail_compilation/preview_complex2.d b/test/fail_compilation/preview_complex2.d new file mode 100644 index 000000000000..f7a7d4cabc6e --- /dev/null +++ b/test/fail_compilation/preview_complex2.d @@ -0,0 +1,15 @@ +/* +REQUIRED_ARGS: -preview=complex +TEST_OUTPUT: +--- +fail_compilation/preview_complex2.d(3): Error: semicolon expected following auto declaration, not `i` +fail_compilation/preview_complex2.d(4): Error: semicolon expected following auto declaration, not `i` +--- + */ + +#line 1 +void main() +{ + auto cv = 1.0+0.0i; + auto iv = 1.0i; +}