fsprojects / FSharp.Compiler.PortaCode

The PortaCode F# code format and corresponding interpreter. Used by Fabulous and others.
Other
42 stars 11 forks source link

Update PortaCode to support 4.7 Language Features + Fabulous.LiveUpdate fails #21

Closed goldfish1974 closed 3 years ago

goldfish1974 commented 4 years ago

Currently it appears Fabulous.LiveUpdate done not support 4.7 Language Features such as implicit yields from Lists.

When using Fabulous.LiveUpdate, when using implicit yields from (for example) View.StackLayout(, children = []), the LiveUpdate PortaCode returns errors like:

C:\Users....\App\Screen.fs (734,37)-(734,99) typecheck warning This expression returns a value of type 'ViewElement' but is implicitly discarded. Consider using 'let' to bind the result to a name, e.g. 'let result = expression'. If you intended to use the expression as a value in the sequence then use an explicit 'yield'.

Compiling, running, debugging the App works fine but in the emulator and on real hardware.

Expected Result: PortaCode should use the same compiler version as being used by the project to compile.

TimLariviere commented 4 years ago

@goldfish1974 As far as I know, F# 4.7 Preview is currently limited to .NET Core. So I don't think it's compatible with Mono (all platforms except WPF Core and UWP).

goldfish1974 commented 4 years ago

@TimLariviere

According to this: https://devblogs.microsoft.com/dotnet/announcing-f-4-7/ it targets Net Standard 2.0 and was released in September (so not a preview any more)

In addition to that, this page https://docs.microsoft.com/en-us/dotnet/standard/net-standard (see the table) for Net Standard 2.0 us supported for different APIs, some of which are mono. I'm Targeting the various Xamarin.XX runtimes as I'm building a phone app.

Lastly, my project is currently building and running under .NetStandard 2.0, using f# 4.7 using Fabulous and Akkling and everything works like a charm currently, it's early days for the app coding though).

My only issue currently seems to be that PortaCode doesn't seem to use the same compiler version for LiveUpdate that was used to build the project.

Happy to be proven wrong, but it seems to be possible given my current expeience with the main App.

N.

Hardt-Coded commented 4 years ago

@TimLariviere are there any news? I can't use Live Update with implicit yields. Thank you.

TimLariviere commented 4 years ago

@DieselMeister I'm curious. How do you manage to use F# 4.7 with Fabulous? I tried, the shared project compile since it's .NET Standard 2.0, but as soon as I build the Xamarin projects, it fails.

That's because only the .NET Core compiler supports F# 4.7. The Xamarin projects are built by MSBuild, which doesn't support F# 4.7. And when building the Xamarin projects, it also tries to build the shared project, failing the build because of the unsupported implicit yields and opened static classes. (MSBuild will try to build all the dependencies itself)

That said, it should be possible to update PortaCode to FSharp.Core 4.7.1 easily. But only @dsyme has write access to this repository.

Hardt-Coded commented 4 years ago

So now I am confused. My Junior Dev currently builds an app, where she uses implicit yields. And she uses your template.

She uses it currently in debug mode and we didn't have a release build yet. But we wanted to use the LiveUpdate and this fails because of the implicit yields. But the App builds and deploy in debug mode fine on her Huawei Mate 9.

Maybe I miss something or I didn't get the problem.

TimLariviere commented 4 years ago

Which IDE is she using?

The problem can be represented like this: .NET Core Compiler Mono Compiler
F# 4.7 Yes No
Xamarin (Android, iOS, etc) No Yes

The thing is, when building the Xamarin projects, MSBuild will try to build every other referenced projects like the shared one.

If the shared project happens to be using F# 4.7 new syntaxes like implicit yields, it will fail (or at least produce invalid results -- see the warning message of the first post of this issue). Though dotnet build SharedProject.fsproj will succeed.

So I don't see how this can be done. Maybe I'm unaware of something?

Except maybe by removing the ProjectReference and directly linking the .NET Core-built dll of the shared project inside the Xamarin projects.


Just tried it again with a fresh 0.52 project from the templates. Both VS4Mac and JetBrains Rider refuse to build the following code (when debugging the iOS project).

Though Rider's IntelliSense will accept implicit yields.

View.ContentPage(
  content =
        View.StackLayout([
            if condition then
                View.Label()
        ])
)

I have .NET Core SDK 3.1.200 installed and dotnet build succeeds

Hardt-Coded commented 4 years ago

Okay we use VS 2019 and the Build-in Build process. So maybe VS does something else. But I am no expert on this.

goldfish1974 commented 4 years ago

Im using VS2019 also to build my app also amd targeting .Net Standard 2.0

dsyme commented 3 years ago

I'm looking to update FsLive.exe now for some of my own purposes.

It looks like Fabulous now internalise the necessary components and decides its own version of FCS, CUrrently this one:

        <PackageReference Update="Dotnet.ProjInfo" Version="0.9.0" /> <!-- Locked to 0.9.0 for FSharp.Compiler.PortaCode -->
        <PackageReference Update="FSharp.Compiler.Service" Version="25.0.1" /> <!-- Locked to 25.0.1 for FSharp.Compiler.PortaCode -->
dsyme commented 3 years ago

@TimLariviere I might rename https://github.com/fsprojects/FSharp.Compiler.PortaCode/ to https://github.com/fsprojects/FsLive I think

goldfish1974 commented 3 years ago

@dsyme As part of the rename, are you thinking of addressing F# 4.7 features too?

TimLariviere commented 3 years ago

@dsyme Ok, fine with me. Thanks for the heads-up. Once you do it, could you open an issue on Fabulous to let me know, please? Thanks.

It looks like Fabulous now internalise the necessary components and decides its own version of FCS.

Not really. Since Fabulous copies the source code of PortaCode directly from this repo, it's bound to the dependencies used here. I tried to update the version of FCS but it failed to compile because of some breaking changes, hence the message Locked to XXX for PortaCode.

dsyme commented 3 years ago

The version of FCS is now updated to F# 5.0

The testing now only creates F# scripts and uses FCS GetProjectOptionsFromScript which works across multiple platforms (using the same logic as dotnet fsi for references)

Many more F# language features are supported. There is an option --dyntypes to dynamically emit actual Reflection.Emit "shell" types and use the interpreter for the rest. This allows many more features to be supported. However it relies on having Reflection.Emit around so may not be appropriate for Fabulous

The payload for JSON serialization of PortaCode will have changed a lot. It may be considerably bigger, a possible issue for Fabulous.

Note my main use for this interpreter at the moment is to interactively execute DiffSharp model constructions and scrape tooltips and red-squiggly error information while that happens, on the same device the user is working on. I believe it's still usable as before for Fabulous but I'm not regularly using it for that, so some QA would be needed.

If Fabulous could move to transferring actual compiled App DLLs on Android things may be a lot simpler and more accurate. It may actually be faster by now

dsyme commented 3 years ago

I will close this as the work is done in this repo. Updating Fabulous would be great but let's do that separately