Skip to content

Make --preserve-order a global CLI flag instead of per-function parameter#218

Draft
vivainio wants to merge 1 commit intoCertainLach:masterfrom
vivainio:global-preserve-order
Draft

Make --preserve-order a global CLI flag instead of per-function parameter#218
vivainio wants to merge 1 commit intoCertainLach:masterfrom
vivainio:global-preserve-order

Conversation

@vivainio
Copy link
Copy Markdown

Summary

  • Replace the exp-preserve-order feature flag and per-function preserve_order parameters with a global thread-local setting (following the existing STACK_LIMIT pattern)
  • The --preserve-order CLI flag sets this globally, affecting all object field iteration without polluting stdlib function signatures
  • Net deletion of ~400 lines of #[cfg]-gated code and parameter threading

Motivation

Feedback on #217: adding preserve_order to every stdlib function pollutes the API surface. A global flag is cleaner — users who want preserved order want it everywhere, not per-call.

How it works

  • Thread-local PRESERVE_ORDER: Cell<bool> in obj/mod.rs with set_preserve_order()/preserve_order() accessors
  • ObjValue::fields(), iter(), etc. read the global setting instead of taking a parameter
  • CLI sets set_preserve_order(true) at startup when --preserve-order is passed
  • The real ordering module (with FieldIndex/SuperDepth tracking) is always compiled — no more no-op stub

Test plan

  • cargo build succeeds
  • cargo test passes
  • jrsonnet -e '{ c: 1, b: 2, a: 3 }' outputs alphabetical order
  • jrsonnet --preserve-order -e '{ c: 1, b: 2, a: 3 }' preserves declaration order

… parameter

Replace the exp-preserve-order feature flag and per-function preserve_order
parameters with a global thread-local setting, following the existing
STACK_LIMIT pattern. The --preserve-order CLI flag sets this globally,
affecting all object field iteration without polluting stdlib function
signatures.

This removes ~400 lines of cfg-gated code and parameter threading while
keeping the same functionality.
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.

1 participant