Skip to content

Commit

Permalink
Apply PR review comments: expand at-connect docstring, clean tests
Browse files Browse the repository at this point in the history
  • Loading branch information
NHDaly committed Mar 2, 2020
1 parent 2a7eae3 commit 7d6e01d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
7 changes: 7 additions & 0 deletions src/Salsa.jl
Original file line number Diff line number Diff line change
Expand Up @@ -850,6 +850,13 @@ used as part of the macro processing. The macro is used to auto-generate a const
correctly initializes the embedded Component. (The generated constructor simply passes the
provided Runtime through to the Component's constructor.)
The `@connect` macro is used by Salsa to automatically add initialization for the specified
field in the auto-generated `Salsa.create(MyComponent)` function. e.g. given a declaration
`@connect a :: A`, `create()` will automatically perform:
```julia
out.a = A(runtime)
```
# Example
```julia
Salsa.@component MyComponent begin
Expand Down
18 changes: 14 additions & 4 deletions test/Salsa.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ Salsa.@component Compiler begin
end
Salsa.@component Workspace begin
Salsa.@input i2::Salsa.InputScalar{Int}
# NOTE: @connect is the simplest way to embed another component and make sure they have
# the same Runtime. It's important that they share the same runtime.
Salsa.@connect compiler::Compiler
end
Salsa.@component TestStorage begin
Expand Down Expand Up @@ -786,17 +788,25 @@ end
@connect a :: A
end



@derived function x_at(a::A, k)
a.x[k]
end
@derived function x_at(b::B, k)
b.a.x[k]
end

@testset "composed component" begin
b = B()
b.a.x[1] = 10
@test b.a.x[1] == 10
@test x_at(b, 1) == 10
@test x_at(b.a, 1) == 10
b.a.x[1] = 20
@test b.a.x[1] == 20
@test x_at(b, 1) == 20
@test x_at(b.a, 1) == 20
end



# --------------------------------------------------
# End of tests, start of benchmark
# --------------------------------------------------
Expand Down

0 comments on commit 7d6e01d

Please sign in to comment.