compiler: add --allow-module-private-access to bypass module-private (#1454)#1458
Open
mbouaziz wants to merge 1 commit into
Open
compiler: add --allow-module-private-access to bypass module-private (#1454)#1458mbouaziz wants to merge 1 commit into
--allow-module-private-access to bypass module-private (#1454)#1458mbouaziz wants to merge 1 commit into
Conversation
An escape hatch for reaching module-`private` elements from outside their
module — primarily for white-box tests that need to poke at internals
without exposing them in the public API. Off by default, so enforcement
stays on everywhere else.
The flag threads from Config through the front end (getOrInitializeBackend
-> makeOuterIst -> type_program -> SkipExpand.program -> Env.allowPrivateAccess)
to check_module, whose private-access arm returns void instead of erroring
when it is set. `Env.allowPrivateAccess` rides `env with { ... }` so it
reaches every check_module on the compile path; Config.withUnit inherits the
field via `this with { ... }`, so it works in batch mode too.
Closes #1454.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
Author
|
Not merging as the code is not the nicest. |
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.
Closes #1454.
Adds
--allow-module-private-access, a compile flag that permits reaching module-privateelements from outside their module. The motivation is white-box tests: with module-privateenforced (#1343), test code in a different module can no longer poke at internals without exposing them in the public API. Off by default, so enforcement stays on everywhere else.Implementation
The flag threads from
Configthrough the front end to the one place that decides:check_modulealready special-cases same-module access; this adds one more guard arm:Notes:
Env.allowPrivateAccessridesenv with { … }unchanged, so it reaches everycheck_moduleon the compile path (which all flow from the singleexpandEnv).Config.withUnitusesthis with { … }, so the field is inherited by per-unit configs.element_privacyand the symbol table are untouched — only the reporting is gated, so nothing else changes.Verification
M.secret()on aprivate fun secretin another module errors as before; with--allow-module-private-accessit compiles and runs.main. (Locally one meta-test,CompilerVersionCheck, tripped on a stale skc version-stamp left by iterative rebuilds; a clean rebuild makesskc --versionmatchHEADagain, so CI's fresh build passes it.)No harness test is added: the invalid/valid test framework compiles every unit with a fixed
skccommand (no per-test flags), so there's no place to exercise a custom flag. Happy to add one if a per-test-flags mechanism is wanted.Design note
This is the "global compile flag" option from the discussion on #1454 — the simplest, bluntest one. The alternatives (white-box tests in a same-module file, which already works since module-
privateis module-scoped; or an explicit per-module "friend" annotation) stay open; this flag doesn't preclude them. Flag name is easy to change if you'd prefer something like--unsafe-allow-private.— Claude Opus 4.8 (1M context)