Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Commit

Permalink
rename TypeInfo's init method to initializer
Browse files Browse the repository at this point in the history
"init" clashes with the type property of the same name.

Adding an alias called "init" to give people a chance to update their
code.

Further deprecation plan:
* 2.071: Do nothing. Keep both init and initializer functional for a while.
* 2.072: Deprecate the alias.
* 2.073: Replace the alias with an `@disable`d method.
* 2.074: Remove the init method, fixing issue 12233.
  • Loading branch information
aG0aep6G committed Dec 1, 2015
1 parent 008bceb commit 0470021
Show file tree
Hide file tree
Showing 36 changed files with 128 additions and 76 deletions.
23 changes: 23 additions & 0 deletions changelog.dd
Expand Up @@ -4,9 +4,32 @@ $(COMMENT Pending changelog for 2.069.2.
)

$(BUGSTITLE Library Changes,

$(LI $(RELATIVE_LINK2 TypeInfo.initializer, `TypeInfo.init` has been renamed to
`TypeInfo.initializer`.))
)

)

$(BUGSTITLE Library Changes,

$(LI $(LNAME2 TypeInfo.initializer, `TypeInfo.init` has been renamed to
`TypeInfo.initializer`.)

$(P The method `TypeInfo.init` has been renamed to
$(A ../phobos-prerelease/object.html#.TypeInfo.initializer,
`TypeInfo.initializer`).
This is necessary because the method clashes with the
$(A ../property.html#init, type property of the same name).
)
$(P An alias with the old name has been added, and it's supposed to stay
around through version 2.071.0. It's scheduled to be deprecated with the
2.072.0 release, and is going to be `@disable`d with the 2.073.0
release. Finally, the special casing is going to be removed with the
2.074.0 release, so that the type property `init` takes over.
)
)

)

Macros:
Expand Down
4 changes: 2 additions & 2 deletions src/core/demangle.d
Expand Up @@ -86,7 +86,7 @@ private struct Demangle
//throw new ParseException( msg );
debug(info) printf( "error: %.*s\n", cast(int) msg.length, msg.ptr );
throw __ctfe ? new ParseException(msg)
: cast(ParseException) cast(void*) typeid(ParseException).init;
: cast(ParseException) cast(void*) typeid(ParseException).initializer;

}

Expand All @@ -95,7 +95,7 @@ private struct Demangle
{
//throw new OverflowException( msg );
debug(info) printf( "overflow: %.*s\n", cast(int) msg.length, msg.ptr );
throw cast(OverflowException) cast(void*) typeid(OverflowException).init;
throw cast(OverflowException) cast(void*) typeid(OverflowException).initializer;
}


Expand Down
2 changes: 1 addition & 1 deletion src/core/exception.d
Expand Up @@ -672,7 +672,7 @@ private T staticError(T, Args...)(auto ref Args args)
static assert(__traits(classInstanceSize, T) <= _store.length,
T.stringof ~ " is too large for staticError()");

_store[0 .. __traits(classInstanceSize, T)] = typeid(T).init[];
_store[0 .. __traits(classInstanceSize, T)] = typeid(T).initializer[];
return cast(T) _store.ptr;
}
auto res = (cast(T function() @trusted pure nothrow @nogc) &get)();
Expand Down
4 changes: 2 additions & 2 deletions src/core/sync/mutex.d
Expand Up @@ -145,7 +145,7 @@ class Mutex :
int rc = pthread_mutex_lock( &m_hndl );
if( rc )
{
SyncError syncErr = cast(SyncError) cast(void*) typeid(SyncError).init;
SyncError syncErr = cast(SyncError) cast(void*) typeid(SyncError).initializer;
syncErr.msg = "Unable to lock mutex.";
throw syncErr;
}
Expand Down Expand Up @@ -176,7 +176,7 @@ class Mutex :
int rc = pthread_mutex_unlock( &m_hndl );
if( rc )
{
SyncError syncErr = cast(SyncError) cast(void*) typeid(SyncError).init;
SyncError syncErr = cast(SyncError) cast(void*) typeid(SyncError).initializer;
syncErr.msg = "Unable to unlock mutex.";
throw syncErr;
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/thread.d
Expand Up @@ -1605,7 +1605,7 @@ private:
{
foreach (ref lock; _locks)
{
lock[] = typeid(Mutex).init[];
lock[] = typeid(Mutex).initializer[];
(cast(Mutex)lock.ptr).__ctor();
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/gc/gc.d
Expand Up @@ -291,7 +291,7 @@ struct GC
{
config.initialize();

mutexStorage[] = typeid(GCMutex).init[];
mutexStorage[] = typeid(GCMutex).initializer[];
gcLock = cast(GCMutex) mutexStorage.ptr;
gcLock.__ctor();
gcx = cast(Gcx*)cstdlib.calloc(1, Gcx.sizeof);
Expand Down
79 changes: 54 additions & 25 deletions src/object.d
Expand Up @@ -287,7 +287,14 @@ class TypeInfo

/// Return default initializer. If the type should be initialized to all zeros,
/// an array with a null ptr and a length equal to the type size will be returned.
abstract const(void)[] init() nothrow pure const @safe @nogc;
abstract const(void)[] initializer() nothrow pure const @safe @nogc;

/// $(RED Scheduled for deprecation.) Please use `initializer` instead.
alias init = initializer; // added in 2.070, to stay in 2.071
version(none) deprecated alias init = initializer; // planned for 2.072
version(none) @disable static const(void)[] init(); // planned for 2.073
/* Planned for 2.074: Remove init, making way for the init type property,
fixing issue 12233. */

/// Get flags for type: 1 means GC should scan for pointers,
/// 2 means arg of this type is passed in XMM register
Expand Down Expand Up @@ -339,7 +346,11 @@ class TypeInfo_Typedef : TypeInfo

override @property inout(TypeInfo) next() nothrow pure inout { return base.next; }
override @property uint flags() nothrow pure const { return base.flags; }
override const(void)[] init() const { return m_init.length ? m_init : base.init(); }

override const(void)[] initializer() const
{
return m_init.length ? m_init : base.initializer();
}

override @property size_t talign() nothrow pure const { return base.talign; }

Expand Down Expand Up @@ -398,7 +409,7 @@ class TypeInfo_Pointer : TypeInfo
return (void*).sizeof;
}

override const(void)[] init() const @trusted
override const(void)[] initializer() const @trusted
{
return (cast(void *)null)[0 .. (void*).sizeof];
}
Expand Down Expand Up @@ -472,7 +483,7 @@ class TypeInfo_Array : TypeInfo
return (void[]).sizeof;
}

override const(void)[] init() const @trusted
override const(void)[] initializer() const @trusted
{
return (cast(void *)null)[0 .. (void[]).sizeof];
}
Expand Down Expand Up @@ -588,7 +599,11 @@ class TypeInfo_StaticArray : TypeInfo
GC.free(pbuffer);
}

override const(void)[] init() nothrow pure const { return value.init(); }
override const(void)[] initializer() nothrow pure const
{
return value.initializer();
}

override @property inout(TypeInfo) next() nothrow pure inout { return value; }
override @property uint flags() nothrow pure const { return value.flags; }

Expand Down Expand Up @@ -661,7 +676,7 @@ class TypeInfo_AssociativeArray : TypeInfo
return (char[int]).sizeof;
}

override const(void)[] init() const @trusted
override const(void)[] initializer() const @trusted
{
return (cast(void *)null)[0 .. (char[int]).sizeof];
}
Expand Down Expand Up @@ -704,7 +719,11 @@ class TypeInfo_Vector : TypeInfo

override @property inout(TypeInfo) next() nothrow pure inout { return base.next; }
override @property uint flags() nothrow pure const { return base.flags; }
override const(void)[] init() nothrow pure const { return base.init(); }

override const(void)[] initializer() nothrow pure const
{
return base.initializer();
}

override @property size_t talign() nothrow pure const { return 16; }

Expand Down Expand Up @@ -738,7 +757,7 @@ class TypeInfo_Function : TypeInfo
return 0; // no size for functions
}

override const(void)[] init() const @safe
override const(void)[] initializer() const @safe
{
return null;
}
Expand Down Expand Up @@ -793,7 +812,7 @@ class TypeInfo_Delegate : TypeInfo
return dg.sizeof;
}

override const(void)[] init() const @trusted
override const(void)[] initializer() const @trusted
{
return (cast(void *)null)[0 .. (int delegate()).sizeof];
}
Expand Down Expand Up @@ -903,7 +922,10 @@ class TypeInfo_Class : TypeInfo
return Object.sizeof;
}

override const(void)[] init() nothrow pure const @safe { return m_init; }
override const(void)[] initializer() nothrow pure const @safe
{
return m_init;
}

override @property uint flags() nothrow pure const { return 1; }

Expand Down Expand Up @@ -993,10 +1015,10 @@ unittest
int a;
}

assert(typeid(X).init is typeid(X).m_init);
assert(typeid(X).init.length == typeid(const(X)).init.length);
assert(typeid(X).init.length == typeid(shared(X)).init.length);
assert(typeid(X).init.length == typeid(immutable(X)).init.length);
assert(typeid(X).initializer is typeid(X).m_init);
assert(typeid(X).initializer.length == typeid(const(X)).initializer.length);
assert(typeid(X).initializer.length == typeid(shared(X)).initializer.length);
assert(typeid(X).initializer.length == typeid(immutable(X)).initializer.length);
}

class TypeInfo_Interface : TypeInfo
Expand Down Expand Up @@ -1058,7 +1080,7 @@ class TypeInfo_Interface : TypeInfo
return Object.sizeof;
}

override const(void)[] init() const @trusted
override const(void)[] initializer() const @trusted
{
return (cast(void *)null)[0 .. Object.sizeof];
}
Expand All @@ -1078,7 +1100,7 @@ class TypeInfo_Struct : TypeInfo
return true;
auto s = cast(const TypeInfo_Struct)o;
return s && this.name == s.name &&
this.init().length == s.init().length;
this.initializer().length == s.initializer().length;
}

override size_t getHash(in void* p) @safe pure nothrow const
Expand All @@ -1093,7 +1115,7 @@ class TypeInfo_Struct : TypeInfo
import core.internal.traits : externDFunc;
alias hashOf = externDFunc!("rt.util.hash.hashOf",
size_t function(const(void)*, size_t, size_t) @trusted pure nothrow);
return hashOf(p, init().length, 0);
return hashOf(p, initializer().length, 0);
}
}

Expand All @@ -1109,7 +1131,7 @@ class TypeInfo_Struct : TypeInfo
return true;
else
// BUG: relies on the GC not moving objects
return memcmp(p1, p2, init().length) == 0;
return memcmp(p1, p2, initializer().length) == 0;
}

override int compare(in void* p1, in void* p2) @trusted pure nothrow const
Expand All @@ -1127,7 +1149,7 @@ class TypeInfo_Struct : TypeInfo
return (*xopCmp)(p2, p1);
else
// BUG: relies on the GC not moving objects
return memcmp(p1, p2, init().length);
return memcmp(p1, p2, initializer().length);
}
else
return -1;
Expand All @@ -1137,10 +1159,13 @@ class TypeInfo_Struct : TypeInfo

override @property size_t tsize() nothrow pure const
{
return init().length;
return initializer().length;
}

override const(void)[] init() nothrow pure const @safe { return m_init; }
override const(void)[] initializer() nothrow pure const @safe
{
return m_init;
}

override @property uint flags() nothrow pure const { return m_flags; }

Expand All @@ -1164,7 +1189,7 @@ class TypeInfo_Struct : TypeInfo
}

string name;
void[] m_init; // initializer; init.ptr == null if 0 initialize
void[] m_init; // initializer; m_init.ptr == null if 0 initialize

@safe pure nothrow
{
Expand Down Expand Up @@ -1273,7 +1298,7 @@ class TypeInfo_Tuple : TypeInfo
assert(0);
}

override const(void)[] init() const @trusted
override const(void)[] initializer() const @trusted
{
assert(0);
}
Expand Down Expand Up @@ -1332,7 +1357,11 @@ class TypeInfo_Const : TypeInfo

override @property inout(TypeInfo) next() nothrow pure inout { return base.next; }
override @property uint flags() nothrow pure const { return base.flags; }
override const(void)[] init() nothrow pure const { return base.init(); }

override const(void)[] initializer() nothrow pure const
{
return base.initializer();
}

override @property size_t talign() nothrow pure const { return base.talign; }

Expand Down Expand Up @@ -2729,7 +2758,7 @@ void destroy(T)(ref T obj) if (is(T == struct))
_destructRecurse(obj);
() @trusted {
auto buf = (cast(ubyte*) &obj)[0 .. T.sizeof];
auto init = cast(ubyte[])typeid(T).init();
auto init = cast(ubyte[])typeid(T).initializer();
if (init.ptr is null) // null ptr means initialize to 0s
buf[] = 0;
else
Expand Down
2 changes: 1 addition & 1 deletion src/rt/aaA.d
Expand Up @@ -249,7 +249,7 @@ TypeInfo_Struct fakeEntryTI(const TypeInfo keyti, const TypeInfo valti)
void* p = GC.malloc(sizeti + 2 * (void*).sizeof);
import core.stdc.string : memcpy;

memcpy(p, typeid(TypeInfo_Struct).init().ptr, sizeti);
memcpy(p, typeid(TypeInfo_Struct).initializer().ptr, sizeti);

auto ti = cast(TypeInfo_Struct) p;
auto extra = cast(TypeInfo*)(p + sizeti);
Expand Down
2 changes: 1 addition & 1 deletion src/rt/deh.d
Expand Up @@ -19,7 +19,7 @@ extern (C)
auto t = cast(Throwable) o;

if (t !is null && t.info is null &&
cast(byte*) t !is typeid(t).init.ptr)
cast(byte*) t !is typeid(t).initializer.ptr)
{
t.info = _d_traceContext(context);
}
Expand Down

0 comments on commit 0470021

Please sign in to comment.