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

Improve code generation to avoid unused variable warnings #3184

Merged
merged 1 commit into from
Feb 6, 2025

Conversation

byroot
Copy link
Contributor

@byroot byroot commented Feb 6, 2025

The Rails test suite had these warnings for ages, which I'd like to fix:

aws-sdk-s3/endpoint_provider.rb:22: warning: assigned but unused variable - key
aws-sdk-s3/endpoint_provider.rb:24: warning: assigned but unused variable - copy_source
aws-sdk-s3/endpoint_provider.rb:23: warning: assigned but unused variable - prefix

Ultimately I don't think pre-assigning to variables is really worth it, as the parameters argument is a T_STRUCT so access is really fast.

But I suspect this was done to make the code generation simpler. In the end this adds a little bit of complexity, but not that much.

NB: I only regenerated the aws-sdk-s3 gem to show what the change looks like. But if this change is accepted I can regenerate all gems, and add a CHANGELOG entry.

@byroot
Copy link
Contributor Author

byroot commented Feb 6, 2025

An alternative strategy would be to prefix all local variables with _ to tell the parser not to emit a warning. I assumed it wasn't a preferable solution, but it's an option.

@mullermp
Copy link
Contributor

mullermp commented Feb 6, 2025

Thanks for opening a pull request. Either approach is fine. This seems ok at a glance, I will review today. We should not include generated changes in the commit because our release system will handle that, and a changelog would be applied for all gems automatically (though it's a generic one about updating generating code - I think that's ok).

@byroot
Copy link
Contributor Author

byroot commented Feb 6, 2025

We should not include generated changes in the commit

Right, I remembered that from previous contributions, but I figured you'd maybe want to see the result?

I can revert that part whenever you like.

@mullermp
Copy link
Contributor

mullermp commented Feb 6, 2025

Yeah, perfectly fine for review! Your post said you would generate all gems unless I misunderstood.

@mullermp
Copy link
Contributor

mullermp commented Feb 6, 2025

I enabled CI for you. It looks like there are failures. rake test:spec:aws-sdk-s3 is a local way to run these.

@byroot byroot force-pushed the avoid-unused-variable-warnings branch from c8929db to 5da9c51 Compare February 6, 2025 16:00
@byroot
Copy link
Contributor Author

byroot commented Feb 6, 2025

Thank you. I think I fixed the problem, and I removed the generated files.

gems/aws-sdk/CHANGELOG.md Outdated Show resolved Hide resolved
The Rails test suite had these warnings for ages, which I'd like
to fix:

```
aws-sdk-s3/endpoint_provider.rb:22: warning: assigned but unused variable - key
aws-sdk-s3/endpoint_provider.rb:24: warning: assigned but unused variable - copy_source
aws-sdk-s3/endpoint_provider.rb:23: warning: assigned but unused variable - prefix
```

Ultimately I don't think pre-assigning to variables is really worth it,
as the `parameters` argument is a T_STRUCT so access is really fast.

But I suspect this was done to make the code generation simpler.
In the end this adds a little bit of complexity, but not that much.
@byroot byroot force-pushed the avoid-unused-variable-warnings branch from 5da9c51 to 78c17a2 Compare February 6, 2025 16:20
@alextwoods
Copy link
Contributor

Adding some historical context here - Smithy validates endpoint rulesets to ensure that all parameters are used. However, S3 needed an exception to support using endpoint rules for a few complex auth resolution cases (eg access grants), so those unused parameters violate our normal validations. We would expect to see these warnings only in S3.

@alextwoods alextwoods merged commit 1af1cbe into aws:version-3 Feb 6, 2025
33 checks passed
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