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

Add support for lazy evaluation of references #675

Open
SanderMertens opened this issue Apr 3, 2018 · 1 comment
Open

Add support for lazy evaluation of references #675

SanderMertens opened this issue Apr 3, 2018 · 1 comment

Comments

@SanderMertens
Copy link
Member

SanderMertens commented Apr 3, 2018

Currently, when an object is being resumed into the in-memory store, its references are immediately resumed as well, typically as a result of serializers performing a corto_lookup or a corto_resolve. While this is convenient in some cases (a developer can walk easily walk references) the behavior is "viral", in that it can easily resume a large part of the complete object graph into the store.

To prevent this from happening, the typesystem and serializers should allow for "lazy" references, that are only resumed when the user explicitly asks for it.

Ideally, the difference between lazy and non-lazy references is hidden from the user, and is encapsulated in corto_set_ref (already exists) and corto_get_ref (doesn't exist yet) functions.

@SanderMertens
Copy link
Member Author

To support lazy references for members, collection elements, function parameters and function return values, a single mechanism is required to indicate whether a reference is lazy or not. Whereas this feature could be easily added for members by adding a new "lazy" constant to corto/lang/modifierMask, this would not make it available for elements and functions.

To address this, a new feature should be added to the typesystem that "wraps" an existing type, and modifiers its behavior (making it a lazy reference). For example:

class Foo {
    ...
}

struct Bar {
    m: lazy_ref[Foo] // wraps Foo, turns it into a "lazy type"
}

This capability would also be useful in a couple of other areas, like creating reference members (or elements, ...) to non-reference types:

struct Foo {
    ...
}

struct Bar {
    m: ref[Foo] // Create a reference member to non-ref type "Foo"
}

Yet another capability of such a design would be to create typedefs:

typedef Foo: Point

struct Bar {
    m: Foo
}

To support this, a new type kind (TYPEDEF) must be introduced that allows one type to wrap another type.

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

1 participant