Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions compiler/src/dmd/dimport.d
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ extern (C++) final class Import : Dsymbol
// corresponding AliasDeclarations for alias=name pairs
AliasDeclarations aliasdecls;

bool forceCodegen; // whether codegen should be forced for the imported module

extern (D) this(const ref Loc loc, Identifier[] packages, Identifier id, Identifier aliasId, int isstatic)
{
Identifier selectIdent()
Expand Down
1 change: 1 addition & 0 deletions compiler/src/dmd/dmodule.d
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ extern (C++) final class Module : Package
Package pkg; // if isPackageFile is true, the Package that contains this package.d
Strings contentImportedFiles; // array of files whose content was imported
int needmoduleinfo;
bool forceCodegen; // if codegen should take place for this module, even if it normally wouldn't
private ThreeState selfimports;
private ThreeState rootimports;
Dsymbol[void*] tagSymTab; /// ImportC: tag symbols that conflict with other symbols used as the index
Expand Down
12 changes: 10 additions & 2 deletions compiler/src/dmd/dsymbolsem.d
Original file line number Diff line number Diff line change
Expand Up @@ -7020,8 +7020,16 @@ extern (D) bool load(Import imp, Scope* sc)
dst.insert(imp.id, imp.mod);
}
}
if (imp.mod && !imp.mod.importedFrom)
imp.mod.importedFrom = sc ? sc._module.importedFrom : Module.rootModule;
if (imp.mod)
{
if (imp.forceCodegen)
imp.mod.forceCodegen = true;
// if codegen is forced, promote imp.mod to a root module, so that codegen takes place
if (imp.mod.forceCodegen)
imp.mod.importedFrom = imp.mod;
else if (!imp.mod.importedFrom)
imp.mod.importedFrom = sc ? sc._module.importedFrom : Module.rootModule;
}
if (!imp.pkg)
{
if (imp.mod && imp.mod.isPackageFile)
Expand Down
2 changes: 2 additions & 0 deletions compiler/src/dmd/frontend.h
Original file line number Diff line number Diff line change
Expand Up @@ -7032,6 +7032,7 @@ class Import final : public Dsymbol
Module* mod;
Package* pkg;
Array<AliasDeclaration* > aliasdecls;
bool forceCodegen;
const char* kind() const override;
Visibility visible() override;
Import* syntaxCopy(Dsymbol* s) override;
Expand Down Expand Up @@ -7086,6 +7087,7 @@ class Module final : public Package
Package* pkg;
Array<const char* > contentImportedFiles;
int32_t needmoduleinfo;
bool forceCodegen;
private:
ThreeState selfimports;
ThreeState rootimports;
Expand Down
16 changes: 16 additions & 0 deletions compiler/src/dmd/main.d
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,22 @@ private int tryMain(size_t argc, const(char)** argv, ref Param params)
}
}
Module.runDeferredSemantic3();

// Ensure codegen is performed for modules where codegen is forced
for (size_t i = 0; i < Module.amodules.length; ++i)
{
auto m = Module.amodules[i];
if (m.forceCodegen && m.semanticRun != PASS.semantic3done)
{
assert(m.isRoot());
if (params.v.verbose)
message("semantic3 %s", m.toChars());
m.semantic3(null);
modules.push(m);
}
}
Module.runDeferredSemantic3();

if (global.errors)
removeHdrFilesAndFail(params, modules);

Expand Down