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

[TEST ONLY] Enable preview=in by default #11632

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
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
10 changes: 10 additions & 0 deletions compiler/src/dmd/dinterpret.d
Original file line number Diff line number Diff line change
Expand Up @@ -2117,6 +2117,16 @@ public:
return CTFEExp.cantexp;
assert(e.type);

// There's a terrible hack in `dmd.dsymbolsem` that special case
// a struct with all zeros to an `ExpInitializer(BlitExp(IntegerExp(0)))`
// There's matching code for it in e2ir (toElem's visitAssignExp),
// so we need the same hack here.
// This does not trigger for global as they get a normal initializer.
if (auto ts = e.type.isTypeStruct())
if (auto ae = e.isBlitExp())
if (ae.e2.op == EXP.int64)
e = ts.defaultInitLiteral(loc);

if (e.op == EXP.construct || e.op == EXP.blit)
{
AssignExp ae = cast(AssignExp)e;
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dmd/globals.d
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ extern (C++) struct Param
// https://digitalmars.com/d/archives/digitalmars/D/Binding_rvalues_to_ref_parameters_redux_325087.html
// Implementation: https://github.com/dlang/dmd/pull/9817
FeatureState noSharedAccess; // read/write access to shared memory objects
bool previewIn; // `in` means `[ref] scope const`, accepts rvalues
bool previewIn = true; // `in` means `[ref] scope const`, accepts rvalues
bool inclusiveInContracts; // 'in' contracts of overridden methods must be a superset of parent contract
bool shortenedMethods = true; // allow => in normal function declarations
bool fixImmutableConv; // error on unsound immutable conversion - https://github.com/dlang/dmd/pull/14070
Expand Down
9 changes: 9 additions & 0 deletions compiler/test/compilable/test17351.d
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// PERMUTE_ARGS: -preview=in
bool fun(S)(ref S[3] a) { assert(a == [42, 84, 169]); return true; }
bool fun2(S)(ref S a) { return true; }
void main()
Expand All @@ -14,4 +15,12 @@ void test2()
{
static immutable int[2] P = [ 0, 1 ];
static assert(f2(P) == 1);
immutable BigInt a, b;
static assert(glob1.twice == b.twice);
static assert(a.twice == b.twice);
}

struct BigInt { int[64] big; }
BigInt twice (in BigInt v) @safe pure nothrow @nogc { return v; }

immutable BigInt glob1 = BigInt.init;
14 changes: 2 additions & 12 deletions compiler/test/compilable/testfptr.d
Original file line number Diff line number Diff line change
Expand Up @@ -107,17 +107,12 @@ void bug3797()
static assert(!is(typeof( purefunc = nonpurefunc )));
static assert( is(typeof( nonpurefunc = purefunc )));

// Cannot convert parameter storage classes (except const to in and in to const)

void function(const(int)) constfunc;
// Cannot convert parameter storage classes
void function(in int) infunc;
void function(out int) outfunc;
void function(ref int) reffunc;
void function(lazy int) lazyfunc;

static assert(is(typeof( infunc = constfunc )));
static assert(is(typeof( constfunc = infunc )));

static assert(!is(typeof( infunc = outfunc )));
static assert(!is(typeof( infunc = reffunc )));
static assert(!is(typeof( infunc = lazyfunc )));
Expand Down Expand Up @@ -250,17 +245,12 @@ void bug3797dg()
static assert(!is(typeof( purefunc = nonpurefunc )));
static assert( is(typeof( nonpurefunc = purefunc )));

// Cannot convert parameter storage classes (except const to in and in to const)

void delegate(const(int)) constfunc;
// Cannot convert parameter storage classes
void delegate(in int) infunc;
void delegate(out int) outfunc;
void delegate(ref int) reffunc;
void delegate(lazy int) lazyfunc;

static assert(is(typeof( infunc = constfunc )));
static assert(is(typeof( constfunc = infunc )));

static assert(!is(typeof( infunc = outfunc )));
static assert(!is(typeof( infunc = reffunc )));
static assert(!is(typeof( infunc = lazyfunc )));
Expand Down
4 changes: 2 additions & 2 deletions compiler/test/fail_compilation/deprecatedinref.d
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
REQUIRED_ARGS: -de
TEST_OUTPUT:
---
fail_compilation/deprecatedinref.d(9): Deprecation: using `in ref` is deprecated, use `-preview=in` and `in` instead
fail_compilation/deprecatedinref.d(10): Deprecation: using `ref in` is deprecated, use `-preview=in` and `in` instead
fail_compilation/deprecatedinref.d(9): Error: attribute `ref` is redundant with previously-applied `in`
fail_compilation/deprecatedinref.d(10): Error: attribute `in` cannot be added after `ref`: remove `ref`
---
*/
void foo(in ref int);
Expand Down
2 changes: 1 addition & 1 deletion compiler/test/fail_compilation/deprecations_preview_in.d
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
REQUIRED_ARGS: -de
TEST_OUTPUT:
---
fail_compilation/deprecations_preview_in.d(1): Deprecation: using `in` parameters with `extern(C)` functions is deprecated
fail_compilation/deprecations_preview_in.d(1): Error: cannot use `in` parameters with `extern(C)` functions
fail_compilation/deprecations_preview_in.d(1): parameter `__anonymous_param` declared as `in` here
---
*/
Expand Down
8 changes: 4 additions & 4 deletions compiler/test/fail_compilation/fail183.d
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
TEST_OUTPUT:
---
fail_compilation/fail183.d(17): Error: attribute `const` is redundant with previously-applied `in`
fail_compilation/fail183.d(18): Error: attribute `scope` cannot be applied with `in`, use `-preview=in` instead
fail_compilation/fail183.d(18): Error: attribute `scope` is redundant with previously-applied `in`
fail_compilation/fail183.d(19): Error: attribute `const` is redundant with previously-applied `in`
fail_compilation/fail183.d(19): Error: attribute `scope` cannot be applied with `in`, use `-preview=in` instead
fail_compilation/fail183.d(20): Error: attribute `scope` cannot be applied with `in`, use `-preview=in` instead
fail_compilation/fail183.d(19): Error: attribute `scope` is redundant with previously-applied `in`
fail_compilation/fail183.d(20): Error: attribute `scope` is redundant with previously-applied `in`
fail_compilation/fail183.d(20): Error: attribute `const` is redundant with previously-applied `in`
fail_compilation/fail183.d(22): Error: attribute `in` cannot be added after `const`: remove `const`
fail_compilation/fail183.d(23): Error: attribute `in` cannot be added after `scope`: remove `scope` and use `-preview=in`
fail_compilation/fail183.d(23): Error: attribute `in` cannot be added after `scope`: remove `scope`
fail_compilation/fail183.d(24): Error: attribute `in` cannot be added after `const`: remove `const`
fail_compilation/fail183.d(25): Error: attribute `in` cannot be added after `const`: remove `const`
---
Expand Down
2 changes: 1 addition & 1 deletion compiler/test/run.d
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ Options:
args = ["all"];

// move any long-running tests to the front
static size_t sortKey(in ref Target target)
static size_t sortKey(const scope ref Target target)
{
const name = target.normalizedTestName;
if (name.startsWith("runnable"))
Expand Down