nit.git
3 years agocontracts: Remove `contract_name` property
Florian Deljarry [Fri, 5 Jun 2020 18:06:01 +0000 (14:06 -0400)]
contracts: Remove `contract_name` property

Signed-off-by: Florian Deljarry <deljarry.florian@gmail.com>

3 years agocontracts: Update contracts declaration
Florian Deljarry [Fri, 5 Jun 2020 15:46:22 +0000 (11:46 -0400)]
contracts: Update contracts declaration

Add the possibility to use contracts annotation many time

Signed-off-by: Florian Deljarry <deljarry.florian@gmail.com>

3 years agocontracts: Remove useless return parameter
Florian Deljarry [Fri, 5 Jun 2020 15:18:44 +0000 (11:18 -0400)]
contracts: Remove useless return parameter

Signed-off-by: Florian Deljarry <deljarry.florian@gmail.com>

3 years agocontracts: Improvement CallSiteVisitor
Florian Deljarry [Thu, 4 Jun 2020 13:21:22 +0000 (09:21 -0400)]
contracts: Improvement CallSiteVisitor

Signed-off-by: Florian Deljarry <deljarry.florian@gmail.com>

3 years agomodel/model_contract: Move contract model representation
Florian Deljarry [Tue, 2 Jun 2020 22:46:33 +0000 (18:46 -0400)]
model/model_contract: Move contract model representation

Signed-off-by: Florian Deljarry <deljarry.florian@gmail.com>

3 years agoMerge: Astbuilder improvement
Jean Privat [Thu, 4 Jun 2020 12:22:43 +0000 (08:22 -0400)]
Merge: Astbuilder improvement

This pr :
- move `do_all` method into ASTBuilder.
- generalize `create_callsite` to take into consideration AAttrPropdef

Pull-Request: #2825

3 years agosrc/astbuilder: generalize `create_callsite`
Florian Deljarry [Tue, 2 Jun 2020 14:59:54 +0000 (10:59 -0400)]
src/astbuilder: generalize `create_callsite`

Generalize `create_callsite` to take into consideration AAttrPropdef

Signed-off-by: Florian Deljarry <deljarry.florian@gmail.com>

3 years agosrc/astbuilder: move `do_all` method in ASTBuilder
Florian Deljarry [Tue, 2 Jun 2020 14:41:21 +0000 (10:41 -0400)]
src/astbuilder: move `do_all` method in ASTBuilder

Signed-off-by: Florian Deljarry <deljarry.florian@gmail.com>

3 years agoMerge: Contract refactoring
Jean Privat [Tue, 26 May 2020 19:26:30 +0000 (15:26 -0400)]
Merge: Contract refactoring

This pr integrate:

- Minor documentation changes
- Addition of the `in_contract` attribute to disable verification of contracts when we are already in verification.
- Improved signature management

This pr depends of #2815 #2816 #2817 #2820

Pull-Request: #2822

3 years agocontracts: Add `in_contract` attribute
Florian Deljarry [Mon, 20 Apr 2020 21:23:10 +0000 (17:23 -0400)]
contracts: Add `in_contract` attribute

This attribute is used to disable contract verification when you are already in a contract verification.

Signed-off-by: Florian Deljarry <deljarry.florian@gmail.com>

3 years agocontracts: Signatures improvement (ASignature and MSignature)
Florian Deljarry [Mon, 20 Apr 2020 14:05:59 +0000 (10:05 -0400)]
contracts: Signatures improvement (ASignature and MSignature)

Signed-off-by: Florian Deljarry <deljarry.florian@gmail.com>

3 years agocontract: Documentation improvement
Florian Deljarry [Fri, 17 Apr 2020 19:10:33 +0000 (15:10 -0400)]
contract: Documentation improvement

Signed-off-by: Florian Deljarry <deljarry.florian@gmail.com>

3 years agoMerge: astbuilder: Introduction of new construction services
Jean Privat [Wed, 20 May 2020 15:00:56 +0000 (11:00 -0400)]
Merge: astbuilder: Introduction of new construction services

Add two new services in the astbuilder module:
- Add a way in ModelBuilder to create AST and module entity at same time (`create_method`, `create_class`, `create_attribute`).

- Add a new property in MEntity `create_ast_representation` to return a ast representation of `self`.

Pull-Request: #2815
Reviewed-by: Jean Privat <jean@pryen.org>

3 years agoastbuilder: Add new AST creation services
Florian Deljarry [Tue, 10 Mar 2020 19:16:28 +0000 (15:16 -0400)]
astbuilder: Add new AST creation services

Signed-off-by: Florian Deljarry <deljarry.florian@gmail.com>

3 years agoMerge: modelize_property: Define a new API to modify AAttrPropdef
Jean Privat [Tue, 28 Apr 2020 19:21:11 +0000 (15:21 -0400)]
Merge: modelize_property: Define a new API to modify AAttrPropdef

Define a small fluent API in order to modify easily AAttrPropdef.

Pull-Request: #2820
Reviewed-by: Jean Privat <jean@pryen.org>

3 years agoMerge: typing: Add a mechanism to disable warnings
Jean Privat [Sat, 25 Apr 2020 07:12:47 +0000 (03:12 -0400)]
Merge: typing: Add a mechanism to disable warnings

Add a mechanism to suppress warnings during the typing phase. I also took the opportunity to modify a bad indentation in the file :smile: .

Pull-Request: #2818
Reviewed-by: Jean Privat <jean@pryen.org>

3 years agoMerge: typing: Add `do_typing` on AExpr
Jean Privat [Sat, 25 Apr 2020 07:12:45 +0000 (03:12 -0400)]
Merge: typing: Add `do_typing` on AExpr

Add a way to type an `AExpr` individually.

In my case this method is used in order to type expressions provided for the `old()` in ensures contract.

Pull-Request: #2819
Reviewed-by: Jean Privat <jean@pryen.org>

3 years agomodelize_property: Define a new API to modify AAttrPropdef
Florian Deljarry [Mon, 20 Apr 2020 19:56:16 +0000 (15:56 -0400)]
modelize_property: Define a new API to modify AAttrPropdef

Signed-off-by: Florian Deljarry <deljarry.florian@gmail.com>

3 years agotyping: Add `do_typing` on AExpr
Florian Deljarry [Fri, 10 Apr 2020 14:20:18 +0000 (10:20 -0400)]
typing: Add `do_typing` on AExpr

Add a way to type `AExpr`.

Signed-off-by: Florian Deljarry <deljarry.florian@gmail.com>

3 years agotyping: text formatting
Florian Deljarry [Mon, 20 Apr 2020 14:50:18 +0000 (10:50 -0400)]
typing: text formatting

Signed-off-by: Florian Deljarry <deljarry.florian@gmail.com>

3 years agotyping: Add a way to disable warnings
Florian Deljarry [Thu, 9 Apr 2020 14:05:04 +0000 (10:05 -0400)]
typing: Add a way to disable warnings

Signed-off-by: Florian Deljarry <deljarry.florian@gmail.com>

3 years agoMerge: modelbuilder_base: Define ANode as nullable
Jean Privat [Mon, 20 Apr 2020 13:14:26 +0000 (09:14 -0400)]
Merge: modelbuilder_base: Define ANode as nullable

Definition of ANode as nullable. When you create entities manually there is not necessarily a current attachment point (in the ast). It is therefore more practical to provide a service with the ANode which can be null.

In addition, the `fun error (n: nullable ANode, text: String)` method that will be called already handles this case.

Pull-Request: #2816

3 years agoMerge: modelize_property: Add `unsafe_add_mclassdef2nclassdef`
Jean Privat [Mon, 20 Apr 2020 13:14:24 +0000 (09:14 -0400)]
Merge: modelize_property: Add `unsafe_add_mclassdef2nclassdef`

Add a way to associate a `nclassdef` with its `mclassdef` without verification.

Currently, to attach an AClass with an MClass, you must use the `build_property` method which performs all the checks and builds the representation in the model. Thanks to the Nitbuilder which facilitates the construction of entities, we find ourselves in a case where we can build the representation of a class in the model and then build the corresponding ast. It is therefore necessary to provide a service to associate the both elements.

Pull-Request: #2817

4 years agomodelbuilder_base: Define ANode as nullable
Florian Deljarry [Mon, 9 Mar 2020 18:52:28 +0000 (14:52 -0400)]
modelbuilder_base: Define ANode as nullable

Signed-off-by: Florian Deljarry <deljarry.florian@gmail.com>

4 years agomodelize_property: Add `unsafe_add_mclassdef2nclassdef`
Florian Deljarry [Mon, 9 Mar 2020 18:56:14 +0000 (14:56 -0400)]
modelize_property: Add `unsafe_add_mclassdef2nclassdef`

Add a way to associate a `nclassdef` with its `mclassdef` without verification.

Signed-off-by: Florian Deljarry <deljarry.florian@gmail.com>

4 years agoMerge: modelize_property: Split the build_property method of AAttrPropdef
Jean Privat [Tue, 17 Mar 2020 21:35:57 +0000 (17:35 -0400)]
Merge: modelize_property: Split the build_property method of AAttrPropdef

This pr split the `build property` method into several methods. The objective is to be able to build the entities of the model (read, write...) more independently according to the current state. The construction of the signature was also split for the same purpose.

Pull-Request: #2813
Reviewed-by: Jean Privat <jean@pryen.org>

4 years agoMerge: src/astbuilder: Add new nodes makers
Jean Privat [Tue, 17 Mar 2020 21:35:55 +0000 (17:35 -0400)]
Merge: src/astbuilder: Add new nodes makers

Add new make method for three kind of nodes (AAttrPropdef, ACallAssignExpr)

Pull-Request: #2810
Reviewed-by: Jean Privat <jean@pryen.org>

4 years agoMerge: neo: Move neo node creation
Jean Privat [Tue, 17 Mar 2020 21:35:52 +0000 (17:35 -0400)]
Merge: neo: Move neo node creation

Move neo node creation in her respective class.

Pull-Request: #2812

4 years agoMerge: gitlabci: no auth for postgress in tests
Jean Privat [Tue, 17 Mar 2020 21:34:19 +0000 (17:34 -0400)]
Merge: gitlabci: no auth for postgress in tests

This should fix recent CICD issues

Pull-Request: #2814

4 years agogitlabci: no auth for postgress in tests
Jean Privat [Tue, 17 Mar 2020 18:12:22 +0000 (14:12 -0400)]
gitlabci: no auth for postgress in tests

This should fix recent CICD issues

Signed-off-by: Jean Privat <jean@pryen.org>

4 years agomodelize_property: Split model build of AAttrPropdef
Florian Deljarry [Fri, 31 Jan 2020 00:59:11 +0000 (19:59 -0500)]
modelize_property: Split model build of AAttrPropdef

Split the build method of AAttrPropdef

Signed-off-by: Florian Deljarry <deljarry.florian@gmail.com>

4 years agoneo: Move neo node creation
Florian Deljarry [Fri, 31 Jan 2020 01:21:54 +0000 (20:21 -0500)]
neo: Move neo node creation

Move neo node creation in her respective class.

Signed-off-by: Florian Deljarry <deljarry.florian@gmail.com>

4 years agoMerge: separate_compiler: Refactored class compilation
Jean Privat [Mon, 16 Mar 2020 18:31:54 +0000 (14:31 -0400)]
Merge: separate_compiler: Refactored class compilation

## Before
Before this update, the method `compile_class_to_c` handled every part
of the class compilation process even special case (universal class).
By doing so, we can't refined this method efficiently without
reimplementing the entire method. This is a pain since each time we
need to add universal class we have to modify the original code instead
of refining the compiler.

## After

The method `compile_class_to_c` has been divided in three main parts:

1. the class's vft compilation (same for every type of class)
2. the compilation of universal class specifics (change alot through
time). This part must managed every part of a universal type, except its
vft compilation which already handled by the 1st step.
3. the compilation of the default `NEW` allocator (apply only for
non-universal type).

Moreover, the state of a class compilation is stored in a new class
called `ClassCompilationInfo`, which has different flag to specify if
the class is dead/alive or need_corpse. This choice was made to prevent
dataclump in each method involved with the class compilation.

With this new way of managing class compilation, we can add new
universal class via refinement instead of code rewriting.

Signed-off-by: Louis-Vincent Boudreault <lv.boudreault95@gmail.com>

Pull-Request: #2808
Reviewed-by: Jean Privat <jean@pryen.org>

4 years agosrc/astbuilder: Add new nodes makers
Florian Deljarry [Sun, 29 Sep 2019 00:46:11 +0000 (20:46 -0400)]
src/astbuilder: Add new nodes makers

Add new node marker for AVarExpr, AStdClassdef, ACallAssignExpr, AAttrPropdef

Signed-off-by: Florian Deljarry <deljarry.florian@gmail.com>

4 years agoseparate_compiler: Refactored class compilation
Louis-Vincent Boudreault [Wed, 4 Dec 2019 21:59:00 +0000 (16:59 -0500)]
separate_compiler: Refactored class compilation

Before this update, the method `compile_class_to_c` handled every part
of the class compilation process even special case (universal class).
By doing so, we can't refined this method efficiently without
reimplementing the entire method. This is a pain, since each time we
need to add universal class we have to modify the original code instead
of refining the compiler.

The method `compile_class_to_c` has been divided in three main parts:

1. the class's vft compilation (same for every type of class)
2. the compilation of universal class specifics (change alot through
time). This part must managed every part of a universal type, except its
vft compilation which already handled by the 1st step.
3. the compilation of the default `NEW` allocator (apply only for
non-universal type).

Moreover, the state of a class compilation is stored in a new class
called `ClassCompilationInfo`, which has different flag to specify if
the class is dead/alive or need_corpse. This choice was made to prevent
dataclump in each method involved with the class compilation.

With this new way of managing class compilation, we can add new
universal class via refinement instead of code rewriting.

Signed-off-by: Louis-Vincent Boudreault <lv.boudreault95@gmail.com>

4 years agoMerge: Fixed quick_sort when array is length 0 or 1
Jean Privat [Tue, 28 Jan 2020 20:03:52 +0000 (15:03 -0500)]
Merge: Fixed quick_sort when array is length 0 or 1

Fixed a bug where quick_sort could access out of bound element when `to` argument smaller or
equal to 0.

# Before

var xs = [1]
default_comparator.quick_sort(xs) # assertion failed

# After

var xs = [1]
default_comparator.quick_sort(xs)
assert xs == [1] # true

Signed-off-by: Louis-Vincent Boudreault <lv.boudreault95@gmail.com>

Pull-Request: #2811

4 years agoMerge: Simplify constructors: next episode
Jean Privat [Tue, 28 Jan 2020 20:03:47 +0000 (15:03 -0500)]
Merge: Simplify constructors: next episode

The current constructors are quite complex, that is why Jean Privat had proposed to simplify them with the pr #1966.

The current init has a double facet, internal with a signature and an empty body and an external one with a signature and initializer represent the attributes to initialize.

This pr replace the external facet by introducing a new constructor defaultinit specific to each class. This default property includes the orchestration of initializers (non-default attributes, autoinit methods, and autoinit annotation in the class). In addition, this property is now the one exposed when a new A is executed.

The current init used to manually set the default constructor it's used to perform a processing after initialization. Note this one must have an empty signature. If this is not the case, an error will be generated.

To use the init in a similar way, we now have to use the old_style_init annotation.

This pr resolve minor bugs and test issues of the Jean's pr .

Pull-Request: #2803
Reviewed-by: Jean Privat <jean@pryen.org>

4 years agoFixed quick_sort when array is length 0 or 1
Louis-Vincent Boudreault [Sun, 22 Dec 2019 16:22:29 +0000 (11:22 -0500)]
Fixed quick_sort when array is length 0 or 1

Signed-off-by: Louis-Vincent Boudreault <lv.boudreault95@gmail.com>

4 years agoModel: Add get_direct_supermtype
Florian Deljarry [Wed, 4 Dec 2019 22:20:53 +0000 (17:20 -0500)]
Model: Add get_direct_supermtype

Add method to return the direct parents mtype of the mclassdef.

Signed-off-by: Florian Deljarry <deljarry.florian@gmail.com>

4 years agobucketed_game: Old_style_init
Florian Deljarry [Tue, 3 Dec 2019 15:52:37 +0000 (10:52 -0500)]
bucketed_game: Old_style_init

Signed-off-by: Florian Deljarry <deljarry.florian@gmail.com>

4 years agotest_neo: Fix error when mparameter is duplicated
Florian Deljarry [Wed, 27 Nov 2019 21:06:38 +0000 (16:06 -0500)]
test_neo: Fix error when mparameter is duplicated

Signed-off-by: Florian Deljarry <deljarry.florian@gmail.com>

4 years agomodelize: Get most specific init from mclass hierarchy
Florian Deljarry [Wed, 20 Nov 2019 21:56:53 +0000 (16:56 -0500)]
modelize: Get most specific init from mclass hierarchy

Signed-off-by: Florian Deljarry <deljarry.florian@gmail.com>

4 years agotyping: Add error when init is not found
Florian Deljarry [Wed, 20 Nov 2019 16:08:37 +0000 (11:08 -0500)]
typing: Add error when init is not found

More explicit error when a potential duplication of root object class.

Signed-off-by: Florian Deljarry <deljarry.florian@gmail.com>

4 years agosrc: Update init
Florian Deljarry [Wed, 13 Nov 2019 23:29:22 +0000 (18:29 -0500)]
src: Update init

Remove useless init and add old_style_init if it's necessary

Signed-off-by: Florian Deljarry <deljarry.florian@gmail.com>

4 years agotests: Fix tests
Florian Deljarry [Wed, 6 Nov 2019 19:08:23 +0000 (14:08 -0500)]
tests: Fix tests

Signed-off-by: Florian Deljarry <deljarry.florian@gmail.com>

4 years agoMerge: Fixed safe-call missed cast when reference primitive data types
Jean Privat [Tue, 3 Dec 2019 15:39:57 +0000 (10:39 -0500)]
Merge: Fixed safe-call missed cast when reference primitive data types

This patch fixed the issue #2804 where the compiler didn't add the cast from primitive data to
`val *` when accessed by safe-call syntax.

Signed-off-by: Louis-Vincent Boudreault <lv.boudreault95@gmail.com>

Pull-Request: #2806
Reviewed-by: Jean Privat <jean@pryen.org>

4 years agoMerge: Remove useless empty line
Jean Privat [Tue, 3 Dec 2019 15:39:52 +0000 (10:39 -0500)]
Merge: Remove useless empty line

I was reading that file recently and noticed this empty line :p

Pull-Request: #2807

4 years agoFixed safe-call miss cast when reference primitive data types
Louis-Vincent Boudreault [Sun, 10 Nov 2019 15:31:15 +0000 (10:31 -0500)]
Fixed safe-call miss cast when reference primitive data types

Signed-off-by: Louis-Vincent Boudreault <lv.boudreault95@gmail.com>

4 years agoRemove useless empty line
Alexandre Terrasa [Mon, 18 Nov 2019 22:28:48 +0000 (16:28 -0600)]
Remove useless empty line

Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>

4 years agopep8analysis: Fix no init call
Florian Deljarry [Wed, 6 Nov 2019 19:06:23 +0000 (14:06 -0500)]
pep8analysis: Fix no init call

Signed-off-by: Florian Deljarry <deljarry.florian@gmail.com>

4 years agohtml_model: Remove new_msignature
Florian Deljarry [Wed, 6 Nov 2019 19:04:15 +0000 (14:04 -0500)]
html_model: Remove new_msignature

Signed-off-by: Florian Deljarry <deljarry.florian@gmail.com>

4 years agoMerge remote-tracking branch 'upstream/master' into init_auto
Florian Deljarry [Wed, 6 Nov 2019 01:56:33 +0000 (20:56 -0500)]
Merge remote-tracking branch 'upstream/master' into init_auto

Signed-off-by: Florian Deljarry <deljarry.florian@gmail.com>

4 years agomodelize_property: Remove root_init in MClass
Florian Deljarry [Wed, 6 Nov 2019 00:58:38 +0000 (19:58 -0500)]
modelize_property: Remove root_init in MClass

Signed-off-by: Florian Deljarry <deljarry.florian@gmail.com>

4 years agoMerge: tests: Test result update for `curl_http`
Jean Privat [Fri, 25 Oct 2019 21:12:10 +0000 (17:12 -0400)]
Merge: tests: Test result update for `curl_http`

The site example.org was modified on October 18th, so that the tests no longer work. This pr fix this problem.

Pull-Request: #2801

4 years agoMerge: Callref compilers
Jean Privat [Fri, 25 Oct 2019 21:09:46 +0000 (17:09 -0400)]
Merge: Callref compilers

Pull-Request: #2793
Reviewed-by: Jean Privat <jean@pryen.org>

4 years agotests: Test result update for `curl_http`
Florian Deljarry [Mon, 21 Oct 2019 21:07:51 +0000 (17:07 -0400)]
tests: Test result update for `curl_http`

Signed-off-by: Florian Deljarry <deljarry.florian@gmail.com>

4 years agoMerge: Contract: Change mpropdef driving
Jean Privat [Wed, 16 Oct 2019 14:47:54 +0000 (10:47 -0400)]
Merge: Contract: Change mpropdef driving

This pr change the driving strategy to resolve the problem when the static type has no contract and the dynamic has one.

Note: now when a mpropdef has a contract after the introduction a facet is added in the intro class. Indeed, as there is no way to know the dynamic type we are going to meet, we must always direct to the facet of contract even if it only redirects to the method and executes no contract.

I change at the same time the syntax of the keywords `ensures` by `ensure` and `expects` by `expect`. The doc will arrive in the next pr.

Pull-Request: #2799

4 years agoCallref bugfix in interpreter and compilers + autosav
Louis-Vincent Boudreault [Sat, 12 Oct 2019 00:02:28 +0000 (20:02 -0400)]
Callref bugfix in interpreter and compilers + autosav

~~~~nitish
class A[E]
fun foo: A[E] do return self
fun bar: Fun0[A[E]] do return &foo # it didn't work before
end
~~~~

- Fixed a bug when `self` was a generic class with unsolved type. It was
impossible to return a callref, since the typing rule were not properly
executed.
- Added a test case in `test_callref.res`

Signed-off-by: Louis-Vincent Boudreault <lv.boudreault95@gmail.com>

4 years agoremoved `nitvm` engine from tests
Louis-Vincent Boudreault [Mon, 7 Oct 2019 13:54:19 +0000 (09:54 -0400)]
removed `nitvm` engine from tests

Signed-off-by: Louis-Vincent Boudreault <lv.boudreault95@gmail.com>

4 years agoUpdated `tests/syntax_callref.nit`
Louis-Vincent Boudreault [Thu, 26 Sep 2019 14:52:15 +0000 (10:52 -0400)]
Updated `tests/syntax_callref.nit`

Signed-off-by: Louis-Vincent Boudreault <lv.boudreault95@gmail.com>

4 years agoCallref expressions support for Erasure Compiler
Louis-Vincent Boudreault [Thu, 12 Sep 2019 15:14:05 +0000 (11:14 -0400)]
Callref expressions support for Erasure Compiler

Signed-off-by: Louis-Vincent Boudreault <lv.boudreault95@gmail.com>

4 years agoCallref expressions support for Global Compiler
Louis-Vincent Boudreault [Thu, 12 Sep 2019 15:10:06 +0000 (11:10 -0400)]
Callref expressions support for Global Compiler

Signed-off-by: Louis-Vincent Boudreault <lv.boudreault95@gmail.com>

4 years agoCallref expression support for Separate Compiler.
Louis-Vincent Boudreault [Thu, 12 Sep 2019 15:01:50 +0000 (11:01 -0400)]
Callref expression support for Separate Compiler.

- Added test case in `src/compiler/test_callref.nit`
- Updated the API of `AbstractCompiler` to support routine reference
call and instantiation services.
- Implemented routine reference (callrefs) handling for separate
compiler

Signed-off-by: Louis-Vincent Boudreault <lv.boudreault95@gmail.com>

4 years agoCallref expression support for the interpreter
Louis-Vincent Boudreault [Wed, 11 Sep 2019 17:08:45 +0000 (13:08 -0400)]
Callref expression support for the interpreter

Signed-off-by: Louis-Vincent Boudreault <lv.boudreault95@gmail.com>

4 years agocontracts: change the contract syntax
Florian Deljarry [Wed, 9 Oct 2019 00:57:01 +0000 (20:57 -0400)]
contracts: change the contract syntax

Replace `ensures` by `ensure` and `expects` `expect`

Signed-off-by: Florian Deljarry <deljarry.florian@gmail.com>

4 years agocontracts: Change mpropdef driving
Florian Deljarry [Tue, 8 Oct 2019 14:56:34 +0000 (10:56 -0400)]
contracts: Change mpropdef driving

The driving strategy was changed to resolve the problem when the static type has no contract and the dynamic has one.

Signed-off-by: Florian Deljarry <deljarry.florian@gmail.com>

4 years agotests: Add contract test with static
Florian Deljarry [Tue, 8 Oct 2019 14:33:18 +0000 (10:33 -0400)]
tests: Add contract test with static

Test when the static type has no contract and the dynamic has one.

Signed-off-by: Florian Deljarry <deljarry.florian@gmail.com>

4 years agoMerge: nitunit the manual
Jean Privat [Wed, 2 Oct 2019 18:38:19 +0000 (14:38 -0400)]
Merge: nitunit the manual

Since the manual is now back in the repository, just use niunit to check the example.

Some examples needed to be updated

* renaming things to avoid conflicts
* using real expression and statements (and not placeholders)
* add `nitish` for example with explicit static or dynamic errors

Pull-Request: #2795

4 years agoMerge: contracts: fix usage of contract with `--erasure`
Jean Privat [Wed, 2 Oct 2019 18:38:15 +0000 (14:38 -0400)]
Merge: contracts: fix usage of contract with `--erasure`

Moving the check if a contract is needed in the visitor to avoid the property creation without definition.

Pull-Request: #2798

4 years agocontracts: fix usage of contract with `--erasure`
Florian Deljarry [Tue, 1 Oct 2019 19:37:52 +0000 (15:37 -0400)]
contracts: fix usage of contract with `--erasure`

Moving the check if a contract is needed in the visitor to avoid the property creation without definition.

Signed-off-by: Florian Deljarry <deljarry.florian@gmail.com>

4 years agomanual: add nitish and avoid name conflicts
Jean Privat [Mon, 30 Sep 2019 19:51:53 +0000 (15:51 -0400)]
manual: add nitish and avoid name conflicts

Signed-off-by: Jean Privat <jean@pryen.org>

4 years agomanual: fix float comparaison and print
Jean Privat [Mon, 30 Sep 2019 19:51:26 +0000 (15:51 -0400)]
manual: fix float comparaison and print

Signed-off-by: Jean Privat <jean@pryen.org>

4 years agomanual: fix examples to be nitunitables
Jean Privat [Fri, 27 Sep 2019 12:53:55 +0000 (08:53 -0400)]
manual: fix examples to be nitunitables

Signed-off-by: Jean Privat <jean@pryen.org>

4 years agoMerge: Contract: bug fix
Jean Privat [Mon, 30 Sep 2019 19:00:39 +0000 (15:00 -0400)]
Merge: Contract: bug fix

This pr fix the bug when the contract is apply with generic or virtual type.

Pull-Request: #2794

4 years agotests: Add tests for generic and virtual types
Florian Deljarry [Mon, 30 Sep 2019 15:48:33 +0000 (11:48 -0400)]
tests: Add tests for generic and virtual types

Signed-off-by: Florian Deljarry <deljarry.florian@gmail.com>

4 years agosrc/contracts: Fix contracts on virtual and generic type
Florian Deljarry [Mon, 30 Sep 2019 02:17:53 +0000 (22:17 -0400)]
src/contracts: Fix contracts on virtual and generic type

Signed-off-by: Florian Deljarry <deljarry.florian@gmail.com>

4 years agoMerge: Contract implementation
Jean Privat [Fri, 27 Sep 2019 12:54:46 +0000 (08:54 -0400)]
Merge: Contract implementation

# Contract.

This pr is a copy of #2747 with some modifications. It has a dependency with the #2779 and #2788.

Adding programming by contract (Design by contract) in Nit language. Contracts works with nit annotations. I decided to cut the contract pr in a smaller part to facilitate reviewing (some feature are not available on it, see section futur feature).

## Annotations

To define a new contract you need to use the corresponding annotation. For example it's possible to define a contract that x parameter must be strictly greater than 5. To do it would be necessary to define the contract in the following way `expects(x > 5)`. All expressions returning a boolean (comparison...) can be used as a condition.

Three annotations were added:

- `expects` to indicate the conditions need to the execution of the methods
- `ensures` to indicate the conditions of guarantee at the end of the execution of the methods
- `no_contract` to remove the inherited contract

This syntaxe is choose because in the next version of c++ (20) (see [P1369](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p1369r0.pdf) for a overview) the contract will be define with the keywords expects and ensures. So I think it would be interesting to keep the same principle. But if all nit developper prefer to use `require` and `ensure` it's fine to change it.

## Method contract (ensures, expects)

For each method it's possible to define preconditions (`expects`) and  post-conditions (`ensures`). If the call of the method satisfies the prerequisites (`expects`) of the method, the caller may assume that the return conditions (`ensures`) will be satisfied.

The method contracts can access all the parameters of the method as well as the set of attributes/methods visible in the context of the method. i.e the set of parameters and the set of methods and attributes of the current class can be used (attributes declare locally in the method can not be used). For post-conditions (ensures) the `result` attribute has been added to perform a check on the return value of the method. Currently it's not possible to refer an old value in a ensures (exemple old(length) == length + 1).

## Process

### Building contract phase

A phase is executed to check all the methods. This check is done to know if:

- The method is annotated (redefined or not)

- The method is a redefinition of a method already having a contract (i.e a method that does not add any new conditions to the existing contract).

When a contract is detected the code is `extended` to add the verification features. Two methods are created. The first method is the contract face. Its goal is to provide the call of the contract verification and the call of the original method. With this strategy, the original code of the method is preserved. The second created method is for the contract verification.

#### Exemple

##### Expect:
```nit
class MyClass
fun foo(x: Int)
is
expects(x > 0)
do
[...]
end
end
```
Representation of the compiled class
```nit
class MyClass
fun foo(x: Int)
is
expects(x > 0)
do
[...]
end

fun _contract_foo(x: Int)
do
_expects_foo(x)
foo(x)
end

fun _expects_foo(x: Int)
do
assert x > 0
end
end
```
##### Ensure:
```nit
class MyClass
fun foo(x: Int): Bool
is
ensures(result == true)
do
[...]
return true
end
end
```
Representation of the compiled class

```nit
class MyClass
fun foo(x: Int): Bool
is
ensures(result == true)
do
[...]
return result
end

fun _contract_foo(x: Intl): Bool
do
var result = foo(x)
_ensures_foo(x, result)
return result
end

fun _ensures_foo(x: Int, result: Bool)
do
assert result == true
end
end
```

## Inheritance

Contracts support redefinition and adding condition. Note that when a contract is define in a parent class, it's no longer possible to remove this contract on all the classes that inherit or redefine them. They only need to be increased according to different subtyping rules.

All preconditions (expects) can be weakened. i.e it's possible to provide a new alternative to validate the contract. This corresponds to the use of a logical OR between the old and the new conditions.

All post-conditions (ensure) can be consolidate. i.e the new condition of the contract will provide a new guarantee to the user of the method. This rule can be translates into a logical AND between the old and the new conditions.

### Exemple

#### Expect

```nit
class SubMyClass
super MyClass

redef fun foo(x: Int)
is
expects(x > 0, x == 0)
do
[...]
end

redef fun _expects_foo(x: Int)
do
if x == 0 then return
super(x)
end

redef fun _contract_foo(x: Int)
do
_expects_foo
super(x)
end

end
```

#### Ensure
```nit
class SubMyClass
super MyClass

redef fun foo(x: Int): Bool
is
ensures(result == true, x > 0)
do
[...]
end

redef fun _ensures_foo(x: Int, result: Bool)
do
super
assert super(x, result)
end

redef fun _contract_foo(x: Int, result: Bool): Bool
do
var result = super
_ensures_foo(x, result)
return result
end
end
```

Summary

| Annotation    |  Inheritance condition type  |
| ------------- | -------------|
| expects       |        and  |
| ensures       |        or  |

## Invocation

All calls to contract methods are intercepted to call the contract version. For the moment the contracts are systematically called, whether it's an internal or external call. Only calls to super do not execute the contracts.

This part is subject to evolution with a parameter to activate or not the internal call verification.

## Building

Since contracts are expensive in resource, several levels of use have been defined based on the needed verification:

- No contract: all contracts are disable (option `--no-contract`).

- Default: By  default  the  contracts  can  be  defined as "semi-global". I.E. All contracts (ensures, expects)used in the main package are enabled, the expects contracts are enabled (ensures contracts are disable) in direct imported package. Other indirected imported package doesn't have active contract.

- Full contract: Contracts are enable (ensures, expects) on all classes (option `--full-contract`).

## Future work

This pr has been simplified to facilitate the reviewing.

Future features:

- Support class invariant contracts
- Ability to put contracts on auto-getters and setter
- Detection of query or command to avoid the contract to change the object state (this functionality will probably be an advice because it's difficult to define if a method has no side effect.)
- `Old` support for the ensures contract  to refer at the same value during the expects condition

Some pr will follow to use the contacts directly in the lib (collection...).

### Note

Currently the syntax of contracts is strict, only comparisons and method calls returning bouleans can be used. Indeed the arguments passed to the annotation of contract are directly used for assert. A solution would be given a more open syntax for more complex contracts instead of using a method. But this would cause problems in the syntax of annotations. If you have any suggestion don't hesitate. An issue is available to talk about the potential syntax. (#1340)

Pull-Request: #2790
Reviewed-by: Jean Privat <jean@pryen.org>

4 years agomanual: CI check with nitunit
Jean Privat [Thu, 26 Sep 2019 19:57:35 +0000 (15:57 -0400)]
manual: CI check with nitunit

Signed-off-by: Jean Privat <jean@pryen.org>

4 years agosrc/toolcontext: Provide contract options
Florian Deljarry [Wed, 29 May 2019 20:49:55 +0000 (16:49 -0400)]
src/toolcontext: Provide contract options

`--no-contract` option to disable the contracts usage
`--full-contract` option to enable the contracts usage in all classes

Signed-off-by: Florian Deljarry <deljarry.florian@gmail.com>

4 years agoshare/man/nitc: Adding the man explication to disable contracts
Florian Deljarry [Wed, 29 May 2019 20:04:06 +0000 (16:04 -0400)]
share/man/nitc: Adding the man explication to disable contracts

Signed-off-by: Florian Deljarry <deljarry.florian@gmail.com>

4 years agocontracts: Adding all contract generation mechanism
Florian Deljarry [Fri, 19 Apr 2019 21:41:23 +0000 (17:41 -0400)]
contracts: Adding all contract generation mechanism

Signed-off-by: Florian Deljarry <deljarry.florian@gmail.com>

4 years agotests: adding contract testing files
Florian Deljarry [Sat, 27 Apr 2019 21:46:35 +0000 (17:46 -0400)]
tests: adding contract testing files

Signed-off-by: Florian Deljarry <deljarry.florian@gmail.com>

4 years agoMerge: astbuilder: First implementation of clonable for ast nodes
Jean Privat [Mon, 16 Sep 2019 14:34:36 +0000 (10:34 -0400)]
Merge: astbuilder: First implementation of clonable for ast nodes

## Astbuilder

- Now all the nodes of the ast is cloneable. Currently just a part of node have an implemented clone method.If we clone a node by default (not implemented) the program abort and print the following message: `The clone method is not implemented for ATestNode class.`. Currently the library is in **test** phase. You can have "maybe" some bug with the clone.

- Add a method to make the creation of a callsite easier.

## Futur work

Currently i am working on a test to make sure the result clone is the same as the original.

Pull-Request: #2779
Reviewed-by: Jean Privat <jean@pryen.org>

4 years agoMerge: Callref types
Jean Privat [Mon, 16 Sep 2019 14:34:31 +0000 (10:34 -0400)]
Merge: Callref types

Extended the functional type hierarchy to include RoutineRef type (aka function pointer).
Added type resolution on callref expression :

```
import functional
fun toto(x: Int) do print x
var x = &toto
assert x isa ProcRef1[Int]
```

Pull-Request: #2791

4 years agotyping: Added typing resolution for `ACallrefExpr`
Louis-Vincent Boudreault [Tue, 27 Aug 2019 19:17:48 +0000 (15:17 -0400)]
typing: Added typing resolution for `ACallrefExpr`

Signed-off-by: Louis-Vincent Boudreault <lv.boudreault95@gmail.com>

4 years agotests: Add test_astbuilder to the skip list of nitcg niti nitvm
Florian Deljarry [Wed, 28 Aug 2019 13:41:16 +0000 (09:41 -0400)]
tests: Add test_astbuilder to the skip list of nitcg niti nitvm

Signed-off-by: Florian Deljarry <deljarry.florian@gmail.com>

4 years agotest_astbuilder: Add a testing tool for the astbuilder
Florian Deljarry [Mon, 26 Aug 2019 21:05:20 +0000 (17:05 -0400)]
test_astbuilder: Add a testing tool for the astbuilder

Signed-off-by: Florian Deljarry <deljarry.florian@gmail.com>

4 years agoastbuilder: First implementation of clonable for ast nodes
Florian Deljarry [Tue, 13 Aug 2019 16:46:35 +0000 (12:46 -0400)]
astbuilder: First implementation of clonable for ast nodes

Add implementation of `clone` method for the ast nodes.

Signed-off-by: Florian Deljarry <deljarry.florian@gmail.com>

4 years agoMerge: Can comment annotations
Jean Privat [Thu, 5 Sep 2019 19:54:04 +0000 (15:54 -0400)]
Merge: Can comment annotations

This was hard but the solution is easier than expected.
Annotations accepted documentation comments but other comments were refused. This should allow all configuration of comments.

close #2786

Pull-Request: #2789
Reviewed-by: Alexandre Terrasa <alexandre@moz-code.org>

4 years agoMerge: model: Add `mpackage` importation hierarchy
Jean Privat [Thu, 5 Sep 2019 19:53:59 +0000 (15:53 -0400)]
Merge: model: Add `mpackage` importation hierarchy

Added a `mpackage_importation_hierarchy` graph to keep the hierarchy of packages. The packages relations are defined when the `set_imported_mmodules` is called.

This pr is related to the programming by contract. The objective is to determine when the use of a contract is necessary in a given context.

Note in this graph all the packages are in relation with themself.

example for all nitc package hierarchy :

![](https://sendeyo.com/up/d/514e168e33)

This pr has a dependency with the #2784

Pull-Request: #2788
Reviewed-by: Jean Privat <jean@pryen.org>
Reviewed-by: Alexandre Terrasa <alexandre@moz-code.org>

4 years agoMerge: Functional api
Jean Privat [Thu, 5 Sep 2019 19:53:49 +0000 (15:53 -0400)]
Merge: Functional api

The functional API provides a type hierarchy for functional types, new `Iterator` services (like pipeline)
and in place `Map` manipulation through `Entry` API.

Pull-Request: #2759
Reviewed-by: Jean Privat <jean@pryen.org>
Reviewed-by: Alexandre Terrasa <alexandre@moz-code.org>

4 years agocheck_annotation: adding no_contract
Florian Deljarry [Sun, 26 May 2019 17:17:09 +0000 (13:17 -0400)]
check_annotation: adding no_contract

Adding option to remove contract on a specific annotated method

Signed-off-by: Florian Deljarry <deljarry.florian@gmail.com>

4 years agocheck_annotation: Adding ensures annotation
Florian Deljarry [Thu, 25 Apr 2019 20:24:03 +0000 (16:24 -0400)]
check_annotation: Adding ensures annotation

Signed-off-by: Florian Deljarry <deljarry.florian@gmail.com>

4 years agocheck_annotation: Adding expects annotation
Florian Deljarry [Fri, 19 Apr 2019 21:39:24 +0000 (17:39 -0400)]
check_annotation: Adding expects annotation

Signed-off-by: Florian Deljarry <deljarry.florian@gmail.com>

4 years agocode_gen: Adding contracts phase
Florian Deljarry [Fri, 19 Apr 2019 21:38:42 +0000 (17:38 -0400)]
code_gen: Adding contracts phase

Signed-off-by: Florian Deljarry <deljarry.florian@gmail.com>

4 years agoscope: Adding variable verification
Florian Deljarry [Fri, 19 Apr 2019 21:32:27 +0000 (17:32 -0400)]
scope: Adding variable verification

If the variable already exists it will be used

Signed-off-by: Florian Deljarry <deljarry.florian@gmail.com>

4 years agomodelize_property: Adding unsafe method to register an mpropdef
Florian Deljarry [Fri, 19 Apr 2019 21:25:02 +0000 (17:25 -0400)]
modelize_property: Adding unsafe method to register an mpropdef

Add method to register an MPropDef with an APropdef without verification

Signed-off-by: Florian Deljarry <deljarry.florian@gmail.com>

4 years agofunctional: Added universal types to callref
Louis-Vincent Boudreault [Tue, 27 Aug 2019 19:00:28 +0000 (15:00 -0400)]
functional: Added universal types to callref

Signed-off-by: Louis-Vincent Boudreault <lv.boudreault95@gmail.com>

4 years agofunctional: Added functional lib
Louis-Vincent Boudreault [Fri, 5 Jul 2019 14:02:18 +0000 (10:02 -0400)]
functional: Added functional lib

- New types hierarchy to manage functions.
- New Pipeline-like API for `Iterator` based on functional type.

Signed-off-by: Louis-Vincent Boudreault <lv.boudreault95@gmail.com>

4 years agonitweb: Update to use packages importation graph
Florian Deljarry [Wed, 28 Aug 2019 02:38:53 +0000 (22:38 -0400)]
nitweb: Update to use packages importation graph

Signed-off-by: Florian Deljarry <deljarry.florian@gmail.com>