Skip to content

Preserve tabled constants during module modernization#464

Draft
prozacchiwawa wants to merge 2 commits intomainfrom
cursor/trace-tabled-env-a988
Draft

Preserve tabled constants during module modernization#464
prozacchiwawa wants to merge 2 commits intomainfrom
cursor/trace-tabled-env-a988

Conversation

@prozacchiwawa
Copy link
Copy Markdown
Contributor

@prozacchiwawa prozacchiwawa commented May 5, 2026

Summary

  • Remove the module modernization assignment that forced all constants to non-tabled.
  • Collapse the remaining constant modernization branch into a guarded match arm to satisfy clippy.

Investigation notes

  • The expected failures reproduce after preserving tabled constants:
    • cargo test test_export_foreign_constant -- --nocapture
    • cargo test test_program_exporting_constant_from_program -- --nocapture
  • Temporary trace output around start_codegen, compute_env_shape, and nil-env mode showed the common phase keeps the tabled constant in the environment shape:
    • test-data.one.QUOTED_ONE: CommonPhase(false) env shape (test-data.one.QUOTED_ONE)
    • programs.single-constant.C: CommonPhase(false) env shape (programs.single-constant.C)
  • In the following standalone pass, compile_module creates StandalonePhaseInfo with empty_common_phase: !common_phase_functions. For these constant-only modules, common_phase_functions is false, so empty_common_phase is true even though the common env is not empty.
  • compute_env_shape then takes the StandalonePhase empty_common_phase branch. Since the tabled constant is already present in sp.env, it is excluded from extra_env_data, and the branch returns an empty left environment (()) for nil args. Nil-env mode subsequently rewrites (()) to ().
  • Assertion check used during investigation: empty_common_phase should imply collect_env_names(sp.env).is_empty(). It failed with the live tabled constant still in sp.env, confirming the invariant violation.

Exact cause

empty_common_phase is derived solely from whether the common phase has defuns, not whether the common phase environment has live tabled constants. That was masked by d.tabled = false; once tabled constants are preserved, constant-only common phases can still have a non-empty environment, but standalone codegen treats it as empty and drops the tabled constants from the environment shape.

Verification

  • cargo clippy --workspace -- -D warnings
Open in Web Open in Cursor 

cursoragent and others added 2 commits May 5, 2026 09:17
Co-authored-by: arty <prozacchiwawa@users.noreply.github.com>
Co-authored-by: arty <prozacchiwawa@users.noreply.github.com>
Base automatically changed from 20260217-introspective-constants to main May 7, 2026 22:12
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