Skip to content

Decide scope of #region mdk preserve: should it protect field/member modifiers? #158

Description

@malware-dev

Summary

CodeSmallifier strips redundant modifiers from declarations inside #region mdk preserve, the same as anywhere else:

So a private readonly List<int> _x; inside a preserve region can come out as List<int> _x;.

This is not a behavior bug

So nothing a user's script does changes, and readability of the region's logic is unaffected.

The actual question

The original intent of preserve was scoped: don't rename identifiers, don't compact whitespace (protect readability and referential stability). The modifier-stripping transforms were added later and are a different category of change (removing a redundant token), not the rename/whitespace/layout compaction that preserve was built to stop. Note that the transforms which do honor preserve today (SymbolRenamer, WhitespaceCompactor, and CodeSmallifier's own CompactFieldDeclarations) all fall inside that original scope; modifier-stripping is the one that does not.

So this isn't clearly a defect - it's a question of what we want preserve to mean going forward:

  • (A) Scoped (matches original intent): preserve guarantees names + formatting, nothing more. Leave the code as-is, but consider a one-line docs clarification so the word doesn't over-promise byte-identical output.
  • (B) Literal/textual: preserve means "this region comes out exactly as written." Then gate the modifier-stripping (and the existing private-stripping) on ShouldBePreserved() in CodeSmallifier, consistent with the layout transforms.

Notes

Activity

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