Skip to content

Threading atomic mvp#55

Merged
itsfuad merged 2 commits into
mainfrom
threading-atomic-mvp
Apr 28, 2026
Merged

Threading atomic mvp#55
itsfuad merged 2 commits into
mainfrom
threading-atomic-mvp

Conversation

@itsfuad

@itsfuad itsfuad commented Apr 23, 2026

Copy link
Copy Markdown
Member

This pull request introduces two major improvements: (1) it adds first-class support for atomic types and atomic storage in the type checker, and (2) it fixes and extends ownership analysis for composite values (such as structs, tuples, slices, and maps), especially regarding move semantics. Additionally, it introduces a new standard library module for explicit task/thread management and enhances test coverage for ownership checks.

Atomic type support and type checker enhancements:

  • Adds support for atomic types (AtomicType) in the type checker, including type synthesis, storage validation, type inference, and type parameter collection. This ensures that variables declared as atomic are handled correctly throughout the type system, and that only permitted types can be marked as atomic. (internal/analysis/semantics/typechecker/typechecker.go, internal/analysis/semantics/typechecker/core.go, internal/analysis/semantics/typechecker/syntax_types.go, internal/analysis/semantics/typechecker/symbol_types.go, internal/analysis/semantics/typechecker/const_eval.go) [1] [2] [3] [4] [5] [6]
  • Ensures proper type binding, assignment, and mutability checks for atomic variables in both declarations and statements. (internal/analysis/semantics/typechecker/typechecker.go, internal/analysis/semantics/typechecker/stmts.go) [1] [2]
  • Updates binary operation and dereferencing logic to correctly handle atomic types as operands, unwrapping the inner type as needed for operations. (internal/analysis/semantics/typechecker/typechecker.go) [1] [2] [3]
  • Extends type parameter inference and collection to support atomic types, ensuring generics work correctly with atomic storage. (internal/analysis/semantics/typechecker/typechecker.go) [1] [2]
  • Updates addressability checks to recognize atomic references as addressable and mutable. (internal/analysis/semantics/typechecker/typechecker.go)

Ownership analysis improvements:

  • Fixes ownership analysis for composite values (structs, tuples, arrays, maps, etc.) by ensuring both keys and values are checked for moves, and moves are tracked at the correct granularity. This prevents use-after-move bugs for fields/elements in composite literals. (internal/analysis/semantics/ownership/ownership.go) [1] [2] [3] [4] [5] [6]
  • Adds comprehensive tests to verify that use-after-move errors are correctly detected in composite literal and variadic argument scenarios. (internal/analysis/semantics/ownership/ownership_test.go) [1] [2]

Standard library and build improvements:

  • Introduces a new std/task module for explicit task/thread management, providing a safe and ergonomic interface for spawning and waiting on OS threads. (ferret_libs_dev/std/task.fer)
  • Ensures that the runtime library is always built with pthread support on non-Windows platforms, improving thread safety and compatibility. (bundler/build_tools.go)

itsfuad added 2 commits April 23, 2026 14:05
Add AST/parser support for 'atomic' types and let/stmt flags. Implement
atomic storage TypeInfo, synthesize and const-eval handling in the
typechecker, and HIR/MIR support for atomic loads/ops. Add LLVM lowering
for atomic instructions and runtime symbols.

Introduce std/task surface and C runtime using pthreads on non-Windows
(platform no-op on Windows). Pass -pthread to compiler/linker on
non-Windows. Add tests and repro programs for atomics and task usage.

Copilot AI 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.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copilot AI 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.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copilot AI 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.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@itsfuad itsfuad requested a review from Copilot April 27, 2026 20:11

Copilot AI 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.

Pull request overview

Copilot reviewed 48 out of 48 changed files in this pull request and generated 1 comment.

Comment on lines +14 to +21
fn run_ref<T>(entry: fn(T) -> void, arg: T) -> ^taskInner;

#[extern("ferret_task_wait")]
fn wait_raw(handle: ^void) -> void;

fn Run<T>(callback: fn(T) -> void, arg: T) -> Handle {
unsafe {
return .{ .raw = mem::Adopt(run_ref(callback, arg)) }
@itsfuad itsfuad merged commit d98dae3 into main Apr 28, 2026
18 checks passed
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.

2 participants