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

Emit error when struct is using infinite size #116

Closed
franklinsch opened this issue Feb 5, 2018 · 8 comments
Closed

Emit error when struct is using infinite size #116

franklinsch opened this issue Feb 5, 2018 · 8 comments

Comments

@franklinsch
Copy link
Collaborator

franklinsch commented Feb 5, 2018

This is a subtask of #106.

@franklinsch
Copy link
Collaborator Author

franklinsch commented Apr 23, 2018

If a struct T contains a property which (directly or indirectly) refers to a value of type T, it uses an infinite amount of memory, and an error should be emitted.

@vietlq
Copy link
Contributor

vietlq commented Apr 23, 2018

Do you have example code and stuff like logs that lets you know that you used an infinite amount of memory?

@franklinsch
Copy link
Collaborator Author

This Flint program currently causes the compiler to segfault: https://github.com/franklinsch/flint/blob/master/examples/invalid/infinite-structs.flint

@vietlq
Copy link
Contributor

vietlq commented Apr 23, 2018

So Flint does not support recursive types and should detect & return error on those cases, right? I assume that there will not be data structures like linked-list in Flint, right?

@franklinsch
Copy link
Collaborator Author

Yes, at the moment, Flint doesn't support recursive types. They can be supported in the future if needed. For now, an error should be produced.

@vietlq
Copy link
Contributor

vietlq commented Apr 23, 2018

I haven't read the code yet so I'd raise a quick question: Do you keep a directed graph of type dependencies? If yes, we could detect loops quickly and abort parsing.

@franklinsch
Copy link
Collaborator Author

Such a graph can easily be generated using the information already collected during parsing (represented in Environment.swift). The parser generates an AST, and multiple passes are performed over it (including SemanticAnalyzer and TypeChecker). I think this error should be produced in the SemanticAnalyzer phase. When visiting a struct declaration, the type dependency graph could be used to detect loops.

Just for context:
In SemanticAnalyzer.struct, process(structDeclaration:passContext:) will be called when visiting the StructDeclaration node, and postProcess(structDeclaration:, passContext:) will be called once the members of the structs have been visited. When visiting the AST, the passContext struct records information it collects during the visit.

@DJRHails
Copy link
Member

DJRHails commented Jul 6, 2018

Recommend closing as PR #231 fixed this

SusanEisenbach pushed a commit that referenced this issue Jan 17, 2019
* fix associativity of dot

* fix linux not running all tests

* fix function calls and variable dereferencing by adding new pass

* fix linter errors in EnclosingTypeAssigner

* add fix for loop variables

* fix property ordering

Properties were added to special declaration bodies in a different order
to how they were declared. This probably isn't a problem right now, but
might be a problem down the line so since I came across it I fixed it.

* Revert "fix property ordering"

This reverts commit d4917f4.

* fix codegen for memory test, same issue as for ForStatement

* update comments to be more descriptive

* fix pivot op tokens
SusanEisenbach pushed a commit that referenced this issue Jan 17, 2019
* [WIP] External traits (#71)

* ABNF syntax for external traits

* Add external token into Sources/Lexer/Token.swift

* Parse new token in Sources/Lexer/Lexer.swift

* Extend Sources/Parser/Parser+Declaration.swift (parseTopLevelDeclarations, parseTraitDeclaration)

* Add tests to Tests/ParserTests

* Change vim plugin to reflect external

* Parse if let statements (#69)

Parsing if let statements

* Parse do-catch statements (#68)

* ABNF grammar for do-catch statements

* Add tokens do, catch, and is Token.swift

* Add parser handling of do ... catch ...

* Add tests

* address review comments

* Address scoping in doCatch

* Fix post catch body scoping

* Parse external calls (#70)

* ABNF grammar for external calls

* Adding backticks for consistency

* Add call token and parse it in lexer

* Add ExternalCall ASTNode

* Parse external calls

* Moved external trait test to Integration folder

* Fix all target in Makefile

* Added tests

* Remove semicolon from Makefile

* Add comment

* Change variable name x to paramVisit

* Remove unnecessary backticks for non-keywords

* Introduce mode enum for external calls

* Removed ASTPass.swift generated file

* Address style changes for enum members

* Prioritise external call on top of binary expression, inside parseExpression

* Remove useless type function

* Create PR

* Add stubs and comments for changes required

* Add external call semantic error messages

* Add isInsideDo context variable

* Add external call type checks

* Remove  from

* Remove  requirements reflecting changed proposal

* Add stubs and comments for changes required

* Add external call semantic error messages

* Add isInsideDo context variable

* Add external call type checks

* Remove  from

* Remove  requirements reflecting changed proposal

* Add semantic checks

* Merge external call semantic checks

* Correct pass context for isInsideDoBlock variable

* Move optional type external call variable declaration to BinaryExpression process function

* Add accidentally deleted process(functionalCall, ...) function

* Improve variable names and comment new error function

* Remove isInsideIfCondition context element

* Add external call in nested do-catch test

* Replace isInsideDoCatch context variable by counter to support nested do-catches

* Replace backticks with single quotation marks in error messages

* Replace backticks with single quotation marks in test case

* added semantic checks for external call hyperparameter types and usage (#106)

Added semantic checks for correct hyperparameter types and usages regarding payable and non-payable functions.

* Fix dot associativity (#116)

* fix associativity of dot

* fix linux not running all tests

* fix function calls and variable dereferencing by adding new pass

* fix linter errors in EnclosingTypeAssigner

* add fix for loop variables

* fix property ordering

Properties were added to special declaration bodies in a different order
to how they were declared. This probably isn't a problem right now, but
might be a problem down the line so since I came across it I fixed it.

* Revert "fix property ordering"

This reverts commit d4917f4.

* fix codegen for memory test, same issue as for ForStatement

* update comments to be more descriptive

* fix pivot op tokens

* Implement casting parsing (#102)

* work in progress – adding parsing for as as? as!

* parse as

* type conversions parser testing

* fix linter issue

* add semantic checks for as? as occurrence

* wip compat check

* add reinterpret checks + tests

* add semantic analyzer tests and messages when types cannot be reinterpreted

* add isSolidityType

* fix tabs

* ignore swp

* fix external call type resolution and rename x-call flag

* preliminary checks and diagnostic message

* fix rebase isExternalCall => isExternalFunctionCall

* correct ExternalCall visit not passing forward process result

* fix type conversion tests

* indicate kind when dumping AST of TCX

* early return in default case for corrected enclosing type resolution in binary expressions

* return true in isComplexStatement for x-calls and tcx

* Add stubs and comments for changes required

* Add external call semantic error messages

* Add isInsideDo context variable

* Add external call type checks

* Remove  from

* Remove  requirements reflecting changed proposal

* Add semantic checks

* Merge external call semantic checks

* Correct pass context for isInsideDoBlock variable

* Move optional type external call variable declaration to BinaryExpression process function

* Improve variable names and comment new error function

* Remove isInsideIfCondition context element

* Add external call in nested do-catch test

* Replace isInsideDoCatch context variable by counter to support nested do-catches

* Replace backticks with single quotation marks in error messages

* Replace backticks with single quotation marks in test case

* Rebase

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

No branches or pull requests

3 participants