diff options
author | Iain Buclaw <ibuclaw@gdcproject.org> | 2022-12-09 18:59:38 +0100 |
---|---|---|
committer | Iain Buclaw <ibuclaw@gdcproject.org> | 2022-12-11 17:17:58 +0100 |
commit | 6d799f0aed18be25a5c908499b6411ab6d06b78c (patch) | |
tree | 3e6a91048c7fe3e78bae9f75b24eb37c5504681b /gcc/d/dmd/expression.d | |
parent | cc7f509d3c0b3ab63891cf7ca2def0fdfb3642c4 (diff) | |
download | gcc-6d799f0aed18be25a5c908499b6411ab6d06b78c.zip gcc-6d799f0aed18be25a5c908499b6411ab6d06b78c.tar.gz gcc-6d799f0aed18be25a5c908499b6411ab6d06b78c.tar.bz2 |
d: Merge upstream dmd, druntime c8ae4adb2e, phobos 792c8b7c1.
D front-end changes:
- Import dmd v2.101.0.
- Deprecate the ability to call `__traits(getAttributes)' on
overload sets.
- Deprecate non-empty `for' statement increment clause with no
effect.
- Array literals assigned to `scope' array variables can now be
allocated on the stack.
D runtime changes:
- Import druntime v2.101.0.
Phobos changes:
- Import phobos v2.101.0.
gcc/d/ChangeLog:
* dmd/MERGE: Merge upstream dmd c8ae4adb2e.
* typeinfo.cc (check_typeinfo_type): Update for new front-end
interface.
(TypeInfoVisitor::visit (TypeInfoStructDeclaration *)): Remove warning
that toHash() must be declared 'nothrow @safe`.
libphobos/ChangeLog:
* libdruntime/MERGE: Merge upstream druntime c8ae4adb2e.
* src/MERGE: Merge upstream phobos 792c8b7c1.
Diffstat (limited to 'gcc/d/dmd/expression.d')
-rw-r--r-- | gcc/d/dmd/expression.d | 78 |
1 files changed, 48 insertions, 30 deletions
diff --git a/gcc/d/dmd/expression.d b/gcc/d/dmd/expression.d index 21f5cc7..4f14d66 100644 --- a/gcc/d/dmd/expression.d +++ b/gcc/d/dmd/expression.d @@ -260,7 +260,7 @@ extern (C++) void expandTuples(Expressions* exps) if (exps is null) return; - for (size_t i = 0; i < exps.dim; i++) + for (size_t i = 0; i < exps.length; i++) { Expression arg = (*exps)[i]; if (!arg) @@ -271,10 +271,10 @@ extern (C++) void expandTuples(Expressions* exps) { if (auto tt = e.type.toBasetype().isTypeTuple()) { - if (!tt.arguments || tt.arguments.dim == 0) + if (!tt.arguments || tt.arguments.length == 0) { exps.remove(i); - if (i == exps.dim) + if (i == exps.length) return; } else // Expand a TypeTuple @@ -296,7 +296,7 @@ extern (C++) void expandTuples(Expressions* exps) TupleExp te = cast(TupleExp)arg; exps.remove(i); // remove arg exps.insert(i, te.exps); // replace with tuple contents - if (i == exps.dim) + if (i == exps.length) return; // empty tuple, no more arguments (*exps)[i] = Expression.combine(te.e0, (*exps)[i]); arg = (*exps)[i]; @@ -339,10 +339,10 @@ TupleDeclaration isAliasThisTuple(Expression e) int expandAliasThisTuples(Expressions* exps, size_t starti = 0) { - if (!exps || exps.dim == 0) + if (!exps || exps.length == 0) return -1; - for (size_t u = starti; u < exps.dim; u++) + for (size_t u = starti; u < exps.length; u++) { Expression exp = (*exps)[u]; if (TupleDeclaration td = exp.isAliasThisTuple) @@ -924,7 +924,7 @@ extern (C++) abstract class Expression : ASTNode Expressions* a = null; if (exps) { - a = new Expressions(exps.dim); + a = new Expressions(exps.length); foreach (i, e; *exps) { (*a)[i] = e ? e.syntaxCopy() : null; @@ -1214,7 +1214,7 @@ extern (C++) abstract class Expression : ASTNode auto ad = cast(AggregateDeclaration) f.toParent2(); assert(ad); - if (ad.userDtors.dim) + if (ad.userDtors.length) { if (!check(ad.userDtors[0])) // doesn't match check (e.g. is impure as well) return; @@ -1401,14 +1401,32 @@ extern (C++) abstract class Expression : ASTNode */ extern (D) final bool checkSafety(Scope* sc, FuncDeclaration f) { - if (!sc.func) - return false; if (sc.func == f) return false; if (sc.intypeof == 1) return false; - if (sc.flags & (SCOPE.ctfe | SCOPE.debug_)) + if (sc.flags & SCOPE.debug_) return false; + if ((sc.flags & SCOPE.ctfe) && sc.func) + return false; + + if (!sc.func) + { + if (sc.varDecl && !f.safetyInprocess && !f.isSafe() && !f.isTrusted()) + { + if (sc.varDecl.storage_class & STC.safe) + { + error("`@safe` variable `%s` cannot be initialized by calling `@system` function `%s`", + sc.varDecl.toChars(), f.toChars()); + return true; + } + else + { + sc.varDecl.storage_class |= STC.system; + } + } + return false; + } if (!f.isSafe() && !f.isTrusted()) { @@ -2867,7 +2885,7 @@ extern (C++) final class TupleExp : Expression super(loc, EXP.tuple, __traits(classInstanceSize, TupleExp)); this.exps = new Expressions(); - this.exps.reserve(tup.objects.dim); + this.exps.reserve(tup.objects.length); foreach (o; *tup.objects) { if (Dsymbol s = getDsymbol(o)) @@ -2913,7 +2931,7 @@ extern (C++) final class TupleExp : Expression if (auto e = o.isExpression()) if (auto te = e.isTupleExp()) { - if (exps.dim != te.exps.dim) + if (exps.length != te.exps.length) return false; if (e0 && !e0.equals(te.e0) || !e0 && te.e0) return false; @@ -3002,9 +3020,9 @@ extern (C++) final class ArrayLiteralExp : Expression return false; if (auto ae = e.isArrayLiteralExp()) { - if (elements.dim != ae.elements.dim) + if (elements.length != ae.elements.length) return false; - if (elements.dim == 0 && !type.equals(ae.type)) + if (elements.length == 0 && !type.equals(ae.type)) { return false; } @@ -3036,14 +3054,14 @@ extern (C++) final class ArrayLiteralExp : Expression override Optional!bool toBool() { - size_t dim = elements ? elements.dim : 0; + size_t dim = elements ? elements.length : 0; return typeof(return)(dim != 0); } override StringExp toStringExp() { TY telem = type.nextOf().toBasetype().ty; - if (telem.isSomeChar || (telem == Tvoid && (!elements || elements.dim == 0))) + if (telem.isSomeChar || (telem == Tvoid && (!elements || elements.length == 0))) { ubyte sz = 1; if (telem == Twchar) @@ -3054,7 +3072,7 @@ extern (C++) final class ArrayLiteralExp : Expression OutBuffer buf; if (elements) { - foreach (i; 0 .. elements.dim) + foreach (i; 0 .. elements.length) { auto ch = this[i]; if (ch.op != EXP.int64) @@ -3114,7 +3132,7 @@ extern (C++) final class AssocArrayLiteralExp : Expression extern (D) this(const ref Loc loc, Expressions* keys, Expressions* values) { super(loc, EXP.assocArrayLiteral, __traits(classInstanceSize, AssocArrayLiteralExp)); - assert(keys.dim == values.dim); + assert(keys.length == values.length); this.keys = keys; this.values = values; } @@ -3128,7 +3146,7 @@ extern (C++) final class AssocArrayLiteralExp : Expression return false; if (auto ae = e.isAssocArrayLiteralExp()) { - if (keys.dim != ae.keys.dim) + if (keys.length != ae.keys.length) return false; size_t count = 0; foreach (i, key; *keys) @@ -3143,7 +3161,7 @@ extern (C++) final class AssocArrayLiteralExp : Expression } } } - return count == keys.dim; + return count == keys.length; } return false; } @@ -3155,7 +3173,7 @@ extern (C++) final class AssocArrayLiteralExp : Expression override Optional!bool toBool() { - size_t dim = keys.dim; + size_t dim = keys.length; return typeof(return)(dim != 0); } @@ -3232,7 +3250,7 @@ extern (C++) final class StructLiteralExp : Expression { if (!type.equals(se.type)) return false; - if (elements.dim != se.elements.dim) + if (elements.length != se.elements.length) return false; foreach (i, e1; *elements) { @@ -3269,7 +3287,7 @@ extern (C++) final class StructLiteralExp : Expression if (i >= sd.nonHiddenFields()) return null; - assert(i < elements.dim); + assert(i < elements.length); e = (*elements)[i]; if (e) { @@ -3310,7 +3328,7 @@ extern (C++) final class StructLiteralExp : Expression { /* Find which field offset is by looking at the field offsets */ - if (elements.dim) + if (elements.length) { const sz = type.size(); if (sz == SIZE_INVALID) @@ -3797,7 +3815,7 @@ extern (C++) final class FuncExp : Expression if (td) { assert(td.literal); - assert(td.members && td.members.dim == 1); + assert(td.members && td.members.length == 1); fd = (*td.members)[0].isFuncLiteralDeclaration(); } tok = fd.tok; // save original kind of function/delegate/(infer) @@ -3928,7 +3946,7 @@ extern (C++) final class FuncExp : Expression return cannotInfer(this, to, flag); auto tiargs = new Objects(); - tiargs.reserve(td.parameters.dim); + tiargs.reserve(td.parameters.length); foreach (tp; *td.parameters) { @@ -4211,7 +4229,7 @@ extern (C++) final class IsExp : Expression TemplateParameters* p = null; if (parameters) { - p = new TemplateParameters(parameters.dim); + p = new TemplateParameters(parameters.length); foreach (i, el; *parameters) (*p)[i] = el.syntaxCopy(); } @@ -4655,7 +4673,7 @@ extern (C++) final class MixinExp : Expression return false; if (auto ce = e.isMixinExp()) { - if (exps.dim != ce.exps.dim) + if (exps.length != ce.exps.length) return false; foreach (i, e1; *exps) { @@ -4846,7 +4864,7 @@ extern (C++) final class DotVarExp : UnaExp if (VarDeclaration vd = var.isVarDeclaration()) { auto ad = vd.isMember2(); - if (ad && ad.fields.dim == sc.ctorflow.fieldinit.length) + if (ad && ad.fields.length == sc.ctorflow.fieldinit.length) { foreach (i, f; ad.fields) { |