TomBebbington / llvm-rs

LLVM wrappers for Rust
BSD 3-Clause "New" or "Revised" License
68 stars 27 forks source link

JitEngine::with_function has strange precondition when StructType::cast fails #5

Closed pnkfelix closed 8 years ago

pnkfelix commented 9 years ago

The logic in fn with_function here seems weird:

            let sig = function.get_signature();
            assert_eq!(Type::get::<R>(ctx), sig.get_return());
            let arg = Type::get::<A>(ctx);
            if let Some(args) = StructType::cast(arg) {
                assert_eq!(sig.get_params(), args.get_elements());
            } else {
                assert_eq!(arg, sig.get_return());
            }

In particular, when the StructType::cast(arg) returns None, it is checking that the return type of the signature matches ... the argument type to the callback (and this is after we have already confirmed that the return type of the signature matches the return type of the callback).

Was this a mistake -- i.e. was your intention to instead assert in the else branch that [arg] == sig.get_params(), (in other words, implicitly promoting a non-struct argument for the callback to a singleton list) ?

Or is there some hidden reasoning behind this that I am missing?