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

Fix issue 10023 - Add rtInfo (or equivalent) to ModuleInfo. #2271

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions src/idgen.c
Expand Up @@ -66,6 +66,7 @@ Msgtable msgtable[] =
{ "Exception" },
{ "AssociativeArray" },
{ "RTInfo" },
{ "RMInfo" },
{ "Throwable" },
{ "Error" },
{ "withSym", "__withSym" },
Expand Down
21 changes: 21 additions & 0 deletions src/module.c
Expand Up @@ -22,6 +22,8 @@
#include "dsymbol.h"
#include "hdrgen.h"
#include "lexer.h"
#include "mtype.h"
#include "template.h"

#ifdef IN_GCC
#include "d-dmd-gcc.h"
Expand Down Expand Up @@ -97,6 +99,8 @@ Module::Module(char *filename, Identifier *ident, int doDocComment, int doHdrGen
nameoffset = 0;
namelen = 0;

rmInfo = NULL;

srcfilename = FileName::defaultExt(filename, global.mars_ext);
if (!FileName::equalsExt(srcfilename, global.mars_ext) &&
!FileName::equalsExt(srcfilename, global.hdr_ext) &&
Expand Down Expand Up @@ -806,6 +810,23 @@ void Module::semantic3()
}

sc = sc->pop();

if (!rmInfo && Type::rminfo &&
(!isDeprecated() || global.params.useDeprecated)) // don't do it for unused deprecated modules
{ // Evaluate: RMInfo!module
Objects *tiargs = new Objects();
tiargs->push(this);
TemplateInstance *ti = new TemplateInstance(loc, Type::rminfo, tiargs);
ti->semantic(sc);
ti->semantic2(sc);
ti->semantic3(sc);
Dsymbol *s = ti->toAlias();
Expression *e = new DsymbolExp(Loc(), s, 0);
e = e->ctfeSemantic(ti->tempdecl->scope);
e = e->ctfeInterpret();
rmInfo = e;
}

sc->pop();
semanticRun = semanticstarted;
}
Expand Down
2 changes: 2 additions & 0 deletions src/module.h
Expand Up @@ -117,6 +117,8 @@ class Module : public Package
size_t nameoffset; // offset of module name from start of ModuleInfo
size_t namelen; // length of module name in characters

Expression* rmInfo; // pointer to user info generated by object.RMInfo(this)

Module(char *arg, Identifier *ident, int doDocComment, int doHdrGen);
~Module();

Expand Down
1 change: 1 addition & 0 deletions src/mtype.c
Expand Up @@ -80,6 +80,7 @@ ClassDeclaration *Type::typeinfowild;

TemplateDeclaration *Type::associativearray;
TemplateDeclaration *Type::rtinfo;
TemplateDeclaration *Type::rminfo;

Type *Type::tvoid;
Type *Type::tint8;
Expand Down
1 change: 1 addition & 0 deletions src/mtype.h
Expand Up @@ -211,6 +211,7 @@ class Type : public RootObject

static TemplateDeclaration *associativearray;
static TemplateDeclaration *rtinfo;
static TemplateDeclaration *rminfo;

static Type *basic[TMAX];
static unsigned char mangleChar[TMAX];
Expand Down
2 changes: 2 additions & 0 deletions src/template.c
Expand Up @@ -570,6 +570,8 @@ void TemplateDeclaration::semantic(Scope *sc)
Type::associativearray = this;
else if (ident == Id::RTInfo)
Type::rtinfo = this;
else if (ident == Id::RMInfo)
Type::rminfo = this;
}

if (sc->func)
Expand Down
13 changes: 13 additions & 0 deletions src/toobj.c
Expand Up @@ -103,6 +103,7 @@ void Module::genmoduleinfo()
#define MIunitTest 0x200
#define MIimportedModules 0x400
#define MIlocalClasses 0x800
#define MIrmInfo 0x1000
#define MInew 0x80000000 // it's the "new" layout

unsigned flags = MInew;
Expand All @@ -124,6 +125,8 @@ void Module::genmoduleinfo()
flags |= MIimportedModules;
if (aclasses.dim)
flags |= MIlocalClasses;
if (rmInfo)
flags |= MIrmInfo;

if (!needmoduleinfo)
flags |= MIstandalone;
Expand Down Expand Up @@ -172,6 +175,10 @@ void Module::genmoduleinfo()
dtxoff(&dt, cd->toSymbol(), 0, TYnptr);
}
}
if (flags & MIrmInfo)
{
rmInfo->toDt(&dt);
}

// Put out module name as a 0-terminated string, to save bytes
nameoffset = dt_size(dt);
Expand All @@ -196,6 +203,7 @@ void Module::genmoduleinfo()
void *sharedctor;
void *shareddtor;
uint index;
void *rmInfo;
void*[1] reserved;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why keep around void*[1] reserved if you're adding a new field that takes up that space?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No reason. I'll remove it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a note that the reserved field brings the size of ModuleInfo is 64 bytes (128 on 64bit) - there's probably am reason why it was padded up to a power of 2. Though can't think why at this moment. :)

}
*/
Expand Down Expand Up @@ -293,6 +301,11 @@ void Module::genmoduleinfo()

dtdword(&dt, 0); // index

if (rmInfo)
rmInfo->toDt(&dt);
else
dtdword(&dt, 0);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't it about time that the 'old' layout be dropped perhaps?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's already been merged. I'll remove that when I update to latest master.

// void*[1] reserved;
dtdword(&dt, 0);
#endif
Expand Down