From eb5388efcf5e2695e754ad4a6575eab1493aff1d Mon Sep 17 00:00:00 2001 From: Dennis Korpel Date: Thu, 27 Jul 2023 13:03:41 +0200 Subject: [PATCH] Add `@safe` to functions --- compiler/src/dmd/aggregate.d | 2 +- compiler/src/dmd/argtypes_sysv_x64.d | 6 +- compiler/src/dmd/cli.d | 4 +- compiler/src/dmd/cond.d | 10 +-- compiler/src/dmd/constfold.d | 4 +- compiler/src/dmd/cppmangle.d | 14 ++-- compiler/src/dmd/cppmanglewin.d | 14 ++-- compiler/src/dmd/ctfeexpr.d | 20 +++--- compiler/src/dmd/ctorflow.d | 2 +- compiler/src/dmd/dclass.d | 2 +- compiler/src/dmd/dinterpret.d | 10 +-- compiler/src/dmd/dmangle.d | 8 +-- compiler/src/dmd/dmdparams.d | 6 +- compiler/src/dmd/dmodule.d | 2 +- compiler/src/dmd/dmsc.d | 2 +- compiler/src/dmd/doc.d | 58 ++++++++-------- compiler/src/dmd/dscope.d | 2 +- compiler/src/dmd/dsymbolsem.d | 4 +- compiler/src/dmd/dtemplate.d | 2 +- compiler/src/dmd/dtoh.d | 20 +++--- compiler/src/dmd/expressionsem.d | 2 +- compiler/src/dmd/globals.d | 12 ++-- compiler/src/dmd/hdrgen.d | 12 ++-- compiler/src/dmd/iasmdmd.d | 12 ++-- compiler/src/dmd/id.d | 8 +-- compiler/src/dmd/imphint.d | 2 +- compiler/src/dmd/init.d | 14 ++-- compiler/src/dmd/inline.d | 6 +- compiler/src/dmd/inlinecost.d | 8 +-- compiler/src/dmd/intrange.d | 50 +++++++------- compiler/src/dmd/json.d | 2 +- compiler/src/dmd/libmscoff.d | 6 +- compiler/src/dmd/link.d | 2 +- compiler/src/dmd/location.d | 2 +- compiler/src/dmd/mtype.d | 12 ++-- compiler/src/dmd/ob.d | 6 +- compiler/src/dmd/objc.d | 6 +- compiler/src/dmd/objc_glue.d | 20 +++--- compiler/src/dmd/opover.d | 4 +- compiler/src/dmd/printast.d | 2 +- compiler/src/dmd/root/complex.d | 8 +-- compiler/src/dmd/root/utf.d | 10 +-- compiler/src/dmd/s2ir.d | 2 +- compiler/src/dmd/semantic2.d | 2 +- compiler/src/dmd/semantic3.d | 4 +- compiler/src/dmd/statement.d | 100 +++++++++++++-------------- compiler/src/dmd/statementsem.d | 2 +- compiler/src/dmd/target.d | 28 ++++---- compiler/src/dmd/templateparamsem.d | 2 +- compiler/src/dmd/tocsym.d | 2 +- compiler/src/dmd/toctype.d | 2 +- compiler/src/dmd/tocvdebug.d | 2 +- compiler/src/dmd/toir.d | 4 +- compiler/src/dmd/toobj.d | 2 +- 54 files changed, 275 insertions(+), 275 deletions(-) diff --git a/compiler/src/dmd/aggregate.d b/compiler/src/dmd/aggregate.d index 42b926be4535..4ae6b6bc5cc2 100644 --- a/compiler/src/dmd/aggregate.d +++ b/compiler/src/dmd/aggregate.d @@ -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) { diff --git a/compiler/src/dmd/argtypes_sysv_x64.d b/compiler/src/dmd/argtypes_sysv_x64.d index 835544d2c461..1ef32fcdf914 100644 --- a/compiler/src/dmd/argtypes_sysv_x64.d +++ b/compiler/src/dmd/argtypes_sysv_x64.d @@ -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; } @@ -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) @@ -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; diff --git a/compiler/src/dmd/cli.d b/compiler/src/dmd/cli.d index 9aef0b0b50dc..694456f03d71 100644 --- a/compiler/src/dmd/cli.d +++ b/compiler/src/dmd/cli.d @@ -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; } @@ -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 = () { diff --git a/compiler/src/dmd/cond.d b/compiler/src/dmd/cond.d index 467f9f1a9901..3df72448a044 100644 --- a/compiler/src/dmd/cond.d +++ b/compiler/src/dmd/cond.d @@ -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; } @@ -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); @@ -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; @@ -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) @@ -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; diff --git a/compiler/src/dmd/constfold.d b/compiler/src/dmd/constfold.d index 415606bd704e..e5526a1c9aaa 100644 --- a/compiler/src/dmd/constfold.d +++ b/compiler/src/dmd/constfold.d @@ -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) @@ -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 && diff --git a/compiler/src/dmd/cppmangle.d b/compiler/src/dmd/cppmangle.d index ee1340d63427..54e43c428485 100644 --- a/compiler/src/dmd/cppmangle.d +++ b/compiler/src/dmd/cppmangle.d @@ -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) @@ -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; } @@ -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) { @@ -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) @@ -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()) { @@ -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; @@ -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; diff --git a/compiler/src/dmd/cppmanglewin.d b/compiler/src/dmd/cppmanglewin.d index 880e6e28335f..bc26b20d451c 100644 --- a/compiler/src/dmd/cppmanglewin.d +++ b/compiler/src/dmd/cppmanglewin.d @@ -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); @@ -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); @@ -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[]; @@ -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; @@ -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) { @@ -875,7 +875,7 @@ extern(D): return false; } - void saveIdent(Identifier name) + void saveIdent(Identifier name) @safe { foreach (ref id; saved_idents) { @@ -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) { diff --git a/compiler/src/dmd/ctfeexpr.d b/compiler/src/dmd/ctfeexpr.d index 289ebeb81ca9..10c5cb006eeb 100644 --- a/compiler/src/dmd/ctfeexpr.d +++ b/compiler/src/dmd/ctfeexpr.d @@ -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) { @@ -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); } @@ -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 @@ -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()) @@ -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_; } diff --git a/compiler/src/dmd/ctorflow.d b/compiler/src/dmd/ctorflow.d index a3953af6ce87..44530a554815 100644 --- a/compiler/src/dmd/ctorflow.d +++ b/compiler/src/dmd/ctorflow.d @@ -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. diff --git a/compiler/src/dmd/dclass.d b/compiler/src/dmd/dclass.d index 1b8e8ef18801..20cb82e1a36e 100644 --- a/compiler/src/dmd/dclass.d +++ b/compiler/src/dmd/dclass.d @@ -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++) diff --git a/compiler/src/dmd/dinterpret.d b/compiler/src/dmd/dinterpret.d index e0d8a44fe1f4..228245db5713 100644 --- a/compiler/src/dmd/dinterpret.d +++ b/compiler/src/dmd/dinterpret.d @@ -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; } @@ -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; @@ -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 (;;) { diff --git a/compiler/src/dmd/dmangle.d b/compiler/src/dmd/dmangle.d index ad1e81656683..ad872c99c744 100644 --- a/compiler/src/dmd/dmangle.d +++ b/compiler/src/dmd/dmangle.d @@ -564,7 +564,7 @@ public: OutBuffer* buf; Backref* backref; - extern (D) this(OutBuffer* buf, Backref* backref) + extern (D) this(OutBuffer* buf, Backref* backref) @safe { this.buf = buf; this.backref = backref; @@ -1214,7 +1214,7 @@ private struct Backref * Mangle basic type ty to buf. */ -private void tyToDecoBuffer(OutBuffer* buf, int ty) +private void tyToDecoBuffer(OutBuffer* buf, int ty) @safe { const c = mangleChar[ty]; buf.writeByte(c); @@ -1225,7 +1225,7 @@ private void tyToDecoBuffer(OutBuffer* buf, int ty) /********************************* * Mangling for mod. */ -private void MODtoDecoBuffer(OutBuffer* buf, MOD mod) +private void MODtoDecoBuffer(OutBuffer* buf, MOD mod) @safe { switch (mod) { @@ -1274,7 +1274,7 @@ private void MODtoDecoBuffer(OutBuffer* buf, MOD mod) * pos = relative position to encode */ private -void writeBackRef(OutBuffer* buf, size_t pos) +void writeBackRef(OutBuffer* buf, size_t pos) @safe { buf.writeByte('Q'); enum base = 26; diff --git a/compiler/src/dmd/dmdparams.d b/compiler/src/dmd/dmdparams.d index 9a25bbaa7896..94e02cfc234f 100644 --- a/compiler/src/dmd/dmdparams.d +++ b/compiler/src/dmd/dmdparams.d @@ -163,7 +163,7 @@ struct Triple } // try parsing vendor if present - bool tryParseVendor(const(char)[] vendor) + bool tryParseVendor(const(char)[] vendor) @safe { switch (vendor) { @@ -240,7 +240,7 @@ struct Triple * Returns: * parsed number */ - private pure static + private pure @safe static uint parseNumber(ref const(char)[] str, ref bool overflow) { auto s = str; @@ -295,7 +295,7 @@ struct Triple } } -void setTriple(ref Target target, const ref Triple triple) +void setTriple(ref Target target, const ref Triple triple) @safe { target.cpu = triple.cpu; target.isX86_64 = triple.isX86_64; diff --git a/compiler/src/dmd/dmodule.d b/compiler/src/dmd/dmodule.d index f00dec7a4e30..d3a9d1794aa9 100644 --- a/compiler/src/dmd/dmodule.d +++ b/compiler/src/dmd/dmodule.d @@ -1380,7 +1380,7 @@ extern (C++) struct ModuleDeclaration bool isdeprecated; // if it is a deprecated module Expression msg; - extern (D) this(const ref Loc loc, Identifier[] packages, Identifier id, Expression msg, bool isdeprecated) + extern (D) this(const ref Loc loc, Identifier[] packages, Identifier id, Expression msg, bool isdeprecated) @safe { this.loc = loc; this.packages = packages; diff --git a/compiler/src/dmd/dmsc.d b/compiler/src/dmd/dmsc.d index 0693d58ad73f..f6842c7c055c 100644 --- a/compiler/src/dmd/dmsc.d +++ b/compiler/src/dmd/dmsc.d @@ -104,6 +104,6 @@ void backend_init() /************************************** */ -void backend_term() +void backend_term() @safe { } diff --git a/compiler/src/dmd/doc.d b/compiler/src/dmd/doc.d index 3e60dc4f9d87..1952c96d2526 100644 --- a/compiler/src/dmd/doc.d +++ b/compiler/src/dmd/doc.d @@ -62,7 +62,7 @@ struct Escape /*************************************** * Find character string to replace c with. */ - const(char)[] escapeChar(char c) + const(char)[] escapeChar(char c) @safe { version (all) { @@ -355,7 +355,7 @@ private Dsymbol getEponymousMember(TemplateDeclaration td) @safe return null; } -private TemplateDeclaration getEponymousParent(Dsymbol s) +private TemplateDeclaration getEponymousParent(Dsymbol s) @safe { if (!s.parent) return null; @@ -683,7 +683,7 @@ private void escapeStrayParenthesis(Loc loc, OutBuffer* buf, size_t start, bool // Basically, this is to skip over things like private{} blocks in a struct or // class definition that don't add any components to the qualified name. -private Scope* skipNonQualScopes(Scope* sc) +private Scope* skipNonQualScopes(Scope* sc) @safe { while (sc && !sc.scopesym) sc = sc.enclosing; @@ -1398,7 +1398,7 @@ private void toDocBuffer(Dsymbol s, ref OutBuffer buf, Scope* sc) } } - static bool inSameModule(Dsymbol s, Dsymbol p) + static bool inSameModule(Dsymbol s, Dsymbol p) @safe { for (; s; s = s.parent) { @@ -1968,7 +1968,7 @@ private const(char)* skipwhitespace(const(char)* p) } /// Ditto -private const(char)[] skipwhitespace(const(char)[] p) +private const(char)[] skipwhitespace(const(char)[] p) @safe { foreach (idx, char c; p) { @@ -1993,7 +1993,7 @@ private const(char)[] skipwhitespace(const(char)[] p) * chars = the characters to skip; order is unimportant * Returns: the index after skipping characters. */ -private size_t skipChars(ref OutBuffer buf, size_t i, string chars) +private size_t skipChars(ref OutBuffer buf, size_t i, string chars) @safe { Outer: foreach (j, c; buf[][i..$]) @@ -2028,7 +2028,7 @@ unittest { * r = the string to replace `c` with * Returns: `s` with `c` replaced with `r` */ -private inout(char)[] replaceChar(inout(char)[] s, char c, string r) pure +private inout(char)[] replaceChar(inout(char)[] s, char c, string r) pure @safe { int count = 0; foreach (char sc; s) @@ -2070,7 +2070,7 @@ unittest * s = the string to lowercase * Returns: the lowercase version of the string or the original if already lowercase */ -private string toLowercase(string s) pure +private string toLowercase(string s) pure @safe { string lower; foreach (size_t i; 0..s.length) @@ -2112,7 +2112,7 @@ unittest * to = the index within `buf` to stop counting at, exclusive * Returns: the indent */ -private int getMarkdownIndent(ref OutBuffer buf, size_t from, size_t to) +private int getMarkdownIndent(ref OutBuffer buf, size_t from, size_t to) @safe { const slice = buf[]; if (to > slice.length) @@ -2129,7 +2129,7 @@ private int getMarkdownIndent(ref OutBuffer buf, size_t from, size_t to) * beginning of next line * end of buf */ -size_t skiptoident(ref OutBuffer buf, size_t i) +size_t skiptoident(ref OutBuffer buf, size_t i) @safe { const slice = buf[]; while (i < slice.length) @@ -2158,7 +2158,7 @@ size_t skiptoident(ref OutBuffer buf, size_t i) /************************************************ * Scan forward past end of identifier. */ -private size_t skippastident(ref OutBuffer buf, size_t i) +private size_t skippastident(ref OutBuffer buf, size_t i) @safe { const slice = buf[]; while (i < slice.length) @@ -2188,7 +2188,7 @@ private size_t skippastident(ref OutBuffer buf, size_t i) * Scan forward past end of an identifier that might * contain dots (e.g. `abc.def`) */ -private size_t skipPastIdentWithDots(ref OutBuffer buf, size_t i) +private size_t skipPastIdentWithDots(ref OutBuffer buf, size_t i) @safe { const slice = buf[]; bool lastCharWasDot; @@ -2356,7 +2356,7 @@ private bool replaceMarkdownThematicBreak(ref OutBuffer buf, ref size_t i, size_ * the detected heading level from 1 to 6, or * 0 if not at an ATX heading */ -private int detectAtxHeadingLevel(ref OutBuffer buf, const size_t i) +private int detectAtxHeadingLevel(ref OutBuffer buf, const size_t i) @safe { const iHeadingStart = i; const iAfterHashes = skipChars(buf, i, "#"); @@ -2566,7 +2566,7 @@ private size_t replaceMarkdownEmphasis(ref OutBuffer buf, const ref Loc loc, ref /**************************************************** */ -private bool isIdentifier(Dsymbols* a, const(char)[] s) +private bool isIdentifier(Dsymbols* a, const(char)[] s) @safe { foreach (member; *a) { @@ -2744,7 +2744,7 @@ private TemplateParameter isTemplateParameter(Dsymbols* a, const(char)* p, size_ * Return true if str is a reserved symbol name * that starts with a double underscore. */ -private bool isReservedName(const(char)[] str) +private bool isReservedName(const(char)[] str) @safe { immutable string[] table = [ @@ -2802,10 +2802,10 @@ private struct MarkdownDelimiter char type; /// the type of delimiter, defined by its starting character /// whether this describes a valid delimiter - @property bool isValid() const { return count != 0; } + @property bool isValid() const @safe { return count != 0; } /// flag this delimiter as invalid - void invalidate() { count = 0; } + void invalidate() @safe { count = 0; } } /**************************************************** @@ -2822,7 +2822,7 @@ private struct MarkdownList char type; /// the type of list, defined by its starting character /// whether this describes a valid list - @property bool isValid() const { return type != type.init; } + @property bool isValid() const @safe { return type != type.init; } /**************************************************** * Try to parse a list item, returning whether successful. @@ -2832,7 +2832,7 @@ private struct MarkdownList * i = the index within `buf` of the potential list item * Returns: the parsed list item. Its `isValid` property describes whether parsing succeeded. */ - static MarkdownList parseItem(ref OutBuffer buf, size_t iLineStart, size_t i) + static MarkdownList parseItem(ref OutBuffer buf, size_t iLineStart, size_t i) @safe { if (buf[i] == '+' || buf[i] == '-' || buf[i] == '*') return parseUnorderedListItem(buf, iLineStart, i); @@ -2848,7 +2848,7 @@ private struct MarkdownList * i = the index within `buf` of the list item * Returns: whether `i` is at a list item of the same type as this list */ - private bool isAtItemInThisList(ref OutBuffer buf, size_t iLineStart, size_t i) + private bool isAtItemInThisList(ref OutBuffer buf, size_t iLineStart, size_t i) @safe { MarkdownList item = (type == '.' || type == ')') ? parseOrderedListItem(buf, iLineStart, i) : @@ -2970,7 +2970,7 @@ private struct MarkdownList * i = the index within `buf` of the list item * Returns: the parsed list item, or a list item with type `.init` if no list item is available */ - private static MarkdownList parseUnorderedListItem(ref OutBuffer buf, size_t iLineStart, size_t i) + private static MarkdownList parseUnorderedListItem(ref OutBuffer buf, size_t iLineStart, size_t i) @safe { if (i+1 < buf.length && (buf[i] == '-' || @@ -2998,7 +2998,7 @@ private struct MarkdownList * i = the index within `buf` of the list item * Returns: the parsed list item, or a list item with type `.init` if no list item is available */ - private static MarkdownList parseOrderedListItem(ref OutBuffer buf, size_t iLineStart, size_t i) + private static MarkdownList parseOrderedListItem(ref OutBuffer buf, size_t iLineStart, size_t i) @safe { size_t iAfterNumbers = skipChars(buf, i, "0123456789"); if (iAfterNumbers - i > 0 && @@ -3156,7 +3156,7 @@ private struct MarkdownLink * delimiter = the delimiter that starts this link * Returns: the index at the end of parsing the link, or `i` if parsing failed. */ - private size_t parseReferenceLink(ref OutBuffer buf, size_t i, MarkdownDelimiter delimiter) + private size_t parseReferenceLink(ref OutBuffer buf, size_t i, MarkdownDelimiter delimiter) @safe { size_t iStart = i + 1; size_t iEnd = iStart; @@ -3233,7 +3233,7 @@ private struct MarkdownLink * If this function returns a non-empty label then `i` will point just after the ']' at the end of the label. * Returns: the parsed and normalized label, possibly empty */ - private bool parseLabel(ref OutBuffer buf, ref size_t i) + private bool parseLabel(ref OutBuffer buf, ref size_t i) @safe { if (buf[i] != '[') return false; @@ -3506,7 +3506,7 @@ private struct MarkdownLink * s = the string to remove escaping backslashes from * Returns: `s` without escaping backslashes in it */ - private static char[] removeEscapeBackslashes(char[] s) + private static char[] removeEscapeBackslashes(char[] s) @safe { if (!s.length) return s; @@ -3550,7 +3550,7 @@ private struct MarkdownLink * s = the string to percent-encode * Returns: `s` with special characters percent-encoded */ - private static inout(char)[] percentEncode(inout(char)[] s) pure + private static inout(char)[] percentEncode(inout(char)[] s) pure @safe { static bool shouldEncode(char c) { @@ -3591,7 +3591,7 @@ private struct MarkdownLink * If this function succeeds `i` will point after the newline. * Returns: whether a newline was skipped */ - private static bool skipOneNewline(ref OutBuffer buf, ref size_t i) pure + private static bool skipOneNewline(ref OutBuffer buf, ref size_t i) pure @safe { if (i < buf.length && buf[i] == '\r') ++i; @@ -3786,7 +3786,7 @@ private struct MarkdownLinkReferences * delimiter = the character to split by * Returns: the resulting array of strings */ - private static string[] split(string s, char delimiter) pure + private static string[] split(string s, char delimiter) pure @safe { string[] result; size_t iStart = 0; @@ -3893,7 +3893,7 @@ private enum TableColumnAlignment * columnAlignments = alignments to populate for each column * Returns: the index of the end of the parsed delimiter, or `0` if not found */ -private size_t parseTableDelimiterRow(ref OutBuffer buf, const size_t iStart, bool inQuote, ref TableColumnAlignment[] columnAlignments) +private size_t parseTableDelimiterRow(ref OutBuffer buf, const size_t iStart, bool inQuote, ref TableColumnAlignment[] columnAlignments) @safe { size_t i = skipChars(buf, iStart, inQuote ? ">| \t" : "| \t"); while (i < buf.length && buf[i] != '\r' && buf[i] != '\n') diff --git a/compiler/src/dmd/dscope.d b/compiler/src/dmd/dscope.d index 95cfec9c2b9e..e94c6029cc54 100644 --- a/compiler/src/dmd/dscope.d +++ b/compiler/src/dmd/dscope.d @@ -614,7 +614,7 @@ extern (C++) struct Scope * Returns: * innermost scope, null if none */ - extern (D) Scope* inner() return + extern (D) Scope* inner() return @safe { for (Scope* sc = &this; sc; sc = sc.enclosing) { diff --git a/compiler/src/dmd/dsymbolsem.d b/compiler/src/dmd/dsymbolsem.d index 9742978ded09..d8d45496838d 100644 --- a/compiler/src/dmd/dsymbolsem.d +++ b/compiler/src/dmd/dsymbolsem.d @@ -274,7 +274,7 @@ private extern(C++) final class DsymbolSemanticVisitor : Visitor alias visit = Visitor.visit; Scope* sc; - this(Scope* sc) scope + this(Scope* sc) scope @safe { this.sc = sc; } @@ -6085,7 +6085,7 @@ void templateInstanceSemantic(TemplateInstance tempinst, Scope* sc, ArgumentList alias visit = Visitor.visit; TemplateInstance inst; - extern (D) this(TemplateInstance inst) scope + extern (D) this(TemplateInstance inst) scope @safe { this.inst = inst; } diff --git a/compiler/src/dmd/dtemplate.d b/compiler/src/dmd/dtemplate.d index f2ab69444bc4..739d2bea3028 100644 --- a/compiler/src/dmd/dtemplate.d +++ b/compiler/src/dmd/dtemplate.d @@ -84,7 +84,7 @@ private enum LOG = false; enum IDX_NOTFOUND = 0x12345678; -pure nothrow @nogc +pure nothrow @nogc @safe { /******************************************** diff --git a/compiler/src/dmd/dtoh.d b/compiler/src/dmd/dtoh.d index 17e019b5bc4c..d2dba02dd6b9 100644 --- a/compiler/src/dmd/dtoh.d +++ b/compiler/src/dmd/dtoh.d @@ -395,7 +395,7 @@ public: } /// Writes a final `;` and insert an empty line outside of aggregates - private void writeDeclEnd() + private void writeDeclEnd() @safe { buf.writestringln(";"); @@ -1212,7 +1212,7 @@ public: buf.writestringln("};"); } - private bool memberField(AST.VarDeclaration vd) + private bool memberField(AST.VarDeclaration vd) @safe { if (!vd.type || !vd.type.deco || !vd.ident) return false; @@ -1410,7 +1410,7 @@ public: /// Ends a custom alignment section using `#pragma pack` if /// `alignment` specifies a custom alignment - private void popAlignToBuffer(structalign_t alignment) + private void popAlignToBuffer(structalign_t alignment) @safe { if (alignment.isDefault() || (tdparent && alignment.isUnknown())) return; @@ -3037,7 +3037,7 @@ public: } /// Returns: Explicit mangling for `sym` if present - extern(D) static const(char)[] getMangleOverride(const AST.Dsymbol sym) + extern(D) static const(char)[] getMangleOverride(const AST.Dsymbol sym) @safe { if (auto decl = sym.isDeclaration()) return decl.mangleOverride; @@ -3089,34 +3089,34 @@ void initialize() } /// Writes `#if ` into the supplied buffer -void hashIf(ref OutBuffer buf, string content) +void hashIf(ref OutBuffer buf, string content) @safe { buf.writestring("#if "); buf.writestringln(content); } /// Writes `#elif ` into the supplied buffer -void hashElIf(ref OutBuffer buf, string content) +void hashElIf(ref OutBuffer buf, string content) @safe { buf.writestring("#elif "); buf.writestringln(content); } /// Writes `#endif` into the supplied buffer -void hashEndIf(ref OutBuffer buf) +void hashEndIf(ref OutBuffer buf) @safe { buf.writestringln("#endif"); } /// Writes `#define ` into the supplied buffer -void hashDefine(ref OutBuffer buf, string content) +void hashDefine(ref OutBuffer buf, string content) @safe { buf.writestring("#define "); buf.writestringln(content); } /// Writes `#include ` into the supplied buffer -void hashInclude(ref OutBuffer buf, string content) +void hashInclude(ref OutBuffer buf, string content) @safe { buf.writestring("#include "); buf.writestringln(content); @@ -3231,7 +3231,7 @@ ASTCodegen.Dsymbol outermostSymbol(ASTCodegen.Dsymbol sym) /// Fetches the symbol for user-defined types from the type `t` /// if `t` is either `TypeClass`, `TypeStruct` or `TypeEnum` -ASTCodegen.Dsymbol symbolFromType(ASTCodegen.Type t) +ASTCodegen.Dsymbol symbolFromType(ASTCodegen.Type t) @safe { if (auto tc = t.isTypeClass()) return tc.sym; diff --git a/compiler/src/dmd/expressionsem.d b/compiler/src/dmd/expressionsem.d index 90dc48bcf3e3..46776f44b72c 100644 --- a/compiler/src/dmd/expressionsem.d +++ b/compiler/src/dmd/expressionsem.d @@ -2609,7 +2609,7 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor Scope* sc; Expression result; - this(Scope* sc) scope + this(Scope* sc) scope @safe { this.sc = sc; } diff --git a/compiler/src/dmd/globals.d b/compiler/src/dmd/globals.d index 26fedf52c865..6fad8a30ba68 100644 --- a/compiler/src/dmd/globals.d +++ b/compiler/src/dmd/globals.d @@ -297,7 +297,7 @@ extern (C++) struct Global * * Returns: the current number of gagged errors, which should later be passed to `endGagging` */ - extern (C++) uint startGagging() + extern (C++) uint startGagging() @safe { ++gag; gaggedWarnings = 0; @@ -311,7 +311,7 @@ extern (C++) struct Global * oldGagged = the previous number of errors, as returned by `startGagging` * Returns: true if errors occurred while gagged. */ - extern (C++) bool endGagging(uint oldGagged) + extern (C++) bool endGagging(uint oldGagged) @safe { bool anyErrs = (gaggedErrors != oldGagged); --gag; @@ -327,7 +327,7 @@ extern (C++) struct Global * * An error message may or may not have been printed. */ - extern (C++) void increaseErrorCount() + extern (C++) void increaseErrorCount() @safe { if (gag) ++gaggedErrors; @@ -397,7 +397,7 @@ extern (C++) struct Global /** * Computes the version number __VERSION__ from the compiler version string. */ - extern (D) private static uint parseVersionNumber(string version_) + extern (D) private static uint parseVersionNumber(string version_) @safe { // // parse _version @@ -429,7 +429,7 @@ extern (C++) struct Global /** Returns: the version as the number that would be returned for __VERSION__ */ - extern(C++) uint versionNumber() + extern(C++) uint versionNumber() @safe { return compileEnv.versionNumber; } @@ -437,7 +437,7 @@ extern (C++) struct Global /** Returns: compiler version string. */ - extern(D) string versionString() + extern(D) string versionString() @safe { return _version; } diff --git a/compiler/src/dmd/hdrgen.d b/compiler/src/dmd/hdrgen.d index 62e0d49fdd5f..2b0e7106746f 100644 --- a/compiler/src/dmd/hdrgen.d +++ b/compiler/src/dmd/hdrgen.d @@ -805,7 +805,7 @@ public: OutBuffer* buf; HdrGenState* hgs; - extern (D) this(OutBuffer* buf, HdrGenState* hgs) scope + extern (D) this(OutBuffer* buf, HdrGenState* hgs) scope @safe { this.buf = buf; this.hgs = hgs; @@ -2775,7 +2775,7 @@ public: OutBuffer* buf; HdrGenState* hgs; - extern (D) this(OutBuffer* buf, HdrGenState* hgs) scope + extern (D) this(OutBuffer* buf, HdrGenState* hgs) scope @safe { this.buf = buf; this.hgs = hgs; @@ -2856,7 +2856,7 @@ public: OutBuffer* buf; HdrGenState* hgs; - extern (D) this(OutBuffer* buf, HdrGenState* hgs) scope + extern (D) this(OutBuffer* buf, HdrGenState* hgs) scope @safe { this.buf = buf; this.hgs = hgs; @@ -2980,7 +2980,7 @@ bool stcToBuffer(OutBuffer* buf, StorageClass stc) * and return a string representation of it. * stc is reduced by the one picked. */ -string stcToString(ref StorageClass stc) +string stcToString(ref StorageClass stc) @safe { static struct SCstring { @@ -3056,7 +3056,7 @@ const(char)* linkageToChars(LINK linkage) return linkageToString(linkage).ptr; } -string linkageToString(LINK linkage) pure nothrow +string linkageToString(LINK linkage) pure nothrow @safe { final switch (linkage) { @@ -3099,7 +3099,7 @@ const(char)* visibilityToChars(Visibility.Kind kind) } /// Ditto -extern (D) string visibilityToString(Visibility.Kind kind) nothrow pure +extern (D) string visibilityToString(Visibility.Kind kind) nothrow pure @safe { final switch (kind) { diff --git a/compiler/src/dmd/iasmdmd.d b/compiler/src/dmd/iasmdmd.d index 2bf226d29c42..8af8f6a1713b 100644 --- a/compiler/src/dmd/iasmdmd.d +++ b/compiler/src/dmd/iasmdmd.d @@ -344,7 +344,7 @@ immutable: ubyte val; opflag_t ty; - bool isSIL_DIL_BPL_SPL() const + bool isSIL_DIL_BPL_SPL() const @safe { // Be careful as these have the same val's as AH CH DH BH return ty == _r8 && @@ -2430,7 +2430,7 @@ void asm_make_modrm_byte( uint rm; uint reg; uint mod; - uint auchOpcode() + uint auchOpcode() @safe { assert(rm < 8); assert(reg < 8); @@ -2444,7 +2444,7 @@ void asm_make_modrm_byte( uint base; uint index; uint ss; - uint auchOpcode() + uint auchOpcode() @safe { assert(base < 8); assert(index < 8); @@ -3143,7 +3143,7 @@ Lmatch: /******************************* */ -bool asm_match_float_flags(opflag_t usOp, opflag_t usTable) +bool asm_match_float_flags(opflag_t usOp, opflag_t usTable) @safe { ASM_OPERAND_TYPE aoptyTable; ASM_OPERAND_TYPE aoptyOp; @@ -4580,7 +4580,7 @@ TOK tryExpressionToOperand(Expression e, out OPND o1, out Dsymbol s) * If c is a power of 2, return that power else -1. */ -private int ispow2(uint c) +private int ispow2(uint c) @safe { int i; @@ -4597,7 +4597,7 @@ private int ispow2(uint c) * Returns: true if szop is one of the values in sztbl */ private -bool isOneOf(OpndSize szop, OpndSize sztbl) +bool isOneOf(OpndSize szop, OpndSize sztbl) @safe { with (OpndSize) { diff --git a/compiler/src/dmd/id.d b/compiler/src/dmd/id.d index a2daf6064d33..43b2e5f5a50e 100644 --- a/compiler/src/dmd/id.d +++ b/compiler/src/dmd/id.d @@ -575,7 +575,7 @@ struct Msgtable * Returns: the name to use in the D executable, `name_` if non-empty, * otherwise `ident` */ - string name() + string name() @safe { return name_ ? name_ : ident; } @@ -602,19 +602,19 @@ string generate(immutable(Msgtable)[] msgtable, string function(Msgtable) dg) } // Used to generate the code for each identifier. -string identifier(Msgtable m) +string identifier(Msgtable m) @safe { return "Identifier " ~ m.ident ~ ";"; } // Used to generate the code for each initializer. -string initializer(Msgtable m) +string initializer(Msgtable m) @safe { return m.ident ~ ` = Identifier.idPool("` ~ m.name ~ `");`; } // Used to generate the code for each deinitializer. -string deinitializer(Msgtable m) +string deinitializer(Msgtable m) @safe { return m.ident ~ " = Identifier.init;"; } diff --git a/compiler/src/dmd/imphint.d b/compiler/src/dmd/imphint.d index 913de9fa61cb..9e9466a38eb2 100644 --- a/compiler/src/dmd/imphint.d +++ b/compiler/src/dmd/imphint.d @@ -20,7 +20,7 @@ module dmd.imphint; * Not meant to be a comprehensive list of names in each module, * just the most common ones. */ -const(char)[] importHint(const(char)[] s) +const(char)[] importHint(const(char)[] s) @safe { if (auto entry = s in hints) return *entry; diff --git a/compiler/src/dmd/init.d b/compiler/src/dmd/init.d index 6f20a3c7a458..e7cf90510341 100644 --- a/compiler/src/dmd/init.d +++ b/compiler/src/dmd/init.d @@ -51,7 +51,7 @@ extern (C++) class Initializer : ASTNode } - extern (D) this(const ref Loc loc, InitKind kind) + extern (D) this(const ref Loc loc, InitKind kind) @safe { this.loc = loc; this.kind = kind; @@ -108,7 +108,7 @@ extern (C++) final class VoidInitializer : Initializer { Type type; // type that this will initialize to - extern (D) this(const ref Loc loc) + extern (D) this(const ref Loc loc) @safe { super(loc, InitKind.void_); } @@ -123,7 +123,7 @@ extern (C++) final class VoidInitializer : Initializer */ extern (C++) final class ErrorInitializer : Initializer { - extern (D) this() + extern (D) this() @safe { super(Loc.initial, InitKind.error); } @@ -206,7 +206,7 @@ extern (C++) final class ExpInitializer : Initializer bool expandTuples; Expression exp; - extern (D) this(const ref Loc loc, Expression exp) + extern (D) this(const ref Loc loc, Expression exp) @safe { super(loc, InitKind.exp); this.exp = exp; @@ -226,8 +226,8 @@ struct Designator Expression exp; /// [ constant-expression ] Identifier ident; /// . identifier - this(Expression exp) { this.exp = exp; } - this(Identifier ident) { this.ident = ident; } + this(Expression exp) @safe { this.exp = exp; } + this(Identifier ident) @safe { this.ident = ident; } } /********************************************* @@ -377,7 +377,7 @@ mixin template VisitInitializer(Result) * handler = string for the name of the visit handler * Returns: boilerplate code for a case */ -pure string visitCase(string handler) +string visitCase(string handler) pure @safe { if (__ctfe) { diff --git a/compiler/src/dmd/inline.d b/compiler/src/dmd/inline.d index 2a522216ce67..1c4ce02005f5 100644 --- a/compiler/src/dmd/inline.d +++ b/compiler/src/dmd/inline.d @@ -962,7 +962,7 @@ public: Expression eresult; bool again; - extern (D) this() scope + extern (D) this() scope @safe { } @@ -1573,7 +1573,7 @@ private extern (C++) final class InlineScanVisitorDsymbol : Visitor alias visit = Visitor.visit; public: - extern (D) this() scope + extern (D) this() scope @safe { } @@ -2302,7 +2302,7 @@ private bool isConstruction(Expression e) * Returns: * true if v's initializer is the only value assigned to v */ -private bool onlyOneAssign(VarDeclaration v, FuncDeclaration fd) +private bool onlyOneAssign(VarDeclaration v, FuncDeclaration fd) @safe { if (!v.type.isMutable()) return true; // currently the only case handled atm diff --git a/compiler/src/dmd/inlinecost.d b/compiler/src/dmd/inlinecost.d index 696c0a719dca..f2abd4b56721 100644 --- a/compiler/src/dmd/inlinecost.d +++ b/compiler/src/dmd/inlinecost.d @@ -53,7 +53,7 @@ static assert(STATEMENT_COST > COST_MAX); * Returns: * true if too costly */ -bool tooCostly(int cost) pure nothrow +bool tooCostly(int cost) pure nothrow @safe { return ((cost & (STATEMENT_COST - 1)) >= COST_MAX); } @@ -156,11 +156,11 @@ public: FuncDeclaration fd; int cost; // zero start for subsequent AST - extern (D) this() scope + extern (D) this() scope @safe { } - extern (D) this(bool hasthis, bool hdrscan, bool allowAlloca, FuncDeclaration fd) scope + extern (D) this(bool hasthis, bool hdrscan, bool allowAlloca, FuncDeclaration fd) scope @safe { this.hasthis = hasthis; this.hdrscan = hdrscan; @@ -168,7 +168,7 @@ public: this.fd = fd; } - extern (D) this(InlineCostVisitor icv) scope + extern (D) this(InlineCostVisitor icv) scope @safe { nested = icv.nested; hasthis = icv.hasthis; diff --git a/compiler/src/dmd/intrange.d b/compiler/src/dmd/intrange.d index d67e0f5958df..442668f63377 100644 --- a/compiler/src/dmd/intrange.d +++ b/compiler/src/dmd/intrange.d @@ -18,7 +18,7 @@ import dmd.mtype; import dmd.expression; import dmd.globals; -private uinteger_t copySign(uinteger_t x, bool sign) +private uinteger_t copySign(uinteger_t x, bool sign) @safe { // return sign ? -x : x; return (x - cast(uinteger_t)sign) ^ -cast(uinteger_t)sign; @@ -29,37 +29,37 @@ struct SignExtendedNumber uinteger_t value; bool negative; - static SignExtendedNumber fromInteger(uinteger_t value_) + static SignExtendedNumber fromInteger(uinteger_t value_) @safe { return SignExtendedNumber(value_, value_ >> 63); } - static SignExtendedNumber extreme(bool minimum) + static SignExtendedNumber extreme(bool minimum) @safe { return SignExtendedNumber(minimum - 1, minimum); } - static SignExtendedNumber max() + static SignExtendedNumber max() @safe { return SignExtendedNumber(ulong.max, false); } - static SignExtendedNumber min() + static SignExtendedNumber min() @safe { return SignExtendedNumber(0, true); } - bool isMinimum() const + bool isMinimum() const @safe { return negative && value == 0; } - bool opEquals(const ref SignExtendedNumber a) const + bool opEquals(const ref SignExtendedNumber a) const @safe { return value == a.value && negative == a.negative; } - int opCmp(const ref SignExtendedNumber a) const + int opCmp(const ref SignExtendedNumber a) const @safe { if (negative != a.negative) { @@ -297,19 +297,19 @@ struct IntRange { SignExtendedNumber imin, imax; - this(IntRange another) + this(IntRange another) @safe { imin = another.imin; imax = another.imax; } - this(SignExtendedNumber a) + this(SignExtendedNumber a) @safe { imin = a; imax = a; } - this(SignExtendedNumber lower, SignExtendedNumber upper) + this(SignExtendedNumber lower, SignExtendedNumber upper) @safe { imin = lower; imax = upper; @@ -358,12 +358,12 @@ struct IntRange return ab; } - static IntRange widest() + static IntRange widest() @safe { return IntRange(SignExtendedNumber.min(), SignExtendedNumber.max()); } - IntRange castSigned(uinteger_t mask) + IntRange castSigned(uinteger_t mask) @safe { // .... 0x1e7f ] [0x1e80 .. 0x1f7f] [0x1f80 .. 0x7f] [0x80 .. 0x17f] [0x180 .... // @@ -405,7 +405,7 @@ struct IntRange return this; } - IntRange castUnsigned(uinteger_t mask) + IntRange castUnsigned(uinteger_t mask) @safe { // .... 0x1eff ] [0x1f00 .. 0x1fff] [0 .. 0xff] [0x100 .. 0x1ff] [0x200 .... // @@ -430,7 +430,7 @@ struct IntRange return this; } - IntRange castDchar() + IntRange castDchar() @safe { // special case for dchar. Casting to dchar means "I'll ignore all // invalid characters." @@ -464,18 +464,18 @@ struct IntRange return castUnsigned(type.sizemask()); } - bool contains(IntRange a) + bool contains(IntRange a) @safe { return imin <= a.imin && imax >= a.imax; } - bool containsZero() const + bool containsZero() const @safe { return (imin.negative && !imax.negative) || (!imin.negative && imin.value == 0); } - IntRange absNeg() const + IntRange absNeg() const @safe { if (imax.negative) return this; @@ -489,13 +489,13 @@ struct IntRange } } - IntRange unionWith(const ref IntRange other) const + IntRange unionWith(const ref IntRange other) const @safe { return IntRange(imin < other.imin ? imin : other.imin, imax > other.imax ? imax : other.imax); } - void unionOrAssign(IntRange other, ref bool union_) + void unionOrAssign(IntRange other, ref bool union_) @safe { if (!union_ || imin > other.imin) imin = other.imin; @@ -513,7 +513,7 @@ struct IntRange return this; } - void splitBySign(ref IntRange negRange, ref bool hasNegRange, ref IntRange nonNegRange, ref bool hasNonNegRange) const + void splitBySign(ref IntRange negRange, ref bool hasNegRange, ref IntRange nonNegRange, ref bool hasNonNegRange) const @safe { hasNegRange = imin.negative; if (hasNegRange) @@ -785,7 +785,7 @@ struct IntRange private: // Credits to Timon Gehr maxOr, minOr, maxAnd, minAnd // https://github.com/tgehr/d-compiler/blob/master/vrange.d - static SignExtendedNumber maxOr(const IntRange lhs, const IntRange rhs) + static SignExtendedNumber maxOr(const IntRange lhs, const IntRange rhs) @safe { uinteger_t x = 0; auto sign = false; @@ -856,14 +856,14 @@ private: // Credits to Timon Gehr maxOr, minOr, maxAnd, minAnd // https://github.com/tgehr/d-compiler/blob/master/vrange.d - static SignExtendedNumber minOr(const IntRange lhs, const IntRange rhs) + static SignExtendedNumber minOr(const IntRange lhs, const IntRange rhs) @safe { return ~maxAnd(~lhs, ~rhs); } // Credits to Timon Gehr maxOr, minOr, maxAnd, minAnd // https://github.com/tgehr/d-compiler/blob/master/vrange.d - static SignExtendedNumber maxAnd(const IntRange lhs, const IntRange rhs) + static SignExtendedNumber maxAnd(const IntRange lhs, const IntRange rhs) @safe { uinteger_t x = 0; bool sign = false; @@ -905,7 +905,7 @@ private: // Credits to Timon Gehr maxOr, minOr, maxAnd, minAnd // https://github.com/tgehr/d-compiler/blob/master/vrange.d - static SignExtendedNumber minAnd(const IntRange lhs, const IntRange rhs) + static SignExtendedNumber minAnd(const IntRange lhs, const IntRange rhs) @safe { return ~maxOr(~lhs, ~rhs); } diff --git a/compiler/src/dmd/json.d b/compiler/src/dmd/json.d index dcf53b8f5474..96899869d529 100644 --- a/compiler/src/dmd/json.d +++ b/compiler/src/dmd/json.d @@ -54,7 +54,7 @@ public: int indentLevel; const(char)[] filename; - extern (D) this(OutBuffer* buf) scope + extern (D) this(OutBuffer* buf) scope @safe { this.buf = buf; } diff --git a/compiler/src/dmd/libmscoff.d b/compiler/src/dmd/libmscoff.d index d4e4529b0c42..ee363a764f5e 100644 --- a/compiler/src/dmd/libmscoff.d +++ b/compiler/src/dmd/libmscoff.d @@ -44,7 +44,7 @@ import dmd.root.stringtable; import dmd.scanmscoff; // Entry point (only public symbol in this module). -public extern (C++) Library LibMSCoff_factory() +public extern (C++) Library LibMSCoff_factory() @safe { return new LibMSCoff(); } @@ -59,13 +59,13 @@ struct MSCoffObjSymbol MSCoffObjModule* om; /// Predicate for `Array.sort`for name comparison - static int name_pred (scope const MSCoffObjSymbol** ppe1, scope const MSCoffObjSymbol** ppe2) nothrow @nogc pure + static int name_pred (scope const MSCoffObjSymbol** ppe1, scope const MSCoffObjSymbol** ppe2) nothrow @nogc pure @safe { return dstrcmp((**ppe1).name, (**ppe2).name); } /// Predicate for `Array.sort`for offset comparison - static int offset_pred (scope const MSCoffObjSymbol** ppe1, scope const MSCoffObjSymbol** ppe2) nothrow @nogc pure + static int offset_pred (scope const MSCoffObjSymbol** ppe1, scope const MSCoffObjSymbol** ppe2) nothrow @nogc pure @safe { return (**ppe1).om.offset - (**ppe2).om.offset; } diff --git a/compiler/src/dmd/link.d b/compiler/src/dmd/link.d index c1a4f3f57b76..a8decd95318d 100644 --- a/compiler/src/dmd/link.d +++ b/compiler/src/dmd/link.d @@ -93,7 +93,7 @@ version (CRuntime_Microsoft) /**************************************** * Write filename to cmdbuf, quoting if necessary. */ -private void writeFilename(OutBuffer* buf, const(char)[] filename) +private void writeFilename(OutBuffer* buf, const(char)[] filename) @safe { /* Loop and see if we need to quote */ diff --git a/compiler/src/dmd/location.d b/compiler/src/dmd/location.d index b2b366130ca6..39edc5cdb5f9 100644 --- a/compiler/src/dmd/location.d +++ b/compiler/src/dmd/location.d @@ -205,7 +205,7 @@ nothrow: * Returns: * true if Loc has been set to other than the default initialization */ - bool isValid() const pure + bool isValid() const pure @safe { return fileIndex != 0; } diff --git a/compiler/src/dmd/mtype.d b/compiler/src/dmd/mtype.d index 7ecd4023ee15..440ae5f47e98 100644 --- a/compiler/src/dmd/mtype.d +++ b/compiler/src/dmd/mtype.d @@ -157,7 +157,7 @@ MOD MODmerge(MOD mod1, MOD mod2) pure nothrow @nogc @safe /********************************* * Store modifier name into buf. */ -void MODtoBuffer(OutBuffer* buf, MOD mod) nothrow +void MODtoBuffer(OutBuffer* buf, MOD mod) nothrow @safe { buf.writestring(MODtoString(mod)); } @@ -174,7 +174,7 @@ const(char)* MODtoChars(MOD mod) nothrow pure } /// Ditto -string MODtoString(MOD mod) nothrow pure +string MODtoString(MOD mod) nothrow pure @safe { final switch (mod) { @@ -6564,7 +6564,7 @@ extern (C++) struct ParameterList VarArg varargs = VarArg.none; bool hasIdentifierList; // true if C identifier-list style - this(Parameters* parameters, VarArg varargs = VarArg.none, StorageClass stc = 0) + this(Parameters* parameters, VarArg varargs = VarArg.none, StorageClass stc = 0) @safe { this.parameters = parameters; this.varargs = varargs; @@ -6667,7 +6667,7 @@ extern (C++) final class Parameter : ASTNode Expression defaultArg; UserAttributeDeclaration userAttribDecl; // user defined attributes - extern (D) this(StorageClass storageClass, Type type, Identifier ident, Expression defaultArg, UserAttributeDeclaration userAttribDecl) + extern (D) this(StorageClass storageClass, Type type, Identifier ident, Expression defaultArg, UserAttributeDeclaration userAttribDecl) @safe { this.type = type; this.ident = ident; @@ -6676,7 +6676,7 @@ extern (C++) final class Parameter : ASTNode this.userAttribDecl = userAttribDecl; } - static Parameter create(StorageClass storageClass, Type type, Identifier ident, Expression defaultArg, UserAttributeDeclaration userAttribDecl) + static Parameter create(StorageClass storageClass, Type type, Identifier ident, Expression defaultArg, UserAttributeDeclaration userAttribDecl) @safe { return new Parameter(storageClass, type, ident, defaultArg, userAttribDecl); } @@ -7646,7 +7646,7 @@ mixin template VisitType(Result) * handler = string for the name of the visit handler * Returns: boilerplate code for a case */ -pure string visitTYCase(string handler) +pure string visitTYCase(string handler) @safe { if (__ctfe) { diff --git a/compiler/src/dmd/ob.d b/compiler/src/dmd/ob.d index 56243a0e035e..4774d1f5243c 100644 --- a/compiler/src/dmd/ob.d +++ b/compiler/src/dmd/ob.d @@ -145,7 +145,7 @@ enum ObType : ubyte fend, } -string toString(ObType obtype) +string toString(ObType obtype) @safe { return obtype == ObType.goto_ ? "goto " : obtype == ObType.return_ ? "ret " : @@ -202,7 +202,7 @@ const(char)* toChars(PtrState state) return toString(state).ptr; } -string toString(PtrState state) +string toString(PtrState state) @safe { return ["Initial", "Undefined", "Owner", "Borrowed", "Readonly"][state]; } @@ -1012,7 +1012,7 @@ void insertFinallyBlockGotos(ref ObNodes obnodes) * Set the `index` field of each ObNode * to its index in the `obnodes[]` array. */ -void numberNodes(ref ObNodes obnodes) +void numberNodes(ref ObNodes obnodes) @safe { //printf("numberNodes()\n"); foreach (i, ob; obnodes) diff --git a/compiler/src/dmd/objc.d b/compiler/src/dmd/objc.d index c493323e2380..34b7077579b9 100644 --- a/compiler/src/dmd/objc.d +++ b/compiler/src/dmd/objc.d @@ -58,7 +58,7 @@ struct ObjcSelector stringtable._init(); } - extern (D) this(const(char)* sv, size_t len, size_t pcount) + extern (D) this(const(char)* sv, size_t len, size_t pcount) @safe { stringvalue = sv; stringlen = len; @@ -167,12 +167,12 @@ extern (C++) struct ObjcClassDeclaration /// List of non-inherited methods. FuncDeclaration[] methodList; - extern (D) this(ClassDeclaration classDeclaration) + extern (D) this(ClassDeclaration classDeclaration) @safe { this.classDeclaration = classDeclaration; } - bool isRootClass() const + bool isRootClass() const @safe { return classDeclaration.classKind == ClassKind.objc && !metaclass && diff --git a/compiler/src/dmd/objc_glue.d b/compiler/src/dmd/objc_glue.d index cd747a58d6eb..8625950e0e36 100644 --- a/compiler/src/dmd/objc_glue.d +++ b/compiler/src/dmd/objc_glue.d @@ -340,7 +340,7 @@ struct Segments immutable int flags; immutable int alignment; - this(typeof(this.tupleof) tuple) + this(typeof(this.tupleof) tuple) @safe { this.tupleof = tuple; } @@ -518,7 +518,7 @@ static: * * Allows to pass the name of the symbol as a D string. */ - Symbol* symbolName(const(char)[] name, SC sclass, type* t) + Symbol* symbolName(const(char)[] name, SC sclass, type* t) @safe { return symbol_name(name, sclass, t); } @@ -532,7 +532,7 @@ static: * * Returns: the symbol */ - Symbol* getGlobal(const(char)[] name, type* t = type_fake(TYnptr)) + Symbol* getGlobal(const(char)[] name, type* t = type_fake(TYnptr)) @safe { return symbolName(name, SC.global, t); } @@ -546,7 +546,7 @@ static: * * Returns: the symbol */ - Symbol* getStatic(const(char)[] name, type* t = type_fake(TYnptr)) + Symbol* getStatic(const(char)[] name, type* t = type_fake(TYnptr)) @safe { return symbolName(name, SC.static_, t); } @@ -748,7 +748,7 @@ static: * * Returns: a string containing the type encoding */ - string getTypeEncoding(Type type) + string getTypeEncoding(Type type) @safe in { assert(type !is null); @@ -973,7 +973,7 @@ struct ObjcClassDeclaration /// `true` if this class is a metaclass. bool isMeta; - this(ClassDeclaration classDeclaration, bool isMeta) + this(ClassDeclaration classDeclaration, bool isMeta) @safe in { assert(classDeclaration !is null); @@ -1198,7 +1198,7 @@ private: return symbol; } - Symbol* getPropertyList() + Symbol* getPropertyList() @safe { // properties are not supported yet return null; @@ -1224,7 +1224,7 @@ private: * * Returns: the flags */ - uint flags() const + uint flags() const @safe { uint flags = isMeta ? Flags.meta : Flags.regular; @@ -1280,7 +1280,7 @@ struct ProtocolDeclaration /// The interface declaration private InterfaceDeclaration interfaceDeclaration; - this(InterfaceDeclaration interfaceDeclaration) + this(InterfaceDeclaration interfaceDeclaration) @safe in { assert(interfaceDeclaration !is null); @@ -1593,7 +1593,7 @@ Symbol* toNameSymbol(const ObjcSelector* selector) * dtb = the dt builder to add the symbol to * symbol = the symbol to add */ -void xoffOrNull(ref DtBuilder dtb, Symbol* symbol) +void xoffOrNull(ref DtBuilder dtb, Symbol* symbol) @safe { if (symbol) dtb.xoff(symbol, 0); diff --git a/compiler/src/dmd/opover.d b/compiler/src/dmd/opover.d index 8b42a91f0afa..457e8b6479c5 100644 --- a/compiler/src/dmd/opover.d +++ b/compiler/src/dmd/opover.d @@ -43,7 +43,7 @@ import dmd.visitor; * Determine if operands of binary op can be reversed * to fit operator overload. */ -bool isCommutative(EXP op) +bool isCommutative(EXP op) @safe { switch (op) { @@ -1840,7 +1840,7 @@ private bool matchParamsToOpApply(TypeFunction tf, Parameters* parameters, bool * Returns: * reverse of op */ -private EXP reverseRelation(EXP op) pure +private EXP reverseRelation(EXP op) pure @safe { switch (op) { diff --git a/compiler/src/dmd/printast.d b/compiler/src/dmd/printast.d index 8c0109524f7d..e43ffad25707 100644 --- a/compiler/src/dmd/printast.d +++ b/compiler/src/dmd/printast.d @@ -39,7 +39,7 @@ extern (C++) final class PrintASTVisitor : Visitor int indent; - extern (D) this(int indent) scope + extern (D) this(int indent) scope @safe { this.indent = indent; } diff --git a/compiler/src/dmd/root/complex.d b/compiler/src/dmd/root/complex.d index fc93bd7d404b..57d1e340eff1 100644 --- a/compiler/src/dmd/root/complex.d +++ b/compiler/src/dmd/root/complex.d @@ -29,7 +29,7 @@ extern (C++) struct complex_t this(re, CTFloat.zero); } - this(real_t re, real_t im) + this(real_t re, real_t im) @safe { this.re = re; this.im = im; @@ -99,18 +99,18 @@ extern (C++) struct complex_t return re || im; } - int opEquals(complex_t y) const + int opEquals(complex_t y) const @safe { return re == y.re && im == y.im; } } -extern (C++) real_t creall(complex_t x) +extern (C++) real_t creall(complex_t x) @safe { return x.re; } -extern (C++) real_t cimagl(complex_t x) +extern (C++) real_t cimagl(complex_t x) @safe { return x.im; } diff --git a/compiler/src/dmd/root/utf.d b/compiler/src/dmd/root/utf.d index c9781a46bc6d..d7ba17f8a0b1 100644 --- a/compiler/src/dmd/root/utf.d +++ b/compiler/src/dmd/root/utf.d @@ -11,7 +11,7 @@ module dmd.root.utf; -nothrow pure @nogc: +@nogc nothrow pure @safe: /// The Unicode code space is the range of code points [0x000000,0x10FFFF] /// except the UTF-16 surrogate pairs in the range [0xD800,0xDFFF] @@ -337,7 +337,7 @@ int utf_codeLength(int sz, dchar c) return 1; } -void utf_encodeChar(char* s, dchar c) +void utf_encodeChar(char* s, dchar c) @system { assert(s !is null); assert(utf_isValidDchar(c)); @@ -367,7 +367,7 @@ void utf_encodeChar(char* s, dchar c) assert(0); } -void utf_encodeWchar(wchar* s, dchar c) +void utf_encodeWchar(wchar* s, dchar c) @system { assert(s !is null); assert(utf_isValidDchar(c)); @@ -382,7 +382,7 @@ void utf_encodeWchar(wchar* s, dchar c) } } -void utf_encode(int sz, void* s, dchar c) +void utf_encode(int sz, void* s, dchar c) @system { if (sz == 1) utf_encodeChar(cast(char*)s, c); @@ -399,7 +399,7 @@ void utf_encode(int sz, void* s, dchar c) * Checks whether an Unicode code point is a bidirectional * control character. */ -@safe bool isBidiControl(dchar c) +bool isBidiControl(dchar c) { // Source: https://www.unicode.org/versions/Unicode15.0.0, table 23-3. switch(c) diff --git a/compiler/src/dmd/s2ir.d b/compiler/src/dmd/s2ir.d index 5215b581eb77..61750886eafe 100644 --- a/compiler/src/dmd/s2ir.d +++ b/compiler/src/dmd/s2ir.d @@ -1753,7 +1753,7 @@ private void setScopeIndex(Blockx *blx, block *b, int scope_index) * Allocate a new block, and set the tryblock. */ -private block *block_calloc(Blockx *blx) +private block *block_calloc(Blockx *blx) @safe { block *b = dmd.backend.global.block_calloc(); b.Btry = blx.tryblock; diff --git a/compiler/src/dmd/semantic2.d b/compiler/src/dmd/semantic2.d index 23e9e83e93d1..b08c1edba990 100644 --- a/compiler/src/dmd/semantic2.d +++ b/compiler/src/dmd/semantic2.d @@ -83,7 +83,7 @@ private extern(C++) final class Semantic2Visitor : Visitor { alias visit = Visitor.visit; Scope* sc; - this(Scope* sc) scope + this(Scope* sc) scope @safe { this.sc = sc; } diff --git a/compiler/src/dmd/semantic3.d b/compiler/src/dmd/semantic3.d index c7d121948203..8c1d84ba1f91 100644 --- a/compiler/src/dmd/semantic3.d +++ b/compiler/src/dmd/semantic3.d @@ -88,7 +88,7 @@ private extern(C++) final class Semantic3Visitor : Visitor alias visit = Visitor.visit; Scope* sc; - this(Scope* sc) scope + this(Scope* sc) scope @safe { this.sc = sc; } @@ -1602,7 +1602,7 @@ private struct FuncDeclSem3 // Scope of analysis Scope* sc; - this(FuncDeclaration fd,Scope* s) scope + this(FuncDeclaration fd,Scope* s) scope @safe { funcdecl = fd; sc = s; diff --git a/compiler/src/dmd/statement.d b/compiler/src/dmd/statement.d index 6aa90d1eb232..877f6d5fd839 100644 --- a/compiler/src/dmd/statement.d +++ b/compiler/src/dmd/statement.d @@ -84,7 +84,7 @@ extern (C++) abstract class Statement : ASTNode return DYNCAST.statement; } - final extern (D) this(const ref Loc loc, STMT stmt) + final extern (D) this(const ref Loc loc, STMT stmt) @safe { this.loc = loc; this.stmt = stmt; @@ -447,7 +447,7 @@ extern (C++) final class PeelStatement : Statement { Statement s; - extern (D) this(Statement s) + extern (D) this(Statement s) @safe { super(s.loc, STMT.Peel); this.s = s; @@ -467,13 +467,13 @@ extern (C++) class ExpStatement : Statement { Expression exp; - final extern (D) this(const ref Loc loc, Expression exp) + final extern (D) this(const ref Loc loc, Expression exp) @safe { super(loc, STMT.Exp); this.exp = exp; } - final extern (D) this(const ref Loc loc, Expression exp, STMT stmt) + final extern (D) this(const ref Loc loc, Expression exp, STMT stmt) @safe { super(loc, stmt); this.exp = exp; @@ -485,7 +485,7 @@ extern (C++) class ExpStatement : Statement this.exp = new DeclarationExp(loc, declaration); } - static ExpStatement create(const ref Loc loc, Expression exp) + static ExpStatement create(const ref Loc loc, Expression exp) @safe { return new ExpStatement(loc, exp); } @@ -508,7 +508,7 @@ extern (C++) final class DtorExpStatement : ExpStatement // Wraps an expression that is the destruction of 'var' VarDeclaration var; - extern (D) this(const ref Loc loc, Expression exp, VarDeclaration var) + extern (D) this(const ref Loc loc, Expression exp, VarDeclaration var) @safe { super(loc, exp, STMT.DtorExp); this.var = var; @@ -540,7 +540,7 @@ extern (C++) final class MixinStatement : Statement this(loc, exps); } - extern (D) this(const ref Loc loc, Expressions* exps) + extern (D) this(const ref Loc loc, Expressions* exps) @safe { super(loc, STMT.Mixin); this.exps = exps; @@ -571,13 +571,13 @@ extern (C++) class CompoundStatement : Statement * loc = Instantiation information * statements = An array of `Statement`s, that will referenced by this class */ - final extern (D) this(const ref Loc loc, Statements* statements) + final extern (D) this(const ref Loc loc, Statements* statements) @safe { super(loc, STMT.Compound); this.statements = statements; } - final extern (D) this(const ref Loc loc, Statements* statements, STMT stmt) + final extern (D) this(const ref Loc loc, Statements* statements, STMT stmt) @safe { super(loc, stmt); this.statements = statements; @@ -649,7 +649,7 @@ extern (C++) class CompoundStatement : Statement */ extern (C++) final class CompoundDeclarationStatement : CompoundStatement { - extern (D) this(const ref Loc loc, Statements* statements) + extern (D) this(const ref Loc loc, Statements* statements) @safe { super(loc, statements, STMT.CompoundDeclaration); } @@ -678,7 +678,7 @@ extern (C++) final class UnrolledLoopStatement : Statement { Statements* statements; - extern (D) this(const ref Loc loc, Statements* statements) + extern (D) this(const ref Loc loc, Statements* statements) @safe { super(loc, STMT.UnrolledLoop); this.statements = statements; @@ -717,7 +717,7 @@ extern (C++) final class ScopeStatement : Statement Statement statement; Loc endloc; // location of closing curly bracket - extern (D) this(const ref Loc loc, Statement statement, Loc endloc) + extern (D) this(const ref Loc loc, Statement statement, Loc endloc) @safe { super(loc, STMT.Scope); this.statement = statement; @@ -767,7 +767,7 @@ extern (C++) final class ForwardingStatement : Statement /// The wrapped statement. Statement statement; - extern (D) this(const ref Loc loc, ForwardingScopeDsymbol sym, Statement statement) + extern (D) this(const ref Loc loc, ForwardingScopeDsymbol sym, Statement statement) @safe { super(loc, STMT.Forwarding); this.sym = sym; @@ -804,7 +804,7 @@ extern (C++) final class WhileStatement : Statement Statement _body; Loc endloc; // location of closing curly bracket - extern (D) this(const ref Loc loc, Expression condition, Statement _body, Loc endloc, Parameter param = null) + extern (D) this(const ref Loc loc, Expression condition, Statement _body, Loc endloc, Parameter param = null) @safe { super(loc, STMT.While); this.condition = condition; @@ -846,7 +846,7 @@ extern (C++) final class DoStatement : Statement Expression condition; Loc endloc; // location of ';' after while - extern (D) this(const ref Loc loc, Statement _body, Expression condition, Loc endloc) + extern (D) this(const ref Loc loc, Statement _body, Expression condition, Loc endloc) @safe { super(loc, STMT.Do); this._body = _body; @@ -894,7 +894,7 @@ extern (C++) final class ForStatement : Statement // treat that label as referring to this loop. Statement relatedLabeled; - extern (D) this(const ref Loc loc, Statement _init, Expression condition, Expression increment, Statement _body, Loc endloc) + extern (D) this(const ref Loc loc, Statement _init, Expression condition, Expression increment, Statement _body, Loc endloc) @safe { super(loc, STMT.For); this._init = _init; @@ -955,7 +955,7 @@ extern (C++) final class ForeachStatement : Statement Statements* cases; // put breaks, continues, gotos and returns here ScopeStatements* gotos; // forward referenced goto's go here - extern (D) this(const ref Loc loc, TOK op, Parameters* parameters, Expression aggr, Statement _body, Loc endloc) + extern (D) this(const ref Loc loc, TOK op, Parameters* parameters, Expression aggr, Statement _body, Loc endloc) @safe { super(loc, STMT.Foreach); this.op = op; @@ -1004,7 +1004,7 @@ extern (C++) final class ForeachRangeStatement : Statement VarDeclaration key; - extern (D) this(const ref Loc loc, TOK op, Parameter prm, Expression lwr, Expression upr, Statement _body, Loc endloc) + extern (D) this(const ref Loc loc, TOK op, Parameter prm, Expression lwr, Expression upr, Statement _body, Loc endloc) @safe { super(loc, STMT.ForeachRange); this.op = op; @@ -1048,7 +1048,7 @@ extern (C++) final class IfStatement : Statement VarDeclaration match; // for MatchExpression results Loc endloc; // location of closing curly bracket - extern (D) this(const ref Loc loc, Parameter prm, Expression condition, Statement ifbody, Statement elsebody, Loc endloc) + extern (D) this(const ref Loc loc, Parameter prm, Expression condition, Statement ifbody, Statement elsebody, Loc endloc) @safe { super(loc, STMT.If); this.prm = prm; @@ -1093,7 +1093,7 @@ extern (C++) final class ConditionalStatement : Statement Statement ifbody; Statement elsebody; - extern (D) this(const ref Loc loc, Condition condition, Statement ifbody, Statement elsebody) + extern (D) this(const ref Loc loc, Condition condition, Statement ifbody, Statement elsebody) @safe { super(loc, STMT.Conditional); this.condition = condition; @@ -1128,7 +1128,7 @@ extern (C++) final class StaticForeachStatement : Statement { StaticForeach sfe; - extern (D) this(const ref Loc loc, StaticForeach sfe) + extern (D) this(const ref Loc loc, StaticForeach sfe) @safe { super(loc, STMT.StaticForeach); this.sfe = sfe; @@ -1154,7 +1154,7 @@ extern (C++) final class PragmaStatement : Statement Expressions* args; // array of Expression's Statement _body; - extern (D) this(const ref Loc loc, const Identifier ident, Expressions* args, Statement _body) + extern (D) this(const ref Loc loc, const Identifier ident, Expressions* args, Statement _body) @safe { super(loc, STMT.Pragma); this.ident = ident; @@ -1180,7 +1180,7 @@ extern (C++) final class StaticAssertStatement : Statement { StaticAssert sa; - extern (D) this(StaticAssert sa) + extern (D) this(StaticAssert sa) @safe { super(sa.loc, STMT.StaticAssert); this.sa = sa; @@ -1291,7 +1291,7 @@ extern (C++) final class CaseStatement : Statement VarDeclaration lastVar; void* extra; // for use by Statement_toIR() - extern (D) this(const ref Loc loc, Expression exp, Statement statement) + extern (D) this(const ref Loc loc, Expression exp, Statement statement) @safe { super(loc, STMT.Case); this.exp = exp; @@ -1318,7 +1318,7 @@ extern (C++) final class CaseRangeStatement : Statement Expression last; Statement statement; - extern (D) this(const ref Loc loc, Expression first, Expression last, Statement statement) + extern (D) this(const ref Loc loc, Expression first, Expression last, Statement statement) @safe { super(loc, STMT.CaseRange); this.first = first; @@ -1346,7 +1346,7 @@ extern (C++) final class DefaultStatement : Statement VarDeclaration lastVar; - extern (D) this(const ref Loc loc, Statement statement) + extern (D) this(const ref Loc loc, Statement statement) @safe { super(loc, STMT.Default); this.statement = statement; @@ -1370,7 +1370,7 @@ extern (C++) final class GotoDefaultStatement : Statement { SwitchStatement sw; - extern (D) this(const ref Loc loc) + extern (D) this(const ref Loc loc) @safe { super(loc, STMT.GotoDefault); } @@ -1395,7 +1395,7 @@ extern (C++) final class GotoCaseStatement : Statement CaseStatement cs; // case statement it resolves to - extern (D) this(const ref Loc loc, Expression exp) + extern (D) this(const ref Loc loc, Expression exp) @safe { super(loc, STMT.GotoCase); this.exp = exp; @@ -1418,12 +1418,12 @@ extern (C++) final class SwitchErrorStatement : Statement { Expression exp; - extern (D) this(const ref Loc loc) + extern (D) this(const ref Loc loc) @safe { super(loc, STMT.SwitchError); } - final extern (D) this(const ref Loc loc, Expression exp) + final extern (D) this(const ref Loc loc, Expression exp) @safe { super(loc, STMT.SwitchError); this.exp = exp; @@ -1443,7 +1443,7 @@ extern (C++) final class ReturnStatement : Statement Expression exp; size_t caseDim; - extern (D) this(const ref Loc loc, Expression exp) + extern (D) this(const ref Loc loc, Expression exp) @safe { super(loc, STMT.Return); this.exp = exp; @@ -1472,7 +1472,7 @@ extern (C++) final class BreakStatement : Statement { Identifier ident; - extern (D) this(const ref Loc loc, Identifier ident) + extern (D) this(const ref Loc loc, Identifier ident) @safe { super(loc, STMT.Break); this.ident = ident; @@ -1496,7 +1496,7 @@ extern (C++) final class ContinueStatement : Statement { Identifier ident; - extern (D) this(const ref Loc loc, Identifier ident) + extern (D) this(const ref Loc loc, Identifier ident) @safe { super(loc, STMT.Continue); this.ident = ident; @@ -1521,7 +1521,7 @@ extern (C++) final class SynchronizedStatement : Statement Expression exp; Statement _body; - extern (D) this(const ref Loc loc, Expression exp, Statement _body) + extern (D) this(const ref Loc loc, Expression exp, Statement _body) @safe { super(loc, STMT.Synchronized); this.exp = exp; @@ -1559,7 +1559,7 @@ extern (C++) final class WithStatement : Statement VarDeclaration wthis; Loc endloc; - extern (D) this(const ref Loc loc, Expression exp, Statement _body, Loc endloc) + extern (D) this(const ref Loc loc, Expression exp, Statement _body, Loc endloc) @safe { super(loc, STMT.With); this.exp = exp; @@ -1588,7 +1588,7 @@ extern (C++) final class TryCatchStatement : Statement Statement tryBody; /// set to enclosing TryCatchStatement or TryFinallyStatement if in _body portion - extern (D) this(const ref Loc loc, Statement _body, Catches* catches) + extern (D) this(const ref Loc loc, Statement _body, Catches* catches) @safe { super(loc, STMT.TryCatch); this._body = _body; @@ -1632,7 +1632,7 @@ extern (C++) final class Catch : RootObject // was generated by the compiler, wasn't present in source code bool internalCatch; - extern (D) this(const ref Loc loc, Type type, Identifier ident, Statement handler) + extern (D) this(const ref Loc loc, Type type, Identifier ident, Statement handler) @safe { //printf("Catch(%s, loc = %s)\n", id.toChars(), loc.toChars()); this.loc = loc; @@ -1660,7 +1660,7 @@ extern (C++) final class TryFinallyStatement : Statement Statement tryBody; /// set to enclosing TryCatchStatement or TryFinallyStatement if in _body portion bool bodyFallsThru; /// true if _body falls through to finally - extern (D) this(const ref Loc loc, Statement _body, Statement finalbody) + extern (D) this(const ref Loc loc, Statement _body, Statement finalbody) @safe { super(loc, STMT.TryFinally); this._body = _body; @@ -1668,7 +1668,7 @@ extern (C++) final class TryFinallyStatement : Statement this.bodyFallsThru = true; // assume true until statementSemantic() } - static TryFinallyStatement create(const ref Loc loc, Statement _body, Statement finalbody) + static TryFinallyStatement create(const ref Loc loc, Statement _body, Statement finalbody) @safe { return new TryFinallyStatement(loc, _body, finalbody); } @@ -1702,7 +1702,7 @@ extern (C++) final class ScopeGuardStatement : Statement TOK tok; Statement statement; - extern (D) this(const ref Loc loc, TOK tok, Statement statement) + extern (D) this(const ref Loc loc, TOK tok, Statement statement) @safe { super(loc, STMT.ScopeGuard); this.tok = tok; @@ -1730,7 +1730,7 @@ extern (C++) final class ThrowStatement : Statement // was generated by the compiler, wasn't present in source code bool internalThrow; - extern (D) this(const ref Loc loc, Expression exp) + extern (D) this(const ref Loc loc, Expression exp) @safe { super(loc, STMT.Throw); this.exp = exp; @@ -1755,7 +1755,7 @@ extern (C++) final class DebugStatement : Statement { Statement statement; - extern (D) this(const ref Loc loc, Statement statement) + extern (D) this(const ref Loc loc, Statement statement) @safe { super(loc, STMT.Debug); this.statement = statement; @@ -1785,7 +1785,7 @@ extern (C++) final class GotoStatement : Statement VarDeclaration lastVar; bool inCtfeBlock; /// set if goto is inside an `if (__ctfe)` block - extern (D) this(const ref Loc loc, Identifier ident) + extern (D) this(const ref Loc loc, Identifier ident) @safe { super(loc, STMT.Goto); this.ident = ident; @@ -1900,7 +1900,7 @@ extern (C++) final class LabelStatement : Statement bool breaks; // someone did a 'break ident' bool inCtfeBlock; // inside a block dominated by `if (__ctfe)` - extern (D) this(const ref Loc loc, Identifier ident, Statement statement) + extern (D) this(const ref Loc loc, Identifier ident, Statement statement) @safe { super(loc, STMT.Label); this.ident = ident; @@ -1956,13 +1956,13 @@ extern (C++) class AsmStatement : Statement { Token* tokens; - extern (D) this(const ref Loc loc, Token* tokens) + extern (D) this(const ref Loc loc, Token* tokens) @safe { super(loc, STMT.Asm); this.tokens = tokens; } - extern (D) this(const ref Loc loc, Token* tokens, STMT stmt) + extern (D) this(const ref Loc loc, Token* tokens, STMT stmt) @safe { super(loc, stmt); this.tokens = tokens; @@ -1990,7 +1990,7 @@ extern (C++) final class InlineAsmStatement : AsmStatement bool refparam; // true if function parameter is referenced bool naked; // true if function is to be naked - extern (D) this(const ref Loc loc, Token* tokens) + extern (D) this(const ref Loc loc, Token* tokens) @safe { super(loc, tokens, STMT.InlineAsm); } @@ -2022,7 +2022,7 @@ extern (C++) final class GccAsmStatement : AsmStatement Identifiers* labels; // list of goto labels GotoStatements* gotos; // of the goto labels, the equivalent statements they represent - extern (D) this(const ref Loc loc, Token* tokens) + extern (D) this(const ref Loc loc, Token* tokens) @safe { super(loc, tokens, STMT.GccAsm); } @@ -2045,7 +2045,7 @@ extern (C++) final class CompoundAsmStatement : CompoundStatement { StorageClass stc; // postfix attributes like nothrow/pure/@trusted - extern (D) this(const ref Loc loc, Statements* statements, StorageClass stc) + extern (D) this(const ref Loc loc, Statements* statements, StorageClass stc) @safe { super(loc, statements, STMT.CompoundAsm); this.stc = stc; @@ -2074,7 +2074,7 @@ extern (C++) final class ImportStatement : Statement { Dsymbols* imports; // Array of Import's - extern (D) this(const ref Loc loc, Dsymbols* imports) + extern (D) this(const ref Loc loc, Dsymbols* imports) @safe { super(loc, STMT.Import); this.imports = imports; diff --git a/compiler/src/dmd/statementsem.d b/compiler/src/dmd/statementsem.d index a7a829c30904..322efb0c02ab 100644 --- a/compiler/src/dmd/statementsem.d +++ b/compiler/src/dmd/statementsem.d @@ -109,7 +109,7 @@ private Identifier fixupLabelName(Scope* sc, Identifier ident) * Returns: * if `true`, then the `LabelStatement`, otherwise `null` */ -private LabelStatement checkLabeledLoop(Scope* sc, Statement statement) +private LabelStatement checkLabeledLoop(Scope* sc, Statement statement) @safe { if (sc.slabel && sc.slabel.statement == statement) { diff --git a/compiler/src/dmd/target.d b/compiler/src/dmd/target.d index e7c3dbc9d68b..cac8df06b734 100644 --- a/compiler/src/dmd/target.d +++ b/compiler/src/dmd/target.d @@ -66,7 +66,7 @@ Target.OS defaultTargetOS() static assert(0, "unknown TARGET"); } -ubyte defaultTargetOSMajor() +ubyte defaultTargetOSMajor() @safe { version (FreeBSD) { @@ -499,7 +499,7 @@ extern (C++) struct Target /** Determine the object format to be used */ - extern(D) Target.ObjectFormat objectFormat() + extern(D) Target.ObjectFormat objectFormat() @safe { if (os == Target.OS.OSX) return Target.ObjectFormat.macho; @@ -514,7 +514,7 @@ extern (C++) struct Target /** * Determine the instruction set to be used */ - void setCPU() + void setCPU() @safe { if(!isXmmSupported()) { @@ -546,7 +546,7 @@ extern (C++) struct Target * This can be used to restore the state set by `_init` to its original * state. */ - void deinitialize() + void deinitialize() @safe { this = this.init; } @@ -653,7 +653,7 @@ extern (C++) struct Target * 2 vector element type is not supported * 3 vector size is not supported */ - extern (C++) int isVectorTypeSupported(int sz, Type type) + extern (C++) int isVectorTypeSupported(int sz, Type type) @safe { if (!isXmmSupported()) return 1; // not supported @@ -931,7 +931,7 @@ extern (C++) struct Target * Returns: * `LINK` to use for `extern(System)` */ - extern (C++) LINK systemLinkage() + extern (C++) LINK systemLinkage() @safe { return os == Target.OS.Windows ? LINK.windows : LINK.c; } @@ -1259,7 +1259,7 @@ extern (C++) struct Target * tf = type of function being called * Returns: `true` if the callee invokes destructors for arguments. */ - extern (C++) bool isCalleeDestroyingArgs(TypeFunction tf) + extern (C++) bool isCalleeDestroyingArgs(TypeFunction tf) @safe { // On windows, the callee destroys arguments always regardless of function linkage, // and regardless of whether the caller or callee cleans the stack. @@ -1294,7 +1294,7 @@ extern (C++) struct Target * Returns: * `false` if the target does not support `pragma(linkerDirective)`. */ - extern (C++) bool supportsLinkerDirective() const + extern (C++) bool supportsLinkerDirective() const @safe { return os == Target.OS.Windows && !omfobj; } @@ -1308,7 +1308,7 @@ extern (C++) struct Target * Returns: * true if xmm usage is supported */ - extern (D) bool isXmmSupported() + extern (D) bool isXmmSupported() @safe { return isX86_64 || os == Target.OS.OSX; } @@ -1317,7 +1317,7 @@ extern (C++) struct Target * Returns: * true if generating code for POSIX */ - extern (D) @property bool isPOSIX() scope const nothrow @nogc + extern (D) @property bool isPOSIX() scope const nothrow @nogc @safe out(result) { assert(result || os == Target.OS.Windows); } do { @@ -1328,7 +1328,7 @@ extern (C++) struct Target * Returns: * alignment of the stack */ - extern (D) uint stackAlign() + extern (D) uint stackAlign() @safe { return isXmmSupported() ? 16 : (isX86_64 ? 8 : 4); } @@ -1373,7 +1373,7 @@ struct TargetC Runtime runtime; /// vendor of the C runtime to link against BitFieldStyle bitFieldStyle; /// different C compilers do it differently - extern (D) void initialize(ref const Param params, ref const Target target) + extern (D) void initialize(ref const Param params, ref const Target target) @safe { const os = target.os; boolsize = 1; @@ -1460,7 +1460,7 @@ struct TargetCPP bool wrapDtorInExternD; /// set if C++ dtors require a D wrapper to be callable from runtime Runtime runtime; /// vendor of the C++ runtime to link against - extern (D) void initialize(ref const Param params, ref const Target target) + extern (D) void initialize(ref const Param params, ref const Target target) @safe { const os = target.os; if (os & (Target.OS.linux | Target.OS.FreeBSD | Target.OS.OpenBSD | Target.OS.DragonFlyBSD | Target.OS.Solaris)) @@ -1618,7 +1618,7 @@ struct TargetObjC { bool supported; /// set if compiler can interface with Objective-C - extern (D) void initialize(ref const Param params, ref const Target target) + extern (D) void initialize(ref const Param params, ref const Target target) @safe { if (target.os == Target.OS.OSX && target.isX86_64) supported = true; diff --git a/compiler/src/dmd/templateparamsem.d b/compiler/src/dmd/templateparamsem.d index 1a9d2520c84e..6b8f949f526e 100644 --- a/compiler/src/dmd/templateparamsem.d +++ b/compiler/src/dmd/templateparamsem.d @@ -50,7 +50,7 @@ private extern (C++) final class TemplateParameterSemanticVisitor : Visitor TemplateParameters* parameters; bool result; - this(Scope* sc, TemplateParameters* parameters) scope + this(Scope* sc, TemplateParameters* parameters) scope @safe { this.sc = sc; this.parameters = parameters; diff --git a/compiler/src/dmd/tocsym.d b/compiler/src/dmd/tocsym.d index 3f4aed756cfd..54afafe8b37e 100644 --- a/compiler/src/dmd/tocsym.d +++ b/compiler/src/dmd/tocsym.d @@ -110,7 +110,7 @@ Symbol *toSymbol(Dsymbol s) Symbol *result; - this() scope + this() scope @safe { result = null; } diff --git a/compiler/src/dmd/toctype.d b/compiler/src/dmd/toctype.d index 653882d5786f..dff371c71555 100644 --- a/compiler/src/dmd/toctype.d +++ b/compiler/src/dmd/toctype.d @@ -39,7 +39,7 @@ import dmd.tocvdebug; * Returns: * corresponding tym_t bits */ -tym_t modToTym(MOD mod) pure +tym_t modToTym(MOD mod) pure @safe { switch (mod) { diff --git a/compiler/src/dmd/tocvdebug.d b/compiler/src/dmd/tocvdebug.d index bc70dfa3a58c..9d11b1da6288 100644 --- a/compiler/src/dmd/tocvdebug.d +++ b/compiler/src/dmd/tocvdebug.d @@ -931,7 +931,7 @@ private extern (C++) class CVMember : Visitor ubyte *p; int result; - this(ubyte *p) + this(ubyte *p) @safe { this.p = p; result = 0; diff --git a/compiler/src/dmd/toir.d b/compiler/src/dmd/toir.d index 4e79df78214d..b5ef47cf94f7 100644 --- a/compiler/src/dmd/toir.d +++ b/compiler/src/dmd/toir.d @@ -105,7 +105,7 @@ struct IRState this.Cfile = m.filetype == FileType.c; } - FuncDeclaration getFunc() + FuncDeclaration getFunc() @safe { return symbol; } @@ -149,7 +149,7 @@ struct IRState * Returns: * true if in a nothrow section of code */ - bool isNothrow() + bool isNothrow() @safe { return !mayThrow; } diff --git a/compiler/src/dmd/toobj.d b/compiler/src/dmd/toobj.d index faed5422f128..2a60950afe2a 100644 --- a/compiler/src/dmd/toobj.d +++ b/compiler/src/dmd/toobj.d @@ -284,7 +284,7 @@ void toObjFile(Dsymbol ds, bool multiobj) public: bool multiobj; - this(bool multiobj) scope + this(bool multiobj) scope @safe { this.multiobj = multiobj; }