Skip to content

Commit 7acdada

Browse files
committed
Merge remote-tracking branch 'origin/dmd-rewrite-stable' into merge-2.111
Conflicts: dmd/mars.d
2 parents 0037827 + 904e24c commit 7acdada

File tree

16 files changed

+174
-94
lines changed

16 files changed

+174
-94
lines changed

dmd/cli.d

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,8 @@ dmd -cov -unittest myprog.d
365365
Sets `__traits(getTargetInfo, \"cppStd\")` to `201703`)
366366
$(LI $(I c++20): Use C++20 name mangling,
367367
Sets `__traits(getTargetInfo, \"cppStd\")` to `202002`)
368+
$(LI $(I c++23): Use C++23 name mangling,
369+
Sets `__traits(getTargetInfo, \"cppStd\")` to `202302`)
368370
)",
369371
),
370372
Option("extern-std=[h|help|?]",
@@ -1134,6 +1136,7 @@ version (IN_LLVM) {} else
11341136
=c++14 Sets `__traits(getTargetInfo, \"cppStd\")` to `201402`
11351137
=c++17 Sets `__traits(getTargetInfo, \"cppStd\")` to `201703`
11361138
=c++20 Sets `__traits(getTargetInfo, \"cppStd\")` to `202002`
1139+
=c++23 Sets `__traits(getTargetInfo, \"cppStd\")` to `202302`
11371140
";
11381141

11391142
/// Options supported by -HC

dmd/dmodule.d

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,10 @@ import dmd.visitor;
5858

5959
version (Windows)
6060
{
61-
import core.sys.windows.winbase : getpid = GetCurrentProcessId;
6261
enum PathSeparator = '\\';
6362
}
6463
else version (Posix)
6564
{
66-
import core.sys.posix.unistd : getpid;
6765
enum PathSeparator = '/';
6866
}
6967
else
@@ -603,12 +601,6 @@ else
603601
else
604602
{
605603
const(char)[] argdoc;
606-
OutBuffer buf;
607-
if (arg == "__stdin.d")
608-
{
609-
buf.printf("__stdin_%d.d", getpid());
610-
arg = buf[];
611-
}
612604
if (global.params.preservePaths)
613605
argdoc = arg;
614606
else

dmd/file_manager.d

Lines changed: 5 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import dmd.root.stringtable : StringTable;
1616
import dmd.root.file : File, Buffer;
1717
import dmd.root.filename : FileName, isDirSeparator;
1818
import dmd.root.string : toDString;
19-
import dmd.errors;
2019
import dmd.globals;
2120
import dmd.identifier;
2221
import dmd.location;
@@ -184,9 +183,6 @@ nothrow:
184183
scope(exit) FileName.free(sdi.ptr);
185184

186185
const sd = FileName.forceExt(filename, mars_ext);
187-
// Special file name representing `stdin`, always assume its presence
188-
if (sd == "__stdin.d")
189-
return sd;
190186
if (checkLocal && FileName.exists(sd) == 1)
191187
return sd;
192188
scope(exit) FileName.free(sd.ptr);
@@ -312,20 +308,12 @@ nothrow:
312308
if (auto val = files.lookup(name)) // if `name` is cached
313309
return val.value; // return its contents
314310

315-
OutBuffer buf;
316-
if (name == "__stdin.d") // special name for reading from stdin
317-
{
318-
if (readFromStdin(buf))
319-
fatal();
320-
}
321-
else
322-
{
323-
if (FileName.exists(name) != 1) // if not an ordinary file
324-
return null;
311+
if (FileName.exists(name) != 1) // if not an ordinary file
312+
return null;
325313

326-
if (File.read(name, buf))
327-
return null; // failed
328-
}
314+
OutBuffer buf;
315+
if (File.read(name, buf))
316+
return null; // failed
329317

330318
buf.write32(0); // terminating dchar 0
331319

@@ -351,36 +339,3 @@ nothrow:
351339
return val == null ? null : val.value;
352340
}
353341
}
354-
355-
private bool readFromStdin(ref OutBuffer sink) nothrow
356-
{
357-
import core.stdc.stdio;
358-
import dmd.errors;
359-
360-
enum BufIncrement = 128 * 1024;
361-
362-
for (size_t j; 1; ++j)
363-
{
364-
char[] buffer = sink.allocate(BufIncrement);
365-
366-
// Fill up buffer
367-
size_t filled = 0;
368-
do
369-
{
370-
filled += fread(buffer.ptr + filled, 1, buffer.length - filled, stdin);
371-
if (ferror(stdin))
372-
{
373-
import core.stdc.errno;
374-
error(Loc.initial, "cannot read from stdin, errno = %d", errno);
375-
return true;
376-
}
377-
if (feof(stdin)) // successful completion
378-
{
379-
sink.setsize(j * BufIncrement + filled);
380-
return false;
381-
}
382-
} while (filled < BufIncrement);
383-
}
384-
385-
assert(0);
386-
}

dmd/frontend.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6234,6 +6234,7 @@ enum class CppStdRevision : uint32_t
62346234
cpp14 = 201402u,
62356235
cpp17 = 201703u,
62366236
cpp20 = 202002u,
6237+
cpp23 = 202302u,
62376238
};
62386239

62396240
enum class CHECKENABLE : uint8_t
@@ -8411,6 +8412,7 @@ struct ImportPathInfo final
84118412
struct Param final
84128413
{
84138414
bool obj;
8415+
bool readStdin;
84148416
bool multiobj;
84158417
bool trace;
84168418
bool tracegc;
@@ -8498,6 +8500,7 @@ struct Param final
84988500
bool parsingUnittestsRequired();
84998501
Param() :
85008502
obj(true),
8503+
readStdin(),
85018504
multiobj(),
85028505
trace(),
85038506
tracegc(),
@@ -8576,8 +8579,9 @@ struct Param final
85768579
timeTraceFile()
85778580
{
85788581
}
8579-
Param(bool obj, bool multiobj = false, bool trace = false, bool tracegc = false, bool vcg_ast = false, DiagnosticReporting useDeprecated = (DiagnosticReporting)1u, bool useUnitTests = false, bool useInline = false, bool release = false, bool preservePaths = false, DiagnosticReporting useWarnings = (DiagnosticReporting)2u, bool cov = false, uint8_t covPercent = 0u, bool ctfe_cov = false, bool ignoreUnsupportedPragmas = true, bool useModuleInfo = true, bool useTypeInfo = true, bool useExceptions = true, bool useGC = true, bool betterC = false, bool addMain = false, bool allInst = false, bool bitfields = false, CppStdRevision cplusplus = (CppStdRevision)201103u, Help help = Help(), Verbose v = Verbose(), FeatureState useDIP25 = (FeatureState)2u, FeatureState useDIP1000 = (FeatureState)0u, bool ehnogc = false, bool useDIP1021 = false, FeatureState fieldwise = (FeatureState)0u, bool fixAliasThis = false, FeatureState rvalueRefParam = (FeatureState)0u, FeatureState safer = (FeatureState)0u, FeatureState noSharedAccess = (FeatureState)0u, bool previewIn = false, bool inclusiveInContracts = false, bool shortenedMethods = true, bool fixImmutableConv = false, bool fix16997 = true, FeatureState dtorFields = (FeatureState)0u, FeatureState systemVariables = (FeatureState)0u, 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, CLIIdentifierTable dIdentifierTable = (CLIIdentifierTable)0u, CLIIdentifierTable cIdentifierTable = (CLIIdentifierTable)0u, _d_dynamicArray< const char > argv0 = {}, Array<const char* > modFileAliasStrings = Array<const char* >(), Array<ImportPathInfo > imppath = Array<ImportPathInfo >(), Array<const char* > fileImppath = Array<const char* >(), _d_dynamicArray< const char > objdir = {}, _d_dynamicArray< const char > objname = {}, _d_dynamicArray< const char > libname = {}, Output ddoc = Output(), Output dihdr = Output(), Output cxxhdr = Output(), Output json = Output(), JsonFieldFlags jsonFieldFlags = (JsonFieldFlags)0u, Output makeDeps = Output(), Output mixinOut = Output(), Output moduleDeps = Output(), bool debugEnabled = false, bool run = false, Array<const char* > runargs = Array<const char* >(), Array<const char* > cppswitches = Array<const char* >(), const char* cpp = nullptr, Array<const char* > objfiles = Array<const char* >(), Array<const char* > linkswitches = Array<const char* >(), Array<bool > linkswitchIsForCC = Array<bool >(), Array<const char* > libfiles = Array<const char* >(), Array<const char* > dllfiles = Array<const char* >(), _d_dynamicArray< const char > deffile = {}, _d_dynamicArray< const char > resfile = {}, _d_dynamicArray< const char > exefile = {}, _d_dynamicArray< const char > mapfile = {}, bool fullyQualifiedObjectFiles = false, bool timeTrace = false, uint32_t timeTraceGranularityUs = 500u, const char* timeTraceFile = nullptr) :
8582+
Param(bool obj, bool readStdin = false, bool multiobj = false, bool trace = false, bool tracegc = false, bool vcg_ast = false, DiagnosticReporting useDeprecated = (DiagnosticReporting)1u, bool useUnitTests = false, bool useInline = false, bool release = false, bool preservePaths = false, DiagnosticReporting useWarnings = (DiagnosticReporting)2u, bool cov = false, uint8_t covPercent = 0u, bool ctfe_cov = false, bool ignoreUnsupportedPragmas = true, bool useModuleInfo = true, bool useTypeInfo = true, bool useExceptions = true, bool useGC = true, bool betterC = false, bool addMain = false, bool allInst = false, bool bitfields = false, CppStdRevision cplusplus = (CppStdRevision)201103u, Help help = Help(), Verbose v = Verbose(), FeatureState useDIP25 = (FeatureState)2u, FeatureState useDIP1000 = (FeatureState)0u, bool ehnogc = false, bool useDIP1021 = false, FeatureState fieldwise = (FeatureState)0u, bool fixAliasThis = false, FeatureState rvalueRefParam = (FeatureState)0u, FeatureState safer = (FeatureState)0u, FeatureState noSharedAccess = (FeatureState)0u, bool previewIn = false, bool inclusiveInContracts = false, bool shortenedMethods = true, bool fixImmutableConv = false, bool fix16997 = true, FeatureState dtorFields = (FeatureState)0u, FeatureState systemVariables = (FeatureState)0u, 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, CLIIdentifierTable dIdentifierTable = (CLIIdentifierTable)0u, CLIIdentifierTable cIdentifierTable = (CLIIdentifierTable)0u, _d_dynamicArray< const char > argv0 = {}, Array<const char* > modFileAliasStrings = Array<const char* >(), Array<ImportPathInfo > imppath = Array<ImportPathInfo >(), Array<const char* > fileImppath = Array<const char* >(), _d_dynamicArray< const char > objdir = {}, _d_dynamicArray< const char > objname = {}, _d_dynamicArray< const char > libname = {}, Output ddoc = Output(), Output dihdr = Output(), Output cxxhdr = Output(), Output json = Output(), JsonFieldFlags jsonFieldFlags = (JsonFieldFlags)0u, Output makeDeps = Output(), Output mixinOut = Output(), Output moduleDeps = Output(), bool debugEnabled = false, bool run = false, Array<const char* > runargs = Array<const char* >(), Array<const char* > cppswitches = Array<const char* >(), const char* cpp = nullptr, Array<const char* > objfiles = Array<const char* >(), Array<const char* > linkswitches = Array<const char* >(), Array<bool > linkswitchIsForCC = Array<bool >(), Array<const char* > libfiles = Array<const char* >(), Array<const char* > dllfiles = Array<const char* >(), _d_dynamicArray< const char > deffile = {}, _d_dynamicArray< const char > resfile = {}, _d_dynamicArray< const char > exefile = {}, _d_dynamicArray< const char > mapfile = {}, bool fullyQualifiedObjectFiles = false, bool timeTrace = false, uint32_t timeTraceGranularityUs = 500u, const char* timeTraceFile = nullptr) :
85808583
obj(obj),
8584+
readStdin(readStdin),
85818585
multiobj(multiobj),
85828586
trace(trace),
85838587
tracegc(tracegc),

dmd/globals.d

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ enum CppStdRevision : uint
7979
cpp14 = 2014_02,
8080
cpp17 = 2017_03,
8181
cpp20 = 2020_02,
82+
cpp23 = 2023_02,
8283
}
8384

8485
/// Trivalent boolean to represent the state of a `revert`able change
@@ -193,6 +194,7 @@ extern (C++) struct ImportPathInfo {
193194
extern (C++) struct Param
194195
{
195196
bool obj = true; // write object file
197+
bool readStdin; // saw "-" on command line, read source file from stdin
196198
bool multiobj; // break one object file into multiple ones
197199
bool trace; // insert profiling hooks
198200
bool tracegc; // instrument calls to 'new'

dmd/globals.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ enum CppStdRevision
8888
CppStdRevisionCpp11 = 201103,
8989
CppStdRevisionCpp14 = 201402,
9090
CppStdRevisionCpp17 = 201703,
91-
CppStdRevisionCpp20 = 202002
91+
CppStdRevisionCpp20 = 202002,
92+
CppStdRevisionCpp23 = 202302,
9293
};
9394

9495
/// Trivalent boolean to represent the state of a `revert`able change
@@ -198,6 +199,7 @@ struct ImportPathInfo
198199
struct Param
199200
{
200201
d_bool obj; // write object file
202+
d_bool readStdin; // read source file from stdin
201203
d_bool multiobj; // break one object file into multiple ones
202204
d_bool trace; // insert profiling hooks
203205
d_bool tracegc; // instrument calls to 'new'

dmd/main.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ version (IN_LLVM) {} else
400400
{
401401
fatal();
402402
}
403-
if (files.length == 0)
403+
if (files.length == 0 && !params.readStdin)
404404
{
405405
if (params.jsonFieldFlags)
406406
{

dmd/mars.d

Lines changed: 97 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,13 @@ import dmd.semantic3;
5959
import dmd.target;
6060
import dmd.utils;
6161

62+
version (Windows)
63+
import core.sys.windows.winbase : getpid = GetCurrentProcessId;
64+
else version (Posix)
65+
import core.sys.posix.unistd : getpid;
66+
else
67+
static assert(0);
68+
6269
version (IN_LLVM)
6370
{
6471
// DMD defines a `driverParams` global (of type DMDParams);
@@ -1255,6 +1262,9 @@ bool parseCommandLine(const ref Strings arguments, const size_t argc, ref Param
12551262
case "c++20":
12561263
params.cplusplus = CppStdRevision.cpp20;
12571264
break;
1265+
case "c++23":
1266+
params.cplusplus = CppStdRevision.cpp23;
1267+
break;
12581268
default:
12591269
error("switch `%s` is invalid", p);
12601270
params.help.externStd = true;
@@ -1843,7 +1853,7 @@ bool parseCommandLine(const ref Strings arguments, const size_t argc, ref Param
18431853
break;
18441854
}
18451855
if (runarg == "-")
1846-
files.push("__stdin.d");
1856+
params.readStdin = true;
18471857
else
18481858
files.push(arguments[i + 1]);
18491859
params.runargs.setDim(length - 1);
@@ -1860,7 +1870,7 @@ bool parseCommandLine(const ref Strings arguments, const size_t argc, ref Param
18601870
}
18611871
}
18621872
else if (p[1] == '\0')
1863-
files.push("__stdin.d");
1873+
params.readStdin = true;
18641874
else
18651875
{
18661876
Lerror:
@@ -2076,22 +2086,66 @@ else
20762086
{
20772087
if (firstmodule)
20782088
{
2079-
global.params.objfiles.push(m.objfile.toChars());
2089+
params.objfiles.push(m.objfile.toChars());
20802090
firstmodule = false;
20812091
}
20822092
}
20832093
}
2094+
20842095
version (IN_LLVM)
20852096
{
2086-
// When compiling to a single object file, move that object file to the
2087-
// beginning of the object files list.
2088-
if (driverParams.oneobj && modules.length > 0 && firstModuleObjectFileIndex != 0)
2097+
scope(exit)
20892098
{
2090-
auto fn = global.params.objfiles[firstModuleObjectFileIndex];
2091-
global.params.objfiles.remove(firstModuleObjectFileIndex);
2092-
global.params.objfiles.insert(0, fn);
2099+
// When compiling to a single object file, move that object file to the
2100+
// beginning of the object files list.
2101+
if (driverParams.oneobj && modules.length > 0 && firstModuleObjectFileIndex != 0)
2102+
{
2103+
auto fn = global.params.objfiles[firstModuleObjectFileIndex];
2104+
global.params.objfiles.remove(firstModuleObjectFileIndex);
2105+
global.params.objfiles.insert(0, fn);
2106+
}
20932107
}
20942108
}
2109+
2110+
// Special module representing `stdin`
2111+
if (params.readStdin)
2112+
{
2113+
Module m;
2114+
if (createModule("__stdin.d", libmodules, params, target, eSink, m))
2115+
return true;
2116+
if (m is null)
2117+
return false;
2118+
2119+
modules.push(m);
2120+
2121+
// Set the source file contents of the module
2122+
OutBuffer buf;
2123+
buf.readFromStdin();
2124+
m.src = cast(ubyte[])buf.extractSlice();
2125+
2126+
// Give unique outfile name
2127+
OutBuffer namebuf;
2128+
namebuf.printf("__stdin_%d", getpid());
2129+
2130+
auto filename = FileName.forceExt(namebuf.extractSlice(), target.obj_ext);
2131+
m.objfile = FileName(filename);
2132+
2133+
version (IN_LLVM)
2134+
{
2135+
if (!driverParams.oneobj || firstModuleObjectFileIndex == size_t.max)
2136+
{
2137+
global.params.objfiles.push(cast(const(char)*)m); // defer to a later stage after parsing
2138+
if (firstModuleObjectFileIndex == size_t.max)
2139+
firstModuleObjectFileIndex = global.params.objfiles.length - 1;
2140+
}
2141+
}
2142+
else
2143+
{
2144+
if (firstmodule)
2145+
params.objfiles.push(m.objfile.toChars());
2146+
}
2147+
}
2148+
20952149
return false;
20962150
}
20972151

@@ -2110,3 +2164,37 @@ Module moduleWithEmptyMain()
21102164
result.semantic3(null);
21112165
return result;
21122166
}
2167+
2168+
private void readFromStdin(ref OutBuffer sink) nothrow
2169+
{
2170+
import core.stdc.stdio;
2171+
import dmd.errors;
2172+
2173+
enum BufIncrement = 128 * 1024;
2174+
2175+
for (size_t j; 1; ++j)
2176+
{
2177+
char[] buffer = sink.allocate(BufIncrement + 16);
2178+
2179+
// Fill up buffer
2180+
size_t filled = 0;
2181+
do
2182+
{
2183+
filled += fread(buffer.ptr + filled, 1, buffer.length - filled, stdin);
2184+
if (ferror(stdin))
2185+
{
2186+
import core.stdc.errno;
2187+
error(Loc.initial, "cannot read from stdin, errno = %d", errno);
2188+
fatal();
2189+
}
2190+
if (feof(stdin)) // successful completion
2191+
{
2192+
memset(buffer.ptr + filled, '\0', 16);
2193+
sink.setsize(j * BufIncrement + filled);
2194+
return;
2195+
}
2196+
} while (filled < BufIncrement);
2197+
}
2198+
2199+
assert(0);
2200+
}

dmd/typesem.d

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3444,8 +3444,16 @@ Expression getProperty(Type t, Scope* scope_, Loc loc, Identifier ident, int fla
34443444
auto s2 = scope_.search_correct(ident);
34453445
// UFCS
34463446
if (s2 && s2.isFuncDeclaration)
3447-
errorSupplemental(loc, "did you mean %s `%s`?",
3448-
s2.kind(), s2.toChars());
3447+
{
3448+
if (s2.ident == ident)
3449+
{
3450+
errorSupplemental(s2.loc, "cannot call %s `%s` with UFCS because it is not declared at module scope",
3451+
s2.kind(), s2.toChars());
3452+
}
3453+
else
3454+
errorSupplemental(s2.loc, "did you mean %s `%s`?",
3455+
s2.kind(), s2.toChars());
3456+
}
34493457
else if (src.type.ty == Tpointer)
34503458
{
34513459
// structPtr.field
@@ -3454,7 +3462,7 @@ Expression getProperty(Type t, Scope* scope_, Loc loc, Identifier ident, int fla
34543462
{
34553463
if (auto s3 = as.search_correct(ident))
34563464
{
3457-
errorSupplemental(loc, "did you mean %s `%s`?",
3465+
errorSupplemental(s3.loc, "did you mean %s `%s`?",
34583466
s3.kind(), s3.toChars());
34593467
}
34603468
}

driver/cl_options.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,9 @@ static cl::opt<CppStdRevision, true> cplusplus(
202202
clEnumValN(CppStdRevisionCpp17, "c++17",
203203
"Sets `__traits(getTargetInfo, \"cppStd\")` to `201703`"),
204204
clEnumValN(CppStdRevisionCpp20, "c++20",
205-
"Sets `__traits(getTargetInfo, \"cppStd\")` to `202002`")));
205+
"Sets `__traits(getTargetInfo, \"cppStd\")` to `202002`"),
206+
clEnumValN(CppStdRevisionCpp23, "c++23",
207+
"Sets `__traits(getTargetInfo, \"cppStd\")` to `202302`")));
206208

207209
static cl::opt<unsigned char, true> debugInfo(
208210
cl::desc("Generating debug information:"), cl::ZeroOrMore,

0 commit comments

Comments
 (0)