Skip to content

Commit 461b6dd

Browse files
committed
fix registration
1 parent d1936f3 commit 461b6dd

1 file changed

Lines changed: 21 additions & 95 deletions

File tree

source/openmethods.d

Lines changed: 21 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,6 @@ mixin template registerClasses(Classes...) {
304304
writefln("Registering class %s", C.stringof);
305305
}
306306
Runtime.additionalClasses ~= C.classinfo;
307-
Runtime.needUpdate = true;
308307
}
309308
}
310309

@@ -318,7 +317,6 @@ mixin template registerClasses(Classes...) {
318317
import std.algorithm, std.array;
319318
Runtime.additionalClasses =
320319
Runtime.additionalClasses.filter!(c => c != C.classinfo).array;
321-
Runtime.needUpdate = true;
322320
}
323321
}
324322
}
@@ -334,22 +332,11 @@ Runtime.Metrics updateMethods()
334332
return rt.update();
335333
}
336334

337-
void unregisterMethods()
338-
{
339-
Runtime rt;
340-
rt.unregister;
341-
}
342-
343335
shared static this()
344336
{
345337
updateMethods;
346338
}
347339

348-
bool needUpdateMethods()
349-
{
350-
return Runtime.needUpdate;
351-
}
352-
353340
/++
354341
Information passed to the error handler function.
355342
@@ -411,7 +398,6 @@ version (GNU) {
411398

412399
debug (explain) {
413400
import std.stdio;
414-
415401
void trace(T...)(T args) nothrow
416402
{
417403
try {
@@ -588,11 +574,11 @@ struct Method(alias module_, string name, int index)
588574
__gshared genericNextPtr nextPtr(QualParams...) = null;
589575

590576
static register() {
591-
info = Runtime.MethodInfo.init;
577+
TheMethod.info = Runtime.MethodInfo.init;
592578
info.name = Name;
593579

594580
debug(explain) {
595-
writefln("registering method %s", info);
581+
writefln("Registering method %s - %s", info, TheMethod.stringof);
596582
}
597583

598584
static if (Mptr == MptrInDeallocator) {
@@ -612,16 +598,6 @@ struct Method(alias module_, string name, int index)
612598
}
613599

614600
Runtime.methodInfos[&info] = &info;
615-
Runtime.needUpdate = true;
616-
}
617-
618-
static unregister() {
619-
debug(explain) {
620-
writefln("Unregistering %s", info);
621-
}
622-
623-
info = Runtime.MethodInfo.init;
624-
Runtime.needUpdate = true;
625601
}
626602

627603
static template specRegistrar(alias Spec) {
@@ -647,18 +623,6 @@ struct Method(alias module_, string name, int index)
647623
si.nextPtr = cast(void**) &TheMethod.nextPtr!SpecParams;
648624

649625
TheMethod.info.specInfos ~= &si;
650-
openmethods.Runtime.needUpdate = true;
651-
}
652-
653-
void unregister()
654-
{
655-
debug(explain) {
656-
tracefln(
657-
"Unregistering override %s%s, pf = %s",
658-
TheMethod.Name, SpecParams.stringof, &wrapper);
659-
}
660-
si = openmethods.Runtime.SpecInfo.init;
661-
Runtime.needUpdate = true;
662626
}
663627
}
664628

@@ -780,8 +744,6 @@ interface Registrar
780744
{
781745
void registerMethods();
782746
void registerSpecs();
783-
void unregisterSpecs();
784-
void unregisterMethods();
785747
}
786748

787749
enum hasVirtualParameters(alias F) =
@@ -838,19 +800,6 @@ mixin template registrar(alias MODULE, alias ModuleName)
838800
}
839801
}
840802

841-
void unregisterMethods()
842-
{
843-
foreach (m; __traits(allMembers, MODULE)) {
844-
static if (is(typeof(__traits(getOverloads, MODULE, m)))) {
845-
foreach (i, o; __traits(getOverloads, MODULE, m)) {
846-
static if (hasVirtualParameters!(o)) {
847-
openmethods.Method!(MODULE, m, i).unregister;
848-
}
849-
}
850-
}
851-
}
852-
}
853-
854803
enum isNamedSpec(alias spec) = is(
855804
typeof(getUDAs!(spec, method)[0]) == openmethods.method);
856805

@@ -886,22 +835,6 @@ mixin template registrar(alias MODULE, alias ModuleName)
886835
}
887836
}
888837
}
889-
890-
void unregisterSpecs() {
891-
foreach (m; __traits(allMembers, MODULE)) {
892-
static if (is(typeof(__traits(getOverloads, MODULE, m)))) {
893-
foreach (i, o; __traits(getOverloads, MODULE, m)) {
894-
static if (hasUDA!(o, method)) {
895-
Parameters!(o) args;
896-
alias Method = typeof(
897-
mixin(specId!(m, o))(
898-
openmethods.MethodTag.init, args));
899-
Method.specRegistrar!(o).unregister;
900-
}
901-
}
902-
}
903-
}
904-
}
905838
}
906839

907840
// ============================================================================
@@ -918,6 +851,7 @@ struct Runtime
918851

919852
struct MethodInfo
920853
{
854+
int registered;
921855
string name;
922856
ClassInfo[] vp;
923857
SpecInfo*[] specInfos;
@@ -1025,7 +959,6 @@ struct Runtime
1025959
__gshared Registry methodInfos;
1026960
__gshared ClassInfo[] additionalClasses;
1027961
__gshared Word[] gv; // Global Vector
1028-
__gshared needUpdate = true;
1029962
__gshared ulong hashMult;
1030963
__gshared uint hashShift, hashSize;
1031964
__gshared uint methodsUsingDeallocator;
@@ -1038,22 +971,24 @@ struct Runtime
1038971

1039972
Metrics update()
1040973
{
1041-
if (!needUpdate)
1042-
return Metrics();
974+
methodInfos.clear();
1043975

1044976
foreach (mod; ModuleInfo) {
1045-
auto registrar = mod.name ~ "." ~ "__OpenMethodsRegistrar__";
977+
auto registrarClassName = mod.name ~ "." ~ "__OpenMethodsRegistrar__";
1046978
foreach (c; mod.localClasses) {
1047-
if (c.name == registrar) {
979+
if (c.name == registrarClassName) {
980+
debug(explain) tracefln("Calling %s.registerMethods", registrarClassName);
981+
auto registrar = (cast(Registrar) c.create());
1048982
(cast(Registrar) c.create()).registerMethods;
1049983
}
1050984
}
1051985
}
1052986

1053987
foreach (mod; ModuleInfo) {
1054-
auto registrar = mod.name ~ "." ~ "__OpenMethodsRegistrar__";
988+
auto registrarClassName = mod.name ~ "." ~ "__OpenMethodsRegistrar__";
1055989
foreach (c; mod.localClasses) {
1056-
if (c.name == registrar) {
990+
if (c.name == registrarClassName) {
991+
debug(explain) tracefln("Calling %s.registerSpecs", registrarClassName);
1057992
(cast(Registrar) c.create()).registerSpecs;
1058993
}
1059994
}
@@ -1114,29 +1049,13 @@ struct Runtime
11141049

11151050
installGlobalData();
11161051

1117-
needUpdate = false;
1118-
11191052
return metrics;
11201053
}
11211054

1122-
void unregister()
1055+
void reset()
11231056
{
1124-
foreach (mod; ModuleInfo) {
1125-
auto registrar = mod.name ~ "." ~ "__OpenMethodsRegistrar__";
1126-
foreach (c; mod.localClasses) {
1127-
if (c.name == registrar) {
1128-
(cast(Registrar) c.create()).unregisterSpecs;
1129-
}
1130-
}
1131-
}
1132-
1133-
foreach (mod; ModuleInfo) {
1134-
auto registrar = mod.name ~ "." ~ "__OpenMethodsRegistrar__";
1135-
foreach (c; mod.localClasses) {
1136-
if (c.name == registrar) {
1137-
(cast(Registrar) c.create()).unregisterMethods;
1138-
}
1139-
}
1057+
foreach (methodInfo; Runtime.methodInfos) {
1058+
methodInfo.specInfos = [];
11401059
}
11411060
}
11421061

@@ -1476,8 +1395,15 @@ struct Runtime
14761395
auto specs = best(applicable);
14771396

14781397
if (specs.length > 1) {
1398+
debug(explain) {
1399+
writefln(
1400+
" warning: ambiguous: %d applicable methods", specs.length);
1401+
}
14791402
m.dispatchTable ~= m.info.ambiguousCallError;
14801403
} else if (specs.empty) {
1404+
debug(explain) {
1405+
writeln(" warning: not implemented");
1406+
}
14811407
m.dispatchTable ~= m.info.notImplementedError;
14821408
} else {
14831409
m.dispatchTable ~= specs[0].info.pf;

0 commit comments

Comments
 (0)