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

Dynamic module loading #10530

Open
DartBot opened this issue May 8, 2013 · 124 comments
Open

Dynamic module loading #10530

DartBot opened this issue May 8, 2013 · 124 comments
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). core-n customer-dart-sass type-enhancement A request for a change that isn't a bug

Comments

@DartBot
Copy link

DartBot commented May 8, 2013

This issue was originally filed by @dam0vm3nt


This feature was initally described in

Issue #3819: Provide a Method to Dynamicaly Load Classes

But it has been closed pretending it was done. IT IS NOT as Mr. gbracha honestly admits: "... where the code being loaded is not known statically. This will require the ability advanced capabilities like mirror builders. This should be a separate issue."

So I'm posting that separate issue hoping sometime in the future will be adressed as it is the only reason stopping me to adopt dart.

In other word: We need some mechanism to dyamically load classes not know at compile time by another module. Something like java class loaders / Flex Module / JS AMD.

@madsager
Copy link
Contributor

madsager commented May 8, 2013

Added Area-Language, Triaged labels.

@DartBot
Copy link
Author

DartBot commented May 8, 2013

This comment was originally written by @seaneagan


Have you seen DeferredLibrary yet:

http://api.dartlang.org/docs/bleeding_edge/dart_async/DeferredLibrary.html

is it tracked in issue #3940. it's currently limited to 2 files, but that should be changing soon.

@DartBot
Copy link
Author

DartBot commented May 9, 2013

This comment was originally written by @dam0vm3nt


That's great. But what do you mean with 'limited to two files'?

I'll do some experiment.
 Il giorno 08/mag/2013 19:34, <dart@googlecode.com> ha scritto:

@DartBot
Copy link
Author

DartBot commented May 10, 2013

This comment was originally written by increo...@gmail.com


You can load code not known at compile time through Isolates and spawnUri().

@DartBot
Copy link
Author

DartBot commented Jun 4, 2013

This comment was originally written by @dam0vm3nt


#­4: I already knew you can use Isoletes and spawnUri, but this is not the solution because:

  1. loading an external library dinamically doesn't necessarily implies we need to spawn a new thread
  2. not needing concurrency comunication by the loading and loaded modules should be possibile in a simpler way then using Send and Receive Ports. For example after loading a module it should be possible to call a function defined in that module passing generic objects

@DartBot
Copy link
Author

DartBot commented Jun 4, 2013

This comment was originally written by @dam0vm3nt


#­2 : I've checked the pointer and this is noy (YET) what I mean. Infact the compiler still needs to know the library at compile time, hence the need of a constant constructor (thus not allowing for truly dynamical library loading) and declaring an import statement (that requires to know the module at compile time).

So I've proposed some changes to that feature and posted a comment on that thread.

For commodity I repeat here the example that should work to satisfy this issue:

queryServerForLibToBeLoaded().then(loadIt);

loadIt(libName) {
 dynamicMod1 = DeferredLibrary(libName);
 dynamicMod1.load(moduleLoaded);
}

moduleLoaded(loadedLibraryMirror) {
 loadedLibraryMirror.classes[libName+".Plugin"].invoke("initPlugin");
}

@DartBot
Copy link
Author

DartBot commented Nov 21, 2013

This comment was originally written by @stevehsu77


i propose an easy definition of dynamic load.

========================================================================
typedef int function(String arg1,int arg2);

funntionmirror=reflect(function);
functionmirror=loadsource(uri);
 -or-
functionmirror="int (String localarg1,int localarg2){ return int.parse(localarg1)+localarg2; }"

var result=functionmirror.invoke(arg1, arg2);
=======================================================================

so that it doesn't need to load a new library and handle dynamic type processing.

@DartBot
Copy link
Author

DartBot commented Nov 21, 2013

This comment was originally written by jirkad...@gmail.com


Going forward, do we really want to use this? There is much[1] talk[2] recently[3] about the security model on the web and being able to dynamically inject stuff into the code of the main app (which is easy in JS) is being frowned upon. XSS, you know. There is even the extreme case[4] of some academics trying to use the first and second W3C standard [1,3] I mentioned to implement in JS something akin to Dart isolates.

As an alternative, the current isolate model could be made more developer friendly by making some API wrapper or so. There is something in these lines in Java. It could be made with the security model of Least Privilege and Information Hiding in mind that is being proposed[2, 4, 5] for the web.

[1] The sandbox attribute http://www.whatwg.org/specs/web-apps/current-work/multipage/the-iframe-element.html#attr-iframe-sandbox
[2] Douglas Crockford: Really. JavaScript. http://www.youtube.com/watch?v=lTWGoL1N-Kc , from 37:00
[3] Content Security Policy 1.0 http://www.w3.org/TR/CSP/
[4] Privilege Separation in HTML5 Applications www.cs.berkeley.edu/~devdatta/papers/LeastPrivileges.pdf
[5] The Lazy Programmer's Guide to Secure Computing http://www.youtube.com/watch?v=eL5o4PFuxTY

@DartBot
Copy link
Author

DartBot commented Nov 21, 2013

This comment was originally written by @dam0vm3nt


I think this is, not only desiderable, but also of extreme importance for
Dart success.

Dart needs a way to create extensible and modular application. Isolates can
actually be used but they are a very poor mechanism when it comes to
intra-module communication.

Let's make an example. I have a project that consist in a new fantastic
social network that's written in DART. I want thirdy party to contribute
with they're fantastic App. But I want them to seamlessly integrate to the
main framework.
If I were using in any other programming language (Flex, Java or even JS)
all I have to do is to provide the contract API, i.e. a set of classes to
extend and interfaces to implement so that a thirdy party can implement
their App.
Then the thirdy party could upload their module (preferably in a "compiled"
form) and their app could be installed and executed - just because it is
conformant to the contract API. The framework in turns could simply load
the compiled code and run it (for examble in Java we have Classloaders, in
Flex URLLoader, in JS a plethora of api).

If I'm not missing something at the moment if we want to implement this
simple and common pattern (i.e. a framework - plugin pattern) with dart we
have only two choices:

  1. use the power of OO approach and provide a contract API in terms of
    classes and interfaces and not using isolates. In this case we need to
    RECOMPILE ALL THE framework every time we have to integrate a new plugin.
    This also means that we cannot provide an authonomous and automatic way for
    a thirdy party to add their plugin but there must be a human procedure.
    Unfeasible.

  2. specify the contract using some sort of "communication protocol" and
    using Isolates. We cannot provide classes to extend because there's no way
    an isolate could return an object to the framework implementing some sort
    of contract. Isolates can communicate only "simple data" and using "copy by
    value". This is a very poor approach, complicated, error prone. But the
    main defect IMHO is that we are restricted to use "copy by value" approach
    making difficult to pass big data structures and to share implementation
    across different peer plugins or between the framework and the plugin.

I hope I'm wrong and someone could teach me a third way because so far this
is the only reason for people like me and my company for not to adopt DART
now and until this is fixed. Don't think we are the only one expecting this.

Security should not be an excuse for not implementing important features
like this. Otherwise the most secure language is the less powerfull.

@DartBot
Copy link
Author

DartBot commented Nov 21, 2013

This comment was originally written by @dam0vm3nt


Maybe this example is more clear of what IMHO it is needed:

// We call our backend and ask for a module to load
queryServerForLibToBeLoaded().then(loadIt);

// Backend provides us with the url of the lib to load
loadIt(libName) {
 dynamicMod1 = DeferredLibrary(libName);
 dynamicMod1.load(moduleLoaded);
}

// The module is loaded we can create object using classes defined
// in the module that extends classes defined in the calling module:
moduleLoaded(loadedLibraryMirror) {
 var myObj: MyClass = loadedLibraryMirror.classes[libName+".Plugin"].create();
 var myArg : MyOtherClass = new MyOtherClass();
 // AND USE IT:
  myObj.doSomething(myArg);
}

@DartBot
Copy link
Author

DartBot commented Nov 21, 2013

This comment was originally written by @stevehsu77


It's concerned about class run-time types while loading whole library.
And another issue is refer to other libraries during compiling it.
Think about this
=============================================================
import 'aaa/bbb/ccc.dart'; //but we don't have ccc.dar under aaa/bbb

class a extends b {} //but b is in another dynamic library we just loaded

var myObj = loadlibrarymirror.class['lib.a'].create();
// there are two problems
// 1. is an independent mirror system differ from current mirror system? if yes, how to use the class in current mirror system in dynamic load mirror system?
// 2. if it's not, the current mirror system seems to have to load a chain of libraries and consider about conflict of naming, because we won't give the alias name before we use them.
===================================================================================
as in my project, i want to pass a class/structure definition to the class which is dynamic loaded and return the class/structure in what i defined the other dynamic library , so, it must import my class/structure definition. it will cause many problems.

because dart is not a pre-compiled language, it does't have any header file or dependency file. and it use language-based vm, does't own any intermediate language like as bytecode or msil.

many things have been done when vm is starting. that's why i assume loading dynamic library will make vm developers to think more about security, performance, convenience, and more then more.

and that's why i propose an easy way to load dynamic functions. it does't to be considered about type and many other things in vm. and easy to modify code in vm in 3 steps. (load source string, parse to object, instance it)


typedef int function(String arg1,int arg2); //as a delegate, supported now

closuremirror=reflect(function); //reflect it, need a little modify
closuremirror.loadsource(uri); //load realcode from web, filer, etc.
 -or-
closuremirror.loadsource("int (String localarg1,int localarg2){ return int.parse(localarg1)+localarg2; }"); //load realcode from string
                                            //add it in mirror system
var result=closuremirror.apply(arg1, arg2); //run it

don't do think too much about runtime-typed, memory heap, garbage collection. and etc. and then support dynamic function, so that we can wrap it as a module.

@DartBot
Copy link
Author

DartBot commented Nov 21, 2013

This comment was originally written by @stevehsu77


believe i would so strongly except dart can support dynamic library. so i can move my c# and as3 architecture to dart. and i was trying to do this. i built everything is class in the project (https://github.com/yunist/yun). but i change my mind since dart 1.0 (there are many changes of mirrors and isolate), i think everything is object in dart as js. so i define structure use map, ans use class as interface(like go language) in the new project (https://github.com/yuner/surebet). now dynamic function is enough for me. dart is not like other language, you need redesign your architecture to suit it.

@DartBot
Copy link
Author

DartBot commented Dec 3, 2013

This comment was originally written by @dam0vm3nt


Another common usecase where we absolutely want this is : a main module that loads a dynamic module that creates a web component to be returned to the main module.

This is not possible with current mirror/isolates.

Example:

the main module implements a browser of a collection. when clicking an item we want to dynamic load a module that will create an editor for the item to be displayed on the current page in a specific div.

@DartBot
Copy link
Author

DartBot commented Dec 3, 2013

This comment was originally written by @stevehsu77


code as below
==============================================================
class Dynamic_Class
{
    Name String;
    Uri Source_File;
    Map<String,dynamic> _inner_Mirror={};

    Dynamic_Class (this.Source_File)
    {
        String source_definition=_load(Source_File);
        _parse(source_definition);
    }
    String _load(Uri source_file) { //implement code - read json file to string}
    String _parse(String source_definition} { //implement code - put to _inner_Mirror}
    Function _parse_a_function(String function_source_code) { //.... }
    get(String function_or_variable_name) => _inner_Mirror[function_or_variable_name];
    void set(String function_or_variable_name, dynamic function_or_variable) { //...
    dynamic invoke(String function_name) { //... }
}
====================================================================================
json definition
===================================================================================
{
   "@class_name" : "my_dynamic_class",
   "_local_field" : 123,
   "public_field" : "456",
   "_local_method" : "dynamic (List arguments){ ... }",
   "public_method" : "dynamic (List arguments){ ... }"
}
=================================================================================
so that we don't need to generate new structure(class type), that will be more easy for modifying vm code.

even you can implement different code for each div by special "class_name";

Map<String div_class, Dynamic_Class> div_wrapper;

is it easy? for vm developer , it's very easy to do this modification.

@DartBot
Copy link
Author

DartBot commented Dec 3, 2013

This comment was originally written by @stevehsu77


and i will put dynamic_class to an independent isolate to manager all dynamic classes for security. dynamic code may cause many injection problems in web apps. for a "div" application, we often listen it's events, so pass the event to another isolate, and then process it in dynamic module, finally, use massage to transfer the result to main isolate will keep everything under control and safety. however, it will cause lots of memory-copied actions and duplicated data. but, vm use a solution like as snapshot(not sure) to solve this problem.

@DartBot
Copy link
Author

DartBot commented Mar 31, 2014

This comment was originally written by nigel.magn...@gmail.com


I'm not sure Isolates, or the definition of DeferredLibrary is the answer.

For a relevant example in the JS world, look at this: https://github.com/dluksza/angular-gerrit - client-side modules, integrating into a bigger application. Comment #­9 is spot-on. Many applications - ones that dart is a good fit for - need this kind of modularisation ability.

Now, I don't really mind if the modules themselves suffer from 'poor minification'. In the (say) Java world, I might load a module into a new classloader, and be able to reference classes from my 'parent' - without having to bundle those classes all over again. I can see how that would be extremely difficult in the Dart case.

But at the moment - somewhat embarrasingly - if I want to reference dart 'module A' from 'dart application B', about the only tractable solution is to compile moduleA entirely into JS, then use the JS interop to access it (!). Yuck!

It would be nice to have even an iterim solution, otherwise dart's going to be a non-starter :-(.

@DartBot
Copy link
Author

DartBot commented Jul 5, 2014

This comment was originally written by danil.kornishev@gmail.com


In Ruby/php you can import a file from anywhere in the code. Why can't I do this in dart?

I'd like to be able to scan a directory and import all dart files found, for example in my dart cucumber project. That seems not possible. Had to resort to generating a dart runner file with all the found files imported and using spawnUri.

@gbracha
Copy link
Contributor

gbracha commented Aug 25, 2014

Set owner to @gbracha.
Added Accepted label.

@DartBot
Copy link
Author

DartBot commented Aug 26, 2014

This comment was originally written by imre.gabes...@gmail.com


I'm looking forward to this feature extension. Currently this shortage is the reason why we use JS instead of Dart. And JS is way uglier and slower than Dart but at least that's dynamic...

@DartBot DartBot added Type-Defect area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). labels Aug 26, 2014
@trentgrover-wf
Copy link

any update on this?

@bergwerf
Copy link

+1, I really need this to be able to use Dart for my project instead of ES6/TypeScript.

@sethladd
Copy link
Contributor

@hermanbergwerf thanks for the comment. Could you provide specific details on exactly what problem you need solved?

@bergwerf
Copy link

@sethladd I want to build a plugin framework where plugins can be executed during runtime so I can move features out of the core into separate modules. Additionally, third party developers will be able to develop and run plugins. In JS I could inject the plugin script which could then access a global object from the core that holds an API. It seems spawnDomURI from Dart can achieve this too (I think I could pass the API object via args), but there is no dart2js implementation yet. I suppose the compiled dart2js could also be injected and the plugin could import the core so it can use the API object (which is really just a class with a lot of functions, this should be passed by reference though).

@sethladd
Copy link
Contributor

@hermanbergwerf thanks! Just for clarity, do you need this only for your web apps, or are you writing VM-based apps, too?

Also for clarity, it sounds like you need to dynamically load a library into an existing isolate, such that the loaded library has access to all the same memory as the isolate it was loaded into?

(where, isolate == app or web app, in this case)

cc @floitschG

@cyberail
Copy link

cyberail commented Jul 29, 2021

I think @mraleph 's Thoughts would be great to hear about it.

@ghost
Copy link

ghost commented Jul 29, 2021

If the objects are handled correctly, you should not have a memory problem.
What amazes me is that the Dart team did not include a good system for dynamically loading modules.
All languages today contemplate this possibility, since it is fundamental for modern applications. 👎

@ghost
Copy link

ghost commented Jul 29, 2021

Yes, it would be very interesting to know the thoughts of @mraleph :)

@cyberail
Copy link

If the objects are handled correctly, you should not have a memory problem.
What amazes me is that the Dart team did not include a good system for dynamically loading modules.
All languages today contemplate this possibility, since it is fundamental for modern applications. 👎

They say AOT compilation principles, excludes possibility of reflection, but I don't really have deep understanding of those principles.

@cyberail
Copy link

cyberail commented Jul 29, 2021

If the objects are handled correctly, you should not have a memory problem.
What amazes me is that the Dart team did not include a good system for dynamically loading modules.
All languages today contemplate this possibility, since it is fundamental for modern applications. 👎

If you are using thousands of complex custom widgets there is a big chance you will came across problems, at least in an android app case you will have battarey consumption very high and it is a big problem.

@ghost
Copy link

ghost commented Jul 29, 2021

@campfire5
Let's specify ideas, a Windows DLL does not have, nor does it need reflection, however it can be loaded from an application.
A Dart module could expose classes as an interface, so the main Dart application, without the need for reflection, could use those classes.
If the Dart development team doesn't want to do this, it's not because they can't.

Neither all the objects nor all the windows of an application are used simultaneously, if someone does that, they have poorly developed their application.
A well-designed application does not have to cause memory problems in any case. :)

@cyberail
Copy link

cyberail commented Jul 29, 2021

I think you should be able to use reflection and reflectable on windows fluently its a problem of flutter mostly, although you will not have ability of static reflection, So let's define a problem, if you are using reflaction dart executable needs to be aware of all of its body all of it's code to introspect it and create reflections of an object, So executables size gets bigger because during compilation dart needs to compile everything for the sake of reflection. With reflectable you are just telling it which class should be compiled fully and not only its parts, it means wherever you have imported file which includes reflectable class, that class will be compiled fully which undermines the tree shaking principle only for that class or classes. So basically, tree shaking is a kinda oposite of reflection in dart, and because of that you don't have modules as interfaces, but if you undermine it and use reflaction basically you will have modules or classes as interfaces but it will be loaded in memory and your executable will be pretty large. Reflactable package just makes it more specific and light weight.
Those are main things in compilation and I think this is the problem but again we need to hear from @mraleph to know it much better. So maybe there are other reasons as you say it.

@ghost
Copy link

ghost commented Jul 29, 2021

Let's hope they say something from the dart development team. :)
Thanks.

@mauriba
Copy link

mauriba commented Jul 30, 2021

I really need a framework-plugin system just like a C++ executable dynamically loading DLLs.

BUT: How can such kind of functionality be secure in Flutter? As soon as my Flutter app loads an infected module, this module has power over the whole device. Things will go bad.

We need a plugin concept working with permissions. A module should not use the camera or even render a widget (e.g. fake login system) unless the app/the user has authorized it to do so. In fact, this must be pretty hard to implement securely. But what about an interpreted approach: The Flutter app can read and parse a script with little functionality. Any special or performance critical function can then be exported from the script engine to the script. BOOM: Full control on the app side.

@ghost
Copy link

ghost commented Jul 30, 2021

Actually, any programming language can have the same problem, the applications that are developed can access most of the functionalities of a computer.
But that is not the important thing, the important thing is that Dart has the possibility of modularizing an application and allows those modules to be dynamically loaded. :)

@markmeeus
Copy link

This security concern could be solved by signing these dynamic libraries with a certificate. So that only trusted code could be loaded in your app.

@sergiossm
Copy link

sergiossm commented Jan 11, 2022

@Josua2012 It supports reflection. I will be precise and say that, It does not support "static reflection" which means just to build the class by givin string as a classname to reflector. You need to have Type already defined, and visivle for reflector so it can create class from it. After that, you can do traditional reflection ops: adding methods and properties dynamically.

Other thing is that when you use reflection dart and its tree shaking freaks out and imports everything from every file, which makes executable huge in size. For that you are using reflectable package to anotate classes which you are going to reflect with @reflectable. So now it knows which class is going to be reflected so tree shaking kinda gets into shape, but I really don't think it is perfect solution.

Problem I was talking about, was about flutter, which does not support reflection in production cause it uses AOT compilation. And also it does not support dynamic module loading.

Note: Last version of flutter, specifically 2.13 was talking about deffered libraries which is supported only on android, which basically does the following, connects to playstore api and downloads needed library while you are opening your app first time. This way download time is less. To put it simply, you can have your libraries somwhere else and it will be downloaded and merged after using opens app first time, main executable or downloadable file only knows about urls that for those libs.

@campfire5 I need to create a deferred component out of a custom package as it contains huge assets and the aab exceeds the 150MB Play Store limit. The deferred libraries you were talking about would be exactly what I need, can you tell me a bit more about them?

@SzczurekYT
Copy link

This comment was originally written by @dam0vm3nt


I think this is, not only desiderable, but also of extreme importance for
Dart success.

Dart needs a way to create extensible and modular application. Isolates can
actually be used but they are a very poor mechanism when it comes to
intra-module communication.

Let's make an example. I have a project that consist in a new fantastic
social network that's written in DART. I want thirdy party to contribute
with they're fantastic App. But I want them to seamlessly integrate to the
main framework.
If I were using in any other programming language (Flex, Java or even JS)
all I have to do is to provide the contract API, i.e. a set of classes to
extend and interfaces to implement so that a thirdy party can implement
their App.
Then the thirdy party could upload their module (preferably in a "compiled"
form) and their app could be installed and executed - just because it is
conformant to the contract API. The framework in turns could simply load
the compiled code and run it (for examble in Java we have Classloaders, in
Flex URLLoader, in JS a plethora of api).

If I'm not missing something at the moment if we want to implement this
simple and common pattern (i.e. a framework - plugin pattern) with dart we
have only two choices:

  1. use the power of OO approach and provide a contract API in terms of
    classes and interfaces and not using isolates. In this case we need to
    RECOMPILE ALL THE framework every time we have to integrate a new plugin.
    This also means that we cannot provide an authonomous and automatic way for
    a thirdy party to add their plugin but there must be a human procedure.
    Unfeasible.

  2. specify the contract using some sort of "communication protocol" and
    using Isolates. We cannot provide classes to extend because there's no way
    an isolate could return an object to the framework implementing some sort
    of contract. Isolates can communicate only "simple data" and using "copy by
    value". This is a very poor approach, complicated, error prone. But the
    main defect IMHO is that we are restricted to use "copy by value" approach
    making difficult to pass big data structures and to share implementation
    across different peer plugins or between the framework and the plugin.

I hope I'm wrong and someone could teach me a third way because so far this
is the only reason for people like me and my company for not to adopt DART
now and until this is fixed. Don't think we are the only one expecting this.

Security should not be an excuse for not implementing important features
like this. Otherwise the most secure language is the less powerfull.

Exactly.

Any news on this? Dart and Flutter really needs plugins/modules system.

@0xchase
Copy link

0xchase commented Oct 7, 2022

I would also be interested to hear if the devs have plans to implement this

@ghost
Copy link

ghost commented Oct 7, 2022

A lot of time has passed and everything is still the same, apparently nobody is interested in this functionality. :(

@ilopX
Copy link

ilopX commented Oct 7, 2022

I need this functionality.

@SzczurekYT
Copy link

Yeah, currently most of the software we use everyday has a system that allows you to add additional third party functionality.
Browsers, IDE's, notetaking apps, some mail clients and a lot of other stuff has some kind of extensions or plugin system.
If we want to make app's that can match modern day user expectations about costumisability we really need a way to load code on the runtime.

@ashim-kr-saha
Copy link

I am waiting for this functionality for a long time.

@dustinlessard-wf
Copy link

If we can just hold in there until May of next year, we will have gone a whole decade hoping for this. That's sorta an achievement in itself.

@Proberts
Copy link

Has any work been started on this? I'm happy to see if I can contribute to the core to get modular deployables implemented.

I'm working on a Flutter SPA that integrates with clients' existing backend ERP, CMS, and/or databases. In addition to those externals being different per client, clients also want UI customization that requires source-level changes Not all clients will be subscribing to all features.

Normally I would modularize all the components and have a list of modules that load per client. Without modularization I either have to maintain one monolithic product per client, or one one single monolithic product that includes everything for every client and runtime logic to call the correct functionality.

Imagine there was no way to dynamically load images and every user you have wants their avatar photo displayed in an App/SPA. You'd have to either build your package with every photo in the assets folder and rebuild and redeploy every time a photo is added or changed, or build unique deployables for each client with their customized avatar.png.

C/C++ has a simple interface for dynamically loading compiled code. Compiling a modular object includes a symbol table that can be used with dlopen/dlmopen and dlsym/dlmsym to interact with components. Given that Dart allows function pointers to be passed as arguments and be stored in Lists/Maps, could a base "DynamicModule" object load a compiled Dart module file and store all the symbol names and pointers in a Map for access? (This could also allow for hot-swapping running code without restart which is useful for services.)

@SzczurekYT
Copy link

What you say feel a little bit complicated to me, but the flutter app example is good. I see that loading additional app modules / parts would really help.
Another example are community made ones. You create an app, and you have community around it. Now the people in this community that are develepers could create their own modules / extensions to add new functionality to your app.
This is a must have for many modern day apps. For example vscode. Without the dart extension development would be way harder.

@njhuan
Copy link

njhuan commented Dec 7, 2022

I also need it. With this functionality, I would definitely use Flutter in my project. Without it, I have to seek other solutions.

@mraleph
Copy link
Member

mraleph commented Dec 12, 2022

The team currently does not have any plans to provide support for modular AOT deployments (at least in short term).

If you need this sort of functionality you either need to run in JIT (which supports dynamic code loading) or run your modules in separate isolates - which is supported in AOT - you can use Isolate.spawnUri to load an AOT compiled module as an new isolate.

@SzczurekYT
Copy link

SzczurekYT commented Feb 3, 2023

If we can just hold in there until May of next year, we will have gone a whole decade hoping for this. That's sorta an achievement in itself.

It isn't may yet, but github shows that it's 10 years already. Someone should make a meme with that skeleton sitting on a chair underwater.
"Me waiting for flutter and dart to get dynamic code loading."
Sorry if this feels rude, don't take it seriously. But I think that such important feature should be addressed after 10 years.

@SzczurekYT
Copy link

The team currently does not have any plans to provide support for modular AOT deployments (at least in short term).

If you need this sort of functionality you either need to run in JIT (which supports dynamic code loading) or run your modules in separate isolates - which is supported in AOT - you can use Isolate.spawnUri to load an AOT compiled module as an new isolate.

That's sad, Isolates won't work for this. They may be good for doing background work, but not for adding new features to an app (and rendering widgets).

@mraleph
Copy link
Member

mraleph commented Feb 6, 2023

That's sad, Isolates won't work for this. They may be good for doing background work, but not for adding new features to an app (and rendering widgets).

If you want to allow new features to bring in arbitrary widgets then things get complicated, yes. But if you limit your features to a fixed set of widgets they can use (those built into the main app), then I think it is possible to use isolates: you just need to develop an API for building widget trees out of supported widgets and sending them to the main isolate to render. It's a bit of boilerplate work (you would have to duplicate API surface of all widget classes you need to use), but it is hardly infeasible. Alternatively you could build on top of something like https://pub.dev/packages/rfw instead.

@Proberts
Copy link

Proberts commented Feb 8, 2023

Found this project that may be a adequate (albeit very heavy) substitute but it's still WIP: https://pub.dev/packages/dart_eval

_dart_eval is an extensible bytecode compiler and interpreter for the Dart language, written in Dart, enabling dynamic codepush for Flutter and Dart AOT.

The primary aspect of dart_eval's goal is to be interoperable with real Dart code. Classes created in 'real Dart' can be used inside the interpreter with a wrapper, and classes created in the interpreter can be used outside it by creating an interface and bridge class.

dart_eval's compiler is powered under the hood by the Dart analyzer, so it achieves 100% correct and up-to-date parsing (although compilation and evaluation aren't quite there yet.)

Currently dart_eval implements a decent amount of the Dart spec, but there are still missing features like generators, Sets and extension methods. In addition, much of the standard library hasn't been implemented._

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). core-n customer-dart-sass type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests