mirror of
https://gcc.gnu.org/git/gcc.git
synced 2026-02-22 20:01:22 -05:00
D front-end changes: - Import dmd v2.112.0. - Bitfields feature is now enabled by default. - The compiler now accepts `-std=d2024' and `-std=d202y'. - An error is now issued for dangling `else' statements. - `finally' statements are no longer rewritten to a sequence if no `Exception' was thrown. - Some forms of `printf' calls are now treated as `@safe'. - Implicit integer conversions in `int op= float` assignments has been deprecated. D runtime changes: - Import druntime v2.112.0. - Added `filterCaughtThrowable' in `core.thread.ThreadBase'. Phobos changes: - Import phobos v2.112.0. gcc/d/ChangeLog: * dmd/VERSION: Bump version to v2.112.0. * dmd/MERGE: Merge upstream dmd 24a41073c2. * d-attribs.cc (build_attributes): Update for new front-end interface. * d-builtins.cc (build_frontend_type): Likewise. (matches_builtin_type): Likewise. (d_init_versions): Predefine D_Profile when compiling with profile enabled. * d-codegen.cc (get_array_length): Update for new front-end interface. (lower_struct_comparison): Likewise. (build_array_from_val): Likewise. (get_function_type): Likewise. (get_frameinfo): Likewise. * d-compiler.cc (Compiler::paintAsType): Likewise. * d-convert.cc (convert_expr): Likewise. (convert_for_rvalue): Likewise. (convert_for_assignment): Likewise. (d_array_convert): Likewise. * d-diagnostic.cc (verrorReport): Rename to ... (vreportDiagnostic): ... this. (verrorReportSupplemental): Rename to ... (vsupplementalDiagnostic): ... this. * d-lang.cc (d_handle_option): Handle -std=d2024 and -std=d202y. (d_parse_file): Update for new front-end interface. * d-target.cc (Target::fieldalign): Likewise. (Target::isVectorTypeSupported): Likewise. (Target::isVectorOpSupported): Likewise. * decl.cc (get_symbol_decl): Likewise. (DeclVisitor::visit): Likewise. (DeclVisitor::visit (FuncDeclaration *)): Do NRVO on `__result' decl. * expr.cc (needs_postblit): Remove. (needs_dtor): Remove. (lvalue_p): Remove. (ExprVisitor::visit): Update for new front-end interface. (ExprVisitor::visit (AssignExp *)): Update for front-end lowering expression using templates. * imports.cc (ImportVisitor::visit): Update for new front-end interface. * intrinsics.def (INTRINSIC_VA_ARG): Update signature. (INTRINSIC_C_VA_ARG): Update signature. (INTRINSIC_VASTART): Update signature. * lang.opt: Add -std=d2024 and -std=d202y. * toir.cc (IRVisitor::visit): Update for new front-end interface. * typeinfo.cc (TypeInfoVisitor::visit): Likewise. (TypeInfoVisitor::visit (TypeInfoStructDeclaration *)): Ensure semantic is ran on all TypeInfo members. (base_vtable_offset): Update for new front-end interface. * types.cc (TypeVisitor::visit): Likewise. libphobos/ChangeLog: * libdruntime/MERGE: Merge upstream druntime 24a41073c2. * libdruntime/__importc_builtins.di: Reimplement. * src/MERGE: Merge upstream phobos 808314eb2. * testsuite/libphobos.aa/test_aa.d: Adjust test. * testsuite/libphobos.gc/forkgc2.d: Removed. * testsuite/libphobos.thread/filterthrownglobal.d: New test. * testsuite/libphobos.thread/filterthrownmethod.d: New test. gcc/testsuite/ChangeLog: * gdc.dg/pr90601.d: Adjust test. * lib/gdc-utils.exp: Handle new compiler options.
170 lines
3.7 KiB
D
170 lines
3.7 KiB
D
/**
|
|
* This module contains compiler support determining equality of arrays.
|
|
*
|
|
* Copyright: Copyright Digital Mars 2000 - 2020.
|
|
* License: Distributed under the
|
|
* $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0).
|
|
* (See accompanying file LICENSE)
|
|
* Source: $(DRUNTIMESRC core/internal/_array/_equality.d)
|
|
*/
|
|
|
|
module core.internal.array.equality;
|
|
|
|
// The compiler lowers `lhs == rhs` to `__equals(lhs, rhs)` for
|
|
// * dynamic arrays,
|
|
// * (most) arrays of different (unqualified) element types, and
|
|
// * arrays of structs with custom opEquals.
|
|
bool __equals(T1, T2)(scope T1[] lhs, scope T2[] rhs) @trusted
|
|
{
|
|
if (lhs.length != rhs.length)
|
|
return false;
|
|
|
|
if (lhs.length == 0)
|
|
return true;
|
|
|
|
alias PureType = bool function(scope T1[], scope T2[], size_t) @safe pure nothrow @nogc;
|
|
|
|
return (cast(PureType)&isEqual!(T1,T2))(lhs, rhs, lhs.length);
|
|
}
|
|
|
|
pragma(inline, true)
|
|
bool __equals(T1, T2, size_t N)(scope ref T1[N] lhs, scope T2[] rhs) @trusted {
|
|
return __equals(lhs[], rhs);
|
|
}
|
|
|
|
pragma(inline, true)
|
|
bool __equals(T1, T2, size_t N)(scope T1[] lhs, scope ref T2[N] rhs) @trusted {
|
|
return __equals(lhs, rhs[]);
|
|
}
|
|
|
|
pragma(inline, true)
|
|
bool __equals(T1, T2, size_t N, size_t M)(scope ref T1[N] lhs, scope ref T2[M] rhs) @trusted {
|
|
return __equals(lhs[], rhs[]);
|
|
}
|
|
|
|
/******************************
|
|
* Helper function for __equals().
|
|
* Outlined to enable __equals() to be inlined, as dmd cannot inline loops.
|
|
*/
|
|
private
|
|
bool isEqual(T1, T2)(scope T1[] lhs, scope T2[] rhs, size_t length)
|
|
{
|
|
// Returns a reference to an array element, eliding bounds check and
|
|
// casting void to ubyte.
|
|
pragma(inline, true)
|
|
static ref at(T)(scope T[] r, size_t i) @trusted
|
|
// exclude opaque structs due to https://issues.dlang.org/show_bug.cgi?id=20959
|
|
if (!(is(T == struct) && !is(typeof(T.sizeof))))
|
|
{
|
|
static if (is(T == void))
|
|
return (cast(ubyte[]) r)[i];
|
|
else
|
|
return r[i];
|
|
}
|
|
|
|
foreach (const i; 0 .. length)
|
|
{
|
|
if (at(lhs, i) != at(rhs, i))
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
@safe unittest
|
|
{
|
|
assert(__equals([], []));
|
|
assert(!__equals([1, 2], [1, 2, 3]));
|
|
}
|
|
|
|
@safe unittest
|
|
{
|
|
auto a = "hello"c;
|
|
|
|
assert(a != "hel");
|
|
assert(a != "helloo");
|
|
assert(a != "betty");
|
|
assert(a == "hello");
|
|
assert(a != "hxxxx");
|
|
|
|
float[] fa = [float.nan];
|
|
assert(fa != fa);
|
|
}
|
|
|
|
@safe unittest
|
|
{
|
|
struct A
|
|
{
|
|
int a;
|
|
}
|
|
|
|
auto arr1 = [A(0), A(2)];
|
|
auto arr2 = [A(0), A(1)];
|
|
auto arr3 = [A(0), A(1)];
|
|
|
|
assert(arr1 != arr2);
|
|
assert(arr2 == arr3);
|
|
}
|
|
|
|
@safe unittest
|
|
{
|
|
struct A
|
|
{
|
|
int a;
|
|
int b;
|
|
|
|
bool opEquals(const A other)
|
|
{
|
|
return this.a == other.b && this.b == other.a;
|
|
}
|
|
}
|
|
|
|
auto arr1 = [A(1, 0), A(0, 1)];
|
|
auto arr2 = [A(1, 0), A(0, 1)];
|
|
auto arr3 = [A(0, 1), A(1, 0)];
|
|
|
|
assert(arr1 != arr2);
|
|
assert(arr2 == arr3);
|
|
}
|
|
|
|
// https://issues.dlang.org/show_bug.cgi?id=18252
|
|
@safe unittest
|
|
{
|
|
string[int][] a1, a2;
|
|
assert(__equals(a1, a2));
|
|
assert(a1 == a2);
|
|
a1 ~= [0: "zero"];
|
|
a2 ~= [0: "zero"];
|
|
assert(__equals(a1, a2));
|
|
assert(a1 == a2);
|
|
a2[0][1] = "one";
|
|
assert(!__equals(a1, a2));
|
|
assert(a1 != a2);
|
|
}
|
|
|
|
// https://issues.dlang.org/show_bug.cgi?id=21094
|
|
unittest
|
|
{
|
|
static class C
|
|
{
|
|
int a;
|
|
}
|
|
static struct S
|
|
{
|
|
bool isValid;
|
|
C fib;
|
|
|
|
inout(C) get() pure @safe @nogc nothrow inout
|
|
{
|
|
return isValid ? fib : C.init;
|
|
}
|
|
T opCast(T : C)() const { return null; }
|
|
|
|
alias get this;
|
|
}
|
|
|
|
auto foo(S[] lhs, S[] rhs)
|
|
{
|
|
return lhs == rhs;
|
|
}
|
|
}
|