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

Adding a validation pass to check types, field IDs and Identifiers #70

Merged
merged 10 commits into from
Sep 21, 2017

Conversation

kevinbgreene
Copy link
Contributor

  • validate that types are being assigned properly
  • validate all identifiers can be resolved
  • validate no duplicate field IDs
  • validate correct enum usage

As part of this I also fix initializing i64 fields to numbers, now Int64.

  * validate that types are being assigned properly
  * validate all identifiers can be resolved
  * validate no duplicate field IDs
  * validate correct enum usage
Copy link
Contributor

@phated phated left a comment

Choose a reason for hiding this comment

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

Looks like a 0-line file debugger.ts got committed. Also made a few inline comments about some things I saw. Haven't run the test suite locally - I'd love to get this on CI.

case SyntaxType.DoubleConstant:
return createLiteral(node.value)
return ts.createLiteral(node.value)

case SyntaxType.ConstList:
Copy link
Contributor

Choose a reason for hiding this comment

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

The parser should differentiate between ConstList and ConstSet for the future.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The IDL only defines ConstList. It's more context awareness than I would like to have the parser add a ConstSet. It should be rendering a Set here though, don't know why I missed that/how I'm not testing for it. Will fix.

])
})

return createNew(
return ts.createNew(
Copy link
Contributor

Choose a reason for hiding this comment

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

Random thought: does Scrooge make this improvement to Maps? If not, this probably needs to generate a plain object until Maps and Sets are used consistently and all normalization applied.

This new Map change was my improvement/fix and required more changed within the codegen output.

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, scrooge uses Map instead of object literals.

@@ -291,12 +320,15 @@ function createResolver(thrift: ThriftDocument, includes: IIncludeMap): IResolve
return false
}

/**
*
* @param name
Copy link
Contributor

Choose a reason for hiding this comment

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

Mistakenly inserted?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup

type: SyntaxType.ServiceDefinition,
name: statement.name,
functions: validateFunctions(statement.functions),
extends: statement.extends,
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 extends should be validated also. You can extend an included service.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch.

if (fieldID === null) {
return {
type: SyntaxType.FieldID,
value: (--generatedFieldID),
Copy link
Contributor

Choose a reason for hiding this comment

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

generatedFieldID should be pushed onto usedFieldIDs after it's used.

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 should be checking that the user supplied id is not negative right. Negative IDs are reserved for generation if I remember correctly?

}

function validateFields(fields: Array<FieldDefinition>): Array<FieldDefinition> {
generatedFieldID = 0
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems fine as long as Thrift continues to not support nested struct definition.

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, the scope of generatedFieldID and usedFieldIDs is probably too broad. I'll fix that.

return {
type: SyntaxType.FunctionDefinition,
name: func.name,
oneway: func.oneway,
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this being validated with void type?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The parser is checking for oneway == void now. I'm thinking about getting rid of that check in the parser and moving all of that sort of validation here. Thoughts?

  * Should check extends identifier to ensure it is referencing a service
  * Should check that user created field IDs are non-negative
  * Get rid of the nasty scoping around generated field IDs
  * Should be rendering Sets where sets have default values (was using array)
@@ -347,6 +347,9 @@ export function readValueForIdentifier(
case SyntaxType.ConstDefinition:
throw new TypeError(`Identifier ${id.definition.name.value} is a value being used as a type`)

case SyntaxType.ServiceDefinition:
throw new TypeError(`Service ${id.definition.name.value} is begin used as a type`)
Copy link
Contributor

Choose a reason for hiding this comment

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

begin -> beign

@@ -146,6 +146,9 @@ function writeValueForIdentifier(
case SyntaxType.ConstDefinition:
throw new TypeError(`Identifier ${id.definition.name.value} is a value being used as a type`)

case SyntaxType.ServiceDefinition:
throw new TypeError(`Service ${id.definition.name.value} is begin used as a type`)
Copy link
Contributor

Choose a reason for hiding this comment

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

begin -> being

@@ -181,6 +181,9 @@ function thriftAccessForIdentifier(id: IIdentifierType, identifiers: IIdentifier
case SyntaxType.ConstDefinition:
throw new TypeError(`Identifier ${id.definition.name.value} is a value being used as a type`)

case SyntaxType.ServiceDefinition:
throw new TypeError(`Service ${id.definition.name.value} is begin used as a type`)
Copy link
Contributor

Choose a reason for hiding this comment

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

begin -> being

@kevinbgreene kevinbgreene merged commit 724cdb4 into master Sep 21, 2017
@kevin-greene-ck kevin-greene-ck deleted the validator branch August 31, 2018 21:12
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.

None yet

4 participants