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

feat(cdk): support encoding Tokens as numbers #2534

Merged
merged 3 commits into from
May 13, 2019

Conversation

rix0rrr
Copy link
Contributor

@rix0rrr rix0rrr commented May 13, 2019

Numbers can now be encoded into a set of (hugely negative) numbers,
and the encoding can be reversed.

This allows APIs that take numbers to take lazy values and intrinsics
that evaluate to numbers.

This change only introduces the capability, it does not use it in any
of the construct libraries yet.

Fixes #1455.


Pull Request Checklist

  • Testing
    • Unit test added (prefer not to modify an existing test, otherwise, it's probably a breaking change)
    • CLI change?: coordinate update of integration tests with team
    • cdk-init template change?: coordinated update of integration tests with team
  • Docs
    • jsdocs: All public APIs documented
    • README: README and/or documentation topic updated
    • Design: For significant features, design document added to design folder
  • Title and Description
    • Change type: title prefixed with fix, feat and module name in parens, which will appear in changelog
    • Title: use lower-case and doesn't end with a period
    • Breaking?: last paragraph: "BREAKING CHANGE: <describe what changed + link for details>"
    • Issues: Indicate issues fixed via: "Fixes #xxx" or "Closes #xxx"
  • Sensitive Modules (requires 2 PR approvers)
    • IAM Policy Document (in @aws-cdk/aws-iam)
    • EC2 Security Groups and ACLs (in @aws-cdk/aws-ec2)
    • Grant APIs (only if not based on official documentation with a reference)

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license.

@rix0rrr rix0rrr requested review from RomainMuller, skinny85 and a team as code owners May 13, 2019 10:26
@RomainMuller
Copy link
Contributor

Is it possible to isolate the package-lock.json changes to a separate PR? I feel like we should better have specific reverse-ability for this PR (although I haven't read the code just yet, so maybe I'm over-indexing on the implications).

Copy link
Contributor

@RomainMuller RomainMuller left a comment

Choose a reason for hiding this comment

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

Nifty little feature! Would be nice if we had (maybe we do, I haven't checked!) checks in JSII runtimes that they don't mess up the magic numbers in the language-native domain, just to be sure.

Numbers can now be encoded into a set of (hugely negative) numbers,
and the encoding can be reversed.

This allows APIs that take numbers to take lazy values and intrinsics
that evaluate to numbers.

This change only introduces the capability, it does not use it in any
of the construct libraries yet.

Fixes #1455.
@rix0rrr rix0rrr force-pushed the huijbers/token-number-encoding branch from 9559b41 to 8acae0e Compare May 13, 2019 10:52
/**
* Return a special Double value that encodes the given integer
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

Mention in the docstring that this is used to encode an index to the token map and therefore it's okay that we don't support negative numbers. Also, mention the limit on the number of number tokens we can support.

*
* We put the following marker into the top 16 bits (exponent and sign), and
* use the mantissa part to encode the token index. To save some bit twiddling
Copy link
Contributor

Choose a reason for hiding this comment

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

"encode the index to the token in the token map"

* Create a unique number representation for this Token and return it
*/
public registerNumber(token: Token): number {
const tokenIndex = this.tokenCounter++;
Copy link
Contributor

Choose a reason for hiding this comment

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

Error if we reached the limit.

@rix0rrr rix0rrr merged commit b9eeaa0 into master May 13, 2019
@rix0rrr rix0rrr deleted the huijbers/token-number-encoding branch May 13, 2019 16:16
@NGL321 NGL321 added the contribution/core This is a PR that came from AWS. label Sep 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contribution/core This is a PR that came from AWS.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Tokens: be able to represent as numbers
4 participants