You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[soundness] option[T] TypeShape erasure allows &option[chan T] / &option[atomic] borrows across tasks (HYB-E3001/E3103/E3104 data race) and send/recv/range on option[T] (HYB-E3007/E2008/E2009) #753
In hy-check/src/shape.rs, Checker::shape_of_type folds option[T] (TypeExpr::Generic { name: "option", args: [T] }) to shape_of_type(T). Several expression and container shape checks rely on shape_of_type or expr_is_option without preserving the outer option[...] wrapper:
Indexed, Dereferenced, Projected, Channel-Received, select-Bound, for-Range-Bound, and Type-Aliased option[T] Operands:
expr_is_option does not handle Expr::Index (xs[0], m["k"]), Expr::Deref (*p), Expr::Field (h.opt), Expr::Paren, or Expr::Move, and checks TypeExpr syntactically without resolving type aliases (type opt_ch = option[chan int]).
ty_of_expr and multi_value_tys do not synthesize TypeExpr for Expr::Index, Expr::Deref, Expr::Receive (opt := <-ch, opt, ok := <-ch), or Expr::Field.
SelectRecv (select { opt := <-ch: ... }) and ForKind::Iterate (for _, opt in xs) pass None as ty to define_binding, losing the option[...] wrapper on the bound variable.
Reassigning opt = none overwrites a specific b.ty (such as option[option[chan int]]) with option[any], erasing nested option wrappers on subsequent match unwraps.
As a result, xs[0], m["k"], *p, h.opt, get_alias(), <-ch, select { opt := <-ch: ... }, and for _, opt in xs of type option[chan int] or opt_ch are treated as bare chan int (bypassing HYB-E3007 on <- and HYB-E2008 on for v in ...) and as Sendable (bypassing HYB-E3001 on &xs[0], p, &h.opt, &opt).
Containers, Pointers, new(alias), and Structs Holding option[T]:
shape_of_type for Slice, Array, Map, Chan, and Pointer recursively calls shape_of_type(inner), turning []option[int] into Slice(Primitive) and *option[atomic.int64] (or new(opt_atomic)) into Pointer(Atomic) (which is Sendable!).
struct_is_sendable checks field shapes via shape_of_type(&f.ty) without checking whether f.ty is option[...], allowing a struct with an option[int] or option[chan int] field to be shared across task spawn without move (HYB-E3001 bypassed).
option[T] values obtained via indexing, dereferencing, field projection, channel receive, select receive arms, for range loops, or type aliases must not be usable as bare T in channel send/receive (HYB-E3007), for ... in channel range (HYB-E2008), or address-of/pointer/struct task spawn (HYB-E3001).
Activity
fix(hy-check): preserve option TypeExpr across receive, select, range…
fix(hy-check): prevent option[T] TypeShape erasure on pointers, sends…
fix(hy-check): preserve option TypeExpr across receive, select, range…