Skip to content

Commit

Permalink
Simplify model loading
Browse files Browse the repository at this point in the history
Model loader is now done through a central Consumer that
receives "operations" from model files. These operations
are things like "addShape", "applyTrait", "addForwardReference",
etc. The consumer processes these events and then coordinates
the traits loaded in the model, shapes added, and how they
are all assembled together.

This approach is able to maintain shapes in-tact when they are
added to a ModelAssembler up until the point in which the shape
might be modified by an applyTrait statement or if another trait
is added that conflicts with it. This should improve performance
and reduce memory usage when building projections with SmithyBuild
since it will cut down on have to deconstruct and the reconstruct
previously built shapes.

Other things to note:

* Ensure a version is emitted from the IDL even if one if not
  set so that the assembler can know to upgrade 1.0 shapes.
* Add an implicit @box trait to members that were nullable in
  1.0 so that tooling can know if the member was considered
  nullable in 1.0 semantics (and this check ignores the
  @required trait to meet 1.0 expectations).
* Now that there are more synthetic traits, the Upgrade12Command
  needs to not try to rewrite and erase deprecated synthetic
  traits since they don't actually appear in the model. No
  new test case was needed.
* Ensure that the @default trait is not allowed in 1.0 models.
* Ignore invalid doc comments within shapes
* Ignore 1.0 deprecation warnings in test runners

  The Smithy test runner no longer requires 1.0 deprecations
  or trait deprecations to be listed explicitly. This allows
  existing model test suites to contine to run without needing
  to be updated. It also allows trait vendors to deprecated a
  trait without breaking consumers.

  To accommodate this, I modified all warnings about 1.0 models to
  use a "ModelDeprecation" event ID, including set deprecation.
  • Loading branch information
mtdowling committed Aug 3, 2022
1 parent f3dc2d1 commit f127adb
Show file tree
Hide file tree
Showing 91 changed files with 2,388 additions and 2,444 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
[ERROR] smithy.example#InvalidBindingOperationInput$listBinding: AWS Protocols only support binding the following shape types to the payload: string, blob, structure, union, and document | ProtocolHttpPayload
[ERROR] smithy.example#InvalidBindingOperationOutput$mapBinding: AWS Protocols only support binding the following shape types to the payload: string, blob, structure, union, and document | ProtocolHttpPayload
[ERROR] smithy.example#InvalidBindingError$setBinding: AWS Protocols only support binding the following shape types to the payload: string, blob, structure, union, and document | ProtocolHttpPayload
[WARNING] -: Smithy IDL 1.0 is deprecated. Please upgrade to Smithy IDL 2.0. | Model
[WARNING] smithy.example#StringSet: Set shapes are deprecated and have been removed in Smithy IDL v2. Use a list shape with the @uniqueItems trait instead. | Set
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ private ProjectionResult applyProjection(
baseModel = assembler.assemble();

// Fail if the model can't be merged with the imports.
if (!baseModel.getResult().isPresent()) {
if (baseModel.isBroken() || !baseModel.getResult().isPresent()) {
LOGGER.severe(String.format(
"The model could not be merged with the following imports: [%s]",
projection.getImports()));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
$version: "1.0"
$version: "2.0"

namespace smithy.test

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -478,8 +478,10 @@ private void eraseLine(int lineNumber) {
}

private void eraseTrait(Shape shape, Trait trait) {
SourceLocation to = findLocationAfterTrait(shape, trait.getClass());
erase(trait.getSourceLocation(), to);
if (trait.getSourceLocation() != SourceLocation.NONE) {
SourceLocation to = findLocationAfterTrait(shape, trait.getClass());
erase(trait.getSourceLocation(), to);
}
}

private SourceLocation findLocationAfterTrait(Shape shape, Class<? extends Trait> target) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ structure PrimitiveBearer {
handlesComments: // Nobody actually does this right?
PrimitiveShort,

@default(0)
handlesPreexistingDefault: PrimitiveShort,

@required
handlesRequired: PrimitiveLong,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ structure PrimitiveBearer {
handlesComments: // Nobody actually does this right?
Short,

@default(0)
handlesPreexistingDefault: Short,

@required
handlesRequired: Long,

Expand Down
11 changes: 11 additions & 0 deletions smithy-model/src/main/java/software/amazon/smithy/model/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -999,6 +999,17 @@ public Builder removeShape(ShapeId shapeId) {
return this;
}

/**
* Gets an immutable view of the current shapes in the builder.
*
* <p>The returned view may not be updated as shapes are added to the builder.
*
* @return Returns the current shapes in the builder.
*/
public Map<ShapeId, Shape> getCurrentShapes() {
return shapeMap.peek();
}

@Override
public Model build() {
return new Model(this);
Expand Down

This file was deleted.

Loading

0 comments on commit f127adb

Please sign in to comment.