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

Implement flags as bigint integers #260

Open
guybedford opened this issue Nov 15, 2023 · 2 comments
Open

Implement flags as bigint integers #260

guybedford opened this issue Nov 15, 2023 · 2 comments
Labels
enhancement New feature or request

Comments

@guybedford
Copy link
Collaborator

This one comes out of discussion with @dbaeumer on the base-level type implementations.

Currently we implement flags as an object of bools, the suggestion would be switch to implementing all flags as BigInt values.

For users to be able to interpret and create flags, they would need to explicitly import from the flag type itself in JavaScript, something like:

import { MyFlags, fnReturningFlags, fnTakingFlags } from 'lib';

const flagValue = fnReturningFlags();
typeof flagValue === 'bigint'; // true
if (flagValue & MyFlags.ValueA) {
  // we have ValueA true
}

fnTakingFlags(MyFlags.ValueA | MyFlags.ValueB);

BigInts have full support for binary operations in JS, so the above works out okay. In addition BigInts have unlimited length so will be fully compatible with arbitrary flags.

There would be a slight savings over allocating full JS objects for all values, but the major benefit would be simplicity from a user interface perspective, where creating bags of bools can feel unintuitive at the moment (especially when it is currently ambiguous that falsy values are optional in inputs).

I'm bringing this up now, because if made it would be the last major breaking change in jco before we stabilize preview2, so seems a good time to think about making this change now.

@yoshuawuyts yoshuawuyts added the enhancement New feature or request label Nov 15, 2023
@whitequark
Copy link
Contributor

I like this idea. I found bags of bools a pretty odd implementation choice.

@guybedford
Copy link
Collaborator Author

Note that #235 is a prerequisite for this work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants