Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge upstream v2.106.0 #4539

Merged
merged 14 commits into from
Dec 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# LDC master

#### Big news
- Frontend, druntime and Phobos are at version [2.106.0](https://dlang.org/changelog/2.106.0.html). (#4522)
- Frontend, druntime and Phobos are at version [2.106.0](https://dlang.org/changelog/2.106.0.html). (#4522, #4539)
- New command-line options `-fno-{exceptions,moduleinfo,rtti}` to selectively enable some `-betterC` effects. (#4522)
- New command-line option `-fprofile-sample-use` for using sample-based profile data for optimization. Functionality and usage is identical to Clang's option with same name. (#4531)
- New `ldc-profgen` tool for sample-based PGO, a copy of LLVM's [llvm-profgen](https://llvm.org/docs/CommandGuide/llvm-profgen.html). (#4536)
Expand Down
7 changes: 7 additions & 0 deletions dmd/dcast.d
Original file line number Diff line number Diff line change
Expand Up @@ -1630,6 +1630,13 @@ Expression castTo(Expression e, Scope* sc, Type t, Type att = null)
}
else if (tob.ty == Tvector && t1b.ty != Tvector)
{
if (t1b.ty == Tsarray)
{
// Casting static array to vector with same size, e.g. `cast(int4) int[4]`
if (t1b.size(e.loc) != tob.size(e.loc))
goto Lfail;
return new VectorExp(e.loc, e, tob).expressionSemantic(sc);
}
//printf("test1 e = %s, e.type = %s, tob = %s\n", e.toChars(), e.type.toChars(), tob.toChars());
TypeVector tv = tob.isTypeVector();
Expression result = new CastExp(e.loc, e, tv.elementType());
Expand Down
2 changes: 1 addition & 1 deletion dmd/dsymbolsem.d
Original file line number Diff line number Diff line change
Expand Up @@ -5981,7 +5981,7 @@ private bool isDRuntimeHook(Identifier id)
id == Id._d_arraysetlengthTImpl || id == Id._d_arraysetlengthT ||
id == Id._d_arraysetlengthTTrace ||
id == Id._d_arrayappendT || id == Id._d_arrayappendTTrace ||
id == Id._d_arrayappendcTXImpl;
id == Id._d_arrayappendcTX;
}

void templateInstanceSemantic(TemplateInstance tempinst, Scope* sc, ArgumentList argumentList)
Expand Down
7 changes: 6 additions & 1 deletion dmd/dtemplate.d
Original file line number Diff line number Diff line change
Expand Up @@ -7549,7 +7549,12 @@ version (IN_LLVM)
}
//printf("\t-. mi = %s\n", mi.toPrettyChars());

assert(!memberOf || (!memberOf.isRoot() && mi.isRoot()), "can only re-append from non-root to root module");
if (memberOf) // already appended to some module
{
assert(mi.isRoot(), "can only re-append to a root module");
if (memberOf.isRoot())
return null; // no need to move to another root module
}

Dsymbols* a = mi.members;
a.push(this);
Expand Down
4 changes: 3 additions & 1 deletion dmd/expression.d
Original file line number Diff line number Diff line change
Expand Up @@ -5666,7 +5666,9 @@ extern (C++) final class UshrAssignExp : BinAssignExp
*/
extern (C++) class CatAssignExp : BinAssignExp
{
extern (D) this(const ref Loc loc, Expression e1, Expression e2) @safe
Expression lowering; // lowered druntime hook `_d_arrayappend{cTX,T}`

extern (D) this(const ref Loc loc, Expression e1, Expression e2)
{
super(loc, EXP.concatenateAssign, e1, e2);
}
Expand Down
2 changes: 2 additions & 0 deletions dmd/expression.h
Original file line number Diff line number Diff line change
Expand Up @@ -1204,6 +1204,8 @@ class UshrAssignExp final : public BinAssignExp
class CatAssignExp : public BinAssignExp
{
public:
Expression *lowering; // lowered druntime hook `_d_arrayappend{cTX,T}`

void accept(Visitor *v) override { v->visit(this); }
};

Expand Down
30 changes: 9 additions & 21 deletions dmd/expressionsem.d
Original file line number Diff line number Diff line change
Expand Up @@ -8505,14 +8505,6 @@ version (IN_LLVM)
return setError();
}

// Look for casting to a vector type
if (tob.ty == Tvector && t1b.ty != Tvector)
{
result = new VectorExp(exp.loc, exp.e1, exp.to);
result = result.expressionSemantic(sc);
return;
}

Expression ex = exp.e1.castTo(sc, exp.to);
if (ex.op == EXP.error)
{
Expand Down Expand Up @@ -11215,8 +11207,7 @@ version (IN_LLVM)

result = res;

if ((exp.op == EXP.concatenateAssign || exp.op == EXP.concatenateElemAssign) &&
sc.needsCodegen())
if ((exp.op == EXP.concatenateAssign || exp.op == EXP.concatenateElemAssign) && sc.needsCodegen())
{
// if aa ordering is triggered, `res` will be a CommaExp
// and `.e2` will be the rewritten original expression.
Expand Down Expand Up @@ -11260,7 +11251,9 @@ version (IN_LLVM)
arguments.push(exp.e1);
arguments.push(exp.e2);
Expression ce = new CallExp(exp.loc, id, arguments);
*output = ce.expressionSemantic(sc);

exp.lowering = ce.expressionSemantic(sc);
*output = exp;
}
else if (exp.op == EXP.concatenateElemAssign)
{
Expand All @@ -11280,15 +11273,12 @@ version (IN_LLVM)
}

Identifier hook = global.params.tracegc ? Id._d_arrayappendcTXTrace : Id._d_arrayappendcTX;
if (!verifyHookExist(exp.loc, *sc, Id._d_arrayappendcTXImpl, "appending element to arrays", Id.object))
if (!verifyHookExist(exp.loc, *sc, hook, "appending element to arrays", Id.object))
return setError();

// Lower to object._d_arrayappendcTXImpl!(typeof(e1))._d_arrayappendcTX{,Trace}(e1, 1), e1[$-1]=e2
// Lower to object._d_arrayappendcTX{,Trace}(e1, 1), e1[$-1]=e2
Expression id = new IdentifierExp(exp.loc, Id.empty);
id = new DotIdExp(exp.loc, id, Id.object);
auto tiargs = new Objects();
tiargs.push(exp.e1.type);
id = new DotTemplateInstanceExp(exp.loc, id, Id._d_arrayappendcTXImpl, tiargs);
id = new DotIdExp(exp.loc, id, hook);

auto arguments = new Expressions();
Expand All @@ -11315,11 +11305,10 @@ version (IN_LLVM)
{
/* Before the template hook, this check was performed in e2ir.d
* for expressions like `a ~= a[$-1]`. Here, $ will be modified
* by calling `_d_arrayappendcT`, so we need to save `a[$-1]` in
* by calling `_d_arrayappendcTX`, so we need to save `a[$-1]` in
* a temporary variable.
*/
value2 = extractSideEffect(sc, "__appendtmp", eValue2, value2, true);
exp.e2 = value2;

// `__appendtmp*` will be destroyed together with the array `exp.e1`.
auto vd = eValue2.isDeclarationExp().declaration.isVarDeclaration();
Expand All @@ -11335,13 +11324,12 @@ version (IN_LLVM)
auto e0 = Expression.combine(ce, ae).expressionSemantic(sc);
e0 = Expression.combine(e0, value1);
e0 = Expression.combine(eValue1, e0);

e0 = Expression.combine(eValue2, e0);

*output = e0.expressionSemantic(sc);
exp.lowering = e0.expressionSemantic(sc);
*output = exp;
}
}

}

override void visit(AddExp exp)
Expand Down
3 changes: 2 additions & 1 deletion dmd/frontend.h
Original file line number Diff line number Diff line change
Expand Up @@ -6539,6 +6539,7 @@ struct Scope final
void* anchorCounts;
Identifier* prevAnchor;
AliasDeclaration* aliasAsg;
Dsymbol* search(const Loc& loc, Identifier* ident, Dsymbol** pscopesym, int32_t flags = 0);
Scope() :
enclosing(),
_module(),
Expand Down Expand Up @@ -7830,6 +7831,7 @@ class UshrAssignExp final : public BinAssignExp
class CatAssignExp : public BinAssignExp
{
public:
Expression* lowering;
void accept(Visitor* v) override;
};

Expand Down Expand Up @@ -8713,7 +8715,6 @@ struct Id final
static Identifier* _d_arraysetlengthTTrace;
static Identifier* _d_arrayappendT;
static Identifier* _d_arrayappendTTrace;
static Identifier* _d_arrayappendcTXImpl;
static Identifier* _d_arrayappendcTX;
static Identifier* _d_arrayappendcTXTrace;
static Identifier* _d_arraycatnTX;
Expand Down
1 change: 0 additions & 1 deletion dmd/id.d
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,6 @@ immutable Msgtable[] msgtable =
{ "_d_arraysetlengthTTrace"},
{ "_d_arrayappendT" },
{ "_d_arrayappendTTrace" },
{ "_d_arrayappendcTXImpl" },
{ "_d_arrayappendcTX" },
{ "_d_arrayappendcTXTrace" },
{ "_d_arraycatnTX" },
Expand Down
23 changes: 23 additions & 0 deletions dmd/inline.d
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,21 @@ version (IN_LLVM) {} else
result = ce;
}

override void visit(CatAssignExp e)
{
auto cae = cast(CatAssignExp) e.copy();

if (auto lowering = cae.lowering)
cae.lowering = doInlineAs!Expression(cae.lowering, ids);
else
{
cae.e1 = doInlineAs!Expression(e.e1, ids);
cae.e2 = doInlineAs!Expression(e.e2, ids);
}

result = cae;
}

override void visit(BinExp e)
{
auto be = cast(BinExp)e.copy();
Expand Down Expand Up @@ -1288,6 +1303,14 @@ public:
inlineScan(e.e2);
}

override void visit(CatAssignExp e)
{
if (auto lowering = e.lowering)
inlineScan(lowering);
else
visit(cast(BinExp) e);
}

override void visit(BinExp e)
{
inlineScan(e.e1);
Expand Down
16 changes: 2 additions & 14 deletions dmd/nogc.d
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,6 @@ public:
return;
f.printGCUsage(e.loc, "setting `length` may cause a GC allocation");
}
else if (fd.ident == Id._d_arrayappendT || fd.ident == Id._d_arrayappendcTX)
{
if (setGC(e, "cannot use operator `~=` in `@nogc` %s `%s`"))
return;
f.printGCUsage(e.loc, "operator `~=` may cause a GC allocation");
}
}

override void visit(ArrayLiteralExp e)
Expand Down Expand Up @@ -187,20 +181,14 @@ public:

override void visit(CatAssignExp e)
{
/* CatAssignExp will exist in `__traits(compiles, ...)` and in the `.e1` branch of a `__ctfe ? :` CondExp.
* The other branch will be `_d_arrayappendcTX(e1, 1), e1[$-1]=e2` which will generate the warning about
* GC usage. See visit(CallExp).
*/
if (checkOnly)
{
err = true;
return;
}
if (f.setGC(e.loc, null))
{
err = true;
if (setGC(e, "cannot use operator `~=` in `@nogc` %s `%s`"))
return;
}
f.printGCUsage(e.loc, "operator `~=` may cause a GC allocation");
}

override void visit(CatExp e)
Expand Down
12 changes: 10 additions & 2 deletions dmd/optimize.d
Original file line number Diff line number Diff line change
Expand Up @@ -928,6 +928,14 @@ Expression Expression_optimize(Expression e, int result, bool keepLvalue)
}
}

void visitCatAssign(CatAssignExp e)
{
if (auto lowering = e.lowering)
Expression_optimize(lowering, result, keepLvalue);
else
visitBinAssign(e);
}

void visitBin(BinExp e)
{
//printf("BinExp::optimize(result = %d) %s\n", result, e.toChars());
Expand Down Expand Up @@ -1392,9 +1400,9 @@ Expression Expression_optimize(Expression e, int result, bool keepLvalue)
case EXP.leftShiftAssign:
case EXP.rightShiftAssign:
case EXP.unsignedRightShiftAssign:
case EXP.concatenateDcharAssign: visitBinAssign(ex.isBinAssignExp()); break;
case EXP.concatenateElemAssign:
case EXP.concatenateDcharAssign:
case EXP.concatenateAssign: visitBinAssign(ex.isBinAssignExp()); break;
case EXP.concatenateAssign: visitCatAssign(cast(CatAssignExp) ex); break;

case EXP.minusMinus:
case EXP.plusPlus:
Expand Down
18 changes: 17 additions & 1 deletion gen/toir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2161,7 +2161,6 @@ class ToElemVisitor : public Visitor {
e->type->toChars());
LOG_SCOPE;

// TODO: still required?
if (!global.params.useGC) {
error(
e->loc,
Expand All @@ -2188,6 +2187,22 @@ class ToElemVisitor : public Visitor {
e->type->toChars());
LOG_SCOPE;

if (!global.params.useGC) {
error(e->loc,
"appending to array in `%s` requires the GC which is not available "
"with -betterC",
e->toChars());
result =
new DSliceValue(e->type, llvm::UndefValue::get(DtoType(e->type)));
return;
}

if (e->lowering) {
assert(e->op != EXP::concatenateDcharAssign);
result = toElem(e->lowering);
return;
}

result = toElem(e->e1);

Type *e1type = e->e1->type->toBasetype();
Expand All @@ -2197,6 +2212,7 @@ class ToElemVisitor : public Visitor {

if (e1type->ty == TY::Tarray && e2type->ty == TY::Tdchar &&
(elemtype->ty == TY::Tchar || elemtype->ty == TY::Twchar)) {
assert(e->op == EXP::concatenateDcharAssign);
if (elemtype->ty == TY::Tchar) {
// append dchar to char[]
DtoAppendDCharToString(e->loc, result, e->e2);
Expand Down
2 changes: 1 addition & 1 deletion packaging/dlang-tools_version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v2.105.3
v2.106.0
2 changes: 1 addition & 1 deletion packaging/dub_version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v1.34.0
v1.35.0
30 changes: 17 additions & 13 deletions runtime/druntime/src/core/cpuid.d
Original file line number Diff line number Diff line change
Expand Up @@ -628,16 +628,17 @@ void getAMDcacheinfo()

if (max_extended_cpuid >= 0x8000_0006) {
// AMD K6-III or K6-2+ or later.
ubyte numcores = 1;
uint numcores = 1;
if (max_extended_cpuid >= 0x8000_0008) {
// read the number of physical cores (minus 1) from the 8 lowest ECX bits
version (GNU_OR_LDC) asm pure nothrow @nogc {
"cpuid" : "=a" (dummy), "=c" (numcores) : "a" (0x8000_0008) : "ebx", "edx";
} else asm pure nothrow @nogc {
mov EAX, 0x8000_0008;
cpuid;
mov numcores, CL;
mov numcores, ECX;
}
++numcores;
numcores = (numcores & 0xFF) + 1;
if (numcores>cpuFeatures.maxCores) cpuFeatures.maxCores = numcores;
}

Expand Down Expand Up @@ -666,10 +667,12 @@ void getAMDcacheinfo()
// to determine number of processors.
void getCpuInfo0B()
{
int level=0;
int threadsPerCore;
uint a, b, c, d;
do {
// I'm not sure about this. The docs state that there
// are 2 hyperthreads per core if HT is factory enabled.
for (int level = 0; level < 2; level++)
{
version (GNU_OR_LDC) asm pure nothrow @nogc {
"cpuid" : "=a" (a), "=b" (b), "=c" (c), "=d" (d) : "a" (0x0B), "c" (level);
} else asm pure nothrow @nogc {
Expand All @@ -681,19 +684,20 @@ void getCpuInfo0B()
mov c, ECX;
mov d, EDX;
}
if (b!=0) {
// I'm not sure about this. The docs state that there
// are 2 hyperthreads per core if HT is factory enabled.
if (level==0)
if (b != 0)
{
if (level == 0)
threadsPerCore = b & 0xFFFF;
else if (level==1) {
else if (level == 1)
{
cpuFeatures.maxThreads = b & 0xFFFF;
cpuFeatures.maxCores = cpuFeatures.maxThreads / threadsPerCore;
}

}
++level;
} while (a!=0 || b!=0);
// Got "invalid domain" returned from cpuid
if (a == 0 && b == 0)
break;
}
}

void cpuidX86()
Expand Down
Loading