Skip to content

Comments

Dwinship/typescript/coder and decoder annotations#13

Open
Cynical-Optimist wants to merge 15 commits intocodethink/typescript-codecfrom
dwinship/typescript/coderAndDecoderAnnotations
Open

Dwinship/typescript/coder and decoder annotations#13
Cynical-Optimist wants to merge 15 commits intocodethink/typescript-codecfrom
dwinship/typescript/coderAndDecoderAnnotations

Conversation

@Cynical-Optimist
Copy link
Collaborator

@Cynical-Optimist Cynical-Optimist commented Oct 27, 2021

  • Reinvents encoder functions and decoder functions for custom types, and custom type variants
  • Adds Type Annotations to encoder and decoder functions, including:
    • function parameters
    • function return types
    • generic type variables for generic variables (things like decodeContainerType<ContentType>())
  • Removes some now-uneeded functions from codecs.ts
  • Updates some type annotations in codecs.ts, changing some compile-time errors.
  • Adds two comments to codecs.ts, telling the TypeScript compiler to ignore two specific errors.

Re the last 2 points: after adding type annotations we started getting typescript compiler errors in some of our decode functions. The annotations gave the compiler enough information to work out what outputs it expected from the codecs.ts functions, but it couldn't confirm that those codecs.ts functions would return the correct value.

By changing the annotations in codecs.ts, those functions now promise to return the correct types. This doesn't remove the error (the TypeScript compiler is still unable to confirm that the codecs.ts functions will return the types that they promise to return) but now the error has been moved. Instead of dozens of errors in the generated code, we now have exactly two compiler errors in codecs.ts.

And we're able to silence those two specific errors using comments that tell the typescript compiler to ignore them. We can safely do this if (and only if) we're absolutely sure that the logic inside the functions does give the correct results.

Terms

THIS SOFTWARE IS CONTRIBUTED SUBJECT TO THE TERMS OF THE TERMS OF THE CCLA DATED 2017-11-07 WITH FINOS/LINUX FOUNDATION (FORMERLY THE SYMPHONY SOFTWARE FOUNDATION CCLA).

THIS SOFTWARE IS LICENSED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE AND ANY WARRANTY OF NON-INFRINGEMENT, ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. THIS SOFTWARE MAY BE REDISTRIBUTED TO OTHERS ONLY BY EFFECTIVELY USING THIS OR ANOTHER EQUIVALENT DISCLAIMER IN ADDITION TO ANY OTHER REQUIRED LICENSE TERMS.

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

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

The structure and flow seems fine, I have various comments around naming things (the hardest problem in CS). I am also a bit worried by how much duplicated code we're adding, I wonder if it's worth waiting until we deduplicated the codecs code a bit to merge the whole thing, rather than landing this now.

}


inputArg : TS.Expression
Copy link

Choose a reason for hiding this comment

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

It seems weird to have this at the top of the MapTypes module. I was thinking about moving codec-related stuff into a separate module, and perhaps it'd make sense there.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

My instinct is to have simple utility values like this defined near the top, where they're easy to find when you want to reference them and check what they are.

Happy to put it wherever you think is better though. And I agree, we can probably make a new module for coders and decoders.

]
}

constructorToCase : ConstructorDetail ta -> ( TS.Expression, List TS.Statement )
Copy link

Choose a reason for hiding this comment

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

Same as above.

@ghost ghost force-pushed the codethink/typescript-codec branch 3 times, most recently from 2606764 to 28ca052 Compare October 27, 2021 11:59
AttilaMihaly and others added 15 commits October 27, 2021 14:08
…codec

Generate JSON codecs for TypeScript
Added some docs about the project setup in the contribution guide.
…docs

Add documentation for TypeScript backend
Skeleton implementation of multiary decision tree data structure.
Makes it possible for any function declaration to have generic type
variables, and a return-type annotation.
IntLiteralExpression: An expression consisting of a literal integer
IndexedExpression: An expression for square bracket indexing (eg foo[bar])
SwitchStatement: A switch statement, with a list of cases
FunctionTypeExpression: a Type Expression for a function type (a list of
parameter types, and a return type)
Puts type annotations on custom type decoders and on type alias decoders
Updates how custom type decoders work.
Update the encoder function for custom types and custom type variants.
These functions now create the return values directly, and do not have
to call on codec.encodeCustomType and codec.encodeCustomTypeVariant.
@Cynical-Optimist Cynical-Optimist force-pushed the dwinship/typescript/coderAndDecoderAnnotations branch from cf40d83 to 5ddaabc Compare October 27, 2021 16:48
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.

2 participants