Preserve tabled constants during module modernization#464
Draft
prozacchiwawa wants to merge 2 commits intomainfrom
Draft
Preserve tabled constants during module modernization#464prozacchiwawa wants to merge 2 commits intomainfrom
prozacchiwawa wants to merge 2 commits intomainfrom
Conversation
Co-authored-by: arty <prozacchiwawa@users.noreply.github.com>
Co-authored-by: arty <prozacchiwawa@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Investigation notes
cargo test test_export_foreign_constant -- --nocapturecargo test test_program_exporting_constant_from_program -- --nocapturestart_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)compile_modulecreatesStandalonePhaseInfowithempty_common_phase: !common_phase_functions. For these constant-only modules,common_phase_functionsisfalse, soempty_common_phaseistrueeven though the common env is not empty.compute_env_shapethen takes theStandalonePhaseempty_common_phasebranch. Since the tabled constant is already present insp.env, it is excluded fromextra_env_data, and the branch returns an empty left environment(())for nil args. Nil-env mode subsequently rewrites(())to().empty_common_phaseshould implycollect_env_names(sp.env).is_empty(). It failed with the live tabled constant still insp.env, confirming the invariant violation.Exact cause
empty_common_phaseis derived solely from whether the common phase has defuns, not whether the common phase environment has live tabled constants. That was masked byd.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