From 76d2c08fdec70a0d11988d13df93cdd9f9f60ffb Mon Sep 17 00:00:00 2001 From: Dennis Korpel Date: Wed, 2 Oct 2024 12:47:01 +0200 Subject: [PATCH] Add more `@safe` annotations --- compiler/src/dmd/backend/debugprint.d | 1 - compiler/src/dmd/backend/ty.d | 1 - compiler/src/dmd/backend/x86/cgcod.d | 1 - compiler/src/dmd/clone.d | 2 +- compiler/src/dmd/common/outbuffer.d | 4 ++-- compiler/src/dmd/dmdparams.d | 2 +- compiler/src/dmd/dscope.d | 4 ++-- compiler/src/dmd/dsymbolsem.d | 10 +++++----- compiler/src/dmd/expression.d | 6 +++--- compiler/src/dmd/funcsem.d | 2 +- compiler/src/dmd/globals.d | 4 ++-- compiler/src/dmd/root/filename.d | 4 ++-- compiler/src/dmd/root/string.d | 4 ++-- compiler/src/dmd/utils.d | 2 +- 14 files changed, 22 insertions(+), 25 deletions(-) diff --git a/compiler/src/dmd/backend/debugprint.d b/compiler/src/dmd/backend/debugprint.d index 17da0b0a87..6ed1943c13 100644 --- a/compiler/src/dmd/backend/debugprint.d +++ b/compiler/src/dmd/backend/debugprint.d @@ -328,7 +328,6 @@ void WRdefnod(ref GlobalOptimizer go) } } -@trusted const(char)* fl_str(FL fl) { immutable char*[FLMAX] fls = diff --git a/compiler/src/dmd/backend/ty.d b/compiler/src/dmd/backend/ty.d index fcaa033401..a8b293f0ca 100644 --- a/compiler/src/dmd/backend/ty.d +++ b/compiler/src/dmd/backend/ty.d @@ -287,7 +287,6 @@ bool tyvector(tym_t ty) { return tybasic(ty) >= TYfloat4 && tybasic(ty) <= TYull uint tyshort(tym_t ty) { return tytab[ty & 0xFF] & TYFLshort; } /* Detect TYlong or TYulong */ -@trusted bool tylong(tym_t ty) { return tybasic(ty) == TYlong || tybasic(ty) == TYulong; } /* Use to detect a pointer type */ diff --git a/compiler/src/dmd/backend/x86/cgcod.d b/compiler/src/dmd/backend/x86/cgcod.d index a45527ac75..1a9673037c 100644 --- a/compiler/src/dmd/backend/x86/cgcod.d +++ b/compiler/src/dmd/backend/x86/cgcod.d @@ -2384,7 +2384,6 @@ private void loadcse(ref CodeBuilder cdb,elem *e,reg_t reg,regm_t regm) } -@trusted void callcdxxx(ref CGstate cg, ref CodeBuilder cdb, elem *e, ref regm_t pretregs, OPER op) { (*cdxxx[op])(cg, cdb, e, pretregs); diff --git a/compiler/src/dmd/clone.d b/compiler/src/dmd/clone.d index 8746baacd0..d67167e716 100644 --- a/compiler/src/dmd/clone.d +++ b/compiler/src/dmd/clone.d @@ -51,7 +51,7 @@ import dmd.tokens; * Returns: * merged storage class */ -StorageClass mergeFuncAttrs(StorageClass s1, const FuncDeclaration f) pure +StorageClass mergeFuncAttrs(StorageClass s1, const FuncDeclaration f) pure @safe { if (!f) return s1; diff --git a/compiler/src/dmd/common/outbuffer.d b/compiler/src/dmd/common/outbuffer.d index f3801cb69c..06d1134cf0 100644 --- a/compiler/src/dmd/common/outbuffer.d +++ b/compiler/src/dmd/common/outbuffer.d @@ -247,7 +247,7 @@ struct OutBuffer /** * Writes a 16 bit value, no reserve check. */ - nothrow + nothrow @safe void write16n(int v) { auto x = cast(ushort) v; @@ -367,7 +367,7 @@ struct OutBuffer } // Position buffer to accept the specified number of bytes at offset - void position(size_t where, size_t nbytes) nothrow + void position(size_t where, size_t nbytes) nothrow @safe { if (where + nbytes > data.length) { diff --git a/compiler/src/dmd/dmdparams.d b/compiler/src/dmd/dmdparams.d index af24b87a18..45c232dd4a 100644 --- a/compiler/src/dmd/dmdparams.d +++ b/compiler/src/dmd/dmdparams.d @@ -319,7 +319,7 @@ struct Triple Initializes Target settings to compile for the same target as the build compiler. */ -void setTargetBuildDefaults(ref Target target) +void setTargetBuildDefaults(ref Target target) @safe { target = target.init; target.os = defaultTargetOS(); diff --git a/compiler/src/dmd/dscope.d b/compiler/src/dmd/dscope.d index 7936086bdd..b2e41b2a53 100644 --- a/compiler/src/dmd/dscope.d +++ b/compiler/src/dmd/dscope.d @@ -253,13 +253,13 @@ extern (C++) struct Scope } /// Copy flags from scope `other` - extern(D) void copyFlagsFrom(Scope* other) + extern(D) void copyFlagsFrom(Scope* other) @safe { this.bitFields = other.bitFields; } /// Set all scope flags to their initial value - extern(D) void resetAllFlags() + extern(D) void resetAllFlags() @safe { this.bitFields = 0; } diff --git a/compiler/src/dmd/dsymbolsem.d b/compiler/src/dmd/dsymbolsem.d index 2958d955f4..b2a25ec6a2 100644 --- a/compiler/src/dmd/dsymbolsem.d +++ b/compiler/src/dmd/dsymbolsem.d @@ -4082,7 +4082,7 @@ private extern(C++) class AddMemberVisitor : Visitor Scope* sc; ScopeDsymbol sds; - this(Scope* sc, ScopeDsymbol sds) + this(Scope* sc, ScopeDsymbol sds) @safe { this.sc = sc; this.sds = sds; @@ -6045,7 +6045,7 @@ private extern(C++) class SearchVisitor : Visitor SearchOptFlags flags; Dsymbol result; - this(const ref Loc loc, Identifier ident, SearchOptFlags flags) + this(const ref Loc loc, Identifier ident, SearchOptFlags flags) @safe { this.loc = loc; this.ident = ident; @@ -6651,7 +6651,7 @@ private extern(C++) class SetScopeVisitor : Visitor alias visit = typeof(super).visit; Scope* sc; - this(Scope* sc) + this(Scope* sc) @safe { this.sc = sc; } @@ -6794,7 +6794,7 @@ extern(C++) class ImportAllVisitor : Visitor alias visit = typeof(super).visit; Scope* sc; - this(Scope* sc) + this(Scope* sc) @safe { this.sc = sc; } @@ -7037,7 +7037,7 @@ private extern(C++) class SetFieldOffsetVisitor : Visitor FieldState* fieldState; bool isunion; - this(AggregateDeclaration ad, FieldState* fieldState, bool isunion) + this(AggregateDeclaration ad, FieldState* fieldState, bool isunion) @safe { this.ad = ad; this.fieldState = fieldState; diff --git a/compiler/src/dmd/expression.d b/compiler/src/dmd/expression.d index a72df72adb..92243127c2 100644 --- a/compiler/src/dmd/expression.d +++ b/compiler/src/dmd/expression.d @@ -1880,7 +1880,7 @@ extern (C++) final class InterpExp : Expression enum char NoPostfix = 0; - extern (D) this(const ref Loc loc, InterpolatedSet* set, char postfix = NoPostfix) scope + extern (D) this(const ref Loc loc, InterpolatedSet* set, char postfix = NoPostfix) scope @safe { super(loc, EXP.interpolated); this.interpolatedSet = set; @@ -4575,7 +4575,7 @@ extern (C++) class CatAssignExp : BinAssignExp { Expression lowering; // lowered druntime hook `_d_arrayappend{cTX,T}` - extern (D) this(const ref Loc loc, Expression e1, Expression e2) + extern (D) this(const ref Loc loc, Expression e1, Expression e2) @safe { super(loc, EXP.concatenateAssign, e1, e2); } @@ -5286,7 +5286,7 @@ extern (C++) final class ObjcClassReferenceExp : Expression { ClassDeclaration classDeclaration; - extern (D) this(const ref Loc loc, ClassDeclaration classDeclaration) + extern (D) this(const ref Loc loc, ClassDeclaration classDeclaration) @safe { super(loc, EXP.objcClassReference); this.classDeclaration = classDeclaration; diff --git a/compiler/src/dmd/funcsem.d b/compiler/src/dmd/funcsem.d index 2ffd3ad5ab..0528cd0384 100644 --- a/compiler/src/dmd/funcsem.d +++ b/compiler/src/dmd/funcsem.d @@ -2802,7 +2802,7 @@ void modifyReturns(FuncLiteralDeclaration fld, Scope* sc, Type tret) * Returns: `true` if the provided scope is the root * of the traits compiles list of scopes. */ -bool isRootTraitsCompilesScope(Scope* sc) +bool isRootTraitsCompilesScope(Scope* sc) @safe { return (sc.traitsCompiles) && !sc.func.skipCodegen; } diff --git a/compiler/src/dmd/globals.d b/compiler/src/dmd/globals.d index ea88445516..6ce04c0052 100644 --- a/compiler/src/dmd/globals.d +++ b/compiler/src/dmd/globals.d @@ -134,7 +134,7 @@ extern(C++) struct Verbose uint errorLimit = 20; uint errorSupplementLimit = 6; // Limit the number of supplemental messages for each error (0 means unlimited) - uint errorSupplementCount() + uint errorSupplementCount() @safe { if (verbose) return uint.max; @@ -256,7 +256,7 @@ extern (C++) struct Param const(char)* timeTraceFile; /// File path of output file /// - bool parsingUnittestsRequired() + bool parsingUnittestsRequired() @safe { return useUnitTests || ddoc.doOutput || dihdr.doOutput; } diff --git a/compiler/src/dmd/root/filename.d b/compiler/src/dmd/root/filename.d index fb9a18b289..a2f074dbfa 100644 --- a/compiler/src/dmd/root/filename.d +++ b/compiler/src/dmd/root/filename.d @@ -277,7 +277,7 @@ nothrow: * Returns: * the slice */ - extern (D) static const(char)[] sansExt(const char[] filename) + extern (D) static const(char)[] sansExt(const char[] filename) @safe { auto e = ext(filename); size_t length = e.length; @@ -1101,7 +1101,7 @@ nothrow: return str.ptr; } - const(char)[] toString() const pure nothrow @nogc @trusted + const(char)[] toString() const pure nothrow @nogc @safe { return str; } diff --git a/compiler/src/dmd/root/string.d b/compiler/src/dmd/root/string.d index 4b4c3e1f64..221ff10935 100644 --- a/compiler/src/dmd/root/string.d +++ b/compiler/src/dmd/root/string.d @@ -433,7 +433,7 @@ Returns: a `FindSplit` object that casts to `true` iff `needle` was found inside `str`. In that case, `split[1]` is the needle, and `split[0]`/`split[2]` are before/after the needle. */ -FindSplit findSplit(return scope const(char)[] str, scope const(char)[] needle) +FindSplit findSplit(return scope const(char)[] str, scope const(char)[] needle) @safe { if (needle.length > str.length) return FindSplit([str, null, null]); @@ -469,7 +469,7 @@ Params: Returns: substring of `str` inbetween `l` and `r` */ -const(char)[] findBetween(const(char)[] str, const(char)[] l, const(char)[] r) +const(char)[] findBetween(const(char)[] str, const(char)[] l, const(char)[] r) @safe { if (auto s0 = str.findSplit(l)) if (auto s1 = s0[2].findSplit(r)) diff --git a/compiler/src/dmd/utils.d b/compiler/src/dmd/utils.d index cde029d586..8b418968da 100644 --- a/compiler/src/dmd/utils.d +++ b/compiler/src/dmd/utils.d @@ -237,7 +237,7 @@ bool parseDigits(T)(ref T val, const(char)[] p, const T max = T.max) * size = 1 for ubyte[], 2 for ushort[], 4 for uint[], 8 for ulong[] * Returns: copy of `data`, with bytes shuffled if compiled for `version(LittleEndian)` */ -ubyte[] arrayCastBigEndian(const ubyte[] data, size_t size) +ubyte[] arrayCastBigEndian(const ubyte[] data, size_t size) @safe { ubyte[] impl(T)() {