Skip to content
Merged
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
71 changes: 1 addition & 70 deletions compiler/src/dmd/dmodule.d
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import dmd.dmacro;
import dmd.doc;
import dmd.dscope;
import dmd.dsymbol;
import dmd.dsymbolsem : dsymbolSemantic, importAll, load;
import dmd.dsymbolsem : dsymbolSemantic;
import dmd.errors;
import dmd.errorsink;
import dmd.expression;
Expand Down Expand Up @@ -1216,75 +1216,6 @@ extern (C++) final class Module : Package
_escapetable = new Escape();
return _escapetable;
}

/****************************
* A Singleton that loads core.stdc.config
* Returns:
* Module of core.stdc.config, null if couldn't find it
*/
extern (D) static Module loadCoreStdcConfig()
{
__gshared Module core_stdc_config;
auto pkgids = new Identifier[2];
pkgids[0] = Id.core;
pkgids[1] = Id.stdc;
return loadModuleFromLibrary(core_stdc_config, pkgids, Id.config);
}

/****************************
* A Singleton that loads core.atomic
* Returns:
* Module of core.atomic, null if couldn't find it
*/
extern (D) static Module loadCoreAtomic()
{
__gshared Module core_atomic;
auto pkgids = new Identifier[1];
pkgids[0] = Id.core;
return loadModuleFromLibrary(core_atomic, pkgids, Id.atomic);
}

/****************************
* A Singleton that loads std.math
* Returns:
* Module of std.math, null if couldn't find it
*/
extern (D) static Module loadStdMath()
{
__gshared Module std_math;
auto pkgids = new Identifier[1];
pkgids[0] = Id.std;
return loadModuleFromLibrary(std_math, pkgids, Id.math);
}

/**********************************
* Load a Module from the library.
* Params:
* mod = cached return value of this call
* pkgids = package identifiers
* modid = module id
* Returns:
* Module loaded, null if cannot load it
*/
extern (D) private static Module loadModuleFromLibrary(ref Module mod, Identifier[] pkgids, Identifier modid)
{
if (mod)
return mod;

auto imp = new Import(Loc.initial, pkgids[], modid, null, true);
// Module.load will call fatal() if there's no module available.
// Gag the error here, pushing the error handling to the caller.
const errors = global.startGagging();
imp.load(null);
if (imp.mod)
{
imp.mod.importAll(null);
imp.mod.dsymbolSemantic(null);
}
global.endGagging(errors);
mod = imp.mod;
return mod;
}
}

/***********************************************************
Expand Down
71 changes: 70 additions & 1 deletion compiler/src/dmd/dsymbolsem.d
Original file line number Diff line number Diff line change
Expand Up @@ -6109,12 +6109,81 @@ bool determineFields(AggregateDeclaration ad)
return true;
}

/****************************
* A Singleton that loads core.stdc.config
* Returns:
* Module of core.stdc.config, null if couldn't find it
*/
Module loadCoreStdcConfig()
{
__gshared Module core_stdc_config;
auto pkgids = new Identifier[2];
pkgids[0] = Id.core;
pkgids[1] = Id.stdc;
return loadModuleFromLibrary(core_stdc_config, pkgids, Id.config);
}

/****************************
* A Singleton that loads core.atomic
* Returns:
* Module of core.atomic, null if couldn't find it
*/
private Module loadCoreAtomic()
{
__gshared Module core_atomic;
auto pkgids = new Identifier[1];
pkgids[0] = Id.core;
return loadModuleFromLibrary(core_atomic, pkgids, Id.atomic);
}

/****************************
* A Singleton that loads std.math
* Returns:
* Module of std.math, null if couldn't find it
*/
Module loadStdMath()
{
__gshared Module std_math;
auto pkgids = new Identifier[1];
pkgids[0] = Id.std;
return loadModuleFromLibrary(std_math, pkgids, Id.math);
}

/**********************************
* Load a Module from the library.
* Params:
* mod = cached return value of this call
* pkgids = package identifiers
* modid = module id
* Returns:
* Module loaded, null if cannot load it
*/
extern (D) private static Module loadModuleFromLibrary(ref Module mod, Identifier[] pkgids, Identifier modid)
{
if (mod)
return mod;

auto imp = new Import(Loc.initial, pkgids[], modid, null, true);
// Module.load will call fatal() if there's no module available.
// Gag the error here, pushing the error handling to the caller.
const errors = global.startGagging();
imp.load(null);
if (imp.mod)
{
imp.mod.importAll(null);
imp.mod.dsymbolSemantic(null);
}
global.endGagging(errors);
mod = imp.mod;
return mod;
}

/// Do an atomic operation (currently tailored to [shared] static ctors|dtors) needs
private CallExp doAtomicOp (string op, Identifier var, Expression arg)
{
assert(op == "-=" || op == "+=");

Module mod = Module.loadCoreAtomic();
Module mod = loadCoreAtomic();
if (!mod)
return null; // core.atomic couldn't be loaded

Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dmd/expressionsem.d
Original file line number Diff line number Diff line change
Expand Up @@ -12931,7 +12931,7 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor
}
}

Module mmath = Module.loadStdMath();
Module mmath = loadStdMath();
if (!mmath)
{
error(e.loc, "`%s` requires `std.math` for `^^` operators", e.toErrMsg());
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dmd/typesem.d
Original file line number Diff line number Diff line change
Expand Up @@ -6365,7 +6365,7 @@ Type getComplexLibraryType(Loc loc, Scope* sc, TY ty)
return *pt;
*pt = Type.terror;

Module mConfig = Module.loadCoreStdcConfig();
Module mConfig = loadCoreStdcConfig();
if (!mConfig)
{
error(loc, "`core.stdc.config` is required for complex numbers");
Expand Down
Loading