I have an issue with moduleTypes and I'm not sure how to solve it.
First, some history: moduleTypes was extracted when I worked on self calls. The way self calls work is fairly simple: the module itself is present in the type schema returned by the engine, so we can generate the necessary code. Before moduleTypes, we invoked the module with an empty function name and it responded with its types. Since the module needs those types for codegen, moduleTypes was extracted as a separate phase.
One nice side effect is that dagger functions doesn't need to execute the module at all, it only needs the types.
moduleTypes only depends on base types, since a module can't expose types from a dependency.
Outside of self calls, it gives cleaner phase separation, but it's not critical.
Now, the problem: I'm working on replacing dagger develop with dagger generate. The idea is to commit generated files, moving all that logic from runtime to a dev-time phase. The runtime shouldn't need any codegen at all.
But the generated code only contains the invocation boilerplate, it doesn't include the moduleTypes part (anymore). So even with generated code present, it can't answer a dagger functions. It also can't serve the types needed to generate self-call bindings. Which makes the generation somewhat useless.
My idea is to also generate moduleTypes. During generation we'd have something like:
- analyze module source code
- generate type defs (
moduleTypes) with local persistence - send types to the engine
- generate bindings and invocation boilerplate (the entrypoint), using the schema with dependencies (and with the analyzed types if self calls are enabled)
This also means the engine needs a way to query the module for its types, a bit like the legacy empty-function-name approach. But what I'd like is to get the types without any build step.
The benefits: we remove all codegen from runtime. And the cost of self calls becomes negligible 🎉 , it only exists at dagger generate time. If that's the case, we can imagine to remove it from experimental and enable it by default. Performance was a blocker.
My question is: I'm not sure how to persist this moduleTypes result. If we could describe it as a single query, that would help a lot, but today that's not the case. Maybe it's something we can make work. Or other ideas?
Any ideas or feedback welcome
