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

fix(compiler): Nested abilities [fixes LNG-214] #816

Merged
merged 15 commits into from
Jul 31, 2023
88 changes: 82 additions & 6 deletions aqua-src/antithesis.aqua
Original file line number Diff line number Diff line change
@@ -1,11 +1,87 @@
aqua Main

export a
use DECLARE_CONST, decl_bar from "declare.aqua" as Declare

alias CL: string -> ()
export SomeService, handleAb, bug214, checkAbCalls

func a(cl: string -> ()) -> CL:
<- cl
service SomeService("wed"):
getStr(s: string) -> string

func b(c: u32, d: u32) -> u32:
<- c + d
ability SomeAb:
someArrow(s: string) -> string, string
str: string

ability SecondAb:
arrow(s: string) -> string
num: u32

func funcStr(s: string) -> string, string:
strInFunc <- SomeService.getStr(Declare.DECLARE_CONST)
strInFunc2 <- SomeService.getStr(s)
<- strInFunc, strInFunc2

func handleSecAb {SomeAb, SecondAb}() -> string, string, string, u32:
SomeAb.someArrow("eferfrfrf")
b, c <- SomeAb.someArrow("efre")
d <- SecondAb.arrow(SomeAb.str)
<- b, c, d, SecondAb.num

func returnAb(s: string) -> SomeAb:
SomeAb = SomeAb(someArrow = funcStr, str = s)
<- SomeAb

func handleAb(fff: string) -> string, string, string, u32:
SomeAb = returnAb(fff)
SecondAb = SecondAb(arrow = funcStr, num = 12)
res1, res2, res3, res4 <- handleSecAb{SomeAb, SecondAb}()
<- res1, res2, res3, res4

data Struct:
int: i8

ability Simple:
st: Struct
arrow(x: i8) -> bool

ability Complex:
simple: Simple
field: string

func foo{Complex, Simple}() -> bool, bool:
closure = () -> bool:
<- Simple.st.int >= 0
res <- closure()
<- Complex.simple.arrow(
Complex.simple.st.int
), res

func bug214() -> bool, bool:
closure = (x: i8) -> bool:
<- x > 0

MyComplex = Complex(
simple = Simple(
st = Struct(int = 0),
arrow = closure
),
field = "complex"
)

res1, res2 <- foo{MyComplex, MyComplex.simple}()
<- res1, res2

ability SSS:
arrow(x: i8) -> bool

ability CCCC:
arrow(x: i8) -> bool
simple: SSS

func checkAbCalls() -> bool, bool:
closure = (x: i8) -> bool:
<- x > 20

MySSS = SSS(arrow = closure)
MyCCCC = CCCC(simple = MySSS, arrow = MySSS.arrow)

<- MySSS.arrow(42), MyCCCC.arrow(12)
52 changes: 51 additions & 1 deletion integration-tests/aqua/examples/abilities.aqua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ aqua Main

use DECLARE_CONST, decl_bar from "imports_exports/declare.aqua" as Declare

export handleAb, SomeService
export handleAb, SomeService, bug214, checkAbCalls

service SomeService("wed"):
getStr(s: string) -> string
Expand Down Expand Up @@ -35,3 +35,53 @@ func handleAb(fff: string) -> string, string, string, u32:
SecondAb = SecondAb(arrow = funcStr, num = 12)
res1, res2, res3, res4 <- handleSecAb{SomeAb, SecondAb}()
<- res1, res2, res3, res4

data Struct:
int: i8

ability Simple:
st: Struct
arrow(x: i8) -> bool

ability Complex:
simple: Simple
field: string

func foo{Complex, Simple}() -> bool, bool:
closure = () -> bool:
<- Simple.st.int >= 0
res <- closure()
<- Complex.simple.arrow(
Complex.simple.st.int
), res

func bug214() -> bool, bool:
closure = (x: i8) -> bool:
<- x > 0

MyComplex = Complex(
simple = Simple(
st = Struct(int = 0),
arrow = closure
),
field = "complex"
)

res1, res2 <- foo{MyComplex, MyComplex.simple}()
<- res1, res2

ability SSS:
arrow(x: i8) -> bool

ability CCCC:
arrow(x: i8) -> bool
simple: SSS

func checkAbCalls() -> bool, bool:
closure = (x: i8) -> bool:
<- x > 20

MySSS = SSS(arrow = closure)
MyCCCC = CCCC(simple = MySSS, arrow = MySSS.arrow)

<- MySSS.arrow(42), MyCCCC.arrow(12)
12 changes: 11 additions & 1 deletion integration-tests/src/__test__/examples.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { bugNG69Call, ifCall, ifWrapCall } from '../examples/ifCall.js';
import { parCall, testTimeoutCall } from '../examples/parCall.js';
import { complexCall } from '../examples/complex.js';
import { constantsCall, particleTtlAndTimestampCall } from '../examples/constantsCall.js';
import { abilityCall, complexAbilityCall, checkAbCallsCall } from '../examples/abilityCall.js';
import {
nilLengthCall,
nilLiteralCall,
Expand Down Expand Up @@ -77,7 +78,6 @@ export const relay2 = config.relays[1];
const relayPeerId2 = relay2.peerId;

import log from 'loglevel';
import { abilityCall } from '../examples/abilityCall';
// log.setDefaultLevel("debug")

async function start() {
Expand Down Expand Up @@ -354,6 +354,16 @@ describe('Testing examples', () => {
expect(result).toStrictEqual(['declare_const123', 'efre123', 'declare_const123', 12]);
});

it('ability.aqua complex', async () => {
let result = await complexAbilityCall();
expect(result).toStrictEqual([false, true]);
});

it('ability.aqua complex', async () => {
DieMyst marked this conversation as resolved.
Show resolved Hide resolved
let result = await checkAbCallsCall();
expect(result).toStrictEqual([true, false]);
});

it('functors.aqua LNG-119 bug', async () => {
let result = await bugLng119Call();
expect(result).toEqual([1]);
Expand Down
10 changes: 9 additions & 1 deletion integration-tests/src/examples/abilityCall.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {handleAb, registerSomeService} from "../compiled/examples/abilities";
import {handleAb, registerSomeService, bug214, checkAbCalls} from "../compiled/examples/abilities";

export async function abilityCall(): Promise<[string, string, string, number]> {
registerSomeService({
Expand All @@ -9,3 +9,11 @@ export async function abilityCall(): Promise<[string, string, string, number]> {

return await handleAb("some_string")
}

export async function complexAbilityCall(): Promise<[boolean, boolean]> {
return await bug214()
}

export async function checkAbCallsCall(): Promise<[boolean, boolean]> {
return await checkAbCalls()
}
Loading