Skip to content
Closed
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
37 changes: 37 additions & 0 deletions documentation/TUTORIAL-ADVANCED-TYPES.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,40 @@ type ACME_Requirement extends Supplier_Requirement {
This makes sure that any and all supplier requirements are completely
uniform, and nobody adds new fields that may be confusing or
unexpected to the suppliers.

### Type Checks

A field within a type can also reference another type.
You can access fields of a referenced type using the `.` notation:

```
type BaseType {
name String
}

type MyType {
name String
link BaseType
}

checks MyType {
link.name != name, "cannot link the type with the same name."
}
```

Self-referencing (recursive) type definitions are also supported.
To prevent infinite recursion, any recursive field must be declared as `optional`:

```
type MyType {
name String
link optional MyType
}

checks MyType {
link != null implies link.name != name,
"link status must be the same as status"
}
```
Excessive recursion may lead to performance degradation,
so complex recursive designs are not recommended.
29 changes: 19 additions & 10 deletions language-reference-manual/lrm.trlc
Original file line number Diff line number Diff line change
Expand Up @@ -1084,8 +1084,13 @@ section "Names" {
a valid literal of that type. If the prefix of
a dot (`.`) access resolves to a tuple, then
the identifier must be a valid field of the
type of that tuple. Any other prefix is an
error.
type of that tuple. If the prefix of a dot (`.`)
access resolves to a record object, then the identifier
must be the name of a component declared inside
that record. Optional components are represented as a
pair `(valid, value)`, and may be accessed using
`record.field.valid` and `record.field.value`. Nested
field access is allowed. Any other prefix is an error.
'''
}

Expand All @@ -1101,7 +1106,6 @@ section "Names" {
'''
}


Static_Semantics Signature_Len {
text = '''The builtin function `len` is of arity 1. Its parameter must
be of type `String` or an array type. Its
Expand Down Expand Up @@ -1197,14 +1201,16 @@ section "Names" {
separator @
version optional Integer
}
type Name_Base {
description string
}
type Name_Examples {
foo Boolean
bar Name_Examples
asil ASIL
potato Integer [0 .. *]
wibble Decimal
field String
cb_link Codebeamer_Item
foo Boolean
bar Name_Base
asil ASIL
potato Integer [0 .. *]
field String
cb_link Codebeamer_Item
}
'''
rsl = '''
Expand All @@ -1223,6 +1229,9 @@ section "Names" {

cb_link.item >= 50000, warning "cb item value is oddly low"
// you can obtain a tuple's values

bar.description, "foo"
// you can obtain a record's component
}
'''
}
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pyvcg==1.0.8
pyvcg==1.0.9
cvc5>=1.2.0
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
project_urls=project_urls,
license="GNU General Public License v3",
packages=setuptools.find_packages(),
install_requires="PyVCG[api]==1.0.8",
install_requires="PyVCG[api]==1.0.9",
python_requires=">=3.8, <3.14",
classifiers=[
"Development Status :: 5 - Production/Stable",
Expand Down
2 changes: 1 addition & 1 deletion tests-system/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
RAW_TARGETS=$(filter-out bulk, $(subst ./,,$(shell find . -mindepth 1 -maxdepth 1 -type d)))
RAW_TARGETS=$(if $(TARGET),$(TARGET),$(filter-out bulk, $(subst ./,,$(shell find . -mindepth 1 -maxdepth 1 -type d))))

TARGETS=\
$(addsuffix /output, $(RAW_TARGETS)) \
Expand Down
7 changes: 2 additions & 5 deletions tests-system/checks-5/output
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
Requirement Potato {
^^^^^^ checks-5/foo.trlc:3: check error: linkage incorrect
| You must either link this requirement to other requirements
| using the derived_from attribute, or you need to set
| top_level to true.
type Requirement {
^^^^^^^^^^^ checks-5/foo.rsl:3: error: Complex recursive is not supported.
Processed 1 model and 1 requirement file and found 1 error
7 changes: 2 additions & 5 deletions tests-system/checks-5/output.smtlib
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
Requirement Potato {
^^^^^^ checks-5/foo.trlc:3: check error: linkage incorrect
| You must either link this requirement to other requirements
| using the derived_from attribute, or you need to set
| top_level to true.
type Requirement {
^^^^^^^^^^^ checks-5/foo.rsl:3: error: Complex recursive is not supported.
Processed 1 model and 1 requirement file and found 1 error
16 changes: 8 additions & 8 deletions tests-system/lint-record-refs/output
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,32 @@ a != b implies x, "potato"
^ lint-record-refs/test2.rsl:10: issue: expression could be null [vcg-evaluation-of-null]
| example record_type triggering error:
| T bad_potato {
| a = T_instance_1
| b = T_instance_0
| a = None
| b = None
| /* x is null */
| }
a == b implies x, "potato"
^ lint-record-refs/test2.rsl:11: issue: expression could be null [vcg-evaluation-of-null]
| example record_type triggering error:
| T bad_potato {
| a = T_instance_0
| b = T_instance_0
| a = None
| b = None
| /* x is null */
| }
a != b implies x, "potato"
^ lint-record-refs/test3.rsl:11: issue: expression could be null [vcg-evaluation-of-null]
| example record_type triggering error:
| T bad_potato {
| a = Other.T_instance_1
| b = Other.T_instance_0
| a = ("")
| b = ("A")
| /* x is null */
| }
a == b implies x, "potato"
^ lint-record-refs/test3.rsl:12: issue: expression could be null [vcg-evaluation-of-null]
| example record_type triggering error:
| T bad_potato {
| a = Other.T_instance_0
| b = Other.T_instance_0
| a = ("")
| b = ("")
| /* x is null */
| }
Processed 4 models and 0 requirement files and found 5 warnings
16 changes: 8 additions & 8 deletions tests-system/lint-record-refs/output.smtlib
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,32 @@ a != b implies x, "potato"
^ lint-record-refs/test2.rsl:10: issue: expression could be null [vcg-evaluation-of-null]
| example record_type triggering error:
| T bad_potato {
| a = T_instance_1
| b = T_instance_0
| a = None
| b = None
| /* x is null */
| }
a == b implies x, "potato"
^ lint-record-refs/test2.rsl:11: issue: expression could be null [vcg-evaluation-of-null]
| example record_type triggering error:
| T bad_potato {
| a = T_instance_0
| b = T_instance_0
| a = None
| b = None
| /* x is null */
| }
a != b implies x, "potato"
^ lint-record-refs/test3.rsl:11: issue: expression could be null [vcg-evaluation-of-null]
| example record_type triggering error:
| T bad_potato {
| a = Other.T_instance_1
| b = Other.T_instance_0
| a = ("")
| b = ("A")
| /* x is null */
| }
a == b implies x, "potato"
^ lint-record-refs/test3.rsl:12: issue: expression could be null [vcg-evaluation-of-null]
| example record_type triggering error:
| T bad_potato {
| a = Other.T_instance_0
| b = Other.T_instance_0
| a = ("")
| b = ("")
| /* x is null */
| }
Processed 4 models and 0 requirement files and found 5 warnings
2 changes: 1 addition & 1 deletion tests-system/tuples-4/output
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ f2 >= 0, warning "potato2", f2
^^ tuples-4/foo.rsl:12: issue: expression could be null [vcg-evaluation-of-null]
| example tuple_type triggering error:
| T bad_potato {
| f1 = R1_instance_0
| f1 = None
| /* f2 is null */
| }
t = potato
Expand Down
2 changes: 1 addition & 1 deletion tests-system/tuples-4/output.smtlib
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ f2 >= 0, warning "potato2", f2
^^ tuples-4/foo.rsl:12: issue: expression could be null [vcg-evaluation-of-null]
| example tuple_type triggering error:
| T bad_potato {
| f1 = R1_instance_0
| f1 = None
| /* f2 is null */
| }
t = potato
Expand Down
29 changes: 29 additions & 0 deletions tests-system/tuples-use-type/bar.rsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package bar

enum Status {
NEW
OLD
DEPRECATED
}

type BaseType {
name String
status Status
}

tuple LinkMy2Base {
link_type BaseType
separator @
version Integer
}

type MyType {
name String
status Status
derived_from optional LinkMy2Base[0 .. *]
}

checks MyType {
derived_from != null implies (forall elem in derived_from => elem.link_type.status == status),
error "link status must be the same as status"
}
14 changes: 14 additions & 0 deletions tests-system/tuples-use-type/instances.trlc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package instances

import bar

bar.BaseType DeprecatedR {
name = "base" // does start with Q
status = bar.Status.NEW
}

bar.MyType NewXR {
name = "new"
status = bar.Status.NEW
derived_from = [ DeprecatedR@1 ]
}
1 change: 1 addition & 0 deletions tests-system/tuples-use-type/output
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Processed 1 model and 1 requirement file and found no issues
1 change: 1 addition & 0 deletions tests-system/tuples-use-type/output.brief
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Processed 1 model and 1 requirement file and found no issues
17 changes: 17 additions & 0 deletions tests-system/tuples-use-type/output.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"DeprecatedR": {
"name": "base",
"status": "NEW"
},
"NewXR": {
"derived_from": [
{
"link_type": "instances.DeprecatedR",
"version": 1
}
],
"name": "new",
"status": "NEW"
}
}
Processed 1 model and 1 requirement file and found no issues
1 change: 1 addition & 0 deletions tests-system/tuples-use-type/output.smtlib
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Processed 1 model and 1 requirement file and found no issues
1 change: 0 additions & 1 deletion tests-system/xref-2/TODO

This file was deleted.

17 changes: 0 additions & 17 deletions tests-system/xref-2/bar.rsl

This file was deleted.

15 changes: 0 additions & 15 deletions tests-system/xref-2/instances.trlc

This file was deleted.

3 changes: 0 additions & 3 deletions tests-system/xref-2/output

This file was deleted.

2 changes: 0 additions & 2 deletions tests-system/xref-2/output.brief

This file was deleted.

3 changes: 0 additions & 3 deletions tests-system/xref-2/output.json

This file was deleted.

3 changes: 0 additions & 3 deletions tests-system/xref-2/output.smtlib

This file was deleted.

2 changes: 1 addition & 1 deletion tests-system/xref-expressions/f1.trlc
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ A.L L1 {

A.L Localref {
l = L1
}
}
22 changes: 22 additions & 0 deletions tests-system/xref-no-recursion/bar.rsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package bar

enum Status {
NEW
OLD
DEPRECATED
}

type BaseType {
name String
status Status
}

type MyType {
name String
status Status
link optional BaseType
}

checks MyType {
link != null implies link.status == status, "link status must be the same as status"
}
Loading
Loading