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

Miscellaneous #121

Merged
merged 21 commits into from
Feb 5, 2025
Merged

Miscellaneous #121

merged 21 commits into from
Feb 5, 2025

Conversation

rvanasa
Copy link
Collaborator

@rvanasa rvanasa commented Jan 28, 2025

  • Requires <system> capability to call CertifiedData.set().
  • Updates Timer and Error modules to reflect changes to original base library.
  • Removes deprecated hash functions.
  • Updates trap messages to include the name of the relevant base library function.

@rvanasa rvanasa requested a review from a team as a code owner January 28, 2025 17:24
Copy link

github-actions bot commented Jan 28, 2025

No description provided.

src/Array.mo Outdated Show resolved Hide resolved
@@ -32,7 +32,9 @@ module {
///
/// See a full example on how to use certified variables here: https://github.com/dfinity/examples/tree/master/motoko/cert-var
///
public let set : (data : Blob) -> () = Prim.setCertifiedData;
public func set<system>(data : Blob) : () {
Prim.setCertifiedData(data)
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess we may need to make the Prim.setCertifiedData take a argument too to make this really safe (otherwise people can directly call Prim.setCertifiedData).

Copy link
Contributor

Choose a reason for hiding this comment

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

Doing this change may also break some third party libraries. But I guess we need to make break some eggs...

Copy link
Collaborator Author

@rvanasa rvanasa Feb 4, 2025

Choose a reason for hiding this comment

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

I guess we may need to make the Prim.setCertifiedData take a argument too to make this really safe

This is probably worth doing, since otherwise there isn't much of a benefit to changing the base library if people can go around it by importing Prim directly.

I'll roll this back to set : (data : Blob) -> () = Prim.setCertifiedData so that it preserves whether the prim function has the <system> requirement.

/// ```
public func equalWithin(x : Float, y : Float, epsilon : Float) : Bool {
public func equal(x : Float, y : Float, epsilon : Float) : Bool {
Copy link
Contributor

Choose a reason for hiding this comment

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

@luc-blaeser are you ok with renaming equalWIthin (and notEqualWithin) to equal and notEqual?
Also another option might be to make both of these curried functions, that take the epsilon as a first argument and return an equality/inequality function of the usual binary type:

  public func equalWithin(epsilon: Float) : (x : Float, y : Float) - > Bool =
       func(x : Float, y: float)  { ... epsilon ...  }
  }
 (and similarly for nonEqualWithin 

Copy link
Collaborator Author

@rvanasa rvanasa Feb 4, 2025

Choose a reason for hiding this comment

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

The motivation here is for API uniformity. I suppose we could curry the arguments, although I think equal(x, y, epsilon) is more consistent with how we handle the compare and equal functions for data structures.

On the other hand, it could be worth doing something different to reduce possible confusion about the argument order, given the equal(Float, Float, Float) signature.

Copy link
Contributor

Choose a reason for hiding this comment

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

Right, I thinking about the situation where you want to pass the equality function as a first-class argument (which is why we define it for convenience...)

I don't have a strong opinion...

@@ -22,29 +22,4 @@ module {
ha == hb
};

/// Computes a hash from the least significant 32-bits of `n`, ignoring other bits.
Copy link
Contributor

@crusso crusso Feb 4, 2025

Choose a reason for hiding this comment

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

If we aren't going to even provide any hash based data structures (are we?) I'd be tempted to get rid of this whole module Hash.mo. length seemes misnamed (should be maxBitIndex or something) and bit is probably an implementation detail of Trie.mo which uses the hash bits to index into a radix tree (IIRC). Might be worth checking if pos/length are used anywhere else.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Opened a separate PR for this: #129.

crusso
crusso previously approved these changes Feb 4, 2025
Copy link
Contributor

@crusso crusso left a comment

Choose a reason for hiding this comment

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

LGTM (see suggestions)

Co-authored-by: Claudio Russo <claudio@dfinity.org>
@rvanasa rvanasa mentioned this pull request Feb 4, 2025
Copy link
Contributor

@crusso crusso left a comment

Choose a reason for hiding this comment

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

LGTM. We can always change the equal notEqual names back if @luc-blaeser feels strongly.

/// ```
public func notEqualWithin(x : Float, y : Float, epsilon : Float) : Bool {
not equalWithin(x, y, epsilon)
public func notEqual(x : Float, y : Float, epsilon : Float) : Bool {
Copy link
Contributor

@crusso crusso Feb 5, 2025

Choose a reason for hiding this comment

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

Do we even want notEqual, since its the literal negation of equal @luc-blaeser and we don't provide notEqual for other primitive types.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Seems reasonable to remove this function. I'll merge and open another PR to start working on the merge conflicts in parallel.

@rvanasa rvanasa merged commit 087f4e2 into main Feb 5, 2025
6 checks passed
@rvanasa rvanasa deleted the misc branch February 5, 2025 17:10
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.

2 participants