Skip to content

Incorrect optimization/effects with GlobalEffects in closed-world #8831

Closed

Description

@stevenfontanella

In GlobalEffects when --closed-world is enabled, we compute effects for indirect calls by aggregating effects for potential callees. This goes wrong in some cases when types are merged. We try to account for this today, but it doesn't handle the case of missing entries in the map correctly; a missing map entry indicates that we don't know the effects and thus need to assume all possible effects (e.g. for a call to an import), but for missing entries we don't copy anything to the renamed map. i.e. if type A has unknown effects and type B has no effects, and we rewrite A -> B, we don't modify B's entry at all and continue to assume that B has no effects.

Lit test demonstrating the issue:

;; RUN: foreach %s %t wasm-opt --all-features --closed-world --generate-global-effects --type-merging --remove-unused-types --vacuum -S -o - | filecheck %s --check-prefix MERGE_FIRST

(module
  (rec
    ;; MERGE_FIRST:       (type $nop-type (func))
    (type $nop-type (func))

    (type $effectful-type (func))
  )

  ;; MERGE_FIRST:      (type $import-type (func))
  (type $import-type (func))

  ;; MERGE_FIRST:      (import "" "" (func $import (type $import-type)))
  (import "" "" (func $import (type $import-type)))

  ;; MERGE_FIRST:      (func $nop (type $nop-type)
  ;; MERGE_FIRST-NEXT:  (nop)
  ;; MERGE_FIRST-NEXT: )
  (func $nop (type $nop-type)
    (nop)
  )

  ;; MERGE_FIRST:      (func $effectful (type $nop-type)
  ;; MERGE_FIRST-NEXT:  (call $import)
  ;; MERGE_FIRST-NEXT: )
  (func $effectful (type $effectful-type)
    (call $import)
  )

  ;; MERGE_FIRST:      (func $test (type $0) (param $ref (ref $nop-type))
  ;; MERGE_FIRST-NEXT:  (nop)
  ;; MERGE_FIRST-NEXT: )
  (func $merges-unknown-effects (param $ref (ref $effectful-type))
    (call_ref $effectful-type
      (local.get $ref)
    )
  )

  (func
    (drop (ref.func $nop))
    (drop (ref.func $effectful))
  )
)

In $merged-unknown-effects, the call_ref that targets an import is incorrectly removed.

Activity

  1. added a commit that references this issue on Jun 12, 2026
    193792f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

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