FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

lint: fix LINT001 false-positive, improve auto-fixer, finish daslib s… · feiyunwill/daScript@f3bdb72 · GitHub

Commit f3bdb72

Browse files
andcommitted
lint: fix LINT001 false-positive, improve auto-fixer, finish daslib sweep
Three layers of lint cleanup that landed together: 1. LINT001 false-positive in daslib/lint.das. Braceless `if (cond) <terminator>` (the form STYLE005 actively asks for) triggered a false LINT001 on the next sibling statement. The visitor's preVisitExprReturn / preVisitExprCall(panic) wrote the return's pointer onto the enclosing block's slot whenever ANY return/panic was walked — which poisoned the outer block when the return was nested inside an ExprIf body that has no surrounding ExprBlock (the AST shape for `if (cond) return X`). Move the terminator tracking into visitExprBlockExpression so only DIRECT block children mark their enclosing block. Resolves the LINT001 hits in daslib/json_boost.das that surfaced after STYLE005 rewrote `} elif (cond) { return X }` to `} elif (cond) return X`. lint.das own STYLE016/STYLE005 warnings cleaned up alongside. 2. utils/fix-lint-errors improvements. is_simple_subject now peels ExprRef2Value (a typer artifact), so PERF017 fires on field-access subjects like `length(blk.list) == 0` whose AST wraps the receiver in Ref2Value — was silently skipping ~60 daslib hits. preVisitFunction's in_template gate drops isTemplate and macroFunction (those bodies are user-written daslang with reliable .at); only flags.generated stays skipped, the documented struct-annotation corruption case from utils/daspkg/commands.das. Post- rewrite try_compile verification continues to catch any edge case. 3. daslib + dastest sweep, 408 -> 0 lint issues. - dastest/testing.das: 16 STYLE005 in equal/success, 2 STYLE016 NaN guards in numericEqual float/double, 2 LINT002 rename unused `i` to `_i` in benchmark loops. (Cross-module STYLE005 leaks into every test_* file until dastest itself is clean.) - 174 empty `//` trailing markers stripped from daslib/perf_lint.das (78) and daslib/style_lint.das (96), leftover noise that was blocking the fixer's text-extraction sanity check. - Auto-fixer sweep on daslib: ~190 mechanical rewrites across ~30 files. Mostly STYLE005 in perf_lint/style_lint, PERF017 in ast_match, rst, decs_boost, contracts, is_local, spoof, and others. - Hand-finish on the long tail (~234 -> 0): STYLE016 adjacent-guard merges across rst/ast_boost/ast_match/das_source_formatter/fio/clargs/coverage/ interfaces/jobque_boost/aot_cpp/fts5_query/profiler/utf8_utils/ validate_code/linq_boost; PERF014 nolint markers on regex char-class primitives; PERF015 ternary -> min/max with `require math`; PERF006 reserve-before-push in bitfield_trait/delegate/match/templates_boost; PERF007 `string(das_string)` strips in ast.das, perf_lint, style_lint; STYLE017 collapses in aot_cpp/typemacro_boost/jobque_boost/ast_match; STYLE013 named-arg ctor in perf_lint; builtin.das `find_index` / `find_index_if` / `has_value` / `sort` one-line guards (the cross-module STYLE005 instantiation sources). - modules/dasPEG/peg/parse_macro.das: STYLE011 single-line move-init. Net: 51 files (excluding the LINT001 fix), 312 insertions / 399 deletions. daslib lint: 408 -> 0. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent b978482 commit f3bdb72

58 files changed

Lines changed: 554 additions & 980 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎daslib/aot_cpp.das‎

Lines changed: 21 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ def isConstRedundantForCpp(typeDecl : TypeDeclPtr) {
168168
if (Type.tBitfield) { return true; }
169169
if (Type.tBitfield8) { return true; }
170170
if (Type.tBitfield16) { return true; }
171-
if (Type.tBitfield64) { return true; }
171+
if (Type.tBitfield64) { return true; } // nolint:STYLE017 (match arm chain)
172172
if (_) { return false; }
173173
}
174174
}
@@ -397,7 +397,7 @@ def describeCppTypeEx(typeDecl : TypeDeclPtr;
397397
if (typeDecl.firstType != null) {
398398
type_name = describeCppTypeEx(typeDecl.firstType, DescribeConfig(redundant_const = true, cross_platform = cfg.cross_platform), useAlias)
399399
}
400-
let extra_comma = length(typeDecl.argTypes) != 0 ? "," : "";
400+
let extra_comma = !empty(typeDecl.argTypes) ? "," : "";
401401
let arg_types = (each(typeDecl.argTypes)
402402
._select(describeCppTypeEx(_, DescribeConfig(redundant_const = true, cross_platform = cfg.cross_platform), useAlias))
403403
.to_array()
@@ -692,8 +692,7 @@ class public AotDebugInfoHelper {
692692
if (si.fields == null) return ;
693693
for (fi in range(si.count)) {
694694
let fld & = unsafe(si.fields[fi])
695-
if (fld.annotation_arguments == null) continue;
696-
if (length(*fld.annotation_arguments) == 0) continue;
695+
if (fld.annotation_arguments == null || empty(*fld.annotation_arguments)) continue;
697696
write(writer, " {structInfoName(si)}_field_{fi}.annotation_arguments = &{structInfoName(si)}_field_{fi}_ann;\n")
698697
}
699698
})
@@ -731,7 +730,7 @@ class public AotDebugInfoHelper {
731730
writeDim(writer, fld, suffix);
732731
writeArgTypes(writer, fld, suffix);
733732
writeArgNames(writer, fld, suffix);
734-
let prefix = (info.module_name |> length() > 0) ? "{info.module_name}::" : "";
733+
let prefix = (info.module_name |> !empty(info.module_name)) ? "{info.module_name}::" : "";
735734
write(*writer, "VarInfo {structInfoName(info)}_field_{fi} = \{ {describeCppVarInfo(prefix + info.name, fld,suffix)} \};\n");
736735
if (fld.annotation_arguments != null) {
737736
if (length(*fld.annotation_arguments) > 0) {
@@ -996,7 +995,7 @@ class public BlockVariableCollector : AstVisitor {
996995
def getFinalBlock() {
997996
for (i in range(length(stack))) {
998997
let blk = stack[length(stack) - i - 1];
999-
if (length(blk.finalList) != 0) return blk;
998+
if (!empty(blk.finalList)) return blk;
1000999
if (blk.blockFlags.isClosure) return null;
10011000
}
10021001
return null;
@@ -1730,10 +1729,10 @@ class public CppAot : AstVisitor {
17301729
that.right._type.baseType == Type.tBool && that.right._type.isSimpleType);
17311730
}
17321731
def isOpPolicy2(that : ExprOp2?) {
1733-
if (is_alpha(first_character(that.op))) return true;
1734-
if (that.op == "/" || that.op == "%") return true;
1735-
if (that.op == "<<<" || that.op == ">>>" || that.op == "<<<=" || that.op == ">>>=") return true;
1736-
if (that.op == "<<" || that.op == ">>" || that.op == "<<=" || that.op == ">>=") return true;
1732+
if (is_alpha(first_character(that.op))
1733+
|| that.op == "/" || that.op == "%"
1734+
|| that.op == "<<<" || that.op == ">>>" || that.op == "<<<=" || that.op == ">>>="
1735+
|| that.op == "<<" || that.op == ">>" || that.op == "<<=" || that.op == ">>=") return true;
17371736
return that._type.isPolicyType || that.left._type.isPolicyType || that.right._type.isPolicyType;
17381737
}
17391738
def opPolicyBase(that : ExprOp2?) {
@@ -3259,7 +3258,7 @@ class public CppAot : AstVisitor {
32593258
}
32603259
}
32613260
def override canVisitExprLooksLikeCallArgument(call : ExprLooksLikeCall?; arg : ExpressionPtr; last : bool) {
3262-
if (length(call.arguments) >= 1 && call.arguments[0] == arg && call is ExprInvoke) {
3261+
if (!empty(call.arguments) && call.arguments[0] == arg && call is ExprInvoke) {
32633262
let inv = call as ExprInvoke;
32643263
if (inv.isInvokeMethod) return false;
32653264
}
@@ -3319,24 +3318,17 @@ class public CppAot : AstVisitor {
33193318
if (!polType.isHandle) {
33203319
if (polType.isVecPolicyType && argType.isVecPolicyType) return false;
33213320
}
3322-
if (!polType.isPolicyType) return false;
3323-
return true;
3321+
return polType.isPolicyType;
33243322
}
33253323
def policyResultNeedCast(polType : TypeDeclPtr; resType : TypeDeclPtr) {
3326-
if (resType.isVoid) return false;
3327-
if (!resType.isPolicyType) return false;
3324+
if (resType.isVoid || !resType.isPolicyType) return false;
33283325
return policyArgNeedCast(polType, resType);
33293326
}
33303327
def isPolicyBasedCall(call : ExprCall?) {
33313328
let bif = call.func as BuiltInFunction;
3332-
if (call.arguments |> empty() && call.func.result.baseType == Type.tHandle) {
3333-
// c-tor?
3334-
return false;
3335-
} elif (bif.flags.policyBased) {
3336-
return true;
3337-
} else {
3338-
return false;
3339-
}
3329+
// empty arg ctor returning handle is NOT policy-based
3330+
if (call.arguments |> empty() && call.func.result.baseType == Type.tHandle) return false;
3331+
return bif.flags.policyBased;
33403332
}
33413333
def isPolicyBasedCallFunc(call : ExprCallFunc?) {
33423334
if (call.func.flags.builtIn) {
@@ -3354,12 +3346,10 @@ class public CppAot : AstVisitor {
33543346
if (func.flags.callBased) {
33553347
panic("we should not be here. call-based calls handled elsewhere");
33563348
}
3357-
return length(bif.cppName) == 0;
3349+
return empty(bif.cppName);
33583350
}
3359-
if (func.flags.noAot) return true;
3360-
if (func.flags.aotHybrid) return true;
3361-
if (func._module == program.getThisModule) return false;
3362-
return true;
3351+
if (func.flags.noAot || func.flags.aotHybrid) return true;
3352+
return func._module != program.getThisModule;
33633353
}
33643354
def needsArgPassType(argType : TypeDeclPtr) {
33653355
return !argType.flags.constant && !argType.isGoodBlockType;
@@ -3448,7 +3438,7 @@ class public CppAot : AstVisitor {
34483438
}
34493439
assume mangledName = call.func |> get_mangled_name();
34503440
let hash = call.func.getMangledNameHash;
3451-
if (length(call.arguments) >= 1) {
3441+
if (!empty(call.arguments)) {
34523442
write(*ss, "<");
34533443
for (arg in call.func.arguments) {
34543444
write(*ss, "{describeCppType(arg._type,DescribeConfig(cross_platform=cross_platform))}");
@@ -3816,8 +3806,8 @@ def collectUsedFunctions(modules : array<Module?>; totalFunctions : int; this_mo
38163806
fnn.reserve(totalFunctions);
38173807
for (pm in modules) {
38183808
pm |> for_each_module_function($(pfun) {
3819-
if (!all_modules && pfun._module != this_module) return ;
3820-
if (pfun.index < 0 || !pfun.flags.used) return ;
3809+
if ((!all_modules && pfun._module != this_module)
3810+
|| pfun.index < 0 || !pfun.flags.used) return ;
38213811
if (!is_all) {
38223812
if (pfun.flags.builtIn || pfun.flags.noAot) return ;
38233813
}

‎daslib/aot_standalone.das‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ def writeStandaloneContextMethods(var prog : ProgramPtr; var logs : StringBuilde
5353
var coll = new BlockVariableCollector();
5454

5555
for (fn in fnn) {
56-
if (!fn.flags.exports) continue;
57-
if (fn._module != prog.getThisModule) continue;
56+
if (!fn.flags.exports || fn._module != prog.getThisModule) continue;
5857
if (declare_only) {
5958
write(logs, " ");
6059
}
@@ -232,8 +231,8 @@ class StandaloneContextGen : CppAot {
232231
var globals : array<Variable?>;
233232
prog.get_ptr() |> for_each_module_no_order($(pm) {
234233
pm |> for_each_global($(pvar) {
235-
if (pvar.index < 0 || !pvar.flags.used) return ;
236-
if (pvar._module == prog.getThisModule) return ;
234+
if (pvar.index < 0 || !pvar.flags.used
235+
|| pvar._module == prog.getThisModule) return ;
237236
globals.push(pvar);
238237
});
239238
});

‎daslib/apply.das‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def for_each_subrange(total : int; blk : block<(r : range) : void>) {
4848
[macro_function]
4949
def generateApplyVisitStruct(stype : TypeDeclPtr; frange : range; fnname : string; at : LineInfo; var names : array<string>; hasExtraArg : bool) {
5050
assert(stype.baseType == Type.tStructure)
51-
assert(stype.dim |> length == 0)
51+
assert(empty(stype.dim))
5252
let nfields = frange.y - frange.x
5353
var selfT = clone_type(stype)
5454
selfT.flags |= TypeDeclFlags.isExplicit | TypeDeclFlags.explicitConst
@@ -124,7 +124,7 @@ def generateApplyVisitStruct(stype : TypeDeclPtr; fnname : string; at : LineInfo
124124
[macro_function]
125125
def generateApplyVisitTuple(stype : TypeDeclPtr; frange : range; fnname : string; at : LineInfo; var names : array<string>) {
126126
assert(stype.baseType == Type.tTuple)
127-
assert(stype.dim |> length == 0)
127+
assert(empty(stype.dim))
128128
let nfields = frange.y - frange.x
129129
var selfT = clone_type(stype)
130130
selfT.flags |= TypeDeclFlags.isExplicit | TypeDeclFlags.explicitConst
@@ -181,7 +181,7 @@ def generateApplyVisitTuple(stype : TypeDeclPtr; fnname : string; at : LineInfo)
181181
[macro_function]
182182
def generateApplyVisitVariant(stype : TypeDeclPtr; frange : range; fnname : string; at : LineInfo; var names : array<string>) {
183183
assert(stype.baseType == Type.tVariant)
184-
assert(stype.dim |> length == 0)
184+
assert(empty(stype.dim))
185185
let nfields = frange.y - frange.x
186186
var selfT = clone_type(stype)
187187
selfT.flags |= TypeDeclFlags.isExplicit | TypeDeclFlags.explicitConst
@@ -272,7 +272,7 @@ class ApplyMacro : AstCallMacro {
272272
macro_verify(expr.arguments |> length == 2, prog, expr.at, "expecting apply(value, block)")
273273
if (expr.arguments[0]._type != null) {// need value inferred
274274
var argT = clone_type(expr.arguments[0]._type)
275-
macro_verify(argT.dim |> length == 0, prog, expr.at, "can't apply to dim")
275+
macro_verify(empty(argT.dim), prog, expr.at, "can't apply to dim")
276276
macro_verify(argT.baseType == Type.tStructure || argT.baseType == Type.tTuple || argT.baseType == Type.tVariant,
277277
prog, expr.at, "can only apply to {describe(expr.arguments[0]._type)}")
278278
macro_verify(expr.arguments[1] is ExprMakeBlock, prog, expr.at, "expecting make block, i.e. $(..)")

‎daslib/ast.das‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -974,7 +974,7 @@ def add_new_optimization_macro(name : string; var someClassPtr) {
974974
def find_module(prog : smart_ptr<Program>; name : string) : Module? {
975975
var rm : Module?
976976
program_for_each_module(prog) $(mod) {
977-
if (string(mod.name) == name) {
977+
if (mod.name == name) {
978978
rm = mod
979979
}
980980
}

‎daslib/ast_boost.das‎

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,7 @@ def describe_function_short(func : FunctionPtr) {
7979

8080
def isExpression(t : TypeDeclPtr; top : bool = true) : bool {
8181
//! Returns true if the type declaration refers to an AST expression node type.
82-
if (t == null) {
83-
return false
84-
} elif (t.dim |> length != 0) {
82+
if (t == null || !empty(t.dim)) {
8583
return false
8684
} elif (t.baseType == Type.tHandle) {
8785
if (t.annotation._module.name == "ast_core") {
@@ -108,11 +106,11 @@ def is_same_or_inherited(parent, child : Structure const?) {
108106

109107
def is_class_method(cinfo : StructurePtr; finfo : TypeDeclPtr) {
110108
//! Returns true if the function type declaration is a method of the given class structure.
111-
if (finfo.baseType != Type.tFunction) return false
112-
if (finfo.dim |> length != 0) return false
113-
if (finfo.argTypes |> length == 0) return false
114-
if (finfo.argTypes[0].baseType != Type.tStructure) return false
115-
if (finfo.argTypes[0].dim |> length != 0) return false
109+
if (finfo.baseType != Type.tFunction
110+
|| !empty(finfo.dim)
111+
|| empty(finfo.argTypes)
112+
|| finfo.argTypes[0].baseType != Type.tStructure
113+
|| !empty(finfo.argTypes[0].dim)) return false
116114
return !!is_same_or_inherited(finfo.argTypes[0].structType, cinfo)
117115
}
118116

@@ -848,7 +846,7 @@ def private walk_and_convert_enumeration(data : uint8 const?; info : TypeDeclPtr
848846
def walk_and_convert(data : uint8 const?; info : TypeDeclPtr; at : LineInfo) : Expression? {
849847
//! Recursively converts raw data to an AST expression based on type information.
850848
// print("0x{intptr(data)} {describe(info)}\n")
851-
if (info.dim |> length != 0) {
849+
if (!empty(info.dim)) {
852850
return walk_and_convert_dim(data, info, at)
853851
} elif (info.baseType == Type.tArray) {
854852
return walk_and_convert_array(data, info, at)
@@ -1262,7 +1260,7 @@ def private debug_expression_impl(var writer : StringBuilderWriter; expr : Expre
12621260
}
12631261
if (tstr == "$::dasvector`ptr`Expression") {
12641262
let pv = unsafe(reinterpret<dasvector`ptr`Expression?> p8)
1265-
if (length(*pv) != 0) {
1263+
if (!empty(*pv)) {
12661264
let ts = repeat(" ", tabs + 2)
12671265
writer |> write("\n{ts}[{name}\n")
12681266
for (l, i in *pv, count()) {
@@ -1276,7 +1274,7 @@ def private debug_expression_impl(var writer : StringBuilderWriter; expr : Expre
12761274
}
12771275
} elif (tstr == "$::dasvector`ptr`Variable") {
12781276
let pv = unsafe(reinterpret<dasvector`ptr`Variable?> p8)
1279-
if (length(*pv) != 0) {
1277+
if (!empty(*pv)) {
12801278
let ts = repeat(" ", tabs + 2)
12811279
writer |> write("\n{ts}[{name}\n")
12821280
for (l, i in *pv, count()) {

‎daslib/ast_debug.das‎

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,21 @@ def report_to_debugger(var ctx : Context; category, name : string; value : auto(
2525
def isExpressionType(_vinfo) {
2626
if (_vinfo.basicType != Type.tPointer || _vinfo.firstType == null) return false
2727
let vinfo = _vinfo.firstType
28-
if (vinfo.basicType != Type.tHandle) return false
29-
if (vinfo.annotation._module.name != "ast_core") return false
30-
return !!string(vinfo.annotation.name) |> starts_with("Expr")
28+
if (vinfo.basicType != Type.tHandle
29+
|| vinfo.annotation._module.name != "ast_core") return false
30+
var result = false
31+
peek(vinfo.annotation.name) $(n) {
32+
result = n |> starts_with("Expr")
33+
}
34+
return result
3135
}
3236

3337
def isModulePtrType(_vinfo; mod, what : string) {
3438
if (_vinfo.basicType != Type.tPointer || _vinfo.firstType == null) return false
3539
let vinfo = _vinfo.firstType
36-
if (vinfo.basicType != Type.tHandle) return false
37-
if (vinfo.annotation._module.name != mod) return false
38-
return !(vinfo.annotation.name != what)
40+
if (vinfo.basicType != Type.tHandle
41+
|| vinfo.annotation._module.name != mod) return false
42+
return vinfo.annotation.name == what
3943
}
4044

4145
def isAstPtrType(_vinfo; what : string) {
@@ -47,9 +51,9 @@ def isRttiPtrType(_vinfo; what : string) {
4751
}
4852

4953
def isRttiType(vinfo; what : string) {
50-
if (vinfo.basicType != Type.tHandle) return false
51-
if (vinfo.annotation._module.name != "rtti_core") return false
52-
return !(vinfo.annotation.name != what)
54+
if (vinfo.basicType != Type.tHandle
55+
|| vinfo.annotation._module.name != "rtti_core") return false
56+
return vinfo.annotation.name == what
5357
}
5458

5559
def describe_arg(var ctxid : Context; vinfo; arg : void?) : void {

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL