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

1488 Passable redux #2238

Merged
merged 21 commits into from
May 2, 2024
Merged

1488 Passable redux #2238

merged 21 commits into from
May 2, 2024

Conversation

turadg
Copy link
Member

@turadg turadg commented Apr 23, 2024

closes: #1488

Description

Reattempting:

Again:

  • Makes Passable a generic type instead of any.
  • Defines overloads for passStyleOf to return the actual style.
  • Defines the Key in terms of Passable
  • Makes a ton of fixes and suppressions in places that relied on the previous any's

Security Considerations

n/a

Scaling Considerations

n/a

Documentation Considerations

Better types are better documentation.

Testing Considerations

Upgrade Considerations

These changes may cause type errors downstream. I don't think we should call those breaking change à la semver because they don't affect the runtime.

@erights
Copy link
Contributor

erights commented Apr 23, 2024

(I just reran the windows-latest flake)

@erights
Copy link
Contributor

erights commented Apr 23, 2024

These changes may cause type errors downstream. I don't think we should call those breaking change à la semver because they don't affect the runtime.

@kriskowal , I defer to you on this. I'll just say I hope we can adopt that precedent as a general rule ;)

Copy link
Contributor

@erights erights left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

packages/marshal/src/encodeToCapData.js Show resolved Hide resolved
@@ -78,7 +78,7 @@ export const makeMarshal = (
const slotMap = new Map();

/**
* @param {Remotable | Promise} passable
* @param {import('@endo/pass-style').PassableCap} passable
Copy link
Contributor

Choose a reason for hiding this comment

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

Now that we have @import, and since you're changing these lines anyway, I prefer to gather these all the top into @import declarations.

Comment on lines +247 to +249
const extant = valMap.get(index);
if (extant) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, when the value is necessarily truthy, this pattern is better. (Likewise extant !== undefined when the value is necessarily not undefined.) Only problem in general is the refactoring hazard if a collection's use changes to include falsy or undefined values. Not worried about that here.

packages/marshal/src/rankOrder.js Outdated Show resolved Hide resolved
@@ -284,9 +299,10 @@ harden(assertRankSorted);
* function. This is a genuine bug for us NOW because sometimes we sort
* in reverse order by passing a reversed rank comparison function.
*
* @param {Iterable<Passable>} passables
* @template {Passable} T
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you think of

Suggested change
* @template {Passable} T
* @template {Passable} [T=Passable]

for all or most of these? It offloads the use site from needing to say <Passable> when that's all it would say anyway. I've been doing essentially this elsewhere and been happy with the results.

Copy link
Member Author

@turadg turadg Apr 24, 2024

Choose a reason for hiding this comment

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

that makes sense for parameterized typedefs, but here the template slot's type is constrained by the first argument. Giving a default doesn't help.

@@ -30,6 +30,7 @@ export const hasOwnPropertyOf = (obj, prop) =>
apply(objectHasOwnProperty, obj, [prop]);
harden(hasOwnPropertyOf);

/** @type {(val) => val is {}} */
Copy link
Contributor

Choose a reason for hiding this comment

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

I've never seen this inline before. Nice.

packages/pass-style/src/passStyleOf.js Outdated Show resolved Hide resolved
@@ -33,13 +33,10 @@ const isRemotable = remotable => passStyleOf(remotable) === 'remotable';
harden(isRemotable);

/**
* @callback AssertArray
Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I don't remember why I have these separate named @callable types. Good riddance, thanks.

@@ -126,14 +128,15 @@ export const checkKey = (val, check) => {
harden(checkKey);

/**
* @param {Passable} val
* @param {Key} val
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this be

Suggested change
* @param {Key} val
/**
* @param {any} val
* @returns {val is Key}
*/

?

Copy link
Member Author

@turadg turadg Apr 24, 2024

Choose a reason for hiding this comment

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

good one!

I've added a test showing how the is Key gets used. I don't think we want to losen the param because if it's not even Passable then that would be good static feedback. If you want to loosen it, please do in a separate PR across all the similar cases.

Comment on lines +4 to +8
// @ts-expect-error M.any missing parens
M.arrayOf(M.any);
Copy link
Contributor

Choose a reason for hiding this comment

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

;)

@erights
Copy link
Contributor

erights commented Apr 24, 2024

Did we stop requiring conventional commits?

@erights
Copy link
Contributor

erights commented Apr 24, 2024

Did we stop requiring conventional commits?

My mistake. All your commits are fine. I was misled by the title, as my habit is to have the title also follow this convention (and usually be identical to the first commit).

@turadg turadg force-pushed the 1488-Passable-redux branch 3 times, most recently from 78ef12b to 8462132 Compare April 26, 2024 21:38
Copy link
Member

@kriskowal kriskowal left a comment

Choose a reason for hiding this comment

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

I’m substantially excited about this change. I would like to break out a PR for the change to the release and build process so that it can suffer a revert separately if necessary. I’d also like to replace temporary markers XXX and FIXME with something but it doesn’t have to be tedious. It could be a single explanation or link to a tracking issue with a bunch of dittos or daggers for the repeated cases.

⚠️I will not die on this hill and I will approve this change regardless⚠️: My intuition (born from typed languages and sympathy for dependant projects that have to adapt when they upgrade this dependency) is that we should consider this a breaking change both in spirit and semver, and rush the necessary adaptations in Agoric SDK and dapps to minimize the pain. Since we are treading heavily over breaking changes with the “sync endo versions” workflow and resolutions farther out, there’s not much reason to spare the major version bump.

@@ -32,7 +32,7 @@
},
"scripts": {
"build": "exit 0",
"build:types": "tsc --build tsconfig.build.json",
"prepack": "tsc --build tsconfig.build.json",
Copy link
Member

Choose a reason for hiding this comment

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

I would like to capture this process change in a separate PR.

Copy link
Member Author

Choose a reason for hiding this comment

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

👍 #2258

*/
// @ts-expect-error intentional hack
Copy link
Member

Choose a reason for hiding this comment

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

What’s the nature of the hack?

Copy link
Member Author

Choose a reason for hiding this comment

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

bad comment. the type was wrong so I just removed it

@@ -413,6 +414,7 @@ export const makeCapTP = (
epoch,
questionID,
target,
// @ts-expect-error XXX
Copy link
Member

Choose a reason for hiding this comment

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

Please expand XXX

Copy link
Member Author

Choose a reason for hiding this comment

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

solved

@@ -1,3 +1,6 @@
export * from './src/exo-makers.js';

// eslint-disable-next-line import/export -- ESLint not aware of type exports in types.d.ts
Copy link
Member

Choose a reason for hiding this comment

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

That’s unfortunate and might explain some of my experience.

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah. I think we should consider disabling the rule. I think it has more false positives and fewer true positives than TS

@@ -0,0 +1,2 @@
/** @file Empty twin for .d.ts */
Copy link
Member

Choose a reason for hiding this comment

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

👍

decodeRemotableFromSmallcaps,
// @ts-expect-error FIXME
Copy link
Member

Choose a reason for hiding this comment

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

👆

if (left < right) {
return -1;
} else {
// @ts-expect-error FIXME narrowed
Copy link
Member

Choose a reason for hiding this comment

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

👆 Is the intention to address all FIXMEs before landing? These could be links to an issue, otherwise.

Copy link
Member Author

Choose a reason for hiding this comment

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

not before landing. maybe never. I've taken out the FIXME

assert(left > right);
return 1;
}
}
case 'symbol': {
return comparator(
// @ts-expect-error FIXME narrowed
Copy link
Member

Choose a reason for hiding this comment

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

I would not object to ditto if these stick around.

Suggested change
// @ts-expect-error FIXME narrowed
// @ts-expect-error ditto, type narrowed

@@ -173,10 +168,12 @@ const makePassStyleOf = passStyleHelpers => {
}
for (const helper of passStyleHelpers) {
if (helper.canBeValid(inner)) {
// @ts-expect-error XXX
Copy link
Member

Choose a reason for hiding this comment

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

👆

Copy link
Member Author

Choose a reason for hiding this comment

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

solved

@@ -133,20 +133,25 @@ export const compareKeys = (left, right) => {
// rank order.
// Because the invariants above apply to the elements of the array,
// they apply to the array as a whole.
// @ts-expect-error FIXME narrowed
Copy link
Member

Choose a reason for hiding this comment

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

👆 I’m fine with a link and dittos if these are intended to commit. (but don’t like FIXME because I like FIXME and XXX to be used as markers for work that needs to be ironed out before a merge.

@kriskowal
Copy link
Member

Also, please add NEWS.md with a description of what you’ve done for Agoric/agoric-sdk#8774 so we can refer developers to this when they upgrade their *apps.

@turadg
Copy link
Member Author

turadg commented Apr 29, 2024

I had to rebase to resolve merge conflicts created by #2256

I squashed the fixups and rolled in other changes requested by review

@turadg turadg force-pushed the 1488-Passable-redux branch 2 times, most recently from f22e68c to 9444daf Compare April 29, 2024 23:39
@turadg turadg requested a review from kriskowal April 30, 2024 00:05
Copy link
Member

@kriskowal kriskowal left a comment

Choose a reason for hiding this comment

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

You may want to look over the remaining XXX and TODO cases.

@turadg turadg enabled auto-merge (rebase) May 2, 2024 22:29
@turadg turadg disabled auto-merge May 2, 2024 22:29
@turadg turadg enabled auto-merge May 2, 2024 22:29
@turadg turadg merged commit 334b016 into master May 2, 2024
17 checks passed
@turadg turadg deleted the 1488-Passable-redux branch May 2, 2024 22:36
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.

missing Remotable and PassByRef types
5 participants