-
Notifications
You must be signed in to change notification settings - Fork 62
Backend-specific dependencies #3605
Comments
[@tombentley] Once we have a way to specify that a compilation unit is only for a particular back end (#3606), this could be done by allowing the dependencies of a module to be declared 'outside' the module descriptor some how. For example using the Would you be allowed to |
[@FroMage] BTW, this would be trivial to implement. |
[@gavinking] I think this makes sense. Of course, it's only 1/2 of the problem. We still need to be able to define a module which has different underlying implementations for different backends. This feature, on its own, is almost useless. The hard bit is how to define a platform-independent module that makes use of platform-specific code. |
[@gavinking] We will solve this and #3606 for Ceylon 1.1. Not for Ceylon 1.0. Sorry. |
[@gavinking] I'm closing this issue. AFAICT, it doesn't propose anything that is not already provided by |
[@FroMage] What? This is not about Also optional would never produce an error if the module is missing, and in the case of multi-backends we surely want to make sure the dependencies exist. |
All of which cases are already handled by judicious application of
Ok, fine, so let's enhance |
[@quintesse] Can't we reuse the |
[@FroMage]
No, because
Well, perhaps, even though I have a feeling this will end up meaning But if you agree |
[@FroMage] |
[@gavinking] Moving to 1.2. |
[@quintesse] I've just pushed some proof of concept code as a solution for the following two issues:
I say proof of concept but the code is completely working and could be merged as-is. I've also created a small project with some test code to look at: https://github.com/quintesse/spec500proposal So with this code you can now add Currently 3 different backends are recognized: So for example: @backend:"jvm"
shared void test() { print("A test for the JVM"; } will only generate this method when compiled with the Java backend compiler. shared void test() { testImpl(); }
@backend:"jvm"
void testImpl() { print("A test for the JVM"; }
@backend:"js"
void testImpl() { print("A test for JS"; } Calling `test()`` will now result in a different result on the JVM backend than on the JS backend. You are even able to do this in module mymod "1.0" {
@backend:"jvm" import ceylon.file "1.1.1";
@backend:"js" import com.nodejs.fileaccess "3.18";
} and then in your source file you could have: import ceylon.file { @backend:jvm home }
import com.nodejs.fileaccess { @backend:js getHomeDir }
@backend:"jvm"
String homeDir => home;
@backend:"js"
String homeDir => getHomeDir(); You can even mark entire files as being just for one backend or the other: @backend:"jvm"; // <-- see the semi-colon!
import ceylon.file { home }
String homeDir => home; (Didn't anyone besides @gavinking even know you could put annotations on the file itself? I found it by accident looking at the grammar) And finally an element can also have multiple annotations, this might be useful in the case of documentation for example, where you can do this: @backend:"jvm" @backend:"doc"
"A very long explanation here documenting the exact behavior of this method"
String homeDir => home;
@backend:"js"
// No docs here
String homeDir => getHomeDir(); I think this work pretty well to be honest. It goes a very long way to make everything we wanted for backend-dependent code and dependencies possible. The only thing I'm not too fond of is the longish name "backend", "for" is unfortunately not possible (of course), other suggestions are welcome. So WDYT? |
[@luolong] Sort of elegant, but I was under impression that compiler annotations were not meant to be surfaced to anyone but compiler developers. I would wait for Gavin's opinion on this one. |
[@quintesse] Sure, but they are far easier to use when making a PoC :) |
[@luolong] I do not actually mind using compiler annotations for this at all. It kind of fits the bill :) |
[@quintesse] In a way it does yes, marking some code in a class file in a .car with |
[@quintesse] I think this can be closed now. Any remaining problems can be put in their own issues. |
…the imported module itself (#3605)
…are not for the JVM backend (#3605)
…the imported module itself (#3605)
…aration` and we initialize it from any `native` annotations it might have (#3605)
…and the native attribute of the imported module itself (#3605)
[@FroMage] We need a way to say that backend JVM depends on those modules, but backend JS on those.
[Migrated from ceylon/ceylon-spec#499]
[Closed at 2015-08-17 17:22:06]
The text was updated successfully, but these errors were encountered: