-
Notifications
You must be signed in to change notification settings - Fork 47
Iterator built-in functions #25
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
Conversation
Fix getListType for list of tuples
Code refactoring of error handling for unsupported types
…ins multiple elements "for a, b in (t1, t2), (t3, t4)" should work now
1. Update visit Ncall, declareVariables, assignToSingleVariable to make iterator related calls work 2. Fix codegen for list of tuples 3. Add support for for loops with iterator as expression
|
Fixed len([]) causing segfault in UDF |
| std::vector<python::Type> types; | ||
|
|
||
| ///! iterator-specific info | ||
| IteratorInfo *iteratorInfo; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe use std::shared_ptr etc. for memory mangement? Avoid potentially also issues with weak vs. deep copy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i.e., is the memory of IteratorInfo etc. released properly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refactored to std::shared_ptr.
| AnnotatedAST& removeParameterTypes(); | ||
|
|
||
| /*! | ||
| * throw exception for unsupported types |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so this function basically checks the error in IFailable and throws an exception? If so, this should be in the description.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added in comments.
| // simplify interfaces a bit | ||
| inline codegen::SerializableValue load(llvm::IRBuilder<>& builder) const { | ||
| assert(ptr && sizePtr); | ||
| // assert(ptr && sizePtr); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we remove this? or why is it commented?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe keep this assertion if it's not an iterator, otherwise check that it's an iterator? i.e. update the assertion rather than removing it altogether
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kept the assertion.
Changed to use dummy LLVM type for iterators during declareVariables() so iterator's slot ptr won't become nullptr.
Comments were added in corresponding places.
|
|
||
| inline void store(llvm::IRBuilder<>& builder, const codegen::SerializableValue& val) { | ||
| assert(ptr && sizePtr); | ||
| // assert(sizePtr); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same regarding it, yet I think leaving the iterator slot may not have ptr yet comment is good.
Maybe add to description when this is the case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kept the assertion.
Changed to use dummy LLVM type for iterators during declareVariables() so iterator's slot ptr won't become nullptr.
Comments were added in corresponding places.
| private: | ||
| LLVMEnvironment& _env; | ||
| bool _sharedObjectPropagation; | ||
| IteratorContextProxy *_icp; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
std::shared_ptr? std::unique_ptr? how is the memory here managed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed to std::shared_ptr.
LeonhardFS
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great work! A very large PR bringing iterator functionality and improved loops to the project. Let's get it merged and released soon.
…t ptr being nullptr
…ltBlockAddress Use curr*sign(step) < end*sign(step) to check if curr is within a range, instead of checking if curr*step < end*step
|
Added support for reversed() built-in function. |
| // store current iteration ending block and loop ending block for for and while loops | ||
| std::deque<llvm::BasicBlock*> _loopBlockStack; | ||
|
|
||
| std::shared_ptr<IteratorContextProxy> _icp; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's try to avoid acronyms here, just call the variable _iteratorContentProxy. Then it's super clear what it is :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refactored variable name in BlockGeneratorVisitor.h and FunctionRegistry.h.
| return createNextCall(lfb, builder, argsType, retType, args, iteratorInfo); | ||
| } | ||
|
|
||
| Logger::instance().defaultLogger().error("unsupported symbol encountered"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe add in error message what symbol, i.e.
"unsupported symbol '" + symbol + "' encountered in createIteratorRelatedSymbolCall"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated.
LeonhardFS
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great work! ready to get merged to master.
Add the following built-in functions in UDF:
iterable can be a list, homogenous tuple, string, range or iterator object.
(i) iter(iterable) : Returns an iterator.
(ii) reversed(seq) : seq can be a list, homogenous tuple, string or range object.
(iii) enumerate(iterable[, start]) : Start=0 by default if not provided. Returns an iterator with yieldType=(I64, iter(iterable).yieldType).
(iv) zip(*iterables): Currently at least one iterable must be provided. Returns an iterator with yieldType=(iter(iterable_1).yieldType, iter(iterable_2).yieldType, ..., iter(iterable_N).yieldType).
(v) next(iterator[, default]): Returns the next item from iterator. If iterator is exhausted, returns default if default is provided, otherwise raise StopIteration.
Reference: Built-in Functions -- Python 3.9.7 documentation
Using unsupported types in the functions above (dictionary as iterable or seq, non-homogenous tuple as iterable or seq, default type in next call different from iterator.yieldType) or returning an iterator from UDF is resolved through fallback mode. Error handling codes are adapted from ASTHelper and now refactoring into IFailable.
Add support for using iterators (generated from iter, enumerate or zip) as testlist in for loops (i.e. for i in iteratorType: ...).