Skip to content

Closures - #1536

Closed
sbillig wants to merge 16 commits into
argotorg:masterfrom
sbillig:closure
Closed

sbillig wants to merge 16 commits into
argotorg:masterfrom
sbillig:closure

Conversation

@sbillig

@sbillig sbillig commented Aug 1, 2026

Copy link
Copy Markdown
Collaborator

No description provided.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 163cba06ce

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@sbillig

sbillig commented Aug 1, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 82a9541377

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +337 to +341
CallableDef::Func(func) => func
.params(db)
.nth(idx)
.map(|param| param.mode(db).into())
.unwrap_or(LogicalCallableParamMode::View),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve ref and mut modes in logical signatures

For an ordinary function parameter such as target: mut u256 or value: ref T, FuncParamMode is View because the ref/mut information lives in the carrier type. Converting only param.mode here and then stripping the carrier below renders the parameter as plain target: u256/value: T in signature help, hover, and inlay hints, hiding the required call-site capability. Derive Ref/Mut from capability-bearing carriers before falling back to the function parameter mode.

Useful? React with 👍 / 👎.

Comment on lines +274 to +277
let mode = closure_modes
.and_then(|modes| modes.get(idx).copied())
.or_else(|| ClosureParamMode::try_from_carrier(db, carrier))
.unwrap_or(ClosureParamMode::View);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Treat unresolved packed parameters as owned

For a generic callable such as F: Fn<(T,), U>, the pack field is a TyParam, so try_from_carrier returns None and this fallback marks the argument as View. The type checker, however, treats every non-capability pack element as Own, so signature help reports _: T even though invoking the callable consumes the T; the identical fallback in signature_from_trait_inst also mislabels hover and completion details. Unknown bare pack carriers should default to Own, reserving View for an explicit capability carrier.

Useful? React with 👍 / 👎.

Comment on lines +948 to +952
let args = param_names
.iter()
.enumerate()
.map(|(idx, name)| format!("${{{}:{name}}}", idx + 1))
.collect::<Vec<_>>()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Insert capability prefixes in callable snippets

When a callable value has a ref or mut logical parameter, this builds the invocation arguments from names alone, so accepting completion for a closure such as |slot: mut u256| ... inserts update(slot) rather than the required update(mut slot) (and likewise omits ref). The type checker requires those explicit capability arguments for place values, making the newly inserted snippet invalid even though the completion detail correctly advertises the mode.

Useful? React with 👍 / 👎.

Comment on lines +195 to +200
for &inst in enclosing_assumptions(db, scope).list(db) {
if inst.self_ty(db) != payload {
continue;
}
let Some(call_trait) = ClosureCallTrait::for_trait(db, scope, inst.def(db)) else {
continue;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Expand supertraits when discovering generic callables

For a generic value constrained through a custom supertrait, such as trait Unary: Fn<(u256,), u256> and F: Unary, the compiler can invoke F through the implied Fn bound, but this loop examines only the directly declared Unary assumption. Because Unary is not itself recognized as a core call trait, callable hover and invocation completions disappear for otherwise callable values; expand the assumption list with its implied bounds before filtering for Fn/FnOnce.

Useful? React with 👍 / 👎.

sbillig added 16 commits August 1, 2026 10:29
Introduce closure literals across the parser, formatter, HIR, type checker,
semantic lowering, runtime lowering, and editor grammar. Establish nominal
closure bodies and initial callable dispatch with end-to-end regression
coverage.
Model capture access and move modes explicitly, distinguish reusable and
consuming closures, and carry captured loans through semantic analysis.
Enforce borrow, move, and noesc rules across direct and generic callable
paths.
Adopt one tuple-packed Fn/FnOnce argument ABI for every arity while retaining
source-level parameter modes. Add contextual parameter and result inference,
and preserve exact layout and borrow provenance through the physical pack.
Finish closure specialization across semantic instances, layout evidence,
effects, MIR interfaces, and runtime lowering. Preserve callable ownership
and provider semantics through generic dispatch and contract execution.
Regenerate Sonatina snapshots and the vendored Tree-sitter WebAssembly output
after the closure runtime and grammar changes.
Bring the compiler parser, Tree-sitter scanner, highlighting queries, corpus,
and vendored editor grammar into agreement for inferred and mode-qualified
closure parameters.
Make deferred closure typing transactional and replay contextual constraints
through calls, projections, aliases, effects, and method selection. Preserve
nominal closure identity while allowing valid generic inference to converge.
Close the remaining soundness gaps in borrow checking, definite assignment,
semantic normalization, layout evidence, and program-point invalidation.
Strengthen non-regular recursion analysis for closure-heavy generic graphs.
Retain callable environments and capability-bearing carriers only when their
runtime identities escape. Keep reusable and consuming closure ABIs stable
through materialization, specialization, and code generation.
Resolve value(args) through the core Fn and FnOnce traits, preferring reusable
dispatch before consuming fallback. Keep ordinary functions and constructors
on their existing path, improve logical diagnostics, and exercise direct
syntax throughout the standard library and closure regression matrix.
Expose one source-level callable signature and target view that hides the
receiver-plus-tuple trait ABI. Use exact selected calls and applicable,
specialized callable impls to power signature help and rich closure hover.
Keep callable values available as values while adding invocation snippets for
locals, parameters, and fields. Parenthesize callable-field edits correctly,
enumerate distinct overloads, and filter inapplicable specializations.
Navigate callable values to closure literals and applicable implementations,
keep call hierarchy at source-level closure targets, and include contract
initializers and receive arms. Add logical parameter hints and a structured
callable-field parenthesization fix.
Use resolved argument spans for signature-help selection so closure parameter commas stay inside the enclosing argument. Preserve explicit callable receivers for UFCS and expose stored function-item signatures to hover, completion, and inlay hints.
Derive ref and mut modes from carrier types, treat unresolved packed arguments as owned, expand implied call-trait bounds, and emit capability-correct invocation snippets.
@sbillig
sbillig marked this pull request as draft September 14, 2026 16:47
@sbillig

sbillig commented Oct 14, 2026

Copy link
Copy Markdown
Collaborator Author

#1798

@sbillig sbillig closed this Oct 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant