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

Rust: first draft of canonical paths rework (WIP) #18223

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from
Draft
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
23 changes: 6 additions & 17 deletions misc/codegen/generators/rustgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,38 +101,27 @@ def _get_class(self, name: str) -> rust.Class:
)

def get_classes(self):
ret = {"": []}
ret = []
for k, cls in self._classmap.items():
if not cls.imported and not cls.synth:
ret.setdefault(cls.group, []).append(self._get_class(cls.name))
ret.append(self._get_class(cls.name))
elif cls.imported:
ret[""].append(rust.Class(name=cls.name))
ret.append(rust.Class(name=cls.name))
return ret


def generate(opts, renderer):
assert opts.rust_output
processor = Processor(schemaloader.load_file(opts.schema))
out = opts.rust_output
groups = set()
with renderer.manage(generated=out.rglob("*.rs"),
stubs=(),
registry=out / ".generated.list",
force=opts.force) as renderer:
for group, classes in processor.get_classes().items():
group = group or "top"
groups.add(group)
renderer.render(
rust.ClassList(
classes,
opts.schema,
),
out / f"{group}.rs",
)
renderer.render(
rust.ModuleList(
groups,
opts.schema,
rust.ClassList(
classes=processor.get_classes(),
source=opts.schema,
),
out / f"mod.rs",
)
9 changes: 7 additions & 2 deletions misc/codegen/loaders/schemaloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,14 @@ def _fill_hideable_information(classes: typing.Dict[str, schema.Class]):


def _check_test_with(classes: typing.Dict[str, schema.Class]):
pragma = "qltest_test_with"
for cls in classes.values():
test_with = typing.cast(str, cls.pragmas.get("qltest_test_with"))
transitive_test_with = test_with and classes[test_with].pragmas.get("qltest_test_with")
if cls.name == cls.pragmas.get(pragma):
# this is already implicit
del cls.pragmas[pragma]
for cls in classes.values():
test_with = typing.cast(str, cls.pragmas.get(pragma))
transitive_test_with = test_with and classes[test_with].pragmas.get(pragma)
if test_with and transitive_test_with:
raise schema.Error(f"{cls.name} has test_with {test_with} which in turn "
f"has test_with {transitive_test_with}, use that directly")
Expand Down
2 changes: 1 addition & 1 deletion rust/ast-generator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ fn write_extractor(grammar: &AstSrc) -> std::io::Result<String> {

use super::base::Translator;
use super::mappings::TextValue;
use crate::emit_detached;
use crate::{{emit_detached,emit_canonical_origin}};
use crate::generated;
use crate::trap::{{Label, TrapId}};
use ra_ap_syntax::ast::{{
Expand Down
3 changes: 1 addition & 2 deletions rust/extractor/src/generated/.generated.list

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion rust/extractor/src/generated/.gitattributes

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading