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

Gelisam/code rabbit test3 #2

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
597 changes: 416 additions & 181 deletions lang/ast/structs.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lang/interfaces/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ type Data struct {
// from the variables, which could actually contain lambda functions.
type Scope struct {
Variables map[string]Expr
Functions map[string]Expr // the Expr will usually be an *ExprFunc
Functions map[string]Expr // the Expr will usually be an *ExprFunc (actually it's usually (or always) an *ExprSingleton, which wraps an *ExprFunc now)
Classes map[string]Stmt

Chain []Node // chain of previously seen node's
Expand Down
6 changes: 6 additions & 0 deletions lang/interfaces/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ const (
// also used with `ModuleSep` for scoped variables like `$foo.bar.baz`.
VarPrefix = "$"

// BareSymbol is the character used primarily for imports to specify
// that we want to import the entire contents and flatten them into our
// current scope. It should probably be removed entirely to force
// explicit imports.
BareSymbol = "*"

// PanicResKind is the kind string used for the panic resource.
PanicResKind = "_panic"
)
22 changes: 22 additions & 0 deletions lang/interpret_test/TestAstFunc2/class-include-as-class0.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
-- main.mcl --
class c1 {
test "t1" {}
$y = "hello"
class c0 {
test "t2" {}
$x = "goodbye"
}
}
include c1 as i1 # has $y
include i1.c0 as i0 # has $x ...and $y

test $i0.x {} # ok
test $i0.y {} # sneaky!
test $i1.y {} # ok
panic($i0.x != "goodbye")
panic($i1.y != "hello")
-- OUTPUT --
Vertex: test[goodbye]
Vertex: test[hello]
Vertex: test[t1]
Vertex: test[t2]
39 changes: 39 additions & 0 deletions lang/interpret_test/TestAstFunc2/class-include-as-class1.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
-- main.mcl --
class c1($b) {
test "t1" {}
if $b {
test "t2" {}
} else {
test "t3" {}
}
class c0 {
test "t4" {}
if $b {
test "t5" {}
} else {
test "t6" {}
}
$x = if $b {
"hello"
} else {
"goodbye"
}
}
}
include c1(true) as i1
include i1.c0 as i01

include c1(false) as i2
include i2.c0 as i02

test $i01.x {}
test $i02.x {}
-- OUTPUT --
Vertex: test[hello]
Vertex: test[goodbye]
Vertex: test[t1]
Vertex: test[t2]
Vertex: test[t3]
Vertex: test[t4]
Vertex: test[t5]
Vertex: test[t6]
17 changes: 17 additions & 0 deletions lang/interpret_test/TestAstFunc2/class-include-as-class2.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
-- main.mcl --
class c1($b) {
if $b { # scope doesn't leak up and out of `if` statement!
class inner() {
test "t1" {}
}
} else {
class inner() {
test "t2" {}
}
}
}

include c1 as i1
include i1.inner
-- OUTPUT --
# err: errSetScope: class `c1` expected 1 args but got 0
Comment on lines +1 to +17
Copy link

@coderabbitai coderabbitai bot Jan 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test file class-include-as-class2.txtar demonstrates the error handling for a class include with a conditional block. The output shows the expected error message due to the missing argument in the include statement.

- include c1 as i1
+ include c1(true) as i1

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
-- main.mcl --
class c1($b) {
if $b { # scope doesn't leak up and out of `if` statement!
class inner() {
test "t1" {}
}
} else {
class inner() {
test "t2" {}
}
}
}
include c1 as i1
include i1.inner
-- OUTPUT --
# err: errSetScope: class `c1` expected 1 args but got 0
-- main.mcl --
class c1($b) {
if $b { # scope doesn't leak up and out of `if` statement!
class inner() {
test "t1" {}
}
} else {
class inner() {
test "t2" {}
}
}
}
include c1(true) as i1
include i1.inner
-- OUTPUT --
# err: errSetScope: class `c1` expected 1 args but got 0

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neat that it can find the fix, but too bad that it doesn't realize it's a test which is making sure that "bug" shows up as an error.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@purpleidea, understood! The test is indeed meant to confirm the correct error handling. I'll take note of this context for future reviews. Thank you for the clarification.

🐰🔍📝

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@coderabbitai Can you tell me anything useful or interesting about the resources in the mcl code? This is a test.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@purpleidea, based on the repository's documentation, particularly the language-guide.md, here are some insights about the class and include statements in the mcl code:

  • Classes: They are used to group a list of statements under a name. Classes can be parameterized with arguments or be 'naked' (without arguments). They follow scoping and shadowing rules similar to variables and functions.
  • Includes: The include statement is used to produce output from a class. A class must be 'included' to generate output, and it can be included multiple times with different arguments, allowing for different instantiations.
  • Scoping: Defining classes adheres to the same scoping rules as other elements. This means you can have a variable and a class with the same name in the same scope without conflict.
  • Limitations: Recursive class definitions are not supported, and it's unclear if they will be. Polymorphic classes were considered but are not currently allowed.

This structure allows for modular and reusable code, where classes can encapsulate functionality and be included as needed, with the flexibility of parameterization to handle different contexts or configurations.

If you need more detailed information or examples, I can look further into the codebase or the documentation.

Analysis chain
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Search for documentation or examples related to `class` and `include` in the mcl code.
rg --type md 'class|include'

Length of output: 6881

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I asked about the resources not the statements.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@purpleidea, the term "resources" in the mcl codebase refers to entities that can be defined, managed, and interacted with within the system. They are defined in YAML configurations, controlled through semaphore mechanisms for concurrency, tested for various scenarios, and monitored via Prometheus metrics. Resources are central to the system's operation, representing the managed elements like files, services, packages, and more, each with specific properties and behaviors. They are marshalled into configurations, and their state is managed and observed throughout the system's runtime.

If you need more specific details or examples of resources, please let me know, and I can provide further information.

🐰📘🔍

Analysis chain
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Search for mentions of "resources" in the mcl codebase to understand what the user is referring to.
rg 'resources'

Length of output: 45991

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be fair, if I wasn't already familiar with the project, I wouldn't know which lines are resources either.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gelisam Yup, I was testing it to see if it was doing anything beyond simple pattern recognition-level stuff =D
I also get the feeling a lot of analysis is based on text docs and comments, which worries me because when do the docs or comments ever match the code 😅

11 changes: 11 additions & 0 deletions lang/interpret_test/TestAstFunc2/class-include-as-duplicate0.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-- main.mcl --
class c1() {
$x = "got: ${s}"
}

# TODO: can this be allowed?
include c1 as i1
include c1 as i1
test $i1.x {}
-- OUTPUT --
# err: errSetScope: could not generate ordering: duplicate assignment to `scoped:i1`, have: include(c1)
11 changes: 11 additions & 0 deletions lang/interpret_test/TestAstFunc2/class-include-as-duplicate1.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-- main.mcl --
class c1($s) {
$x = "got: ${s}"
}

# TODO: can this be allowed?
include c1("hey") as i1
include c1("hey") as i1
test $i1.x {}
-- OUTPUT --
# err: errSetScope: could not generate ordering: duplicate assignment to `scoped:i1`, have: include(c1)
10 changes: 10 additions & 0 deletions lang/interpret_test/TestAstFunc2/class-include-as-duplicate2.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
-- main.mcl --
class c1($s) {
$x = "got: ${s}"
}

include c1("hey") as i1
include c1("there") as i1
test $i1.x {}
-- OUTPUT --
# err: errSetScope: could not generate ordering: duplicate assignment to `scoped:i1`, have: include(c1)
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
-- main.mcl --
class c1 {
$x = "outside"
test "t1" {}
func f1($x) {
"hello" + $x
}
}
include c1 as i1

test i1.f1("world") {}
-- OUTPUT --
Vertex: test[helloworld]
Vertex: test[t1]
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
-- main.mcl --
class c1 {
$x = "world"
test "t1" {}
func f1($y) {
"hello" + $x
}
}
include c1 as i1

test i1.f1("whatever") {}
-- OUTPUT --
Vertex: test[helloworld]
Vertex: test[t1]
13 changes: 13 additions & 0 deletions lang/interpret_test/TestAstFunc2/class-include-as-func0.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
-- main.mcl --
class c1 {
test "t1" {}
func f1() {
"hello"
}
}
include c1 as i1

test i1.f1() {}
-- OUTPUT --
Vertex: test[hello]
Vertex: test[t1]
27 changes: 27 additions & 0 deletions lang/interpret_test/TestAstFunc2/class-include-as-func1.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
-- main.mcl --
class c1($b) {
test "t1" {}
if $b {
test "t2" {}
} else {
test "t3" {}
}
func f1() {
if $b {
"hello"
} else {
"goodbye"
}
}
}
include c1(true) as i1
include c1(false) as i2

test i1.f1() {}
test i2.f1() {}
-- OUTPUT --
Vertex: test[hello]
Vertex: test[goodbye]
Vertex: test[t1]
Vertex: test[t2]
Vertex: test[t3]
42 changes: 42 additions & 0 deletions lang/interpret_test/TestAstFunc2/class-include-as-func2.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
-- main.mcl --
class c0($b) {
test "t1" {}
if $b {
test "t2" {}
} else {
test "t3" {}
}
func f0() {
if $b {
"hello"
} else {
"goodbye"
}
}
}
class c1($b) {
test "t4" {}
if $b {
test "t5" {}
} else {
test "t6" {}
}
include c0($b) as i0
func f1() { i0.f0() }
}
include c1(true) as i1
include c1(false) as i2

test i1.f1() {}
test i2.f1() {}
test i1.i0.f0() {} # I think these might work directly too. Do we want them to?
test i2.i0.f0() {}
-- OUTPUT --
Vertex: test[goodbye]
Vertex: test[hello]
Vertex: test[t1]
Vertex: test[t2]
Vertex: test[t3]
Vertex: test[t4]
Vertex: test[t5]
Vertex: test[t6]
10 changes: 10 additions & 0 deletions lang/interpret_test/TestAstFunc2/class-include-as-import1.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
-- main.mcl --
import "fmt" as i1
class c1($s) {
$x = fmt.printf("got: %s", $s)
}

include c1("hey") as i1
test $i1.x {}
-- OUTPUT --
# err: errSetScope: could not generate ordering: duplicate assignment to `scoped:i1`, have: import(fmt)
10 changes: 10 additions & 0 deletions lang/interpret_test/TestAstFunc2/class-include-as-import2.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
-- main.mcl --
import "fmt"
class c1($s) {
$x = fmt.printf("got: %s", $s)
}

include c1("hey") as fmt
test $fmt.x {}
-- OUTPUT --
# err: errSetScope: could not generate ordering: duplicate assignment to `scoped:fmt`, have: import(fmt)
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
-- main.mcl --
class c1 {
$x = "outside"
test "t1" {}
$f1 = func($x) {
"hello" + $x
}
}
include c1 as i1

test $i1.f1("world") {}
-- OUTPUT --
Vertex: test[helloworld]
Vertex: test[t1]
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
-- main.mcl --
class c1 {
$x = "world"
test "t1" {}
$f1 = func($y) {
"hello" + $x
}
}
include c1 as i1

test $i1.f1("whatever") {}
-- OUTPUT --
Vertex: test[helloworld]
Vertex: test[t1]
13 changes: 13 additions & 0 deletions lang/interpret_test/TestAstFunc2/class-include-as-lambda0.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
-- main.mcl --
class c1 {
test "t1" {}
$f1 = func() {
"hello"
}
}
include c1 as i1

test $i1.f1() {}
-- OUTPUT --
Vertex: test[hello]
Vertex: test[t1]
27 changes: 27 additions & 0 deletions lang/interpret_test/TestAstFunc2/class-include-as-lambda1.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
-- main.mcl --
class c1($b) {
test "t1" {}
if $b {
test "t2" {}
} else {
test "t3" {}
}
$f1 = func() {
if $b {
"hello"
} else {
"goodbye"
}
}
}
include c1(true) as i1
include c1(false) as i2

test $i1.f1() {}
test $i2.f1() {}
-- OUTPUT --
Vertex: test[hello]
Vertex: test[goodbye]
Vertex: test[t1]
Vertex: test[t2]
Vertex: test[t3]
44 changes: 44 additions & 0 deletions lang/interpret_test/TestAstFunc2/class-include-as-lambda2.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
-- main.mcl --
class c0($b) {
test "t1" {}
if $b {
test "t2" {}
} else {
test "t3" {}
}
$f0 = func() {
if $b {
"hello"
} else {
"goodbye"
}
}
#$f0 = "hey"
}
class c1($b) {
test "t4" {}
if $b {
test "t5" {}
} else {
test "t6" {}
}
include c0($b) as i0
$x = $i0.f0
}
include c1(true) as i1
include c1(false) as i2

test $i1.x() {}
test $i1.i0.f0() {}
test $i2.x() {}
test $i1.i0.f0() {} # I think these should work directly too. Do we want them to?
test $i2.i0.f0() {}
-- OUTPUT --
Vertex: test[goodbye]
Vertex: test[hello]
Vertex: test[t1]
Vertex: test[t2]
Vertex: test[t3]
Vertex: test[t4]
Vertex: test[t5]
Vertex: test[t6]
Loading
Loading