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

Support Full AOT (Ahead of Time compilation). #38

Closed
veblush opened this issue Jul 19, 2016 · 3 comments
Closed

Support Full AOT (Ahead of Time compilation). #38

veblush opened this issue Jul 19, 2016 · 3 comments

Comments

@veblush
Copy link
Contributor

veblush commented Jul 19, 2016

In full AOT environment like iOS, runtime jitting is not allowed, which means no runtime code generation at all.
For example, it's impossible to emit code and use a generic type which parameter types are not determined at compile time.

To support this, we need to put workaround code for every dynamic code. For example, CodeGenerator.GenerateWriteAllFieldsDelegate can be changed like:

private static ValueWriter GenerateWriteAllFieldsDelegate(
    List<ValueWriter> fieldWriters)
{
    if (fieldWriters == null)
        throw new ArgumentNullException(nameof(fieldWriters));

    if (use_dynamic_code) // CHECK SERIALIZER OPTION TO USE DYNAMIC CODE
    {
        // fast but not working code on AOT.
        var streamParam = Parameter(typeof (Stream));
        var objectParam = Parameter(typeof (object));
        var sessionParam = Parameter(typeof (SerializerSession));
        var xs = fieldWriters
            .Select(Constant)
            .Select(
                fieldWriterExpression =>
                    Invoke(fieldWriterExpression, streamParam, objectParam, sessionParam))
            .ToList();
        var body = Block(xs);
        var writeallFields =
            Lambda<ValueWriter>(body, streamParam, objectParam,
                sessionParam)
                .Compile();
        return writeallFields;
    }
    else
    {
        // slow but working code on AOT.
        return (stream, obj, session) => fieldWriters.ForEach(w => w(stream, obj, session));
    }
}

How about this?

@veblush veblush changed the title Full AOT (Ahead of Time compilation) support. Support Full AOT (Ahead of Time compilation). Jul 19, 2016
@rogeralsing
Copy link
Collaborator

Asked on Gitter but Ill add it here too.
How does the AOT path work? it will end up using reflection with FieldInfo.Get/SetValue or how does that work?

@veblush
Copy link
Contributor Author

veblush commented Jul 20, 2016

Yes. It usually ends up with a bunch of Get/SetValue that is safe on AOT environment. And it's also possible to use generic types or methods which can be instantiated in compile-time.

@rogeralsing
Copy link
Collaborator

I will close this one as it is out of scope

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

No branches or pull requests

2 participants