Skip to content

Dead-code elimination removes textfieldGetString calls used in conditional branches #11

Closed

Description

@proggeramlug

Bug Description

Perry's codegen eliminates textfieldGetString() calls when the result variable is only used inside a conditional branch (e.g., if (user.length > 0)).

Reproduction

const userRaw = textfieldGetString(userField);
const user = (typeof userRaw === 'string' && userRaw.length > 0) ? userRaw : '';
const passRaw = textfieldGetString(passField);
const pass = (typeof passRaw === 'string' && passRaw.length > 0) ? passRaw : '';

// user and pass are only used inside this if:
if (user.length > 0 && pass.length > 0) {
  uri = 'mongodb://' + encodeURIComponent(user) + ':' + encodeURIComponent(pass) + '@' + host;
}

The textfieldGetString(userField) and textfieldGetString(passField) calls are eliminated entirely (confirmed via Rust debug prints — only 4 of 6 expected calls execute).

The same code pattern works for name/host/port because those variables are used unconditionally in later code.

Expected Behavior

Side-effectful native function calls should never be eliminated, even if the result is only used conditionally.

Activity

  1. proggeramlug commented on Mar 31, 2026

    @proggeramlug
    ContributorAuthor

    Fixed in v0.4.37 (bf9779d). The calls were not actually eliminated by DCE — they executed, but the return values were corrupted due to the same NaN-boxing bug as #10. When the I64 string pointer was bitcast to F64 without STRING_TAG, the runtime couldn't identify the value as a string, making it appear as undefined. This made it look like the calls were eliminated since the result variables held garbage.

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