Files
Iain Buclaw 8b0ccc95f1 d: Merge upstream dmd, druntime e1f6680f50, phobos f87979028
D front-end changes:

	- Import latest fixes from v2.112.0-beta.1.
	- Associative array operations are now lowered to templates
	  defined in `core.internal.newaa'.

D runtime changes:

	- Import latest fixes from v2.112.0-beta.1.

Phobos changes:

	- Import latest fixes from v2.112.0-beta.1.

gcc/d/ChangeLog:

	* dmd/MERGE: Merge upstream dmd e1f6680f50.
	* Make-lang.in (D_FRONTEND_OBJS): Remove d/gluelayer.o, d/iasm.o,
	d/iasmgcc.o.  Add d/iasm-package.o, d/iasm-gcc.o.
	(d/iasm-%.o): New recipe.
	* d-convert.cc (convert_expr): Remove library call to dynamic_cast.
	* d-lang.cc (d_init_options): Set errorSupplementLimit parameter.
	* decl.cc (DeclVisitor::visit): Update for new front-end interface.
	* expr.cc (ExprVisitor::visit (EqualExp *)): Update for front-end
	lowering expression using templates.
	(ExprVisitor::visit (InExp *)): Likewise.
	(ExprVisitor::visit (IndexExp *)): Likewise.
	(ExprVisitor::visit (CastExp *)): Likewise.
	(ExprVisitor::visit (RemoveExp *)): Likewise.
	(ExprVisitor::visit (AddrExp *)): Likewise.
	(ExprVisitor::visit (NewExp *)): Likewise.
	(ExprVisitor::visit (ArrayLiteralExp *)): Likewise.
	(ExprVisitor::visit (AssocArrayLiteralExp *)): Likewise.
	* imports.cc (ImportVisitor::visit (AliasDeclaration *)): Update for
	new front-end interface.
	* runtime.def (DYNAMIC_CAST): Remove.
	(INTERFACE_CAST): Remove.
	(ARRAYLITERALTX): Remove.
	(ADEQ2): Remove.
	(ASSOCARRAYLITERALTX): Remove.
	(AANEW): Remove.
	(AAEQUAL): Remove.
	(AAINX): Remove.
	(AAGETY): Remove.
	(AAGETRVALUEX): Remove.
	(AADELX): Remove.
	* typeinfo.cc (TypeInfoVisitor::visit): Layout xopEquals and xtoHash
	in TypeInfo_AssociativeArray.
	(create_typeinfo): Add new fields to internal typeinfo.
	(check_typeinfo_type): Print instantiation trace of error.
	* types.cc (TypeVisitor::visit (TypeStruct *)): Update for new
	front-end interface.

libphobos/ChangeLog:

	* libdruntime/MERGE: Merge upstream druntime e1f6680f50.
	* libdruntime/Makefile.am (DRUNTIME_DSOURCES): Add
	core/internal/cast_.d.  Remove rt/aaA.d, rt/adi.d, rt/cast_.d.
	(DRUNTIME_DSOURCES_POSIX): Add core/sys/posix/endian.d.
	* libdruntime/Makefile.in: Regenerate.
	* src/MERGE: Merge upstream phobos f87979028.
	* src/Makefile.am (PHOBOS_DSOURCES): Add std/internal/entropy.d.
	* src/Makefile.in: Regenerate.
	* testsuite/libphobos.aa/test_aa.d: Adjust test.
	* testsuite/libphobos.init_fini/custom_gc.d: Likewise.

gcc/testsuite/ChangeLog:

	* gdc.dg/asm1.d: Adjust test.
	* gdc.dg/asm5.d: Likewise.
	* gdc.dg/pr100967.d: Likewise.
	* gdc.dg/rtti1.d: Likewise.
	* gdc.dg/rtti2.d: New test.
2026-01-31 09:37:45 +01:00

127 lines
3.9 KiB
D

/**
* Contains a registry for GC factories.
*
* Copyright: Copyright Digital Mars 2016.
* License: $(WEB www.boost.org/LICENSE_1_0.txt, Boost License 1.0).
* Authors: Martin Nowak
*/
module core.gc.registry;
import core.gc.gcinterface : GC;
import core.thread.threadbase : ThreadBase;
/*@nogc nothrow:*/
/**
* A factory function that instantiates an implementation of the GC interface.
* In case the instance was allocated on the C heap, it is supposed to
* free itself upon calling it's destructor.
*
* The factory should print an error and abort the program if it
* cannot successfully initialize the GC instance.
*/
alias GCFactory = GC function();
/**
* A function that will initialize a thread before the GC has been initialized.
* Once the GC is initialized, the interface method GC.initThread for each new
* thread.
*/
alias GCThreadInitFunction = void function(ThreadBase base) nothrow @nogc;
/**
* Register a GC factory under the given `name`. This function must be called
* from a C constructor before druntime is initialized.
*
* To use the registered GC, it's name must be specified gcopt runtime option,
* e.g. by passing $(TT, --DRT-gcopt=gc:my_gc_name) as application argument.
*
* The thread init function will be called *only before* the GC has been
* initialized to the registered GC. It is called as the first step in starting
* the new thread before the thread is registered with the runtime as a running
* thread. This allows any specific thread data that is needed for running the
* GC to be registered with the thread object.
*
* After the GC is initialized, the GC interface function `initThread` is
* called instead. This function should expect the possibility that the
* reciprocal `cleanupThread` method may not be called if the GC is never
* initialized.
*
* Params:
* name = name of the GC implementation; should be unique
* factory = function to instantiate the implementation
* threadInit = function to call from a new thread *before* registration in
* the list of running threads, to set up any GC-specific data.
* Note: The registry does not perform synchronization, as registration is
* assumed to be executed serially, as is the case for C constructors.
* See_Also:
* $(LINK2 https://dlang.org/spec/garbage.html#gc_config, Configuring the Garbage Collector)
*/
void registerGCFactory(string name, GCFactory factory,
GCThreadInitFunction threadInit = null) nothrow @nogc
{
import core.stdc.stdlib : realloc;
auto ptr = cast(Entry*)realloc(entries.ptr, (entries.length + 1) * Entry.sizeof);
entries = ptr[0 .. entries.length + 1];
entries[$ - 1] = Entry(name, factory, threadInit);
}
/**
* Called during runtime initialization to initialize a GC instance of given `name`.
*
* Params:
* name = name of the GC to instantiate
* Returns:
* The created GC instance or `null` if no factory for that name was registered
*/
GC createGCInstance(string name)
{
import core.stdc.stdlib : free;
foreach (entry; entries)
{
if (entry.name != name)
continue;
auto instance = entry.factory();
// only one GC at a time for now, so free the registry to not leak
free(entries.ptr);
entries = null;
return instance;
}
return null;
}
/**
* Get the thread init function used for the selected GC.
*
* Note, this must be called before `createGCInstance`. It is typically called by
* `rt_init`.
*/
GCThreadInitFunction threadInit(string name) nothrow @nogc
{
foreach (entry; entries)
{
if (entry.name == name)
return entry.threadInit;
}
return null;
}
// list of all registerd GCs
const(Entry[]) registeredGCFactories(scope int dummy=0) nothrow @nogc
{
return entries;
}
private:
struct Entry
{
string name;
GCFactory factory;
GCThreadInitFunction threadInit;
}
__gshared Entry[] entries;