Skip to content

Construct Records only through checked helpers - #11386

Merged
sholderbach merged 6 commits into
nushell:mainfrom
sholderbach:record-construction
Dec 21, 2023
Merged

sholderbach merged 6 commits into
nushell:mainfrom
sholderbach:record-construction

Conversation

@sholderbach

Copy link
Copy Markdown
Member

Description

Constructing the internals of Record without checking the lengths is bad. (also incompatible with changes to how we store records)

  • Use Record::from_raw_cols_vals in dataframe code
  • Use record! macro in dataframe test
  • Use record! in nu-color-config tests
  • Stop direct record construction in nu-command
  • Refactor table construction in from nuon

User-Facing Changes

None

Tests + Formatting

No new tests, updated tests in equal fashion

This can probably be refactored to `FromIterator` as most are direclty
collected above. (this would be future proof)
Use `.collect` for capacity optimization and lift length check before
the evaluation.
@sholderbach
sholderbach merged commit 8cfa96b into nushell:main Dec 21, 2023
@sholderbach
sholderbach deleted the record-construction branch December 24, 2023 11:37
sholderbach added a commit to sholderbach/nushell that referenced this pull request Dec 24, 2023
With nushell#11386 we don't have any nushell-internal code directly accessing
the `vals` field of `Record`, so let's make it private so everyone in
the future uses the checked ways guaranteeing matching cols/vals.

The `cols` feel has to remain pub for now as `rename` still directly
mutates this field. See nushell#11020 for challenges for this refactor.

This is a breaking change for outside plugins that relied on the pub
fields.
sholderbach added a commit that referenced this pull request Dec 24, 2023
# Description
With #11386 we don't have any nushell-internal code directly accessing
the `vals` field of `Record`, so let's make it private so everyone in
the future uses the checked ways guaranteeing matching cols/vals.

The `cols` feel has to remain pub for now as `rename` still directly
mutates this field. See #11020 for challenges for this refactor.

# Plugin-Author-Facing Changes
This is a breaking change for outside plugins that relied on the `pub`
fields.
dmatos2012 pushed a commit to dmatos2012/nushell that referenced this pull request Feb 20, 2024
# Description

Constructing the internals of `Record` without checking the lengths is
bad. (also incompatible with changes to how we store records)

- Use `Record::from_raw_cols_vals` in dataframe code
- Use `record!` macro in dataframe test
- Use `record!` in `nu-color-config` tests
- Stop direct record construction in `nu-command`
- Refactor table construction in `from nuon`

# User-Facing Changes
None

# Tests + Formatting
No new tests, updated tests in equal fashion
dmatos2012 pushed a commit to dmatos2012/nushell that referenced this pull request Feb 20, 2024
# Description
With nushell#11386 we don't have any nushell-internal code directly accessing
the `vals` field of `Record`, so let's make it private so everyone in
the future uses the checked ways guaranteeing matching cols/vals.

The `cols` feel has to remain pub for now as `rename` still directly
mutates this field. See nushell#11020 for challenges for this refactor.

# Plugin-Author-Facing Changes
This is a breaking change for outside plugins that relied on the `pub`
fields.
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