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

Running Flint #31

Open
beatrizmoreira opened this issue Oct 9, 2020 · 26 comments
Open

Running Flint #31

beatrizmoreira opened this issue Oct 9, 2020 · 26 comments

Comments

@beatrizmoreira
Copy link

Hello,
I am trying to install and run flint on my mac, but I cannot do it.
I tried through Docker (in your language-guide there's a . (dot) missing at the end of the command sudo docker build -t "flint_docker" ) and on the [15/17] there is an undeclared type 'PropertyListEncoder' which then results in an error.
I also tried building from source, and I installed the Solidity Compiler but when I do which solc nothing appears, only when I do solcjs. So I cannot run your code as there is no solc command.
Is there another way to do it?
Thank you!!

Screenshot 2020-10-08 at 18 22 56

@SusanEisenbach
Copy link
Member

Hi Beatriz,

You seem to be trying to install an old version of Flint. We have done a complete rewrite. The instructions for building the new Flint compiler are at:

https://github.com/flintlang/flint-2/blob/master/docs/guide.md#building-from-source

You need to start by installing LLVM and Rust.

We're interested if this works for you.

Cheers

@beatrizmoreira
Copy link
Author

Hello!

I have a Mac and I cannot build it. I have installed LLVM and Rust but when i do cargo build this error appears:

Screenshot 2020-10-16 at 09 23 24

I tried installing it through homebrew and cargo but no luck :(

Thank you !!

@SusanEisenbach
Copy link
Member

You may be having trouble because your default LLVM installation is the wrong version. If you homebrewed LLVM, I imagine you would have LLVM 10 (which is correct). But you may have another version acting as the default. If you can find the path to your llvm-10 installation, you can compile with LLVM_SYS_100_PREFIX=/usr/lib/llvm-10 cargo build, as seen in the travis file.

We’re just curious. What are you hoping to do with Flint?

@beatrizmoreira
Copy link
Author

Ok, I did that and I was able to install flint successfully but when I try to compile your example Counter this appears:

Screenshot 2020-10-23 at 08 48 46

And then I remove the parenthesis and I get this error:

Screenshot 2020-10-23 at 08 49 45

Regarding your question, I am trying to formalize Flint's semantic and use Racket to see a step-by-step execution.

@SusanEisenbach
Copy link
Member

It would be nice to have a formal semantics. We don't actually have a published paper (there is one on Arxiv and a short one right at the begining of Flint) on Flint and if you produce good semantics we would be happy to try to put a Flint paper together for publication.

George said: You will need to run cargo with the LLVM_SYS_100_PREFIX=<path_to_her_llvm> argument every time. Otherwise the LLVM API will get confused about which version to use. The brackets should not be used.

To compile a contract, the syntax (I think) is cargo run <libra | ethereum> <path to contract>. I believe there is a command line help menu, which Matthew wrote. This can be accessed by cargo run -- -h​. Again, she will need to use the LLVM_SYS... each time.

@beatrizmoreira
Copy link
Author

The goal of our work is to define a small smart language with behavioural types. Flint is a good starting point, since it has typestates; Featherweight Solidity (FS) is another source of inspiration since it is a core language with a formal semantics and a type system.

To better understand a formal language and to debug its definition, we use Racket, as it allows to take a formalisation of a programming language and to have a step-by-step visualisation of the formal semantics, by using Redex (one of its many tools). With it, we are able to generate reduction graphs automatically, and see the environments change with the progression of the evaluation of the expressions and check if the formalisations are indeed correct.

Right now we wrote in Racket the formal semantics of FS. It was not super easy, but we managed to achieve the goal. With the lessons learned we intend to formalize Flint, so we can better understand your language. The aim would be then to get the “best” from Flint and FS and add a typestate/behavioural type system, inspired by yours and by approaches like Mungo.

Also, can you give me an example on where am I supposed to write LLVM_SYS_100_PREFIX=<path_to_her_llvm> in the command line to run cargo?

Thank you :)

@Aurel300
Copy link

Aurel300 commented Nov 9, 2020

LLVM_SYS_100_PREFIX=<path_to_llvm> is an environment variable, so you can prepend it to your cargo call like so:

LLVM_SYS_100_PREFIX=<path_to_llvm> cargo run ...

You can also make it permanent for the current command-line session by running:

export LLVM_SYS_100_PREFIX=<path_to_llvm>

@beatrizmoreira
Copy link
Author

Hi,
Thank you! I executed the command export and tried to run cargo run (libra|ethereum) main.flint like you have in your Language Guide but this error appears:

Screenshot 2020-11-12 at 14 57 23

So I removed the parenthesis and run cargo run libra|ethereum main.flint but this happened :

Screenshot 2020-11-12 at 15 00 25

My version of llvm is 10.0.1_2 .
Thank you for your time :)

@Aurel300
Copy link

A Flint source file named main.flint containing a contract Counter can be compiled to a blockchain-specific IR file using:

$ cargo run (libra|ethereum) main.flint

This part (and any use of the (libra|ethereum) syntax) means:

  • run cargo run libra main.flint to compile for Libra
  • run cargo run ethereum main.flint to compile for Ethereum

@beatrizmoreira
Copy link
Author

This happens with either the commands :c

Screenshot 2020-11-13 at 15 40 05

@Aurel300
Copy link

That still seems to be complaining about no LLVM found. Have you run the export ... command I posted above before running cargo run? It only applies to the current terminal window and only until it is closed. Out of curiosity, what is your LLVM path?

@beatrizmoreira
Copy link
Author

Yes, I ran the export LLVM_SYS_100_PREFIX=usr/local/Cellar/llvm/10.0.1_2 command before cargo run.

@Aurel300
Copy link

Maybe that is the problem, try with a slash in front of usr:

export LLVM_SYS_100_PREFIX=/usr/local/Cellar/llvm/10.0.1_2 

@beatrizmoreira
Copy link
Author

Thank you, now it compiles but im still not able to run it :c
Screenshot 2020-11-19 at 13 49 02

@Aurel300 Aurel300 transferred this issue from flintlang/flint Nov 19, 2020
@Aurel300
Copy link

Does the file main.flint exist? Is there a contract defined in it? You could try compiling one of the test cases, e.g. counter.flint.

@beatrizmoreira
Copy link
Author

I tried your main.flint from your language guide (btw the public init() {} is commented on your example), and this happened:

Screenshot 2020-11-20 at 12 34 47

And then i tried multiple of your test cases and this kept happening:

Screenshot 2020-11-20 at 12 35 05

@egroge
Copy link
Collaborator

egroge commented Nov 21, 2020

As for the main.flint in the language guide, this is not your fault. It was an oversight on our part and should not be in the guide, since it is not implemented in flint2. The working version of this is the counter.flint contract in behaviour tests.

However, the assert contract is compiling for me. I get the same error as you when I change my flint-config.json file to make it wrong. Have you set up your flint-json file to specify where flint can find llc (needed to create LLVM byte code) and wasm-ld (needed to link web assembly methods into the LLVM code)?

@jessicalally
Copy link
Collaborator

I've just run the assert contract and had the same error message as you. I didn't have wasm-ld-10 installed, but after installing the lld-10 package the assert contract is now compiling for me. Let us know if this fixes your issue!

@beatrizmoreira
Copy link
Author

As for the main.flint in the language guide, this is not your fault. It was an oversight on our part and should not be in the guide, since it is not implemented in flint2. The working version of this is the counter.flint contract in behaviour tests.

However, the assert contract is compiling for me. I get the same error as you when I change my flint-config.json file to make it wrong. Have you set up your flint-json file to specify where flint can find llc (needed to create LLVM byte code) and wasm-ld (needed to link web assembly methods into the LLVM code)?

I'm sorry, I didn't understand, what am i supposed to change in the flint-config.json file ?

I've just run the assert contract and had the same error message as you. I didn't have wasm-ld-10 installed, but after installing the lld-10 package the assert contract is now compiling for me. Let us know if this fixes your issue!

Im running it on a mac, should i install lld?

@egroge
Copy link
Collaborator

egroge commented Nov 24, 2020

So the flint-config file tells the compiler how to construct the LLVM code when you compile to eWASM. For this, it needs the llc command to create the bytecode, and the wasm-ld command to import the various eWASM functions. So you need to set the paths in the config file. This will depend where your llc and wasm-ld commands are. I am on a mac, and my LLVM installed llc and wasm-ld into my path, so for me I just set my llcPath to llc, and my wasm-ldPath to wasm-ld.

Obviously you will first need to find your installations (probably to be found in the bin of your llvm installation).

@beatrizmoreira
Copy link
Author

So I have updated the flint-config file with the respective paths.
I ran the counter.flint and i don't know if something is supposed to happen, it only does this

Screenshot 2020-11-25 at 15 41 43

@jessicalally
Copy link
Collaborator

Once you've run the counter.flint contract you should find an output directory containing four files: Counter.json (which gives a public interface of the contract which the Ethereum blockchain requires), Counter.ll (the contract compiled to LLVM), Counter.wasm (the contract compiled to eWASM) and Counter.wat (a more human-readable version of the eWASM contract).

@beatrizmoreira
Copy link
Author

Thank you very much for your help :D

Another question, in your language guide you refer some constants and variables can be declared without a value associated to it, therefore being set to unimplemented. Can you tell me if there are any predefined values for each type of variable?

@jessicalally
Copy link
Collaborator

I think you're referring to this sentence in the language guide:

If a constant is a state property of a contract, it may be given no initial value, but in that case it must be set unimplemented in each initialiser of that contract:

let <name>: <type>  

What we meant was that if you don't assign a value to a constant in the contract declaration, you must assign a value to it in the contract initialiser, therefore there are not any predefined values for these constants. However, the check for this in the compiler is currently unimplemented.

I hope that helps!

@beatrizmoreira
Copy link
Author

Oh ok :) thank you!

Btw I have been trying to run the .wat files and i get this error message on every file: 21:5: error: unexpected token local.get, expected ). Any idea what i should do here?

@jessicalally
Copy link
Collaborator

If you're using the WebAssembly Studio website to run the .wat files then the Studio might be the problem as it uses an obsolete assembler (see wasdk/WebAssemblyStudio#434), but otherwise we're not sure what's causing the error. You won't be able to run the .wat and .wasm files due to the ewasm-specific ethereum imports in these files (e.g. getExternalBalance), but you could try running them on the ewasm testnet (although we were not able to try this in the Summer as it was down).

I hope that helps :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants