Skip to content

Commit

Permalink
Add @safe to functions (dlang#15460)
Browse files Browse the repository at this point in the history
  • Loading branch information
dkorpel committed Jul 27, 2023
1 parent f47b4eb commit 8b42848
Show file tree
Hide file tree
Showing 54 changed files with 275 additions and 275 deletions.
2 changes: 1 addition & 1 deletion compiler/src/dmd/aggregate.d
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ enum ClassKind : ubyte
* Returns:
* 0-terminated string for `c`
*/
const(char)* toChars(ClassKind c)
const(char)* toChars(ClassKind c) @safe
{
final switch (c)
{
Expand Down
6 changes: 3 additions & 3 deletions compiler/src/dmd/argtypes_sysv_x64.d
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ enum Class : ubyte
memory
}

Class merge(Class a, Class b)
Class merge(Class a, Class b) @safe
{
bool any(Class value) { return a == value || b == value; }

Expand All @@ -140,7 +140,7 @@ struct Classification
Class[4] classes;
int numEightbytes;

const(Class[]) slice() const return { return classes[0 .. numEightbytes]; }
const(Class[]) slice() const return @safe { return classes[0 .. numEightbytes]; }
}

Classification classify(Type t, size_t size)
Expand All @@ -156,7 +156,7 @@ extern (C++) final class ToClassesVisitor : Visitor
int numEightbytes;
Class[4] result = Class.noClass;

this(size_t size) scope
this(size_t size) scope @safe
{
assert(size > 0);
this.size = size;
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dmd/cli.d
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ Params:
Returns: true iff `os` contains the current targetOS.
*/
bool isCurrentTargetOS(TargetOS os)
bool isCurrentTargetOS(TargetOS os) @safe
{
return (os & targetOS) > 0;
}
Expand Down Expand Up @@ -916,7 +916,7 @@ struct CLIUsage
Returns a string of all available CLI options for the current targetOS.
Options are separated by newlines.
*/
static string usage()
static string usage() @safe
{
enum maxFlagLength = 18;
enum s = () {
Expand Down
10 changes: 5 additions & 5 deletions compiler/src/dmd/cond.d
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ extern (C++) abstract class Condition : ASTNode
return DYNCAST.condition;
}

extern (D) this(const ref Loc loc)
extern (D) this(const ref Loc loc) @safe
{
this.loc = loc;
}
Expand Down Expand Up @@ -124,7 +124,7 @@ extern (C++) final class StaticForeach : RootObject
*/
bool needExpansion = false;

extern (D) this(const ref Loc loc, ForeachStatement aggrfe, ForeachRangeStatement rangefe)
extern (D) this(const ref Loc loc, ForeachStatement aggrfe, ForeachRangeStatement rangefe) @safe
{
assert(!!aggrfe ^ !!rangefe);

Expand Down Expand Up @@ -496,7 +496,7 @@ extern (C++) class DVCondition : Condition
Identifier ident;
Module mod;

extern (D) this(const ref Loc loc, Module mod, uint level, Identifier ident)
extern (D) this(const ref Loc loc, Module mod, uint level, Identifier ident) @safe
{
super(loc);
this.mod = mod;
Expand Down Expand Up @@ -637,7 +637,7 @@ extern (C++) final class VersionCondition : DVCondition
* Returns:
* `true` if it is reserved, `false` otherwise
*/
extern(D) private static bool isReserved(const(char)[] ident)
extern(D) private static bool isReserved(const(char)[] ident) @safe
{
// This list doesn't include "D_*" versions, see the last return
switch (ident)
Expand Down Expand Up @@ -902,7 +902,7 @@ extern (C++) final class StaticIfCondition : Condition
{
Expression exp;

extern (D) this(const ref Loc loc, Expression exp)
extern (D) this(const ref Loc loc, Expression exp) @safe
{
super(loc);
this.exp = exp;
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dmd/constfold.d
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ private Expression expType(Type type, Expression e)
* Returns:
* true if e is a constant
*/
int isConst(Expression e)
int isConst(Expression e) @safe
{
//printf("Expression::isConst(): %s\n", e.toChars());
switch (e.op)
Expand Down Expand Up @@ -1286,7 +1286,7 @@ UnionExp Slice(Type type, Expression e1, Expression lwr, Expression upr)

/* Check whether slice `[newlwr .. newupr]` is in the range `[lwr .. upr]`
*/
bool sliceBoundsCheck(uinteger_t lwr, uinteger_t upr, uinteger_t newlwr, uinteger_t newupr) pure
bool sliceBoundsCheck(uinteger_t lwr, uinteger_t upr, uinteger_t newlwr, uinteger_t newupr) pure @safe
{
assert(lwr <= upr);
return !(newlwr <= newupr &&
Expand Down
14 changes: 7 additions & 7 deletions compiler/src/dmd/cppmangle.d
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ private struct Context
* Returns:
* The previous state of this `Context` object
*/
private Context push(lazy RootObject next)
private Context push(lazy RootObject next) @safe
{
auto r = this.res;
if (r !is null)
Expand All @@ -150,7 +150,7 @@ private struct Context
/**
* Reset the context to a previous one, making any adjustment necessary
*/
private void pop(ref Context prev)
private void pop(ref Context prev) @safe
{
this.res = prev.res;
}
Expand Down Expand Up @@ -236,7 +236,7 @@ private final class CppMangleVisitor : Visitor
* See-Also:
* https://itanium-cxx-abi.github.io/cxx-abi/abi.html#mangle.seq-id
*/
private void writeSequenceFromIndex(size_t idx)
private void writeSequenceFromIndex(size_t idx) @safe
{
if (idx)
{
Expand Down Expand Up @@ -1597,7 +1597,7 @@ private final class CppMangleVisitor : Visitor
* or `params.length` if there wasn't any match.
*/
private static size_t templateParamIndex(
const ref Identifier ident, TemplateParameters* params)
const ref Identifier ident, TemplateParameters* params) @safe
{
foreach (idx, param; *params)
if (param.ident == ident)
Expand Down Expand Up @@ -2177,7 +2177,7 @@ private extern(C++) final class ComponentVisitor : Visitor
/// Set to the result of the comparison
private bool result;

public this(RootObject base)
public this(RootObject base) @safe
{
switch (base.dyncast())
{
Expand Down Expand Up @@ -2353,7 +2353,7 @@ private bool isNamespaceEqual (CPPNamespaceDeclaration a, Nspace b, size_t idx =

/// Returns:
/// Whether two `CPPNamespaceDeclaration` are equals
private bool isNamespaceEqual (CPPNamespaceDeclaration a, CPPNamespaceDeclaration b)
private bool isNamespaceEqual (CPPNamespaceDeclaration a, CPPNamespaceDeclaration b) @safe
{
if (a is null || b is null)
return false;
Expand Down Expand Up @@ -2558,7 +2558,7 @@ void leftOver(TypeFunction tf, const(Array!StringExp)* previous, Array!StringExp
private const(Array!StringExp)* ignore;

///
public this(const(Array!StringExp)* previous, Array!StringExp* toWrite)
public this(const(Array!StringExp)* previous, Array!StringExp* toWrite) @safe
{
this.ignore = previous;
this.toWrite = toWrite;
Expand Down
14 changes: 7 additions & 7 deletions compiler/src/dmd/cppmanglewin.d
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const(char)* toCppMangleMSVC(Dsymbol s)
return v.mangleOf(s);
}

const(char)* cppTypeInfoMangleMSVC(Dsymbol s)
const(char)* cppTypeInfoMangleMSVC(Dsymbol s) @safe
{
//printf("cppTypeInfoMangle(%s)\n", s.toChars());
assert(0);
Expand All @@ -59,7 +59,7 @@ const(char)* toCppMangleDMC(Dsymbol s)
return v.mangleOf(s);
}

const(char)* cppTypeInfoMangleDMC(Dsymbol s)
const(char)* cppTypeInfoMangleDMC(Dsymbol s) @safe
{
//printf("cppTypeInfoMangle(%s)\n", s.toChars());
assert(0);
Expand Down Expand Up @@ -105,7 +105,7 @@ private final class VisualCPPMangler : Visitor

OutBuffer buf;

extern (D) this(VisualCPPMangler rvl) scope
extern (D) this(VisualCPPMangler rvl) scope @safe
{
saved_idents[] = rvl.saved_idents[];
saved_types[] = rvl.saved_types[];
Expand All @@ -114,7 +114,7 @@ private final class VisualCPPMangler : Visitor
}

public:
extern (D) this(bool isDmc, Loc loc) scope
extern (D) this(bool isDmc, Loc loc) scope @safe
{
saved_idents[] = null;
saved_types[] = null;
Expand Down Expand Up @@ -857,7 +857,7 @@ extern(D):
}

// returns true if name already saved
bool checkAndSaveIdent(Identifier name)
bool checkAndSaveIdent(Identifier name) @safe
{
foreach (i, ref id; saved_idents)
{
Expand All @@ -875,7 +875,7 @@ extern(D):
return false;
}

void saveIdent(Identifier name)
void saveIdent(Identifier name) @safe
{
foreach (ref id; saved_idents)
{
Expand Down Expand Up @@ -1280,7 +1280,7 @@ void mangleNumber(ref OutBuffer buf, dinteger_t num)

/*************************************
*/
void mangleVisibility(ref OutBuffer buf, Declaration d, string privProtDef)
void mangleVisibility(ref OutBuffer buf, Declaration d, string privProtDef)@safe
{
switch (d.visibility.kind)
{
Expand Down
20 changes: 10 additions & 10 deletions compiler/src/dmd/ctfeexpr.d
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ extern (C++) final class ClassReferenceExp : Expression
* Returns:
* index of the field, or -1 if not found
*/
int findFieldIndexByName(const StructDeclaration sd, const VarDeclaration v) pure
int findFieldIndexByName(const StructDeclaration sd, const VarDeclaration v) pure @safe
{
foreach (i, field; sd.fields)
{
Expand Down Expand Up @@ -205,19 +205,19 @@ extern (C++) final class CTFEExp : Expression
*/
extern (D) __gshared CTFEExp showcontext;

extern (D) static bool isCantExp(const Expression e)
extern (D) static bool isCantExp(const Expression e) @safe
{
return e && e.op == EXP.cantExpression;
}

extern (D) static bool isGotoExp(const Expression e)
extern (D) static bool isGotoExp(const Expression e) @safe
{
return e && e.op == EXP.goto_;
}
}

// True if 'e' is CTFEExp::cantexp, or an exception
bool exceptionOrCantInterpret(const Expression e)
bool exceptionOrCantInterpret(const Expression e) @safe
{
return e && (e.op == EXP.cantExpression || e.op == EXP.thrownException || e.op == EXP.showCtfeContext);
}
Expand Down Expand Up @@ -1068,25 +1068,25 @@ private bool numCmp(N)(EXP op, N n1, N n2)
}

/// Returns cmp OP 0; where OP is ==, !=, <, >=, etc. Result is 0 or 1
bool specificCmp(EXP op, int rawCmp)
bool specificCmp(EXP op, int rawCmp) @safe
{
return numCmp!int(op, rawCmp, 0);
}

/// Returns e1 OP e2; where OP is ==, !=, <, >=, etc. Result is 0 or 1
bool intUnsignedCmp(EXP op, dinteger_t n1, dinteger_t n2)
bool intUnsignedCmp(EXP op, dinteger_t n1, dinteger_t n2) @safe
{
return numCmp!dinteger_t(op, n1, n2);
}

/// Returns e1 OP e2; where OP is ==, !=, <, >=, etc. Result is 0 or 1
bool intSignedCmp(EXP op, sinteger_t n1, sinteger_t n2)
bool intSignedCmp(EXP op, sinteger_t n1, sinteger_t n2) @safe
{
return numCmp!sinteger_t(op, n1, n2);
}

/// Returns e1 OP e2; where OP is ==, !=, <, >=, etc. Result is 0 or 1
bool realCmp(EXP op, real_t r1, real_t r2)
bool realCmp(EXP op, real_t r1, real_t r2) @safe
{
// Don't rely on compiler, handle NAN arguments separately
if (CTFloat.isNaN(r1) || CTFloat.isNaN(r2)) // if unordered
Expand Down Expand Up @@ -1176,7 +1176,7 @@ private int ctfeCmpArrays(const ref Loc loc, Expression e1, Expression e2, uinte
/* Given a delegate expression e, return .funcptr.
* If e is NullExp, return NULL.
*/
private FuncDeclaration funcptrOf(Expression e)
private FuncDeclaration funcptrOf(Expression e) @safe
{
assert(e.type.ty == Tdelegate);
if (auto de = e.isDelegateExp())
Expand All @@ -1187,7 +1187,7 @@ private FuncDeclaration funcptrOf(Expression e)
return null;
}

private bool isArray(const Expression e)
private bool isArray(const Expression e) @safe
{
return e.op == EXP.arrayLiteral || e.op == EXP.string_ || e.op == EXP.slice || e.op == EXP.null_;
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dmd/ctorflow.d
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ struct CtorFlow
* Returns:
* false means one of the paths skips construction
*/
bool mergeCallSuper(ref CSX a, const CSX b) pure nothrow
bool mergeCallSuper(ref CSX a, const CSX b) pure nothrow @safe
{
// This does a primitive flow analysis to support the restrictions
// regarding when and how constructors can appear.
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dmd/dclass.d
Original file line number Diff line number Diff line change
Expand Up @@ -1130,7 +1130,7 @@ extern (C++) final class InterfaceDeclaration : ClassDeclaration
* Returns:
* true if the `bc` implements `id`, false otherwise
**/
private bool baseClassImplementsInterface(InterfaceDeclaration id, BaseClass* bc, int* poffset) pure nothrow @nogc
private bool baseClassImplementsInterface(InterfaceDeclaration id, BaseClass* bc, int* poffset) pure nothrow @nogc @safe
{
//printf("%s.InterfaceDeclaration.isBaseOf(bc = '%s')\n", id.toChars(), bc.sym.toChars());
for (size_t j = 0; j < bc.baseInterfaces.length; j++)
Expand Down
10 changes: 5 additions & 5 deletions compiler/src/dmd/dinterpret.d
Original file line number Diff line number Diff line change
Expand Up @@ -280,19 +280,19 @@ private:
Expression localThis; // value of 'this', or NULL if none

public:
size_t stackPointer()
size_t stackPointer() @safe
{
return values.length;
}

// The current value of 'this', or NULL if none
Expression getThis()
Expression getThis() @safe
{
return localThis;
}

// Largest number of stack positions we've used
size_t maxStackUsage()
size_t maxStackUsage() @safe
{
return maxStackPointer;
}
Expand Down Expand Up @@ -1646,7 +1646,7 @@ public:
Expression result;
UnionExp* pue; // storage for `result`

extern (D) this(UnionExp* pue, InterState* istate, CTFEGoal goal) scope
extern (D) this(UnionExp* pue, InterState* istate, CTFEGoal goal) scope @safe
{
this.pue = pue;
this.istate = istate;
Expand Down Expand Up @@ -3246,7 +3246,7 @@ public:
*/
// Returns the variable which is eventually modified, or NULL if an rvalue.
// thisval is the current value of 'this'.
static VarDeclaration findParentVar(Expression e)
static VarDeclaration findParentVar(Expression e) @safe
{
for (;;)
{
Expand Down
Loading

0 comments on commit 8b42848

Please sign in to comment.