Skip to content

Commit cfb8a57

Browse files
committed
Added action composition feature flag
Also updated tree-sitter-tlaplus version Signed-off-by: Andrew Helwer <[email protected]>
1 parent 13817f2 commit cfb8a57

7 files changed

+50
-17
lines changed

.github/scripts/check_manifest_features.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ def build_queries(language):
4747
feature_query = language.query(
4848
'(pcal_algorithm_start) @pluscal'
4949
+ '[(terminal_proof) (non_terminal_proof)] @proof'
50+
+ '(cdot) @action_composition'
5051
)
5152

5253
return Queries(import_query, module_name_query, feature_query)
@@ -62,7 +63,11 @@ def get_tree_features(tree, queries):
6263
"""
6364
Returns any notable features in the parse tree, such as pluscal or proofs
6465
"""
65-
return set([name for _, name in queries.features.captures(tree.root_node)])
66+
return set([
67+
capture_name.replace('_', ' ')
68+
for capture_name, _
69+
in queries.features.captures(tree.root_node).items()
70+
])
6671

6772
def get_module_features(examples_root, path, parser, queries):
6873
"""
@@ -147,13 +152,13 @@ def get_community_imports(examples_root, tree, text, dir, has_proof, queries):
147152
imports = set(
148153
[
149154
tla_utils.node_to_string(text, node)
150-
for node, _ in queries.imports.captures(tree.root_node)
155+
for node in tla_utils.all_nodes_of(queries.imports.captures(tree.root_node))
151156
]
152157
)
153158
modules_in_file = set(
154159
[
155160
tla_utils.node_to_string(text, node)
156-
for node, _ in queries.module_names.captures(tree.root_node)
161+
for node in tla_utils.all_nodes_of(queries.module_names.captures(tree.root_node))
157162
]
158163
)
159164
imports = (

.github/scripts/check_small_models.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
skip_models = args.skip
3434
only_models = args.only
3535

36-
def check_model(module_path, model, expected_runtime):
37-
module_path = tla_utils.from_cwd(examples_root, module_path)
36+
def check_model(module, model, expected_runtime):
37+
module_path = tla_utils.from_cwd(examples_root, module['path'])
3838
model_path = tla_utils.from_cwd(examples_root, model['path'])
3939
logging.info(model_path)
4040
hard_timeout_in_seconds = 60
@@ -47,6 +47,8 @@ def check_model(module_path, model, expected_runtime):
4747
tlapm_lib_path,
4848
community_jar_path,
4949
model['mode'],
50+
module['features'],
51+
model['features'],
5052
hard_timeout_in_seconds
5153
)
5254
end_time = timer()
@@ -85,7 +87,7 @@ def check_model(module_path, model, expected_runtime):
8587
manifest = tla_utils.load_json(manifest_path)
8688
small_models = sorted(
8789
[
88-
(module['path'], model, tla_utils.parse_timespan(model['runtime']))
90+
(module, model, tla_utils.parse_timespan(model['runtime']))
8991
for spec in manifest['specifications']
9092
for module in spec['modules']
9193
for model in module['models']

.github/scripts/requirements.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
jsonschema==4.20.0
22
mistletoe==1.2.1
3-
tree-sitter==0.22
4-
tree-sitter-tlaplus
3+
tree-sitter==0.23.1
4+
tree-sitter-tlaplus==1.5.0
55

.github/scripts/smoke_test_large_models.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
skip_models = args.skip
3232
only_models = args.only
3333

34-
def check_model(module_path, model):
35-
module_path = tla_utils.from_cwd(examples_root, module_path)
34+
def check_model(module, model):
35+
module_path = tla_utils.from_cwd(examples_root, module['path'])
3636
model_path = tla_utils.from_cwd(examples_root, model['path'])
3737
logging.info(model_path)
3838
smoke_test_timeout_in_seconds = 5
@@ -44,6 +44,8 @@ def check_model(module_path, model):
4444
tlapm_lib_path,
4545
community_jar_path,
4646
model['mode'],
47+
module['features'],
48+
model['features'],
4749
smoke_test_timeout_in_seconds
4850
)
4951
match tlc_result:
@@ -78,7 +80,7 @@ def check_model(module_path, model):
7880
manifest = tla_utils.load_json(manifest_path)
7981

8082
large_models = [
81-
(module['path'], model)
83+
(module, model)
8284
for spec in manifest['specifications']
8385
for module in spec['modules']
8486
for model in module['models']

.github/scripts/tla_utils.py

+28-4
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,17 @@ def parse_module(examples_root, parser, path):
6262
tree = parser.parse(module_text)
6363
return (tree, module_text, tree.root_node.has_error)
6464

65+
def all_nodes_of(query_map):
66+
"""
67+
Flatten a query result to get all matched nodes. Returned in order of
68+
occurrence in file.
69+
"""
70+
return sorted([
71+
node
72+
for capture in query_map.values()
73+
for node in capture
74+
], key=lambda node: node.start_byte)
75+
6576
def node_to_string(module_bytes, node):
6677
"""
6778
Gets the string covered by the given tree-sitter parse tree node.
@@ -93,6 +104,15 @@ def get_run_mode(mode):
93104
else:
94105
raise NotImplementedError(f'Undefined model-check mode {mode}')
95106

107+
def get_tlc_feature_flags(module_features, model_features):
108+
"""
109+
Selectively enables experimental TLC features according to needs.
110+
"""
111+
jvm_parameters = []
112+
if 'action composition' in module_features:
113+
jvm_parameters.append('-Dtlc2.tool.impl.Tool.cdot=true')
114+
return jvm_parameters
115+
96116
def check_model(
97117
tools_jar_path,
98118
apalache_path,
@@ -101,6 +121,8 @@ def check_model(
101121
tlapm_lib_path,
102122
community_jar_path,
103123
mode,
124+
module_features,
125+
model_features,
104126
hard_timeout_in_seconds
105127
):
106128
"""
@@ -127,8 +149,7 @@ def check_model(
127149
)
128150
return apalache
129151
else:
130-
tlc = subprocess.run([
131-
'java',
152+
jvm_parameters = [
132153
'-enableassertions',
133154
'-Dtlc2.TLC.ide=Github',
134155
'-Dutil.ExecutionStatisticsCollector.id=abcdef60f238424fa70d124d0c77ffff',
@@ -140,13 +161,16 @@ def check_model(
140161
community_jar_path,
141162
tlapm_lib_path
142163
]),
143-
'tlc2.TLC',
164+
] + get_tlc_feature_flags(module_features, model_features)
165+
tlc_parameters = [
144166
module_path,
145167
'-config', model_path,
146168
'-workers', 'auto',
147169
'-lncheck', 'final',
148170
'-cleanup'
149-
] + get_run_mode(mode),
171+
] + get_run_mode(mode)
172+
tlc = subprocess.run(
173+
['java'] + jvm_parameters + ['tlc2.TLC'] + tlc_parameters,
150174
timeout=hard_timeout_in_seconds,
151175
stdout=subprocess.PIPE,
152176
stderr=subprocess.STDOUT,

.github/scripts/unicode_number_set_shim.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def replace_imports(module_bytes, tree, query):
9393
shim_modules = {shim.module : shim for shim in shims}
9494
imported_modules = [
9595
(imported_module, shim_modules[module_name])
96-
for imported_module, _ in query.captures(tree.root_node)
96+
for imported_module in tla_utils.all_nodes_of(query.captures(tree.root_node))
9797
if (module_name := tla_utils.node_to_string(module_bytes, imported_module)) in shim_modules
9898
]
9999
byte_offset = 0

manifest-schema.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"tlaLanguageVersion": {"type": "number"},
4141
"features": {
4242
"type": "array",
43-
"items": {"enum": ["pluscal", "proof"]}
43+
"items": {"enum": ["pluscal", "proof", "action composition"]}
4444
},
4545
"models": {
4646
"type": "array",

0 commit comments

Comments
 (0)