Spike feat(exo): take 1: opt out individual arguments#1724
Closed
erights wants to merge 1 commit intomarkm-type-guardsfrom
Closed
Spike feat(exo): take 1: opt out individual arguments#1724erights wants to merge 1 commit intomarkm-type-guardsfrom
erights wants to merge 1 commit intomarkm-type-guardsfrom
Conversation
erights
commented
Aug 16, 2023
| * non-raw method guards. | ||
| */ | ||
| const MinMethodGuard = M.call().rest(M.any()).returns(M.any()); | ||
|
|
Contributor
Author
There was a problem hiding this comment.
The use of M.splitArray that caused me to give up on take1 is on line 38 below.
Member
There was a problem hiding this comment.
Here is what I would do to make it work. Am I missing something?
const defendSyncArgs = (args, methodGuard, label) => {
const { argGuards, optionalArgGuards, restArgGuard } = methodGuard;
const paramsPattern = M.splitArray(
argGuards,
optionalArgGuards,
restArgGuard,
);
const positionalGuards = [...argGuards, ...(optionalArgGuards || [])];
const numPositionalArgs = Math.min(positionalGuards.length, args.length);
const startOfRawArgs = isRawValueGuard(restArgGuard) ? numPositionalArgs : undefined;
const cookedArgs = args.slice(0, startOfRawArgs);
for (let i = 0; i < numPositionalArgs; i += 1) {
if (isRawValueGuard(positionalGuards[i])) {
// Replace the raw argument with something innocuous as a
// placeholder to be matched by the raw value guard without
// hardening the caller's argument.
cookedArgs[i] = null;
}
}
mustMatch(harden(cookedArgs), paramsPattern, label);
};
// ...
// Note purposeful use of `this` and concise method syntax
syncMethod(...args) {
defendSyncArgs(args, methodGuard, label);
const result = apply(method, this, args);
if (!isRawValueGuard(returnGuard)) {
// Only harden non-raw return values.
mustMatch(harden(result), returnGuard, `${label}: result`);
}
return result;
},
Contributor
Author
There was a problem hiding this comment.
OMG that’s beautiful! I love how local it is. Please do try this, thanks!
Contributor
Author
|
Closing in favor of #1725 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Staged on #1715 , though if feasible I would have preferred to stage it on #1712
This take 1 is a failed experiment, or at least an incomplete one.
Add an
M.rawValue()guard as kind of a peer toM.await(), whose purpose is to allow the argument in that position to pass through as is, with no checking or enforcement, to be bound to the corresponding raw method parameter.This experiment failed when I got to exo's use of
M.splitArrayto process the matching of required, optional, and rest arguments. A lot of work went into generating good error messages, all of which would need to be redone if the argument list is not a Passable list, and the components are not Pattern lists.Attn @michaelfig , though not a reviewer because I do not consider this PR a candidate for merging.