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

Codegen direct index access and map member model #5720

Merged
merged 2 commits into from
Nov 22, 2024

Conversation

davidh44
Copy link
Contributor

Motivation and Context

  1. Add support for parsing direct index access in endpoint rules set, e.g., [123]

  2. Add support for map MemberModel in client endpoint tests

Testing

Added codegen tests
Builds pass locally for new feature

@davidh44 davidh44 requested a review from a team as a code owner November 21, 2024 18:45
Comment on lines -93 to -98
List<RuleType> args = expr.arguments().stream().map(RuleExpression::type).collect(Collectors.toList());
if (!function.matches(args)) {
addError("Arguments for function `%s` doesn't match, expected: `%s`, got: `%s`",
name,
function.arguments().values(), args);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We need to remove this error check here and above since they will fail when there is two assigns (LetExpression) in a row where second assign depends on the first assigned variable.

Because of the order of execution of the visitors, the first variable will not be stored in SymbolTable.locals before the second assign executes initially. The second assign will execute again successfully after the first variable is stored when super.visitXX is invoked

MemberModel keyModel = memberModel.getMapModel().getKeyModel();
MemberModel valueModel = memberModel.getMapModel().getValueModel();

b.add("$T.of(", ImmutableMap.class);
Copy link
Contributor

Choose a reason for hiding this comment

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

should we use builder(), since of only supports up to 4 KV pairs?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried to use that initially, but ImmutableMap.builder().build() returns ImmutableMap<K, V>, so its not compatible. We'd have to update build() to return <K, V> ImmutableMap<K, V> like of() does , which would entail an unchecked cast. WDYT?

        public <K, V> ImmutableMap<K, V> build() {
            HashMap<K, V> builtMap = (HashMap<K, V>) new HashMap<>(entries);
            return new ImmutableMap<>(builtMap);
        }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will merge as is, can update in follow up PR if needed, or can also add new of() overloads to support more pairs if necessary in future

Comment on lines +191 to +197
if ((firstArn = RulesFunctions.listAccess(params.arnList(), 0)) != null) {
locals = locals.toBuilder().firstArn(firstArn).build();
} else {
return RuleResult.carryOn();
}
if ((parsedArn = RulesFunctions.awsParseArn(locals.firstArn())) != null) {
locals = locals.toBuilder().parsedArn(parsedArn).build();
Copy link
Contributor

Choose a reason for hiding this comment

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

I was thinking more along the lines of

            if ((firstArn = RulesFunctions.listAccess(params.arnList(), 0)) != null
                && (parsedArn = RulesFunctions.awsParseArn(firstArn)) != null) {
                locals = locals.toBuilder().parsedArn(parsedArn).firstArn(firstArn).build();

What you have works I think, just feeling uneasy about being able to reach the end of the second if with locals modified. That doesn't matter now, but before I would've never matter as the side effects would only happen in the if body scope.

Copy link
Contributor

Choose a reason for hiding this comment

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

NOTE, No action item or change is expected, just leaving this as a side note.

Nesting could also work leaving the previous semantics, e.g.,

        if ((firstArn = RulesFunctions.listAccess(params.arnList(), 0)) != null) {
                locals = locals.toBuilder().firstArn(firstArn).build();
                if ((parsedArn = RulesFunctions.awsParseArn(locals.firstArn())) != null) {
                    locals = locals.toBuilder().parsedArn(parsedArn).build();
                    return RuleResult.endpoint(Endpoint
                                                   .builder()
                                                   .url(URI.create("https://" + params.endpointId() + ".query."
                                                                   + locals.partitionResult().dualStackDnsSuffix()))
                                                   .putAttribute(
                                                       AwsEndpointAttribute.AUTH_SCHEMES,
                                                       Arrays.asList(SigV4aAuthScheme.builder().signingName("query")
                                                                                     .signingRegionSet(Arrays.asList("*")).build())).build());
                }
        }
        return RuleResult.carryOn();

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I also came up with that at first when handwriting it, just not sure how to modify the logic to do so. Need to plumb deeper through the call stack which is already pretty complicated

Comment on lines +191 to +197
if ((firstArn = RulesFunctions.listAccess(params.arnList(), 0)) != null) {
locals = locals.toBuilder().firstArn(firstArn).build();
} else {
return RuleResult.carryOn();
}
if ((parsedArn = RulesFunctions.awsParseArn(locals.firstArn())) != null) {
locals = locals.toBuilder().parsedArn(parsedArn).build();
Copy link
Contributor

Choose a reason for hiding this comment

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

NOTE, No action item or change is expected, just leaving this as a side note.

Nesting could also work leaving the previous semantics, e.g.,

        if ((firstArn = RulesFunctions.listAccess(params.arnList(), 0)) != null) {
                locals = locals.toBuilder().firstArn(firstArn).build();
                if ((parsedArn = RulesFunctions.awsParseArn(locals.firstArn())) != null) {
                    locals = locals.toBuilder().parsedArn(parsedArn).build();
                    return RuleResult.endpoint(Endpoint
                                                   .builder()
                                                   .url(URI.create("https://" + params.endpointId() + ".query."
                                                                   + locals.partitionResult().dualStackDnsSuffix()))
                                                   .putAttribute(
                                                       AwsEndpointAttribute.AUTH_SCHEMES,
                                                       Arrays.asList(SigV4aAuthScheme.builder().signingName("query")
                                                                                     .signingRegionSet(Arrays.asList("*")).build())).build());
                }
        }
        return RuleResult.carryOn();

@davidh44 davidh44 added this pull request to the merge queue Nov 22, 2024
Merged via the queue into master with commit 152e409 Nov 22, 2024
17 checks passed
@davidh44 davidh44 deleted the hdavidh/codegen-directIndexAccess-and-mapMemberModel branch November 22, 2024 19:01
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.

3 participants