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

external imports have safety now #1966

Merged
merged 10 commits into from
Feb 16, 2023
Merged

Conversation

lsingh123
Copy link
Contributor

@lsingh123 lsingh123 commented Feb 15, 2023

If an Alias, Field, or Argument is an external import type, use the underlying import's safety instead of the declared safety (which will be empty). Converts all usages of AliasDefinition.getSafety(), FieldDefinition.getSafety(), and ArgumentDefinition.getSafety() to the corresponding wrapper methods in SafetyUtils.java.

Tested locally against two large internal repos with complex conjure definitions.

@changelog-app
Copy link

changelog-app bot commented Feb 15, 2023

Generate changelog in changelog/@unreleased

Type

  • Feature
  • Improvement
  • Fix
  • Break
  • Deprecation
  • Manual task
  • Migration

Description

If an Alias, Field, or Argument is an external import type, use the underlying import's safety instead of the declared safety (which will be empty).

Check the box to generate changelog(s)

  • Generate changelog entry

checkNotBuilt();
this.safeExternalLongList.add(safeExternalLongList);
return this;
}

@JsonSetter(value = "safeExternalLongSet", nulls = Nulls.SKIP, contentNulls = Nulls.FAIL)
public Builder safeExternalLongSet(@Nonnull Iterable<? extends Long> safeExternalLongSet) {
public Builder safeExternalLongSet(@Safe @Nonnull Iterable<? extends Long> safeExternalLongSet) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

ideally this would be @Nonnull Iterable<@Safe ? extends Long> but there is a bug in poet that makes that impossible. i think this is a pretty good workaround.

Copy link
Contributor

Choose a reason for hiding this comment

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

👍 looks reasonable to me

}

public static boolean isBoxedPrimitive(TypeName type) {
return type.withoutAnnotations().isBoxedPrimitive();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

poet's isBoxedPrimitive method uses object equality but its isPrimitive method uses reference equality


// SafetyEvaluator uses its TypeDefinitionMap to resolve the safety of reference types, but these utils
// only evaluate the safety of external imports and primitives, so it's safe to use a placeholder
private static final SafetyEvaluator safetyEvaluator = new SafetyEvaluator(ImmutableMap.of());
Copy link
Contributor

Choose a reason for hiding this comment

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

As al alternative, we could make these methods non-static and add them to the SafetyEvaluator -- that may be more robust (or simply add the static methods to SafetyEvaluator so the safety evaluation pieces live in the same place)

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 was trying to avoid plumbing through a SafetyEvaluator instance everywhere these utils are used, but it's probably a good idea to do so

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we already have one plumbed in a bunch of places where it's not actually used, heh. If that turns out to require a great deal of plumbing, we could use static methods on SafetyEvaluator, and defer the plumbing to a follow-up commit. Up to you.


public final class PrimitiveHelpers {

private PrimitiveHelpers() {}
Copy link
Contributor

Choose a reason for hiding this comment

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

Pedantic naming nit: Rather than Helper or Util prefixes, we generally use plural of the target, e.g. Primitives.

@@ -78,6 +79,27 @@ public Optional<LogSafety> evaluate(Type type, Optional<LogSafety> declaredSafet
return declaredSafety.or(() -> evaluate(type));
}

public Optional<LogSafety> getUsageTimeSafety(ArgumentDefinition argument) {
Copy link
Contributor

Choose a reason for hiding this comment

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

We should add some javadoc to these methods since it's not entirely obvious when they should be used without the full context of this change

@carterkozak
Copy link
Contributor

Aside from the javadoc request, this looks good to me -- great work!

@bulldozer-bot bulldozer-bot bot merged commit a365f7f into develop Feb 16, 2023
@bulldozer-bot bulldozer-bot bot deleted the lsingh/external-imports-safety branch February 16, 2023 18:47
@svc-autorelease
Copy link
Collaborator

Released 6.73.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants