这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@yunzhi-jake
Copy link
Collaborator

@yunzhi-jake yunzhi-jake commented Sep 1, 2021

  1. 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

  2. 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.

  3. Add support for using iterators (generated from iter, enumerate or zip) as testlist in for loops (i.e. for i in iteratorType: ...).

@yunzhi-jake yunzhi-jake changed the title Iterators built-in functions Iterator built-in functions Sep 1, 2021
@yunzhi-jake
Copy link
Collaborator Author

Fixed len([]) causing segfault in UDF

std::vector<python::Type> types;

///! iterator-specific info
IteratorInfo *iteratorInfo;
Copy link
Contributor

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.

Copy link
Contributor

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?

Copy link
Collaborator Author

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
Copy link
Contributor

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.

Copy link
Collaborator Author

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);
Copy link
Contributor

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?

Copy link
Collaborator

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

Copy link
Collaborator Author

@yunzhi-jake yunzhi-jake Sep 23, 2021

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);
Copy link
Contributor

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?

Copy link
Collaborator Author

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;
Copy link
Contributor

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?

Copy link
Collaborator Author

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.

Copy link
Contributor

@LeonhardFS LeonhardFS left a 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.

@yunzhi-jake
Copy link
Collaborator Author

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;
Copy link
Contributor

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 :)

Copy link
Collaborator Author

@yunzhi-jake yunzhi-jake Sep 24, 2021

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");
Copy link
Contributor

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"

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Updated.

Copy link
Contributor

@LeonhardFS LeonhardFS left a 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.

@LeonhardFS LeonhardFS merged commit b0a7d35 into tuplex:master Oct 1, 2021
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.

3 participants