Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(store): do not render push and pop for static arrays, use static length [M-02] #2175

Merged
merged 6 commits into from
Jan 23, 2024

Conversation

yonadaaa
Copy link
Contributor

@yonadaaa yonadaaa commented Jan 23, 2024

Static arrays are now treated differently to dynamic arrays:

  • The push and pop methods should not be used in static arrays so they are not rendered.
  • The length method now returns the hardcoded known length.

Copy link

changeset-bot bot commented Jan 23, 2024

🦋 Changeset detected

Latest commit: dabf602

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 30 packages
Name Type
@latticexyz/store Patch
@latticexyz/cli Patch
@latticexyz/dev-tools Patch
@latticexyz/react Patch
@latticexyz/store-indexer Patch
@latticexyz/store-sync Patch
@latticexyz/world-modules Patch
@latticexyz/world Patch
@latticexyz/abi-ts Patch
@latticexyz/block-logs-stream Patch
@latticexyz/common Patch
@latticexyz/config Patch
create-mud Patch
@latticexyz/ecs-browser Patch
@latticexyz/faucet Patch
@latticexyz/gas-report Patch
@latticexyz/network Patch
@latticexyz/noise Patch
@latticexyz/phaserx Patch
@latticexyz/protocol-parser Patch
@latticexyz/recs Patch
@latticexyz/schema-type Patch
@latticexyz/services Patch
@latticexyz/solecs Patch
solhint-config-mud Patch
solhint-plugin-mud Patch
@latticexyz/std-client Patch
@latticexyz/std-contracts Patch
@latticexyz/store-cache Patch
@latticexyz/utils Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

renderWithStore(
storeArgument,
({ _typedStore, _store, _commentSuffix, _methodNamePrefix }) => `
if (field.typeWrappingData && field.typeWrappingData.kind === "staticArray") {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't love this check as is, we repeat it for pop and push, then again for length.

It's also weird to treat static arrays as dynamic with the if (field.isDynamic) check, but then differentiate them using this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

curious if @dk1a has any insight into this

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

terminology is weird here
isDynamic, as well as dynamic and static table fields is a mud-specific thing
A better name for isDynamic might be isNonPrimitive - it indicates any array or struct
The word static in static arrays is used in an unrelated context, taken from solidity

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#1668 is related, I also don't like how hacky this check is, especially since now it's used in more places

holic
holic previously approved these changes Jan 23, 2024
Copy link
Member

@holic holic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good enough imo!

only thing I can think of that might help make this easier to understand is separate how we codegen dynamic vs static fields, but not sure if it's worth it here (we'll do a bigger refactor pass later)

holic
holic previously approved these changes Jan 23, 2024
Copy link
Member

@holic holic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did a quick indent change to match other parts of the codebase, because it was hard to explain over text

need to add a changeset but otherwise lgtm!

@yonadaaa yonadaaa merged commit 1bf2e90 into main Jan 23, 2024
11 checks passed
@yonadaaa yonadaaa deleted the yonadaaa/static-not-extendable branch January 23, 2024 14:46
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.

3 participants