| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 1144bf7 commit 3a151c4
9 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -248,7 +248,7 @@ def array_view( | |||
| 248 | 248 | var res : array<TT -const># | |
| 249 | 249 | if (length > 0) { | |
| 250 | 250 | let data = addr<TT -const?>(bytes[byte_offset]) | |
| 251 | - if (intptr(reinterpret<void? -const>(data)) % uint64(element_align) != 0_ul) { | ||
| 251 | + if (intptr(reinterpret<void?>(data)) % uint64(element_align) != 0_ul) { | ||
| 252 | 252 | panic("array_view: unaligned typed view") | |
| 253 | 253 | } | |
| 254 | 254 | _builtin_make_temp_array(res, data, length) | |
@@ -262,7 +262,7 @@ def array_view( | |||
| 262 | 262 | var res : array<TT -const># | |
| 263 | 263 | if (length > 0_l) { | |
| 264 | 264 | let data = addr<TT -const?>(bytes[byte_offset]) | |
| 265 | - if (intptr(reinterpret<void? -const>(data)) % uint64(element_align) != 0_ul) { | ||
| 265 | + if (intptr(reinterpret<void?>(data)) % uint64(element_align) != 0_ul) { | ||
| 266 | 266 | panic("array_view: unaligned typed view") | |
| 267 | 267 | } | |
| 268 | 268 | _builtin_make_temp_array_i64(res, data, length) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -9,7 +9,6 @@ module async_boost shared private | |||
| 9 | 9 | //! Provides ``[async]`` function annotation and ``await`` call macro that | |
| 10 | 10 | //! rewrite annotated functions into generator-based coroutines. | |
| 11 | 11 | ||
| 12 | - require strings | ||
| 13 | 12 | require daslib/ast_boost | |
| 14 | 13 | require daslib/templates_boost | |
| 15 | 14 | require daslib/macro_boost | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1303,7 +1303,7 @@ class private DAgent : DapiDebugAgent { | |||
| 1303 | 1303 | return | |
| 1304 | 1304 | } | |
| 1305 | 1305 | } | |
| 1306 | - frame.state |> emplace <| (uid = STATE_VARS + uint64(length(frame.state)), name = category, vars = [ variable]) | ||
| 1306 | + frame.state |> emplace <| (uid = STATE_VARS + uint64(long_length(frame.state)), name = category, vars = [ variable]) | ||
| 1307 | 1307 | } | |
| 1308 | 1308 | }) | |
| 1309 | 1309 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -205,7 +205,7 @@ def func_call_length(var st : TokenStream; result : Result) : Result { | |||
| 205 | 205 | } | |
| 206 | 206 | if (TypeInfo(basicType = Type.tString)) { | |
| 207 | 207 | let pstr = unsafe(reinterpret<string?>(getPD(st, result))) | |
| 208 | - return <- Result(int64(length(*pstr))) | ||
| 208 | + return <- Result(long_length(*pstr)) | ||
| 209 | 209 | } | |
| 210 | 210 | if (TypeInfo(basicType = Type.tArray)) { | |
| 211 | 211 | let parr = unsafe(reinterpret<DapiArray?>(getPD(st, result))) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -22,7 +22,6 @@ module delegate shared private | |||
| 22 | 22 | ||
| 23 | 23 | require daslib/macro_boost | |
| 24 | 24 | require daslib/typemacro_boost | |
| 25 | - require strings | ||
| 26 | 25 | ||
| 27 | 26 | // ── helpers ──────────────────────────────────────────────────────────── | |
| 28 | 27 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -612,7 +612,7 @@ def public subst_consts(var e : ExpressionPtr; constmap : table<string; Expressi | |||
| 612 | 612 | var tmpl : Template | |
| 613 | 613 | for (nm in keys(constmap)) { | |
| 614 | 614 | // ?[] yields a const view; const-strip the raw pointer (apply_template clones per use anyway). | |
| 615 | - var ex = unsafe(reinterpret<Expression? -const>(constmap?[nm] ?? null)) | ||
| 615 | + var ex = unsafe(reinterpret<Expression?>(constmap?[nm] ?? null)) | ||
| 616 | 616 | tmpl |> replaceVariable(nm, ex) | |
| 617 | 617 | } | |
| 618 | 618 | var res = apply_template(tmpl, e.at, e, false) | |
@@ -718,7 +718,7 @@ def public store_base(e : Expression const?) : ExpressionPtr { | |||
| 718 | 718 | if (e is ExprSwizzle) return store_base((e as ExprSwizzle).value) | |
| 719 | 719 | if (e is ExprPtr2Ref) return store_base((e as ExprPtr2Ref).subexpr) | |
| 720 | 720 | if (e is ExprRef2Value) return store_base((e as ExprRef2Value).subexpr) | |
| 721 | - return e is ExprVar ? unsafe(reinterpret<Expression? -const>(e)) : null | ||
| 721 | + return e is ExprVar ? unsafe(reinterpret<Expression?>(e)) : null | ||
| 722 | 722 | } | |
| 723 | 723 | ||
| 724 | 724 | // Names reassigned somewhere in the block (live/loop masks `__flat_*`, any reassigned user `var`). | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -606,7 +606,7 @@ def private regroup_to_share(var blk : ExprBlock?; no_fast_math : bool) : bool { | |||
| 606 | 606 | def private alias_source(e : Expression const?) : ExpressionPtr { | |
| 607 | 607 | if (e == null) return null | |
| 608 | 608 | if (e is ExprRef2Value) return alias_source((e as ExprRef2Value).subexpr) | |
| 609 | - return e is ExprVar ? unsafe(reinterpret<Expression? -const>(e)) : null | ||
| 609 | + return e is ExprVar ? unsafe(reinterpret<Expression?>(e)) : null | ||
| 610 | 610 | } | |
| 611 | 611 | ||
| 612 | 612 | def private eliminate_aliases(var blk : ExprBlock?) : bool { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2367,6 +2367,26 @@ class StyleLintVisitor : AstVisitor { | |||
| 2367 | 2367 | && !expr.subexpr.genFlags.generated) { | |
| 2368 | 2368 | style_warning("STYLE034: reinterpret<{describe(expr.castType)}>(addr(...)) collapses to addr<{describe(expr.castType)}>(...); one unsafe() covers both halves", expr.at) | |
| 2369 | 2369 | } | |
| 2370 | + // ===== STYLE036 — type contract that cannot act on a resolved cast type ===== | ||
| 2371 | + if (!expr.genFlags.generated && expr.castType != null) { | ||
| 2372 | + let inert = style036_inert_contract(expr.castType) | ||
| 2373 | + if (!empty(inert)) { | ||
| 2374 | + let tail = inert == "-const" ? "; drop it, along with any 'const' it was meant to cancel" : "; drop it" | ||
| 2375 | + style_warning("STYLE036: '{inert}' does nothing on the already-resolved cast type {describe(expr.castType)}{tail}", expr.at) | ||
| 2376 | + } | ||
| 2377 | + } | ||
| 2378 | + } | ||
| 2379 | + | ||
| 2380 | + def style036_inert_contract(t : TypeDecl?) : string { | ||
| 2381 | + // Substitution contracts: infer clears them when a generic binds (ast_typedecl.cpp:223,422), so one still set on a concrete target was never consumed — but an auto/unresolved-alias target has simply not been substituted yet (linq's `reinterpret<ARGT -const>` does strip const). | ||
| 2382 | + if (t.isAutoOrAlias) return "" | ||
| 2383 | + if (t.flags.removeConstant) return "-const" | ||
| 2384 | + if (t.flags.removeRef) return "-&" | ||
| 2385 | + if (t.flags.removeDim) return "-[]" | ||
| 2386 | + if (t.flags.removeTemporary) return "-#" | ||
| 2387 | + if (t.flags.explicitConst) return "==const" | ||
| 2388 | + if (t.flags.explicitRef) return "==&" | ||
| 2389 | + return "" | ||
| 2370 | 2390 | } | |
| 2371 | 2391 | ||
| 2372 | 2392 | def override preVisitExprAt(expr : ExprAt?) : void { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,58 @@ | |||
| 1 | + options gen2 | ||
| 2 | + options auto_inline_functions = false // lint fixtures assert SOURCE shapes; splices rewrite them | ||
| 3 | + // STYLE036: type contract that cannot act on an already-resolved cast type | ||
| 4 | + // | ||
| 5 | + // Problem: -const / -& / -[] / -# / ==const / ==& are substitution contracts. | ||
| 6 | + // They do work only while a generic binds, and infer clears them once it | ||
| 7 | + // consumes them. A cast target is already concrete, so nothing ever consumes | ||
| 8 | + // the contract — void? is void? regardless of -const. | ||
| 9 | + // | ||
| 10 | + // Bad pattern: | ||
| 11 | + // let p = unsafe(addr<void? -const>(x)) | ||
| 12 | + // | ||
| 13 | + // Good pattern: | ||
| 14 | + // let p = unsafe(addr<void?>(x)) | ||
| 15 | + | ||
| 16 | + typedef CI = int const | ||
| 17 | + | ||
| 18 | + // bad: -const on an already-resolved pointer type (1 warning) | ||
| 19 | + def bad_remove_const(p : void?) : int? { | ||
| 20 | + return unsafe(reinterpret<int? -const>(p)) | ||
| 21 | + } | ||
| 22 | + | ||
| 23 | + // bad: -const through the addr<T?> sugar (1 warning) | ||
| 24 | + def bad_addr_sugar(var x : int) : void? { | ||
| 25 | + return unsafe(addr<void? -const>(x)) | ||
| 26 | + } | ||
| 27 | + | ||
| 28 | + // bad: -# on a type that is not temporary (1 warning) | ||
| 29 | + def bad_remove_temporary(p : void?) : int? { | ||
| 30 | + return unsafe(reinterpret<int? -#>(p)) | ||
| 31 | + } | ||
| 32 | + | ||
| 33 | + // bad: an alias is no different — the contract is inert there too (1 warning) | ||
| 34 | + def bad_alias_remove_const(p : void?) : CI? { | ||
| 35 | + return unsafe(reinterpret<CI? -const>(p)) | ||
| 36 | + } | ||
| 37 | + | ||
| 38 | + // good: no contract at all | ||
| 39 | + def good_plain(p : void?) : int? { | ||
| 40 | + return unsafe(reinterpret<int?>(p)) | ||
| 41 | + } | ||
| 42 | + | ||
| 43 | + // good: the sugar without a contract | ||
| 44 | + def good_addr_sugar(var x : int) : void? { | ||
| 45 | + return unsafe(addr<void?>(x)) | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | + // good: a contract on a generic parameter is consumed by substitution, so it is | ||
| 49 | + // already cleared by the time any cast target is inspected | ||
| 50 | + def good_generic_contract(a : array<auto(TT)> -const) : int { | ||
| 51 | + return length(a) | ||
| 52 | + } | ||
| 53 | + | ||
| 54 | + [export] | ||
| 55 | + def use_generic_contract() : int { | ||
| 56 | + var xs = [1, 2, 3] | ||
| 57 | + return good_generic_contract(xs) | ||
| 58 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments