Skip to content

Intermittent SIGSEGV in generate_default_trait_method_for_impl_ext during self-hosted build #72

Closed

Description

@ehartford

Summary

The compiler intermittently crashes with SIGSEGV during codegen when building out/gen/main.w (the compiler's own source). The crash occurs in default trait method generation when resolving an unbound generic type parameter, and affects ~20-40% of build attempts.

This is not related to any specific source change — the installed release binary (v0.12.0-663-g6bc26c5ec) exhibits the same crash.

Crash location

sema_str_contains_char
Sema.suggest_type_name
Sema.emit_unknown_type_error
Codegen.resolve_type
Codegen.generate_default_trait_method_for_impl_ext
Codegen.generate_default_trait_methods_for_impl
Codegen.generate_default_trait_methods
Codegen.gen_module_from_mir
Zcu.compile_to_object_backend

resolve_type returns 0 for an unbound generic type parameter T during default trait method codegen, then emit_unknown_type_error calls suggest_type_name which dereferences a null/invalid string pointer in sema_str_contains_char.

Reproduction

# Using the installed compiler (no local changes required):
for i in 1 2 3 4 5; do
    /Users/eric/.local/bin/with build out/gen/main.w -o /tmp/crash-probe-$i -O0 2>/dev/null
    echo "attempt $i: $?"
done

Typical output:

attempt 1: 0
attempt 2: 0
attempt 3: 139
attempt 4: 139
attempt 5: 139

The crash is nondeterministic — likely depends on HashMap iteration order or memory layout affecting which impl/trait/method combination triggers the unbound type parameter.

Analysis

With WITH_DEBUG_STAGE1_TRACE=1, the trace shows [unknown-type] T appearing during default trait method generation. The codegen path at generate_default_trait_method_for_impl_ext (src/CodegenTraits.w) sets up type parameter bindings from impl_trait_type_args before generating the method body, but for some impl/trait combinations the binding fails to resolve, leaving the generic T unbound. resolve_type then returns 0, and the diagnostic path null-dereferences trying to suggest corrections.

Two sub-issues:

  1. Root cause: generate_default_trait_method_for_impl_ext does not always bind all trait type parameters before generating the method body. This may be due to missing or misordered entries in impl_trait_type_args, or a blanket impl whose type parameters aren't carried through.
  2. Crash amplifier: suggest_type_name / sema_str_contains_char does not guard against null or invalid type name strings. Even when resolve_type fails, the diagnostic path should not SIGSEGV.

Expected behavior

The compiler should either:

  • Correctly bind all trait type parameters during default method generation, or
  • Gracefully skip/error on methods with unresolvable type parameters without crashing

Environment

  • macOS 15.5 (Darwin 25.3.0), Apple Silicon (arm64)
  • Compiler version: v0.12.0-663-g6bc26c5ec
  • Commit: 6bc26c5ecd57e63d460038e349b85064c4f8a821

Activity

  1. ehartford commented on Apr 4, 2026

    @ehartford
    ContributorAuthor

    Fixed in 701b243. The crash was eliminated by deferring generic trait type lowering until bindings exist, hardening unknown-type handling, and avoiding eager primitive-name string resolution on unresolved generic paths. Verified with 30/30 clean self-hosted builds of out/gen/main.w, plus make build, make selfcheck, and make fixpoint.

  2. added a commit that references this issue on Aug 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions